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
[bugfix] Added additional visibility check for file links
Eric Schubertfa150d44e165
diff --git a/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rbindex 2578997a6b2..d1a3c182135 100644--- a/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb+++ b/modules/storages/app/models/queries/storages/work_packages/filter/file_link_origin_id_filter.rb@@ -41,5 +41,13 @@ module Queries::Storages::WorkPackages::Filterdef permission:view_file_linksend++ def joins+ %i[file_links storages]+ end++ def additional_where_condition+ "AND #{::Storages::FileLink.table_name}.storage_id = #{::Storages::Storage.table_name}.id"+ endendenddiff --git a/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rbindex b3a24593cfc..f0733a41b77 100644--- a/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb+++ b/modules/storages/app/models/queries/storages/work_packages/filter/storage_id_filter.rb@@ -41,5 +41,13 @@ module Queries::Storages::WorkPackages::Filterdef permission:view_file_linksend++ def joins+ [:file_links, { project: :projects_storages }]+ end++ def additional_where_condition+ "AND #{::Storages::FileLink.table_name}.storage_id = #{::Storages::ProjectStorage.table_name}.storage_id"+ endendenddiff --git a/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb b/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rbindex 56de183c698..12b2c464192 100644--- a/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb+++ b/modules/storages/app/models/queries/storages/work_packages/filter/storage_url_filter.rb@@ -47,7 +47,11 @@ module Queries::Storages::WorkPackages::Filterenddef joins- { file_links: :storage }+ [{ file_links: :storage }, { project: :projects_storages }]+ end++ def additional_where_condition+ "AND #{::Storages::FileLink.table_name}.storage_id = #{::Storages::ProjectStorage.table_name}.storage_id"endendenddiff --git a/modules/storages/app/models/queries/storages/work_packages/filter/storages_filter_mixin.rb b/modules/storages/app/models/queries/storages/work_packages/filter/storages_filter_mixin.rbindex 69b26ca71eb..7bffb8123e3 100644--- a/modules/storages/app/models/queries/storages/work_packages/filter/storages_filter_mixin.rb+++ b/modules/storages/app/models/queries/storages/work_packages/filter/storages_filter_mixin.rb@@ -55,6 +55,7 @@ module Queries::Storages::WorkPackages::Filter::StoragesFilterMixin<<-SQL.squish#{::Queries::Operators::Equals.sql_for_field(where_values, filter_model.table_name, filter_column)}AND work_packages.project_id IN (#{Project.allowed_to(User.current, permission).select(:id).to_sql})+ #{additional_where_condition}SQLend@@ -62,6 +63,10 @@ module Queries::Storages::WorkPackages::Filter::StoragesFilterMixinvaluesend+ def additional_where_condition+ ''+ end+def joinsfilter_model.table_name.to_symenddiff --git a/modules/storages/app/models/storages/file_link.rb b/modules/storages/app/models/storages/file_link.rbindex d411fc70911..79317938a9f 100644--- a/modules/storages/app/models/storages/file_link.rb+++ b/modules/storages/app/models/storages/file_link.rb@@ -64,9 +64,10 @@ class Storages::FileLink < ApplicationRecord# join projects through the container, and filter on projects visible from# the userincludes(:container)- .includes(container: :project)+ .includes(container: { project: :projects_storages }).references(:projects).merge(Project.allowed_to(user, :view_file_links))+ .where('projects_storages.storage_id = file_links.storage_id')}delegate :project, to: :containerdiff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rbindex 119b6dbca13..17a0ab2617f 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb@@ -50,9 +50,14 @@ describe 'API v3 file links resource', type: :request dolet(:file_link) docreate(:file_link, creator: current_user, container: work_package, storage: storage)end- let(:another_file_link) do+ let(:file_link_of_other_work_package) docreate(:file_link, creator: current_user, container: another_work_package, storage: storage)end+ # If a storage mapping between a project and a storage is removed, the file link still persist. This can occur on+ # moving a work package to another project, too, if target project does not yet have the storage mapping.+ let(:file_link_of_unlinked_storage) do+ create(:file_link, creator: current_user, container: work_package, storage: another_storage)+ endsubject(:response) { last_response }@@ -65,7 +70,8 @@ describe 'API v3 file links resource', type: :request dobefore dofile_link- another_file_link+ file_link_of_other_work_package+ file_link_of_unlinked_storageget pathend@@ -312,11 +318,17 @@ describe 'API v3 file links resource', type: :request doit_behaves_like 'not found'end- context 'if no storage with that id exists' do+ context 'if no file link with that id exists' dolet(:path) { api_v3_paths.file_link(1337) }it_behaves_like 'not found'end++ context 'if file link is in a work package, while its project is not mapped to the file link\'s storage.' do+ let(:path) { api_v3_paths.file_link(file_link_of_unlinked_storage.id) }++ it_behaves_like 'not found'+ endenddescribe 'DELETE /api/v3/file_links/:file_link_id' dodiff --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.rbindex df8992c633b..b3577eb61ca 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@@ -63,6 +63,9 @@ describe 'API v3 work packages resource with filters for linked storage file',storage: storage2,origin_id: file_link1.origin_id)end+ # This link is considered invisible, as it is linking a work package to a file, where the work package's project+ # and the file's storage are not linked together.+ let(:file_link4) { create(:file_link, creator: current_user, container: work_package3, storage: storage1) }subject(:response) { last_response }@@ -73,6 +76,7 @@ describe 'API v3 work packages resource with filters for linked storage file',file_link1file_link2file_link3+ file_link4login_as current_userend@@ -116,6 +120,14 @@ describe 'API v3 work packages resource with filters for linked storage file',let(:elements) { [] }endend++ context 'if the filter is set to a file linked to a work package in an unlinked project' do+ let(:origin_id_value) { file_link4.origin_id.to_s }++ it_behaves_like 'API V3 collection response', 0, 0, 'WorkPackage', 'WorkPackageCollection' do+ let(:elements) { [] }+ end+ endendcontext 'with single filter for storage id' do@@ -169,6 +181,14 @@ describe 'API v3 work packages resource with filters for linked storage file',let(:elements) { [work_package3] }end+ context 'if any of the matching work packages is in a project without a mapping to that storage' do+ let(:storage_url_value) { CGI.escape(storage1.host) }++ it_behaves_like 'API V3 collection response', 2, 2, 'WorkPackage', 'WorkPackageCollection' do+ let(:elements) { [work_package1, work_package2] }+ end+ end+context 'if one project has not sufficient permissions' dolet(:role2) { create :role, permissions: %i(view_work_packages) }