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

Added API endpoint representation for storage files

Andreas Pfohle4bde8fa829c
diff --git a/modules/storages/app/models/storages/storage_file.rb b/modules/storages/app/models/storages/storage_file.rb
new file mode 100644
index 00000000000..a4ad113cc42
--- /dev/null
+++ b/modules/storages/app/models/storages/storage_file.rb
@@ -0,0 +1,47 @@
+class Storages::StorageFile
+ attr_reader :id, :name, :mime_type, :created_at, :last_modified_at, :created_by_name, :last_modified_by_name, :location
+
+ def initialize(id, name, mime_type, created_at, last_modified_at, created_by_name, last_modified_by_name, location)
+ @id = id
+ @name = name
+ @mime_type = mime_type
+ @created_at = created_at
+ @last_modified_at = last_modified_at
+ @created_by_name = created_by_name
+ @last_modified_by_name = last_modified_by_name
+ @location = location
+ end
+
+ def self.all
+ [
+ {
+ id: 1,
+ name: 'image.png',
+ mimeType: 'image/png',
+ lastModifiedAt: '2022-09-16T12:00Z',
+ lastModifiedByName: 'Leia Organa',
+ location: '/data'
+ },
+ {
+ id: 2,
+ name: 'Readme.md',
+ mimeType: 'text/markdown',
+ lastModifiedAt: '2022-09-16T13:00Z',
+ lastModifiedByName: 'Anakin Skywalker',
+ location: '/data'
+ },
+ {
+ id: 3,
+ name: 'folder',
+ mimeType: 'application/x-op-directory',
+ location: '/data'
+ },
+ {
+ id: 4,
+ name: 'directory',
+ mimeType: 'application/x-op-directory',
+ location: '/data'
+ }
+ ].map { |obj| ::Storages::StorageFile.new(obj[:id], obj[:name], obj[:mimeType], nil, obj[:lastModifiedAt], nil, obj[:lastModifiedByName], obj[:location]) }
+ end
+end
diff --git a/modules/storages/lib/api/v3/storage_files/storage_file_collection_representer.rb b/modules/storages/lib/api/v3/storage_files/storage_file_collection_representer.rb
new file mode 100644
index 00000000000..96a6b9e77b6
--- /dev/null
+++ b/modules/storages/lib/api/v3/storage_files/storage_file_collection_representer.rb
@@ -0,0 +1,36 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module API
+ module V3
+ module StorageFiles
+ class StorageFileCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
+ end
+ end
+ end
+end
diff --git a/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb b/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
new file mode 100644
index 00000000000..d3a56c39054
--- /dev/null
+++ b/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
@@ -0,0 +1,50 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module API
+ module V3
+ module StorageFiles
+ class StorageFileRepresenter < ::API::Decorators::Single
+ include API::Decorators::DateProperty
+
+ property :id
+ property :name
+ property :mime_type
+ date_time_property :created_at
+ date_time_property :last_modified_at
+ property :created_by_name
+ property :last_modified_by_name
+ property :location
+
+ def _type
+ 'StorageFile'
+ end
+ end
+ end
+ end
+end
diff --git a/modules/storages/lib/api/v3/storages/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
similarity index 52%
rename from modules/storages/lib/api/v3/storages/storage_files_api.rb
rename to modules/storages/lib/api/v3/storage_files/storage_files_api.rb
index eeb3631cd65..e775b372a45 100644
--- a/modules/storages/lib/api/v3/storages/storage_files_api.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
@@ -28,47 +28,12 @@
module API
module V3
- module Storages
+ module StorageFiles
class StorageFilesAPI < ::API::OpenProjectAPI
resources :files do
get do
- {
- count: 4,
- total: 4,
- _embedded: {
- elements:
- [
- {
- id: 1,
- name: 'image.png',
- mimeType: 'image/png',
- lastModifiedAt: '2022-09-16T12:00Z',
- lastModifiedByName: 'Leia Organa',
- location: '/data'
- },
- {
- id: 2,
- name: 'Readme.md',
- mimeType: 'text/markdown',
- lastModifiedAt: '2022-09-16T13:00Z',
- lastModifiedByName: 'Anakin Skywalker',
- location: '/data'
- },
- {
- id: 3,
- name: 'folder',
- mimeType: 'application/x-op-directory',
- location: '/data'
- },
- {
- id: 4,
- name: 'directory',
- mimeType: 'application/x-op-directory',
- location: '/data'
- }
- ]
- }
- }
+ files = ::Storages::StorageFile.all
+ StorageFileCollectionRepresenter.new(files, self_link: api_v3_paths.storage_files(@storage.id), current_user:)
end
end
end
diff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rb
index 25e54c7b2d8..117a19e1bd2 100644
--- a/modules/storages/lib/api/v3/storages/storages_api.rb
+++ b/modules/storages/lib/api/v3/storages/storages_api.rb
@@ -60,7 +60,7 @@ module API
# route.
get &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::Storage).mount
- mount API::V3::Storages::StorageFilesAPI
+ mount API::V3::StorageFiles::StorageFilesAPI
end
end
end
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index 1107c78ddb8..e9e6629b779 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -103,6 +103,8 @@ module OpenProject::Storages
::Queries::Register.register(::Queries::Storages::FileLinks::FileLinkQuery) do
filter ::Queries::Storages::FileLinks::Filter::StorageFilter
end
+
+ #::Queries::Register.register(::Queries::Storages::StorageFiles::StorageFileQuery)
end
end
@@ -112,6 +114,10 @@ module OpenProject::Storages
"#{root}/storages/#{storage_id}"
end
+ add_api_path :storage_files do |storage_id|
+ "#{root}/storages/#{storage_id}/files"
+ end
+
add_api_path :file_links do |work_package_id|
"#{work_package(work_package_id)}/file_links"
end