Explorar el Código

Merge pull request #1567 from visuddhinanda/laravel

Laravel 允许在协作文集中新建协作文章
visuddhinanda hace 2 años
padre
commit
d9d1ff7cfb

+ 9 - 1
app/Http/Controllers/ArticleController.php

@@ -254,7 +254,15 @@ class ArticleController extends Controller
 
         $canManage = ArticleController::userCanManage($user_uid,$request->get('studio'));
         if(!$canManage){
-            return $this->error(__('auth.failed'),[],403);
+            //判断是否有文集权限
+            if($request->has('anthologyId')){
+                $currPower = ShareApi::getResPower($user_uid,$request->get('anthologyId'));
+                if($currPower <= 10){
+                    return $this->error(__('auth.failed'),[],403);
+                }
+            }else{
+                return $this->error(__('auth.failed'),[],403);
+            }
         }
         //权限判断结束
 

+ 4 - 6
app/Http/Controllers/CollectionController.php

@@ -147,7 +147,7 @@ class CollectionController extends Controller
                     $newOne->create_time = time()*1000;
                     $newOne->modify_time = time()*1000;
                     $newOne->save();
-                    return $this->ok($newOne);
+                    return $this->ok(new CollectionResource($newOne));
                 }
             }else{
                 return $this->error(__('auth.failed'));
@@ -185,10 +185,8 @@ class CollectionController extends Controller
                     return $this->error(__('auth.failed'));
                 }
             }
-			if(!empty($result->article_list)){
-				$result->article_list = \json_decode($result->article_list);
-			}
-			return $this->ok($result);
+            $result->fullArticleList = true;
+			return $this->ok(new CollectionResource($result));
 		}else{
 			return $this->error("没有查询到数据");
 		}
@@ -219,7 +217,7 @@ class CollectionController extends Controller
                 $collection->status = $request->get('status');
                 $collection->modify_time = time()*1000;
                 $collection->save();
-                return $this->ok($collection);
+                return $this->ok(new CollectionResource($collection));
             }else{
                 //鉴权失败
 

+ 9 - 4
app/Http/Resources/CollectionResource.php

@@ -28,12 +28,17 @@ class CollectionResource extends JsonResource
             "created_at" => $this->created_at,
             "updated_at" => $this->updated_at,
         ];
-        if(isset($this->article_list) && !empty($this->article_list) ){
-            $arrList = \json_decode($this->article_list);
-            if(is_array($arrList)){
-                $data["article_list"] = array_slice($arrList,0,4);
+        if($this->fullArticleList===true){
+            $data["article_list"] = \json_decode($this->article_list);
+        }else{
+            if(isset($this->article_list) && !empty($this->article_list) ){
+                $arrList = \json_decode($this->article_list);
+                if(is_array($arrList)){
+                    $data["article_list"] = array_slice($arrList,0,4);
+                }
             }
         }
+
         return $data;
     }
 }