Fix comment policy
This commit is contained in:
@ -112,13 +112,13 @@ class CommentsController < ApplicationController
|
|||||||
|
|
||||||
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])
|
||||||
|
authorize!
|
||||||
@comments.delete_all
|
@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.' }
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
end
|
end
|
||||||
authorize!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
class CommentPolicy < ApplicationPolicy
|
class CommentPolicy < ApplicationPolicy
|
||||||
def author?
|
def author?
|
||||||
@user == @record.author
|
if @record.is_a?(ActiveRecord::Relation)
|
||||||
|
flag = true
|
||||||
|
@record.all {|item| flag = (flag and item.author == @user)}
|
||||||
|
flag
|
||||||
|
else
|
||||||
|
@user == @record.author
|
||||||
|
end
|
||||||
end
|
end
|
||||||
private :author?
|
private :author?
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ do not put a carriage return in the line below. it will be present in the presen
|
|||||||
|
|
||||||
commentModal.find('#removeAllButton').on('click', function(e){
|
commentModal.find('#removeAllButton').on('click', function(e){
|
||||||
var file_id = $(editor.container).data('file-id');
|
var file_id = $(editor.container).data('file-id');
|
||||||
deleteComment(file_id,row, editor);
|
deleteComment(file_id, row, editor);
|
||||||
commentModal.modal('hide');
|
commentModal.modal('hide');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user