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

Check IllegalPermissionContextError as well in helper

Klaus Zanders8959d65a8d9a
diff --git a/app/services/authorization/illegal_permission_context_error.rb b/app/services/authorization/illegal_permission_context_error.rb
index 67e48dff3d5..8fcd146dd3b 100644
--- a/app/services/authorization/illegal_permission_context_error.rb
+++ b/app/services/authorization/illegal_permission_context_error.rb
@@ -28,8 +28,11 @@
module Authorization
class IllegalPermissionContextError < StandardError
+ attr_reader :allowed_contexts
+
def initialize(permission, mapped_permissions, context)
- super("Used permission \"#{permission}\" which maps to #{mapped_permissions.map(&:name).join(', ')} in #{context} context. Correct contexts for this permission are: #{mapped_permissions.flat_map(&:permissible_on).uniq.join(', ')}.")
+ @allowed_contexts = mapped_permissions.flat_map(&:permissible_on).uniq
+ super("Used permission \"#{permission}\" which maps to #{mapped_permissions.map(&:name).join(', ')} in #{context} context. Correct contexts for this permission are: #{@allowed_contexts.join(', ')}.")
end
end
end
diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb
index 0b07181684e..8174d746101 100644
--- a/lib/redmine/menu_manager/menu_helper.rb
+++ b/lib/redmine/menu_manager/menu_helper.rb
@@ -425,6 +425,17 @@ module Redmine::MenuManager::MenuHelper
# As we might throw every possible URL in here, we might also have URLs
# that are not backed by any permissions. Let's just ignore those.
false
+ rescue Authorization::IllegalPermissionContextError => e
+ # We tried to check the permission in project context, but it seems to be
+ # a global permission. Let's try again in global context.
+ #
+ # Eventhough this was NOT done in the old system.
+ # TODO: Maybe remove, when we now show weird new links in unexpected places
+ if e.allowed_contexts.include?(:global)
+ user.allowed_globally?(url)
+ else
+ false
+ end
end
end