Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

forcing to specify allowed actions when forfeiting authorization check

ulfertsfdbd6b6d5ad0
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 7c977c1fd01..a9b2423c55e 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -36,19 +36,19 @@ class AccountController < ApplicationController
# prevents login action to be filtered by check_if_login_required application scope filter
skip_before_action :check_if_login_required
- no_authorization_required! only: %i[login
- internal_login
- logout
- lost_password
- register
- activate
- consent
- confirm_consent
- decline_consent
- stage_success
- stage_failure
- change_password
- auth_source_sso_failed]
+ no_authorization_required! :login,
+ :internal_login,
+ :logout,
+ :lost_password,
+ :register,
+ :activate,
+ :consent,
+ :confirm_consent,
+ :decline_consent,
+ :stage_success,
+ :stage_failure,
+ :change_password,
+ :auth_source_sso_failed
before_action :apply_csp_appends, only: %i[login]
before_action :disable_api
diff --git a/app/controllers/angular_controller.rb b/app/controllers/angular_controller.rb
index dc70f86e0c8..40e623c9027 100644
--- a/app/controllers/angular_controller.rb
+++ b/app/controllers/angular_controller.rb
@@ -29,7 +29,7 @@
class AngularController < ApplicationController
before_action :require_login
- no_authorization_required! only: %i[empty_layout notifications_layout]
+ no_authorization_required! :empty_layout, :notifications_layout
def empty_layout
# Frontend will handle rendering
diff --git a/app/controllers/api_docs_controller.rb b/app/controllers/api_docs_controller.rb
index 5a1bec3d2ed..3a78ca1c7a5 100644
--- a/app/controllers/api_docs_controller.rb
+++ b/app/controllers/api_docs_controller.rb
@@ -28,7 +28,7 @@
class APIDocsController < ApplicationController
before_action :require_login
- no_authorization_required! only: :index
+ no_authorization_required! :index
helper API::APIDocsHelper
diff --git a/app/controllers/colors_controller.rb b/app/controllers/colors_controller.rb
index 569dacf9540..b911b9451cf 100644
--- a/app/controllers/colors_controller.rb
+++ b/app/controllers/colors_controller.rb
@@ -28,7 +28,7 @@
class ColorsController < ApplicationController
before_action :require_admin_unless_readonly_api_request
- authorization_checked! only: %i[index show new edit create update confirm_destroy destroy]
+ authorization_checked! :index, :show, :new, :edit, :create, :update, :confirm_destroy, :destroy
layout "admin"
diff --git a/app/controllers/concerns/accounts/authorization.rb b/app/controllers/concerns/accounts/authorization.rb
index 8000d6ac766..afcc1f302f6 100644
--- a/app/controllers/concerns/accounts/authorization.rb
+++ b/app/controllers/concerns/accounts/authorization.rb
@@ -144,14 +144,19 @@ module Accounts::Authorization
def set_authorization_checked_if_covered(*names)
return unless METHODS_ENFORCING_AUTHORIZATION.intersect?(names)
- authorization_checked!(only: names.last.is_a?(Hash) ? Array(names.last[:only]) : [],
- except: names.last.is_a?(Hash) ? Array(names.last[:except]) : [])
+ authorization_checked_by_default_action(only: names.last.is_a?(Hash) ? Array(names.last[:only]) : [],
+ except: names.last.is_a?(Hash) ? Array(names.last[:except]) : [])
end
- def no_authorization_required!(only: [], except: [])
- only = Array(only)
- except = Array(except)
+ def no_authorization_required!(*actions)
+ raise ArgumentError, "no_authorization_required! needs to have actions specified" unless actions.any?
+ authorization_checked_by_default_action(only: actions)
+ end
+
+ alias :authorization_checked! :no_authorization_required!
+
+ def authorization_checked_by_default_action(only: [], except: [])
# A class_attribute is used so that inheritance works also for defined only/except actions.
# But since the only/accept arrays are only modified in place, the same object would be used from the
# ApplicationController downwards. So whenever it is detected that the controller the authorization_ensured
@@ -165,19 +170,17 @@ module Accounts::Authorization
end
end
- alias :authorization_checked! :no_authorization_required!
-
def update_authorization_ensured_on_actions(only: [], except: [])
update_authorization_ensured_on_action_only(only)
update_authorization_ensured_on_action_except(only, except)
end
def update_authorization_ensured_on_action_only(only)
- authorization_ensured[:generally_allowed] = true if only.empty?
-
if only.any?
authorization_ensured[:only] += only
authorization_ensured[:only].uniq!
+ else
+ update_authorization_ensured_on_all
end
end
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rb
index 96a7a447531..c037b28196a 100644
--- a/app/controllers/concerns/accounts/omniauth_login.rb
+++ b/app/controllers/concerns/accounts/omniauth_login.rb
@@ -44,7 +44,7 @@ module Accounts::OmniauthLogin
check_session_lifetime
]
.each { |key| skip_before_action key, only: [:omniauth_login] }
- no_authorization_required! only: %i[omniauth_login omniauth_failure]
+ no_authorization_required! :omniauth_login, :omniauth_failure
helper :omniauth
end
diff --git a/app/controllers/custom_styles_controller.rb b/app/controllers/custom_styles_controller.rb
index 228c47c8343..a8467ed35a7 100644
--- a/app/controllers/custom_styles_controller.rb
+++ b/app/controllers/custom_styles_controller.rb
@@ -42,7 +42,7 @@ class CustomStylesController < ApplicationController
except: UNGUARDED_ACTIONS + %i[upsale]
skip_before_action :check_if_login_required,
only: UNGUARDED_ACTIONS
- no_authorization_required! only: UNGUARDED_ACTIONS
+ no_authorization_required! *UNGUARDED_ACTIONS
def show
@custom_style = CustomStyle.current || CustomStyle.new
diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 3dc66c8bdea..cdc157058e4 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -29,7 +29,7 @@
class FavoritesController < ApplicationController
before_action :find_favored_by_object
before_action :require_login
- no_authorization_required! only: %i[favorite unfavorite]
+ no_authorization_required! :favorite, :unfavorite
def favorite
if @favored.visible?(User.current)
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index ba45fc56000..778ddd6082c 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -31,7 +31,7 @@ class GroupsController < ApplicationController
layout "admin"
before_action :require_admin, except: %i[show]
- no_authorization_required! only: %i[show]
+ no_authorization_required! :show
before_action :find_group, only: %i[destroy update show create_memberships destroy_membership
edit_membership add_users]
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index ffcc23bfe19..3eb2c7b2885 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -27,7 +27,7 @@
#++
class HelpController < ApplicationController
- no_authorization_required! only: %i[keyboard_shortcuts text_formatting]
+ no_authorization_required! :keyboard_shortcuts, :text_formatting
def keyboard_shortcuts
redirect_to OpenProject::Static::Links[:shortcuts][:href]
diff --git a/app/controllers/highlighting_controller.rb b/app/controllers/highlighting_controller.rb
index b67442cd91f..e859e429bb8 100644
--- a/app/controllers/highlighting_controller.rb
+++ b/app/controllers/highlighting_controller.rb
@@ -29,7 +29,7 @@
class HighlightingController < ApplicationController
before_action :determine_freshness
skip_before_action :check_if_login_required, only: [:styles]
- no_authorization_required! only: [:styles]
+ no_authorization_required! :styles
def styles
response.content_type = Mime[:css]
diff --git a/app/controllers/homescreen_controller.rb b/app/controllers/homescreen_controller.rb
index a989230b62a..92660ae2ada 100644
--- a/app/controllers/homescreen_controller.rb
+++ b/app/controllers/homescreen_controller.rb
@@ -28,7 +28,7 @@
class HomescreenController < ApplicationController
skip_before_action :check_if_login_required, only: [:robots]
- no_authorization_required! only: %i[index robots]
+ no_authorization_required! :index, :robots
layout "global"
diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb
index 5fbf7e6766f..d7ea7714252 100644
--- a/app/controllers/journals_controller.rb
+++ b/app/controllers/journals_controller.rb
@@ -33,7 +33,7 @@ class JournalsController < ApplicationController
before_action :find_journal,
:ensure_permitted,
only: [:diff]
- authorization_checked! only: %i[diff]
+ authorization_checked! :diff
accept_key_auth :index
menu_item :issues
diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb
index 397afab2373..980c69da2e8 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -33,7 +33,7 @@ class MessagesController < ApplicationController
before_action :find_object_and_scope
before_action :authorize, except: %i[edit update destroy]
# Checked inside the method.
- no_authorization_required! only: %i[edit update destroy]
+ no_authorization_required! :edit, :update, :destroy
include AttachmentsHelper
include PaginationHelper
diff --git a/app/controllers/my/auto_login_tokens_controller.rb b/app/controllers/my/auto_login_tokens_controller.rb
index f0222b9f856..d8c78fd8dd0 100644
--- a/app/controllers/my/auto_login_tokens_controller.rb
+++ b/app/controllers/my/auto_login_tokens_controller.rb
@@ -1,7 +1,7 @@
module My
class AutoLoginTokensController < ::ApplicationController
before_action :require_login
- no_authorization_required! only: %i(destroy)
+ no_authorization_required! :destroy
before_action :find_token, only: %i(destroy)
diff --git a/app/controllers/my/sessions_controller.rb b/app/controllers/my/sessions_controller.rb
index 2c6094505d6..98d9a6307f6 100644
--- a/app/controllers/my/sessions_controller.rb
+++ b/app/controllers/my/sessions_controller.rb
@@ -1,7 +1,9 @@
module My
class SessionsController < ::ApplicationController
before_action :require_login
- no_authorization_required! only: %i(index show destroy)
+ no_authorization_required! :index,
+ :show,
+ :destroy
self._model_object = ::Sessions::UserSession
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 95bd8021132..ff46385f4a7 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -39,21 +39,21 @@ class MyController < ApplicationController
before_action :set_grouped_ical_tokens, only: %i[access_token]
before_action :set_ical_token, only: %i[revoke_ical_token]
- no_authorization_required! only: %i[account
- update_account
- settings
- update_settings
- password
- change_password
- access_token
- delete_storage_token
- notifications
- reminders
- generate_rss_key
- revoke_rss_key
- generate_api_key
- revoke_api_key
- revoke_ical_token]
+ no_authorization_required! :account,
+ :update_account,
+ :settings,
+ :update_settings,
+ :password,
+ :change_password,
+ :access_token,
+ :delete_storage_token,
+ :notifications,
+ :reminders,
+ :generate_rss_key,
+ :revoke_rss_key,
+ :generate_api_key,
+ :revoke_api_key,
+ :revoke_ical_token
menu_item :account, only: [:account]
menu_item :settings, only: [:settings]
diff --git a/app/controllers/oauth/auth_base_controller.rb b/app/controllers/oauth/auth_base_controller.rb
index d2b703007a6..8ec97a4ceba 100644
--- a/app/controllers/oauth/auth_base_controller.rb
+++ b/app/controllers/oauth/auth_base_controller.rb
@@ -37,9 +37,9 @@ module OAuth
prepend_before_action :extend_content_security_policy
skip_before_action :check_if_login_required
- no_authorization_required! only: %i[new
- create
- show]
+ no_authorization_required! :new,
+ :create,
+ :show
layout "only_logo"
diff --git a/app/controllers/oauth/grants_controller.rb b/app/controllers/oauth/grants_controller.rb
index c4587b5e5e8..dc9206b1a48 100644
--- a/app/controllers/oauth/grants_controller.rb
+++ b/app/controllers/oauth/grants_controller.rb
@@ -29,7 +29,7 @@
module OAuth
class GrantsController < ::ApplicationController
before_action :require_login
- authorization_checked! only: %i[index revoke_application]
+ authorization_checked! :index, :revoke_application
layout "my"
menu_item :access_token
diff --git a/app/controllers/oauth_clients_controller.rb b/app/controllers/oauth_clients_controller.rb
index afe14e36985..a2a09b3c1eb 100644
--- a/app/controllers/oauth_clients_controller.rb
+++ b/app/controllers/oauth_clients_controller.rb
@@ -38,7 +38,7 @@ class OAuthClientsController < ApplicationController
before_action :set_code, only: [:callback]
before_action :set_connection_manager, only: [:callback]
- no_authorization_required! only: %i[callback ensure_connection]
+ no_authorization_required! :callback, :ensure_connection
after_action :clear_oauth_state_cookie, only: [:callback]
diff --git a/app/controllers/onboarding_controller.rb b/app/controllers/onboarding_controller.rb
index 95bc94725a4..59105b0a543 100644
--- a/app/controllers/onboarding_controller.rb
+++ b/app/controllers/onboarding_controller.rb
@@ -27,7 +27,7 @@
#++
class OnboardingController < ApplicationController
- no_authorization_required! only: %i[user_settings]
+ no_authorization_required! :user_settings
def user_settings
@user = User.current
diff --git a/app/controllers/placeholder_users_controller.rb b/app/controllers/placeholder_users_controller.rb
index daaf585fce5..9936ed29032 100644
--- a/app/controllers/placeholder_users_controller.rb
+++ b/app/controllers/placeholder_users_controller.rb
@@ -30,7 +30,7 @@ class PlaceholderUsersController < ApplicationController
include EnterpriseTrialHelper
layout "admin"
before_action :authorize_global, except: %i[show]
- no_authorization_required! only: %i[show]
+ no_authorization_required! :show
before_action :find_placeholder_user, only: %i[show
edit
diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rb
index 08c92d81fc3..cdecdf19bbd 100644
--- a/app/controllers/projects/menus_controller.rb
+++ b/app/controllers/projects/menus_controller.rb
@@ -29,7 +29,7 @@ module Projects
class MenusController < ApplicationController
# No authorize as every user (or logged in user)
# is allowed to see the menu.
- no_authorization_required! only: :show
+ no_authorization_required! :show
def show
projects_menu = Menus::Projects.new(controller_path: params[:controller_path], params:, current_user:)
diff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rb
index 27b7018364e..04914ac7d6a 100644
--- a/app/controllers/projects/queries_controller.rb
+++ b/app/controllers/projects/queries_controller.rb
@@ -30,7 +30,7 @@ class Projects::QueriesController < ApplicationController
include Projects::QueryLoading
# No need for a more specific authorization check. That is carried out in the contracts.
- no_authorization_required! only: %i[show new create rename update publish unpublish destroy]
+ no_authorization_required! :show, :new, :create, :rename, :update, :publish, :unpublish, :destroy
before_action :require_login
before_action :find_query, only: %i[show rename update destroy publish unpublish]
before_action :build_query_or_deny_access, only: %i[new create]
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 04503237f79..49a816dff3d 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -36,7 +36,7 @@ class ProjectsController < ApplicationController
before_action :authorize_global, only: %i[new]
before_action :require_admin, only: %i[destroy destroy_info]
- no_authorization_required! only: %i[index]
+ no_authorization_required! :index
include SortHelper
include PaginationHelper
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 9f7ea9ea6ef..50a0f970613 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -44,8 +44,8 @@ class UsersController < ApplicationController
before_action :authorize_for_user, only: [:destroy]
before_action :check_if_deletion_allowed, only: %i[deletion_info
destroy]
- no_authorization_required! only: %i[show]
- authorization_checked! only: %i[destroy deletion_info]
+ no_authorization_required! :show
+ authorization_checked! :destroy, :deletion_info
before_action :set_current_activity_page, only: [:show]
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb
index 9d367af4b51..ee4e32938ac 100644
--- a/app/controllers/watchers_controller.rb
+++ b/app/controllers/watchers_controller.rb
@@ -32,7 +32,8 @@ class WatchersController < ApplicationController
:require_login,
:deny_access_unless_visible
- authorization_checked! only: %i[watch unwatch]
+ authorization_checked! :watch,
+ :unwatch
def watch
set_watcher(User.current, true)
diff --git a/app/controllers/work_packages/auto_completes_controller.rb b/app/controllers/work_packages/auto_completes_controller.rb
index f5533e281c7..5a06d103d14 100644
--- a/app/controllers/work_packages/auto_completes_controller.rb
+++ b/app/controllers/work_packages/auto_completes_controller.rb
@@ -30,7 +30,7 @@ require "rack/utils"
class WorkPackages::AutoCompletesController < ApplicationController
# Authorization is checked by the query.
- no_authorization_required! only: :index
+ no_authorization_required! :index
def index
@work_packages = work_packages_matching_query_prop
diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rb
index f10dc61cf1e..194bbad8c1b 100644
--- a/app/controllers/work_packages/progress_controller.rb
+++ b/app/controllers/work_packages/progress_controller.rb
@@ -37,7 +37,7 @@ class WorkPackages::ProgressController < ApplicationController
layout false
before_action :set_work_package
before_action :extract_persisted_progress_attributes, only: %i[edit create update]
- authorization_checked! only: %i[new edit create update]
+ authorization_checked! :new, :edit, :create, :update
helper_method :modal_class
diff --git a/app/controllers/work_packages_controller.rb b/app/controllers/work_packages_controller.rb
index d67001318a2..513d5d9e174 100644
--- a/app/controllers/work_packages_controller.rb
+++ b/app/controllers/work_packages_controller.rb
@@ -39,7 +39,7 @@ class WorkPackagesController < ApplicationController
before_action :load_and_authorize_in_optional_project,
:check_allowed_export,
:protect_from_unauthorized_export, only: :index
- authorization_checked! only: %i[index show]
+ authorization_checked! :index, :show
before_action :load_and_validate_query, only: :index, unless: -> { request.format.html? }
before_action :load_work_packages, only: :index, if: -> { request.format.atom? }
diff --git a/modules/avatars/app/controllers/avatars/avatar_controller.rb b/modules/avatars/app/controllers/avatars/avatar_controller.rb
index 3450061cddc..e76b67ea3b5 100644
--- a/modules/avatars/app/controllers/avatars/avatar_controller.rb
+++ b/modules/avatars/app/controllers/avatars/avatar_controller.rb
@@ -3,7 +3,7 @@ module ::Avatars
before_action :ensure_enabled
before_action :find_avatar
- no_authorization_required! only: %i[show]
+ no_authorization_required! :show
def show
send_file @avatar.diskfile,
diff --git a/modules/avatars/app/controllers/avatars/my_avatar_controller.rb b/modules/avatars/app/controllers/avatars/my_avatar_controller.rb
index 9054b3c03a7..ba6bcda521d 100644
--- a/modules/avatars/app/controllers/avatars/my_avatar_controller.rb
+++ b/modules/avatars/app/controllers/avatars/my_avatar_controller.rb
@@ -3,7 +3,9 @@ module ::Avatars
before_action :require_login
before_action :set_user
- no_authorization_required! only: %i[show update destroy]
+ no_authorization_required! :show,
+ :update,
+ :destroy
layout "my"
menu_item :avatar
diff --git a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
index 0e3ac8abe60..a2b62136608 100644
--- a/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
+++ b/modules/bim/app/controllers/bim/ifc_models/ifc_models_controller.rb
@@ -39,7 +39,8 @@ module Bim
before_action :authorize, except: %i[direct_upload_finished set_direct_upload_file_name]
before_action :require_login, only: [:set_direct_upload_file_name]
skip_before_action :verify_authenticity_token, only: [:set_direct_upload_file_name] # AJAX request in page, so skip authenticity token
- no_authorization_required! only: %i[set_direct_upload_file_name direct_upload_finished]
+ no_authorization_required! :set_direct_upload_file_name,
+ :direct_upload_finished
menu_item :ifc_models
diff --git a/modules/budgets/app/controllers/budgets_controller.rb b/modules/budgets/app/controllers/budgets_controller.rb
index 2f2ee53bffc..6e94db62576 100644
--- a/modules/budgets/app/controllers/budgets_controller.rb
+++ b/modules/budgets/app/controllers/budgets_controller.rb
@@ -42,7 +42,8 @@ class BudgetsController < ApplicationController
:update_material_budget_item,
:update_labor_budget_item
]
- no_authorization_required! only: %i[update_material_budget_item update_labor_budget_item]
+ no_authorization_required! :update_material_budget_item,
+ :update_labor_budget_item
helper :sort
include SortHelper
diff --git a/modules/calendar/app/controllers/calendar/ical_controller.rb b/modules/calendar/app/controllers/calendar/ical_controller.rb
index ad2deaffad1..1153dfb0422 100644
--- a/modules/calendar/app/controllers/calendar/ical_controller.rb
+++ b/modules/calendar/app/controllers/calendar/ical_controller.rb
@@ -30,7 +30,7 @@ module ::Calendar
class ICalController < ApplicationController
# Authentication and authorization is handled within the service.
skip_before_action :check_if_login_required
- no_authorization_required! only: :show
+ no_authorization_required! :show
def show
begin
diff --git a/modules/costs/app/controllers/hourly_rates_controller.rb b/modules/costs/app/controllers/hourly_rates_controller.rb
index b47f0cf22e6..dfc835f2601 100644
--- a/modules/costs/app/controllers/hourly_rates_controller.rb
+++ b/modules/costs/app/controllers/hourly_rates_controller.rb
@@ -40,7 +40,9 @@ class HourlyRatesController < ApplicationController
# #show, #edit and #update have their own authorization
before_action :authorize, except: %i[show edit update]
- no_authorization_required! only: %i[show edit update]
+ no_authorization_required! :show,
+ :edit,
+ :update
# TODO: this should be an index
def show
diff --git a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
index 63f81b212f1..55d423a9e67 100644
--- a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
+++ b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
@@ -7,7 +7,8 @@ module ::Recaptcha
# User is not yet logged in, so skip login required check
skip_before_action :check_if_login_required
- no_authorization_required! only: %i[perform verify]
+ no_authorization_required! :perform,
+ :verify
# Skip if recaptcha was disabled
before_action :skip_if_disabled
diff --git a/modules/storages/app/controllers/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/project_storages_controller.rb
index 530e79b8f18..8dbde0d3a26 100644
--- a/modules/storages/app/controllers/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/project_storages_controller.rb
@@ -36,7 +36,7 @@ class Storages::ProjectStoragesController < ApplicationController
before_action :find_model_object
before_action :find_project_by_project_id
before_action :render_403, unless: -> { User.current.allowed_in_project?(:view_file_links, @project) }
- no_authorization_required! only: %i[open]
+ no_authorization_required! :open
# rubocop:disable Metrics/AbcSize
def open
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
index d94aa599058..a2cb5a50380 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/authentication_controller.rb
@@ -11,12 +11,12 @@ module ::TwoFactorAuthentication
# User is not yet logged in, so skip login required check
skip_before_action :check_if_login_required
- no_authorization_required! only: %i[request_otp
- confirm_otp
- enter_backup_code
- verify_backup_code
- retry
- webauthn_challenge]
+ no_authorization_required! :request_otp,
+ :confirm_otp,
+ :enter_backup_code,
+ :verify_backup_code,
+ :retry,
+ :webauthn_challenge
# Avoid catch-all from core resulting in methods
before_action :only_post, only: :confirm_otp
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb
index 0a5f2363cae..35ec4564a37 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/forced_registration/two_factor_devices_controller.rb
@@ -6,12 +6,12 @@ module ::TwoFactorAuthentication
# Skip default login
skip_before_action :check_if_login_required
- no_authorization_required! only: %i[register
- new
- confirm
- web_authn
- make_default
- destroy]
+ no_authorization_required! :register,
+ :new,
+ :confirm,
+ :web_authn,
+ :make_default,
+ :destroy
before_action :find_device, only: [:confirm]
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb
index a6eb12a0f84..0f46af2e804 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/backup_codes_controller.rb
@@ -3,7 +3,7 @@ module ::TwoFactorAuthentication
class BackupCodesController < ::ApplicationController
# Ensure user is logged in
before_action :require_login
- no_authorization_required! only: %i[show create]
+ no_authorization_required! :show, :create
# Password confirmation helpers and actions
include PasswordConfirmation
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb
index eb23b6f50ba..e3d5ac206ee 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/remember_cookie_controller.rb
@@ -6,7 +6,7 @@ module ::TwoFactorAuthentication
# Ensure user is logged in
before_action :require_login
- no_authorization_required! only: :destroy
+ no_authorization_required! :destroy
layout "my"
menu_item :two_factor_authentication
diff --git a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb
index 4295a95a5eb..55e72a3cd47 100644
--- a/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb
+++ b/modules/two_factor_authentication/app/controllers/two_factor_authentication/my/two_factor_devices_controller.rb
@@ -6,14 +6,14 @@ module ::TwoFactorAuthentication
before_action :set_user_variables
# Authorization is not handled explicitly but as the user on which changes can be done is only the current user
# (and that user needs to be logged in), no action harmful to other users can be done.
- no_authorization_required! only: %i[new
- index
- create
- register
- confirm
- destroy
- make_default
- webauthn_challenge]
+ no_authorization_required! :new,
+ :index,
+ :create,
+ :register,
+ :confirm,
+ :destroy,
+ :make_default,
+ :webauthn_challenge
before_action :find_device, except: %i[new index register webauthn_challenge]
diff --git a/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb b/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb
index f1ef5786a89..bdea4697828 100644
--- a/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb
+++ b/modules/webhooks/app/controllers/webhooks/incoming/hooks_controller.rb
@@ -37,7 +37,7 @@ module Webhooks
skip_before_action :verify_authenticity_token
# Authorization cannot be applied since authentication is skipped.
# It is then to be ensured when handling the hook.
- no_authorization_required! only: [:handle_hook]
+ no_authorization_required! :handle_hook
# Wrap the JSON body as 'payload' param
# making it available as params[:payload]
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 0d39fe54a3f..b280a0c134c 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -33,7 +33,7 @@ RSpec.describe ApplicationController do
# Fake controller to test calling an action
controller do
- no_authorization_required!
+ no_authorization_required! :index
def index
# just do anything that doesn't require an extra template
@@ -154,7 +154,7 @@ RSpec.describe ApplicationController do
controller do
include OpenProjectErrorHelper
- no_authorization_required!
+ no_authorization_required! :index
def index
op_handle_error "fail"
diff --git a/spec/controllers/concerns/authorization_spec.rb b/spec/controllers/concerns/authorization_spec.rb
index 45296d7eaf8..de0e0fee0ae 100644
--- a/spec/controllers/concerns/authorization_spec.rb
+++ b/spec/controllers/concerns/authorization_spec.rb
@@ -150,26 +150,6 @@ RSpec.describe ApplicationController, "enforcement of authorization" do # ruboco
it_behaves_like "is prevented"
end
- context "when forfeiting authorization checks" do
- controller do
- no_authorization_required!
-
- include controller_setup
- end
-
- it_behaves_like "succeeds"
- end
-
- context "when stating that authorization has been checked" do
- controller do
- authorization_checked!
-
- include controller_setup
- end
-
- it_behaves_like "succeeds"
- end
-
context "with authorization check in the superclass" do
controller(described_class) do
before_action :require_admin
@@ -182,21 +162,19 @@ RSpec.describe ApplicationController, "enforcement of authorization" do # ruboco
it_behaves_like "succeeds"
end
- context "when stating that authorization has been checked in the superclass" do
- controller(described_class) do
- authorization_checked!
- end
+ context "when forfeiting authorization checks on this specific action" do
+ controller do
+ no_authorization_required! :index
- controller(controller_class) do
include controller_setup
end
it_behaves_like "succeeds"
end
- context "when forfeiting authorization checks in the superclass" do
+ context "when stating that authorization has been checked in the superclass" do
controller(described_class) do
- no_authorization_required!
+ authorization_checked! :index
end
controller(controller_class) do
@@ -206,39 +184,21 @@ RSpec.describe ApplicationController, "enforcement of authorization" do # ruboco
it_behaves_like "succeeds"
end
- context "when forfeiting authorization checks on this specific action with only" do
- controller do
- no_authorization_required! only: %i[index]
-
- include controller_setup
- end
-
- it_behaves_like "succeeds"
- end
-
- context "when forfeiting authorization checks on another action with only" do
- controller do
- no_authorization_required! only: %i[some_other_action]
-
- include controller_setup
+ context "when forfeiting authorization checks in the superclass" do
+ controller(described_class) do
+ no_authorization_required! :index
end
- it_behaves_like "is prevented"
- end
-
- context "when forfeiting authorization checks on all but another action with except" do
- controller do
- no_authorization_required! except: %i[some_other_action]
-
+ controller(controller_class) do
include controller_setup
end
it_behaves_like "succeeds"
end
- context "when forfeiting authorization on all other actions with except" do
+ context "when forfeiting authorization checks on another action" do
controller do
- no_authorization_required! except: %i[index]
+ no_authorization_required! :some_other_action
include controller_setup
end