Skip to content

Commit

Permalink
Merge pull request #15359 from opf/feature/54356-move-permissions-fro…
Browse files Browse the repository at this point in the history
…m-file-storages-to-work-packages-section

[#54356] Move permissions from FILE STORAGES to WORK PACKAGES section
  • Loading branch information
ba1ash authored Apr 26, 2024
2 parents de2e1ab + c132379 commit d1a9a56
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
10 changes: 6 additions & 4 deletions modules/storages/lib/open_project/storages/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/storages/spec/features/storages_menu_links_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}" }
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand All @@ -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] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand Down Expand Up @@ -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] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand Down

0 comments on commit d1a9a56

Please sign in to comment.