Move diary comments hide/unhide actions to comments controller
This commit is contained in:
parent
1a5adb2a4a
commit
a128b4f585
8 changed files with 104 additions and 97 deletions
|
@ -54,7 +54,7 @@ class Ability
|
|||
can [:index, :create, :destroy], UserMute
|
||||
|
||||
if user.moderator?
|
||||
can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
|
||||
can [:hide, :unhide], [DiaryEntry, DiaryComment]
|
||||
can [:index, :show, :resolve, :ignore, :reopen], Issue
|
||||
can :create, IssueComment
|
||||
can [:new, :create, :edit, :update, :destroy], Redaction
|
||||
|
@ -62,7 +62,7 @@ class Ability
|
|||
end
|
||||
|
||||
if user.administrator?
|
||||
can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
|
||||
can [:hide, :unhide], [DiaryEntry, DiaryComment]
|
||||
can [:index, :show, :resolve, :ignore, :reopen], Issue
|
||||
can :create, IssueComment
|
||||
can [:set_status, :destroy, :index], User
|
||||
|
|
|
@ -11,6 +11,7 @@ class DiaryCommentsController < ApplicationController
|
|||
authorize_resource
|
||||
|
||||
before_action :lookup_user, :only => :index
|
||||
before_action :check_database_writable, :only => [:hide, :unhide]
|
||||
|
||||
allow_thirdparty_images :only => :index
|
||||
|
||||
|
@ -18,10 +19,22 @@ class DiaryCommentsController < ApplicationController
|
|||
@title = t ".title", :user => @user.display_name
|
||||
|
||||
comments = DiaryComment.where(:user => @user)
|
||||
comments = comments.visible unless can? :unhidecomment, DiaryEntry
|
||||
comments = comments.visible unless can? :unhide, DiaryComment
|
||||
|
||||
@params = params.permit(:display_name, :before, :after)
|
||||
|
||||
@comments, @newer_comments_id, @older_comments_id = get_page_items(comments, :includes => [:user])
|
||||
end
|
||||
|
||||
def hide
|
||||
comment = DiaryComment.find(params[:comment])
|
||||
comment.update(:visible => false)
|
||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||
end
|
||||
|
||||
def unhide
|
||||
comment = DiaryComment.find(params[:comment])
|
||||
comment.update(:visible => true)
|
||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class DiaryEntriesController < ApplicationController
|
|||
authorize_resource
|
||||
|
||||
before_action :lookup_user, :only => :show
|
||||
before_action :check_database_writable, :only => [:new, :create, :edit, :update, :comment, :hide, :hidecomment, :subscribe, :unsubscribe]
|
||||
before_action :check_database_writable, :only => [:new, :create, :edit, :update, :comment, :hide, :unhide, :subscribe, :unsubscribe]
|
||||
|
||||
allow_thirdparty_images :only => [:new, :create, :edit, :update, :index, :show]
|
||||
|
||||
|
@ -69,7 +69,7 @@ class DiaryEntriesController < ApplicationController
|
|||
if @entry
|
||||
@title = t ".title", :user => params[:display_name], :title => @entry.title
|
||||
@og_image = @entry.body.image
|
||||
@comments = can?(:unhidecomment, DiaryEntry) ? @entry.comments : @entry.visible_comments
|
||||
@comments = can?(:unhide, DiaryComment) ? @entry.comments : @entry.visible_comments
|
||||
else
|
||||
@title = t "diary_entries.no_such_entry.title", :id => params[:id]
|
||||
render :action => "no_such_entry", :status => :not_found
|
||||
|
@ -229,18 +229,6 @@ class DiaryEntriesController < ApplicationController
|
|||
redirect_to :action => "index", :display_name => entry.user.display_name
|
||||
end
|
||||
|
||||
def hidecomment
|
||||
comment = DiaryComment.find(params[:comment])
|
||||
comment.update(:visible => false)
|
||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||
end
|
||||
|
||||
def unhidecomment
|
||||
comment = DiaryComment.find(params[:comment])
|
||||
comment.update(:visible => true)
|
||||
redirect_to diary_entry_path(comment.diary_entry.user, comment.diary_entry)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
</p>
|
||||
|
||||
<div class="richtext text-break"><%= diary_comment.body.to_html %></div>
|
||||
<% if can? :hidecomment, DiaryEntry %>
|
||||
<% if can? :hide, DiaryComment %>
|
||||
<span>
|
||||
<% if diary_comment.visible? %>
|
||||
<%= link_to t(".hide_link"), hide_diary_comment_path(diary_comment.diary_entry.user, diary_comment.diary_entry, diary_comment), :method => :post, :data => { :confirm => t(".confirm") } %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue