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

Implement contracts for sharing project queries

Klaus Zanders72804295a90f
diff --git a/app/contracts/shares/project_queries/base_extension.rb b/app/contracts/shares/project_queries/base_extension.rb
new file mode 100644
index 00000000000..688fce333a9
--- /dev/null
+++ b/app/contracts/shares/project_queries/base_extension.rb
@@ -0,0 +1,45 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 Shares
+ module ProjectQueries
+ module BaseExtension
+ extend ActiveSupport::Concern
+
+ private
+
+ def user_allowed_to_manage?
+ model.entity.editable?
+ end
+
+ def assignable_role_class
+ ProjectQueryRole
+ end
+ end
+ end
+end
diff --git a/app/contracts/shares/project_queries/create_contract.rb b/app/contracts/shares/project_queries/create_contract.rb
new file mode 100644
index 00000000000..58eeb1fdf13
--- /dev/null
+++ b/app/contracts/shares/project_queries/create_contract.rb
@@ -0,0 +1,35 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 Shares
+ module ProjectQueries
+ class CreateContract < Shares::CreateContract
+ include Shares::ProjectQueries::BaseExtension
+ end
+ end
+end
diff --git a/app/contracts/shares/project_queries/delete_contract.rb b/app/contracts/shares/project_queries/delete_contract.rb
new file mode 100644
index 00000000000..b5486e3425d
--- /dev/null
+++ b/app/contracts/shares/project_queries/delete_contract.rb
@@ -0,0 +1,37 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 Shares
+ module ProjectQueries
+ class DeleteContract < Shares::DeleteContract
+ # DeleteContract has its own permission check and does not care about the role class,
+ # so we do not need to include the BaseExtension here.
+ delete_permission -> { model.entity.editable? }
+ end
+ end
+end
diff --git a/app/contracts/shares/project_queries/update_contract.rb b/app/contracts/shares/project_queries/update_contract.rb
new file mode 100644
index 00000000000..5148b92951e
--- /dev/null
+++ b/app/contracts/shares/project_queries/update_contract.rb
@@ -0,0 +1,35 @@
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 Shares
+ module ProjectQueries
+ class UpdateContract < Shares::UpdateContract
+ include Shares::ProjectQueries::BaseExtension
+ end
+ end
+end
diff --git a/app/models/sharing_strategies/project_query_strategy.rb b/app/models/sharing_strategies/project_query_strategy.rb
index cc009ecd605..4bef025c523 100644
--- a/app/models/sharing_strategies/project_query_strategy.rb
+++ b/app/models/sharing_strategies/project_query_strategy.rb
@@ -22,18 +22,15 @@ module SharingStrategies
end
def create_contract_class
- # Shares::WorkPackages::CreateContract
- EmptyContract
+ Shares::ProjectQueries::CreateContract
end
def update_contract_class
- # Shares::WorkPackages::UpdateContract
- EmptyContract
+ Shares::ProjectQueries::UpdateContract
end
def delete_contract_class
- # Shares::WorkPackages::DeleteContract
- EmptyContract
+ Shares::ProjectQueries::DeleteContract
end
end
end