示例#1
0
 public function isStoryteller()
 {
     return Cache::remember('user-storyteller-' . $this->id, 60, function () {
         $p_id = PermissionDefinition::where('name', 'Storyteller')->firstOrFail()->id;
         return $this->permissions()->where('permission_id', $p_id)->count() > 0;
     });
 }
 public function removePermission()
 {
     $user_id = Input::get("user");
     $permission_id = Input::get("permission");
     $user = User::find($user_id);
     $permission = PermissionDefinition::find($permission_id);
     if ($user) {
         if ($permission) {
             Permission::where(['permission_id' => $permission_id, 'user_id' => $user_id])->delete();
             return Redirect::to('/dashboard/storyteller/manage/permissions');
         } else {
             return Response::json(['success' => false, 'message' => 'Invalid permission definition.']);
         }
     } else {
         return Response::json(['success' => false, 'message' => 'Invalid user.']);
     }
 }
示例#3
0
 function postReply()
 {
     if (!Auth::check()) {
         return Redirect::to("/forums");
     }
     $post_id = Input::get("post_id");
     if (isset($post_id)) {
         //Edit logic
         $post = ForumPost::find(Input::get("post_id"));
         $user = Auth::user();
         if (!$user->canAccessTopic($post->topic_id)) {
             return "Access denied.";
         }
         if ($post->posted_by == $user->id || $user->isStoryteller()) {
             $body = ForumPost::replaceSpecialTerms(Input::get("body"));
             $post->body = $body;
             if ($user->isStoryteller()) {
                 $post->is_storyteller_reply = Input::get("st-reply") == "on" ? 0 : 1;
             }
             $post->save();
             //Save an edit record
             $posted_by = Input::get("post-as");
             $poster = User::find($posted_by);
             if (!$poster) {
                 $poster = Auth::user();
             }
             $edit = new ForumEdit();
             $edit->post_id = $post->id;
             $edit->user_id = $poster->id;
             $edit->save();
             if (Input::get("watch") == "on") {
                 $this->subscribeToTopic($post->topic->id);
             }
             return Redirect::to($post->topic->getLinkForLastPost($user));
         } else {
             return "Post does not belong to user";
         }
     } else {
         $user = Auth::user();
         $topic_id = Input::get("topic_id");
         $body = Input::get("body");
         if ($topic_id == null || $body == null) {
             //Validate.
             return "failed.";
         } else {
             //Ensure this user has access to the forum to which we're trying to post, and the relevant write permission
             $topic = ForumTopic::find($topic_id);
             if ($user->canAccessForum($topic->forum_id)) {
                 $forum = $topic->forum;
                 $permission = PermissionDefinition::find($forum->reply_permission);
                 if (!$forum->reply_permission || Auth::user()->hasPermission($permission->name) || Auth::user()->isStoryteller()) {
                     $posted_by = Input::get("post-as");
                     $poster_id = $posted_by ? $posted_by : $user->id;
                     $body = ForumPost::replaceSpecialTerms($body);
                     $post = $topic->postReply($poster_id, $body);
                     if ($user->isStoryteller()) {
                         $post->is_storyteller_reply = Input::get("st-reply") == "on" ? 0 : 1;
                         $post->save();
                     }
                     //Mark the thread as incomplete again.
                     $topic->is_complete = false;
                     $topic->save();
                     $this->messageSubscribers($post);
                     if (Input::get("watch") == "on") {
                         $this->subscribeToTopic($post->topic->id);
                     }
                     //Check for @mentions.
                     $this->alertMentions($poster_id, $body, $topic);
                     return Redirect::to($post->topic->getLinkForLastPost($user));
                 } else {
                     return 'No write permission';
                 }
             } else {
                 return "No access.";
             }
         }
     }
 }