Correctly authorize comment deletion

This commit is contained in:
Maximilian Grundke
2016-04-27 17:16:23 +02:00
parent 57b773698b
commit 8ef615ffaa
2 changed files with 3 additions and 10 deletions

View File

@ -111,9 +111,8 @@ class CommentsController < ApplicationController
end
def destroy
@comments = Comment.where(file_id: params[:file_id], row: params[:row])
authorize!
@comments.delete_all
@comments = Comment.where(file_id: params[:file_id], row: params[:row], user: current_user)
@comments.each { |comment| authorize comment; comment.destroy }
respond_to do |format|
#format.html { redirect_to comments_url, notice: 'Comments were successfully destroyed.' }
format.html { head :no_content, notice: 'Comments were successfully destroyed.' }

View File

@ -1,13 +1,7 @@
class CommentPolicy < ApplicationPolicy
def 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
private :author?
def create?