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
[#42204] fixed tests and permission check
Eric Schubert44392cfb9611
diff --git a/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rb b/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rbindex ea34f73e97c..595891d821d 100644--- a/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rb+++ b/modules/storages/lib/api/v3/file_links/file_link_relation_representer.rb@@ -33,13 +33,13 @@ module APIextend ActiveSupport::Concernincluded do- link :fileLinks, cache_if: -> { render_file_links? } do+ link :fileLinks, cache_if: -> { current_user.allowed_to?(:view_file_links, represented.project) } do{href: api_v3_paths.file_links(represented.id)}end- link :addFileLink, cache_if: -> { render_action_link? } do+ link :addFileLink, cache_if: -> { current_user.allowed_to?(:manage_file_links, represented.project) } do{href: api_v3_paths.file_links(represented.id),method: :post@@ -49,7 +49,7 @@ module APIproperty :file_links,embedded: true,exec_context: :decorator,- if: ->(*) { embed_links && render_file_links? },+ if: ->(*) { embed_links && current_user.allowed_to?(:view_file_links, represented.project) },uncacheable: truedef file_links@@ -57,19 +57,6 @@ module APIself_link: api_v3_paths.file_links(represented.id),current_user: current_user)end-- private-- def render_action_link?- render_file_links? &&- current_user.allowed_to?(:manage_file_links, represented.project)- end-- def render_file_links?- OpenProject::FeatureDecisions.storages_module_active? &&- represented.project.module_enabled?('storages') &&- current_user.allowed_to?(:view_file_links, represented.project)- endendendenddiff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rbindex 91fb5177b4e..fb10e836200 100644--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb@@ -718,12 +718,6 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doenddescribe 'fileLinks' do- let(:storages_feature_enabled) { true }-- before do- allow(OpenProject::FeatureDecisions).to receive(:storages_module_active?).and_return(storages_feature_enabled)- end-it_behaves_like 'has an untitled link' dolet(:link) { 'fileLinks' }let(:href) { api_v3_paths.file_links(work_package.id) }@@ -743,32 +737,6 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter dolet(:link) { 'fileLinks' }endend-- context 'if file storages feature is disabled' do- let(:storages_feature_enabled) { false }-- it_behaves_like 'has no link' do- let(:link) { 'fileLinks' }- end-- it_behaves_like 'has no link' do- let(:link) { 'addFileLink' }- end- end-- context 'if project has storages module disabled' do- before do- project.enabled_module_names = project.enabled_module_names - ['storages']- end-- it_behaves_like 'has no link' do- let(:link) { 'fileLinks' }- end-- it_behaves_like 'has no link' do- let(:link) { 'addFileLink' }- end- endendcontext 'when the user is not watching the work package' do@@ -1208,12 +1176,10 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doenddescribe 'fileLinks' do- let(:storages_feature_enabled) { true }let(:storage) { build_stubbed(:storage) }let(:file_link) { build_stubbed(:file_link, storage: storage, container: work_package) }before do- allow(OpenProject::FeatureDecisions).to receive(:storages_module_active?).and_return(storages_feature_enabled)allow(work_package).to receive(:file_links).and_return([file_link])end@@ -1312,7 +1278,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter doendit 'changes when the work_package is updated' do- work_package.updated_at = Time.zone.now + 20.seconds+ work_package.updated_at = 20.seconds.from_nowexpect(representer.json_cache_key).not_to eql former_cache_key