From: Andy Allan Date: Wed, 7 Nov 2018 12:28:58 +0000 (+0100) Subject: Use CanCanCan for redaction authorizations X-Git-Tag: live~2775^2 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/79207ee5948a11f920d90c9bdaba394bc4316115 Use CanCanCan for redaction authorizations --- diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index ea60d496f..d7a100057 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -8,6 +8,7 @@ class Ability can [:index, :rss, :show, :comments], DiaryEntry can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim, :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder + can [:index, :show], Redaction can [:index, :show, :blocks_on, :blocks_by], UserBlock if user @@ -19,6 +20,7 @@ class Ability if user.moderator? can [:index, :show, :resolve, :ignore, :reopen], Issue can :create, IssueComment + can [:new, :create, :edit, :update, :destroy], Redaction can [:new, :edit, :create, :update, :revoke], UserBlock end diff --git a/app/controllers/redactions_controller.rb b/app/controllers/redactions_controller.rb index b8ecce9e2..45a41058c 100644 --- a/app/controllers/redactions_controller.rb +++ b/app/controllers/redactions_controller.rb @@ -3,8 +3,9 @@ class RedactionsController < ApplicationController before_action :authorize_web before_action :set_locale - before_action :require_user, :only => [:new, :create, :edit, :update, :destroy] - before_action :require_moderator, :only => [:new, :create, :edit, :update, :destroy] + + authorize_resource + before_action :lookup_redaction, :only => [:show, :edit, :update, :destroy] before_action :check_database_readable before_action :check_database_writable, :only => [:create, :update, :destroy] diff --git a/test/controllers/redactions_controller_test.rb b/test/controllers/redactions_controller_test.rb index e2123f725..08f32d4d0 100644 --- a/test/controllers/redactions_controller_test.rb +++ b/test/controllers/redactions_controller_test.rb @@ -64,8 +64,7 @@ class RedactionsControllerTest < ActionController::TestCase session[:user] = create(:user).id get :new - assert_response :redirect - assert_redirected_to redactions_path + assert_response :forbidden end def test_create_moderator @@ -141,8 +140,7 @@ class RedactionsControllerTest < ActionController::TestCase session[:user] = create(:user).id get :edit, :params => { :id => create(:redaction).id } - assert_response :redirect - assert_redirected_to(redactions_path) + assert_response :forbidden end def test_update_moderator