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

[32177] Disable recaptcha for admins

Oliver Günthere52989ec97f9
diff --git a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
index 1e0f84c60b4..5bb7c9376c5 100644
--- a/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
+++ b/modules/recaptcha/app/controllers/recaptcha/request_controller.rb
@@ -14,6 +14,9 @@ module ::Recaptcha
# Require authenticated user from the core to be present
before_action :require_authenticated_user
+ # Skip if user is admin
+ before_action :skip_if_admin
+
# Skip if user has confirmed already
before_action :skip_if_user_verified
@@ -90,6 +93,12 @@ module ::Recaptcha
end
end
+ def skip_if_admin
+ if @authenticated_user&.admin?
+ complete_stage_redirect
+ end
+ end
+
def skip_if_user_verified
if ::Recaptcha::Entry.where(user_id: @authenticated_user.id).exists?
Rails.logger.debug { "User #{@authenticated_user.id} already provided recaptcha. Skipping. " }
diff --git a/modules/recaptcha/spec/controllers/request_controller_spec.rb b/modules/recaptcha/spec/controllers/request_controller_spec.rb
index 7d12dde453f..da23794cb61 100644
--- a/modules/recaptcha/spec/controllers/request_controller_spec.rb
+++ b/modules/recaptcha/spec/controllers/request_controller_spec.rb
@@ -27,6 +27,17 @@ describe ::Recaptcha::RequestController, type: :controller do
get :perform
expect(response).to redirect_to stage_success_path(stage: :recaptcha, secret: 'asdf')
end
+
+ context 'if the user is an admin' do
+ let(:user) { FactoryBot.create :admin }
+
+ it 'skips the verification' do
+ expect(controller).not_to receive(:perform)
+
+ get :perform
+ expect(response).to redirect_to stage_success_path(stage: :recaptcha, secret: 'asdf')
+ end
+ end
end
describe 'verify' do