Correctly authorize comment deletion
This commit is contained in:
@ -111,9 +111,8 @@ class CommentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@comments = Comment.where(file_id: params[:file_id], row: params[:row])
|
@comments = Comment.where(file_id: params[:file_id], row: params[:row], user: current_user)
|
||||||
authorize!
|
@comments.each { |comment| authorize comment; comment.destroy }
|
||||||
@comments.delete_all
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
#format.html { redirect_to comments_url, notice: 'Comments were successfully destroyed.' }
|
#format.html { redirect_to comments_url, notice: 'Comments were successfully destroyed.' }
|
||||||
format.html { head :no_content, notice: 'Comments were successfully destroyed.' }
|
format.html { head :no_content, notice: 'Comments were successfully destroyed.' }
|
||||||
|
@ -1,12 +1,6 @@
|
|||||||
class CommentPolicy < ApplicationPolicy
|
class CommentPolicy < ApplicationPolicy
|
||||||
def author?
|
def author?
|
||||||
if @record.is_a?(ActiveRecord::Relation)
|
@user == @record.author
|
||||||
flag = true
|
|
||||||
@record.all {|item| flag = (flag and item.author == @user)}
|
|
||||||
flag
|
|
||||||
else
|
|
||||||
@user == @record.author
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
private :author?
|
private :author?
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user