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

Add helper to look for an error key in the ServiceResult errors

Oliver Günther2ef33d2a3a17
diff --git a/app/controllers/concerns/accounts/omniauth_login.rb b/app/controllers/concerns/accounts/omniauth_login.rb
index af420a04ea7..20e8a6dbefe 100644
--- a/app/controllers/concerns/accounts/omniauth_login.rb
+++ b/app/controllers/concerns/accounts/omniauth_login.rb
@@ -90,7 +90,7 @@ module Accounts::OmniauthLogin
if call.success?
login_user_if_active(call.result)
- elsif call.errors[:user].any?
+ elsif call.includes_error?(:base, :failed_to_activate)
redirect_omniauth_register_modal(call.result, auth_hash)
else
error = call.message
diff --git a/app/services/service_result.rb b/app/services/service_result.rb
index 0ff2b1ae690..528b3abb491 100644
--- a/app/services/service_result.rb
+++ b/app/services/service_result.rb
@@ -94,6 +94,15 @@ class ServiceResult
[errors] + dependent_results.map(&:errors)
end
+ ##
+ # Test whether the returned errors respond
+ # to the search key
+ def includes_error?(attribute, error_key)
+ all_errors.any? do |error|
+ error.symbols_for(attribute).include?(error_key)
+ end
+ end
+
##
# Collect all present errors for the given result
# and dependent results.