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
Add custom permission checks based on SharingStrategy
Klaus Zanderse4da1d0754cd
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex e7706b0c3d9..059fd2cefd2 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -37,8 +37,9 @@ class SharesController < ApplicationControllerbefore_action :load_share, only: %i[destroy update resend_invite]before_action :enterprise_check, only: %i[index]- # TODO: Permission checks need to be implemented correctly depending on entity- before_action :authorize+ before_action :check_if_manageable, except: %i[index dialog]+ before_action :check_if_viewable, only: %i[index dialog]+ authorization_checked! :dialog, :index, :create, :update, :destroy, :resend_invite, :bulk_update, :bulk_destroydef dialog; end@@ -131,6 +132,18 @@ class SharesController < ApplicationControllerattr_reader :sharing_strategy+ def check_if_viewable+ return if sharing_strategy.viewable? || sharing_strategy.manageable?++ render_403+ end++ def check_if_manageable+ return if sharing_strategy.manageable?++ render_403+ end+def enterprise_checkreturn if EnterpriseToken.allows_to?(:work_package_sharing)diff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rbindex e92f1d362c8..6b1a82fb59f 100644--- a/app/models/sharing_strategies/base_strategy.rb+++ b/app/models/sharing_strategies/base_strategy.rb@@ -40,6 +40,11 @@ module SharingStrategiesraise NotImplementedError, "Override in a subclass and return an array of roles that should be displayed"end+ def vieable?+ raise NotImplementedError,+ "Override in a subclass and return true if the current user can view who the entity is shared with"+ end+def manageable?raise NotImplementedError, "Override in a subclass and return true if the current user can manage sharing"enddiff --git a/app/models/sharing_strategies/project_query_strategy.rb b/app/models/sharing_strategies/project_query_strategy.rbindex c9ad2c383e4..279bd32a0a8 100644--- a/app/models/sharing_strategies/project_query_strategy.rb+++ b/app/models/sharing_strategies/project_query_strategy.rb@@ -43,6 +43,10 @@ module SharingStrategies@entity.editable?end+ def viewable?+ @entity.visible?+ end+def create_contract_classShares::ProjectQueries::CreateContractenddiff --git a/app/models/sharing_strategies/work_package_strategy.rb b/app/models/sharing_strategies/work_package_strategy.rbindex 1935b0d0c20..3d24ef89a81 100644--- a/app/models/sharing_strategies/work_package_strategy.rb+++ b/app/models/sharing_strategies/work_package_strategy.rb@@ -49,6 +49,10 @@ module SharingStrategiesuser.allowed_in_project?(:share_work_packages, @entity.project)end+ def viewable?+ user.allowed_in_project?(:view_shared_work_packages, @entity.project)+ end+def create_contract_classShares::WorkPackages::CreateContractenddiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 89482abc2c2..896a1c495ad 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -330,17 +330,14 @@ Rails.application.reloader.to_prepare domap.permission :share_work_packages,{- members: %i[destroy_by_principal],- shares: %i[dialog index create destroy update resend_invite bulk_update bulk_destroy]+ members: %i[destroy_by_principal]},permissible_on: :project,dependencies: %i[edit_work_packages view_shared_work_packages],require: :membermap.permission :view_shared_work_packages,- {- shares: %i[index]- },+ {},permissible_on: :project,require: :member,contract_actions: { work_package_shares: %i[index] }