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
BaseStrategy to show what can be implemented
Klaus Zandersee78a83fd932
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex 71abd7fc818..539416f72b1 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -307,14 +307,15 @@ class SharesController < ApplicationControllerdef load_entity # rubocop:disable Metrics/AbcSizeif params["work_package_id"]@entity = WorkPackage.visible.find(params["work_package_id"])- @sharing_strategy = SharingStrategies::WorkPackageStrategy.new(work_package: @entity)+ @sharing_strategy = SharingStrategies::WorkPackageStrategy.new(@entity, user: current_user)elsif params["project_query_id"]@entity = ProjectQuery.visible.find(params["project_query_id"])- @sharing_strategy = SharingStrategies::ProjectQueryStrategy.new(project_query: @entity)+ @sharing_strategy = SharingStrategies::ProjectQueryStrategy.new(@entity, user: current_user)elseraise ArgumentError, <<~ERRORNested the SharesController under an entity controller that is not yet configured to support sharing.- Edit the SharesController#load_entity method to load the entity from the correct parent.+ Edit the SharesController#load_entity method to load the entity from the correct parent and specify what sharing+ strategy should be applied.Params: #{params.to_unsafe_h}Request Path: #{request.path}diff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rbnew file mode 100644index 00000000000..dcceb0aacac--- /dev/null+++ b/app/models/sharing_strategies/base_strategy.rb@@ -0,0 +1,59 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module SharingStrategies+ class BaseStrategy+ attr_reader :entity, user++ def initialize(entity, user: User.current)+ @entity = entity+ @user = user+ end++ def available_roles+ # format: [{ label: "Role name", value: 42, description: "Role description", default: true }]+ raise NotImplementedError, "Override in a subclass and return an array of roles that should be displayed"+ end++ def sharing_manageable?+ raise NotImplementedError, "Override in a subclass and return true if the current user can manage sharing"+ end++ def create_contract_class+ raise NotImplementedError, "Override in a subclass and return the contract class for creating a share"+ end++ def update_contract_class+ raise NotImplementedError, "Override in a subclass and return the contract class for updating a share"+ end++ def delete_contract_class+ raise NotImplementedError, "Override in a subclass and return the contract class for deleting a share"+ end+ end+enddiff --git a/app/models/sharing_strategies/project_query_strategy.rb b/app/models/sharing_strategies/project_query_strategy.rbindex 4bef025c523..c1b7b4551b0 100644--- a/app/models/sharing_strategies/project_query_strategy.rb+++ b/app/models/sharing_strategies/project_query_strategy.rb@@ -1,11 +1,33 @@-module SharingStrategies- class ProjectQueryStrategy- attr_reader :project_query-- def initialize(project_query:)- @project_query = project_query- end+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++module SharingStrategies+ class ProjectQueryStrategy < BaseStrategydef available_rolesProjectQueryRole.all.map.with_index do |role, index|{@@ -18,7 +40,7 @@ module SharingStrategiesenddef sharing_manageable?- @project_query.editable?+ @entity.editable?enddef create_contract_classdiff --git a/app/models/sharing_strategies/work_package_strategy.rb b/app/models/sharing_strategies/work_package_strategy.rbindex 6b40ee39006..b5a3770c9eb 100644--- a/app/models/sharing_strategies/work_package_strategy.rb+++ b/app/models/sharing_strategies/work_package_strategy.rb@@ -1,11 +1,33 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#+++module SharingStrategiesclass WorkPackageStrategy- attr_reader :work_package-- def initialize(work_package:)- @work_package = work_package- end-def available_rolesrole_mapping = WorkPackageRole.unscoped.pluck(:builtin, :id).to_h@@ -24,7 +46,7 @@ module SharingStrategiesenddef sharing_manageable?- User.current.allowed_in_project?(:share_work_packages, @work_package.project)+ user.allowed_in_project?(:share_work_packages, @entity.project)enddef create_contract_class