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
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.rbnew file mode 100644index 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+enddiff --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.rbnew file mode 100644index 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+enddiff --git a/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb b/modules/storages/lib/api/v3/storage_files/storage_file_representer.rbnew file mode 100644index 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+enddiff --git a/modules/storages/lib/api/v3/storages/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rbsimilarity index 52%rename from modules/storages/lib/api/v3/storages/storage_files_api.rbrename to modules/storages/lib/api/v3/storage_files/storage_files_api.rbindex 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 APImodule V3- module Storages+ module StorageFilesclass StorageFilesAPI < ::API::OpenProjectAPIresources :files doget 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:)endendenddiff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rbindex 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::StorageFilesAPIendendenddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 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) dofilter ::Queries::Storages::FileLinks::Filter::StorageFilterend++ #::Queries::Register.register(::Queries::Storages::StorageFiles::StorageFileQuery)endend@@ -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