diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index dfbb4f8d..90922fb1 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,5 +1,5 @@ class CommentsController < ApplicationController - before_action :set_comment, only: [:show, :edit, :update, :destroy_by_id] + before_action :set_comment, only: [:show, :edit, :update, :destroy] # to disable authorization check: comment the line below back in # skip_after_action :verify_authorized @@ -84,7 +84,8 @@ class CommentsController < ApplicationController # DELETE /comments/1 # DELETE /comments/1.json - def destroy_by_id + def destroy + authorize! @comment.destroy respond_to do |format| format.html { head :no_content, notice: 'Comment was successfully destroyed.' } @@ -92,16 +93,6 @@ class CommentsController < ApplicationController end end - def destroy - @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.' } - format.json { head :no_content } - end - end - private # Use callbacks to share common setup or constraints between actions. def set_comment diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index 549c8438..3bdcdda0 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -12,14 +12,10 @@ class CommentPolicy < ApplicationPolicy everyone end - [:new?, :destroy?, :update?].each do |action| + [:new?, :destroy?, :update?, :edit?].each do |action| define_method(action) { admin? || author? } end - def edit? - admin? - end - def index? everyone end diff --git a/config/routes.rb b/config/routes.rb index 65a8f56a..b0003895 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,11 +14,7 @@ Rails.application.routes.draw do post :set_thank_you_note end end - resources :comments, except: [:destroy] do - collection do - delete :destroy - end - end + resources :comments get '/my_request_for_comments', as: 'my_request_for_comments', to: 'request_for_comments#get_my_comment_requests' get '/my_rfc_activity', as: 'my_rfc_activity', to: 'request_for_comments#get_rfcs_with_my_comments'