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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Only apply non-member and anonymous checks when no projects exist
Klaus Zandersf79c3b2c73bc
diff --git a/app/services/authorization/user_permissible_service.rb b/app/services/authorization/user_permissible_service.rbindex 06c0431bb03..04968f031a9 100644--- a/app/services/authorization/user_permissible_service.rb+++ b/app/services/authorization/user_permissible_service.rb@@ -30,20 +30,16 @@ module Authorizationperms = contextual_permissions(permission, :project)return true if admin_and_all_granted_to_admin?(perms)- # If no projects matching the scope exists, it could still be that the user has access to the- # permission either via the anonymous or non-member role, especially when there are no projects- # in the database. So if this returns false, we check non-member and anonymous permissions as well.Project.allowed_to(user, perms).exists? ||- non_member_permissions.intersect?(perms.map { |perm| perm.name.to_sym }) ||- anonymous_permissions.intersect?(perms.map { |perm| perm.name.to_sym })+ no_projects_but_granted_to_non_member?(perms) ||+ no_projects_but_granted_to_anonymous?(perms)enddef allowed_in_entity?(permission, entities_to_check, entity_class)return false if entities_to_check.blank?return false unless authorizable_user?- perms = contextual_permissions(permission,- context_name(entity_class))+ perms = contextual_permissions(permission, context_name(entity_class))entities = Array(entities_to_check)@@ -52,7 +48,7 @@ module Authorizationendend- def allowed_in_any_entity?(permission, entity_class, in_project: nil) # rubocop:disable Metrics/AbcSize+ def allowed_in_any_entity?(permission, entity_class, in_project: nil)perms = contextual_permissions(permission, context_name(entity_class))return true if admin_and_all_granted_to_admin?(perms)@@ -62,12 +58,7 @@ module Authorizationif in_projectallowed_scope.exists?(project: in_project)else- # If no entities matching the scope exists, it could still be that the user has access to the- # permission either via the anonymous or non-member role, especially when there are no projects- # or entities in the database. So if this returns false, we check non-member and anonymous permissions as well.- allowed_scope.exists? ||- non_member_permissions.intersect?(perms.map { |perm| perm.name.to_sym }) ||- anonymous_permissions.intersect?(perms.map { |perm| perm.name.to_sym })+ allowed_scope.exists? || no_projects_but_granted_to_non_member?(perms) || no_projects_but_granted_to_anonymous?(perms)endend@@ -132,16 +123,23 @@ module Authorizationentity_class.model_name.element.to_symend+ def no_projects_but_granted_to_non_member?(permissions)+ Project.none? &&+ non_member_permissions.intersect?(permissions.map { |perm| perm.name.to_sym })+ end++ def no_projects_but_granted_to_anonymous?(permissions)+ Project.none? &&+ user.anonymous? &&+ anonymous_permissions.intersect?(permissions.map { |perm| perm.name.to_sym })+ end+def non_member_permissions@non_member_permissions ||= ProjectRole.non_member.permissionsenddef anonymous_permissions- @anonymous_permissions ||= if user.anonymous?- ProjectRole.anonymous.permissions- else- []- end+ @anonymous_permissions ||= ProjectRole.anonymous.permissionsendendend