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

[#40228] added get file link collection endpoint

Eric Schubert0e7bc8b4d94f
diff --git a/app/services/params_to_query_service.rb b/app/services/params_to_query_service.rb
index b8e479a4ace..0142ac128f7 100644
--- a/app/services/params_to_query_service.rb
+++ b/app/services/params_to_query_service.rb
@@ -133,7 +133,7 @@ class ParamsToQueryService
else
model_name = model.name
- "::Queries::#{model_name.pluralize}::#{model_name}Query".constantize
+ "::Queries::#{model_name.pluralize}::#{model_name.demodulize}Query".constantize
end
end
end
diff --git a/lib/api/v3/utilities/endpoints/index.rb b/lib/api/v3/utilities/endpoints/index.rb
index 6285d50881c..a7f24bff372 100644
--- a/lib/api/v3/utilities/endpoints/index.rb
+++ b/lib/api/v3/utilities/endpoints/index.rb
@@ -61,7 +61,7 @@ module API
if query.valid?
render_success(query,
request.params,
- request.api_v3_paths.send(self_path),
+ self_path.respond_to?(:call) ? request.instance_exec(&self_path) : request.api_v3_paths.send(self_path),
scope ? request.instance_exec(&scope) : model)
else
render_error(query)
diff --git a/modules/storages/app/models/queries/storages/file_links/file_link_query.rb b/modules/storages/app/models/queries/storages/file_links/file_link_query.rb
index e38709bf7c9..763f292693b 100644
--- a/modules/storages/app/models/queries/storages/file_links/file_link_query.rb
+++ b/modules/storages/app/models/queries/storages/file_links/file_link_query.rb
@@ -1 +1,7 @@
-class Queries::Storages::FileLinks::FileLinkQuery < Queries::BaseQuery; end
+class Queries::Storages::FileLinks::FileLinkQuery < Queries::BaseQuery
+ class << self
+ def model
+ @model ||= '::Storages::FileLink'.constantize
+ end
+ end
+end
diff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rb
index 8bd80cbc87e..1ee9cfff373 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb
@@ -37,12 +37,11 @@ module API
end
resources :file_links do
- # get &::API::V3::Utilities::Endpoints::Index
- # .new(model: ::Storages::FileLink, scope: -> { visible_file_links_scope })
- # .mount
- get do
- raise ::API::Errors::NotImplemented
- end
+ get &::API::V3::Utilities::Endpoints::Index
+ .new(model: ::Storages::FileLink,
+ scope: -> { visible_file_links_scope },
+ self_path: -> { api_v3_paths.file_links(params[:id]) })
+ .mount
post do
raise ::API::Errors::NotImplemented
diff --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.rb
index a14e63709db..f85fb4f408c 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
@@ -63,8 +63,16 @@ describe 'API v3 file links resource', type: :request do
get path
end
- it 'returns not implemented' do
- expect(subject.status).to be 501
+ it 'is successful' do
+ expect(subject.status).to be 200
+ end
+
+ context 'if user has not sufficient permissions' do
+ let(:permissions) { %i(view_work_packages) }
+
+ it_behaves_like 'API V3 collection response', 0, 0, 'FileLink', 'Collection' do
+ let(:elements) { [] }
+ end
end
end