Add 'post as moderator' option for comments.

* Add 'post as moderator' option to comment form. This creates a so-called sticky comment.
* Downvotes have no effect on stickied comments; they're always visible, regardless of comment thresholds.
* Only mods may sticky comments.
* Mods may sticky comments by other users.
This commit is contained in:
evazion
2016-12-26 22:24:01 -06:00
parent 390524c7f5
commit 1257639109
9 changed files with 44 additions and 32 deletions

View File

@@ -23,12 +23,12 @@ class CommentsController < ApplicationController
def update
@comment = Comment.find(params[:id])
check_privilege(@comment)
@comment.update_attributes(params[:comment].permit(:body))
@comment.update(update_params, :as => CurrentUser.role)
respond_with(@comment, :location => post_path(@comment.post_id))
end
def create
@comment = Comment.create(params[:comment])
@comment = Comment.create(create_params, :as => CurrentUser.role)
respond_with(@comment) do |format|
format.html do
if @comment.errors.any?
@@ -110,4 +110,12 @@ private
raise User::PrivilegeError
end
end
def create_params
params.require(:comment).permit(:post_id, :body, :do_not_bump_post, :is_sticky)
end
def update_params
params.require(:comment).permit(:body, :is_deleted, :is_sticky)
end
end