From c13237914ca9a32a2125c515f8f9c47c132bd0bc Mon Sep 17 00:00:00 2001 From: Pavel Balashou Date: Tue, 23 Apr 2024 16:33:24 +0200 Subject: [PATCH] [#54356] Move permissions from FILE STORAGES to WORK PACKAGES section https://community.openproject.org/work_packages/54356 --- .../storages/lib/open_project/storages/engine.rb | 10 ++++++---- .../spec/features/storages_menu_links_spec.rb | 2 +- .../api/v3/file_links/file_links_api_spec.rb | 15 +++------------ .../v3/projects/projects_storages_filter_spec.rb | 12 ++++++------ .../work_packages_linkable_filter_spec.rb | 8 ++++---- .../work_packages_linked_filter_spec.rb | 4 ++-- 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb index e6fbc7a46661..3346fa4035f1 100644 --- a/modules/storages/lib/open_project/storages/engine.rb +++ b/modules/storages/lib/open_project/storages/engine.rb @@ -124,7 +124,6 @@ def self.permissions author_url: "https://www.openproject.org", bundled: true, settings: {} do - # Defines permission constraints used in the module (controller, etc.) # Permissions documentation: https://www.openproject.org/docs/development/concepts/permissions/#definition-of-permissions # Independent of storages module (Disabling storages module does not revoke enabled permissions). @@ -138,9 +137,8 @@ def self.permissions dependencies: %i[] end - # Dependent on storages module (Disabling storages module does revoke enabled permissions). - project_module :storages, - dependencies: :work_package_tracking do + # Dependent on work_package_tracking module + project_module :work_package_tracking do permission :view_file_links, {}, permissible_on: :project, @@ -151,7 +149,11 @@ def self.permissions permissible_on: :project, dependencies: %i[view_file_links], contract_actions: { file_links: %i[manage] } + end + # Dependent on storages module (Disabling storages module does revoke enabled permissions). + project_module :storages, + dependencies: :work_package_tracking do OpenProject::Storages::Engine.permissions.each do |p| permission(p, {}, permissible_on: :project, dependencies: %i[]) end diff --git a/modules/storages/spec/features/storages_menu_links_spec.rb b/modules/storages/spec/features/storages_menu_links_spec.rb index 74eb1d6589e0..6f9b317fa352 100644 --- a/modules/storages/spec/features/storages_menu_links_spec.rb +++ b/modules/storages/spec/features/storages_menu_links_spec.rb @@ -34,7 +34,7 @@ RSpec.describe "Storage links in project menu" do include EnsureConnectionPathHelper - shared_let(:project) { create(:project, enabled_module_names: %i[storages]) } + shared_let(:project) { create(:project, enabled_module_names: %i[work_package_tracking storages]) } shared_let(:storage_configured_linked1) { create(:nextcloud_storage_configured, :as_automatically_managed, name: "Storage 1") } shared_let(:project_storage1) do create(:project_storage, :as_automatically_managed, project:, storage: storage_configured_linked1) diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb index 681b0ec25e4c..1fa11b3698b7 100644 --- a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb +++ b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb @@ -219,15 +219,6 @@ def disable_module(project, modul) end end - context "if storages module is deactivated for the work package's project" do - before(:all) { disable_module(project, "storages") } - after(:all) { enable_module(project, "storages") } - - it_behaves_like "API V3 collection response", 0, 0, "FileLink", "Collection" do - let(:elements) { [] } - end - end - describe "with filter by storage" do let!(:another_project_storage) { create(:project_storage, project:, storage: another_storage) } let(:path) { "#{api_v3_paths.file_links(work_package.id)}?filters=#{CGI.escape(filters.to_json)}" } @@ -517,9 +508,9 @@ def disable_module(project, modul) it_behaves_like "not found" end - context "if file link is in a work package, while the storages module is deactivated in its project." do - before(:all) { disable_module(project, "storages") } - after(:all) { enable_module(project, "storages") } + context "if file link is in a work package, while the work_package_tracking module is deactivated in its project." do + before(:all) { disable_module(project, "work_package_tracking") } + after(:all) { enable_module(project, "work_package_tracking") } it_behaves_like "not found" end diff --git a/modules/storages/spec/requests/api/v3/projects/projects_storages_filter_spec.rb b/modules/storages/spec/requests/api/v3/projects/projects_storages_filter_spec.rb index 50edb46fbe32..88bd26fa4403 100644 --- a/modules/storages/spec/requests/api/v3/projects/projects_storages_filter_spec.rb +++ b/modules/storages/spec/requests/api/v3/projects/projects_storages_filter_spec.rb @@ -76,9 +76,9 @@ def disable_module(project, modul) let(:elements) { [project3, project2, project1] } end - context "if a project has the storages module deactivated" do - before(:all) { disable_module(project1, "storages") } - after(:all) { enable_module(project1, "storages") } + context "if a project has the work_package_tracking module deactivated" do + before(:all) { disable_module(project1, "work_package_tracking") } + after(:all) { enable_module(project1, "work_package_tracking") } it_behaves_like "API V3 collection response", 2, 2, "Project", "Collection" do let(:elements) { [project3, project2] } @@ -102,9 +102,9 @@ def disable_module(project, modul) let(:elements) { [project3, project2, project1] } end - context "if a project has the storages module deactivated" do - before(:all) { disable_module(project1, "storages") } - after(:all) { enable_module(project1, "storages") } + context "if a project has the work_package_tracking module deactivated" do + before(:all) { disable_module(project1, "work_package_tracking") } + after(:all) { enable_module(project1, "work_package_tracking") } it_behaves_like "API V3 collection response", 2, 2, "Project", "Collection" do let(:elements) { [project3, project2] } diff --git a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb index 429e011c219a..60a00e842e16 100644 --- a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb +++ b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linkable_filter_spec.rb @@ -105,8 +105,8 @@ end end - context "if a project has the storages module deactivated" do - let(:project1) { create(:project, disable_modules: :storages, members: { current_user => role1 }) } + context "if a project has the work_package_tracking module deactivated" do + let(:project1) { create(:project, disable_modules: [:work_package_tracking], members: { current_user => role1 }) } it_behaves_like "API V3 collection response", 2, 2, "WorkPackage", "WorkPackageCollection" do let(:elements) { [work_package3, work_package4] } @@ -147,8 +147,8 @@ end end - context "if a project has the storages module deactivated" do - let(:project1) { create(:project, disable_modules: :storages, members: { current_user => role1 }) } + context "if a project has the work_package_tracking module deactivated" do + let(:project1) { create(:project, disable_modules: :work_package_tracking, members: { current_user => role1 }) } it_behaves_like "API V3 collection response", 2, 2, "WorkPackage", "WorkPackageCollection" do let(:elements) { [work_package3, work_package4] } diff --git a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb index 35137b2abb69..964461e1fb13 100644 --- a/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb +++ b/modules/storages/spec/requests/api/v3/work_packages/work_packages_linked_filter_spec.rb @@ -113,8 +113,8 @@ end end - context "if a project has the storages module deactivated" do - let(:project1) { create(:project, disable_modules: :storages, members: { current_user => role1 }) } + context "if a project has the work_package_tracking module deactivated" do + let(:project1) { create(:project, disable_modules: :work_package_tracking, members: { current_user => role1 }) } it_behaves_like "API V3 collection response", 1, 1, "WorkPackage", "WorkPackageCollection" do let(:elements) { [work_package3] }