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
Fix tests
Klaus Zanders96c2646671af
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex c10004abb46..eaa815270d8 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -293,14 +293,14 @@ class ApplicationController < ActionController::Base# Authorize the user for the requested controller action.# To be used in before_action hooksdef authorize(ctrl = params[:controller], action = params[:action])- OpenProject::Deprecation.deprecate_method(ApplicationController, :authorize)+ # OpenProject::Deprecation.deprecate_method(ApplicationController, :authorize)do_authorize({ controller: ctrl, action: }, global: false)end# Authorize the user for the requested controller action outside a project# To be used in before_action hooksdef authorize_global- OpenProject::Deprecation.deprecate_method(ApplicationController, :authorize_global)+ # OpenProject::Deprecation.deprecate_method(ApplicationController, :authorize_global)action = { controller: params[:controller], action: params[:action] }do_authorize(action, global: true)@@ -311,17 +311,21 @@ class ApplicationController < ActionController::Base# Action can be:# * a parameter-like Hash (eg. { controller: '/projects', action: 'edit' })# * a permission Symbol (eg. :edit_project)- def do_authorize(action, global: false)- OpenProject::Deprecation.deprecate_method(ApplicationController, :do_authorize)+ def do_authorize(action, global: false) # rubocop:disable Metrics/PerceivedComplexity+ # OpenProject::Deprecation.deprecate_method(ApplicationController, :do_authorize)# context = @project || @projects- # is_authorized = User.current.allowed_to?(action, context, global:)-- is_authorized = if global- User.current.allowed_based_on_permission_context?(action)- else- User.current.allowed_based_on_permission_context?(action, project: @project || @projects,- entity: @work_package || @work_packages)- end+ # old_authorized = User.current.allowed_to?(action, context, global:)++ is_authorized = begin+ if global+ User.current.allowed_based_on_permission_context?(action)+ else+ User.current.allowed_based_on_permission_context?(action, project: @project || @projects,+ entity: @work_package || @work_packages)+ end+ rescue Authorization::UnknownPermissionError+ false+ endunless is_authorizedif @project&.archived?diff --git a/app/models/users/permission_checks.rb b/app/models/users/permission_checks.rbindex 2ec18911af1..fe0615a98ca 100644--- a/app/models/users/permission_checks.rb+++ b/app/models/users/permission_checks.rb@@ -103,17 +103,17 @@ module Users::PermissionCheckspermissions.any? do |perm|if perm.global?allowed_globally?(perm)- elsif perm.work_package? && entity.is_a?(WorkPackage)+ elsif perm.work_package? && (entity.is_a?(WorkPackage) || (entity.is_a?(Array) && entity.all? { |e| e.is_a?(WorkPackage) }))allowed_in_work_package?(perm, entity)- elsif perm.work_package? && entity.nil? && project.nil?+ elsif perm.work_package? && entity.blank? && project.blank?allowed_in_any_work_package?(perm)- elsif perm.work_package? && project && entity.nil?+ elsif perm.work_package? && project && entity.blank?allowed_in_any_work_package?(perm, in_project: project)elsif perm.project? && projectallowed_in_project?(perm, project)elsif perm.project? && entity && entity.respond_to?(:project)allowed_in_project?(perm, entity.project)- elsif perm.project? && entity.nil? && project.nil?+ elsif perm.project? && entity.blank? && project.blank?allowed_in_any_project?(perm)elsefalsediff --git a/app/services/authorization/user_permissible_service.rb b/app/services/authorization/user_permissible_service.rbindex f0a15b776c8..e158da8531d 100644--- a/app/services/authorization/user_permissible_service.rb+++ b/app/services/authorization/user_permissible_service.rb@@ -28,6 +28,7 @@ module Authorizationdef allowed_in_any_project?(permission)perms = contextual_permissions(permission, :project)+ return false unless authorizable_user?return true if admin_and_all_granted_to_admin?(perms)Project.allowed_to(user, perms).exists?@@ -48,15 +49,17 @@ module Authorizationdef allowed_in_any_entity?(permission, entity_class, in_project: nil)perms = contextual_permissions(permission, context_name(entity_class))+ return false unless authorizable_user?return true if admin_and_all_granted_to_admin?(perms)# entity_class.allowed_to will also check whether the user has the permission via a membership in the project.+ # TODO: ^--- thats' actually not the case weirdly...allowed_scope = entity_class.allowed_to(user, perms)if in_project- allowed_scope.exists?(project: in_project)+ allowed_in_single_project?(perms, in_project) || allowed_scope.exists?(project: in_project)else- allowed_scope.exists?+ allowed_in_any_project?(perms) || allowed_scope.exists?endend