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

Transformed StorageFile class into a struct

Andreas Pfohl572045ae5ace
diff --git a/modules/storages/app/models/storages/storage_file.rb b/modules/storages/app/models/storages/storage_file.rb
index 24e258d6deb..983c3c99a20 100644
--- a/modules/storages/app/models/storages/storage_file.rb
+++ b/modules/storages/app/models/storages/storage_file.rb
@@ -1,15 +1,51 @@
-class Storages::StorageFile
- attr_reader :id, :name, :size, :mime_type, :created_at, :last_modified_at, :created_by_name, :last_modified_by_name, :location
+#-- 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.
+#++
- def initialize(id, name, size, mime_type, created_at, last_modified_at, created_by_name, last_modified_by_name, location)
- @id = id
- @name = name
- @size = size
- @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
+module Storages
+ struct_name = 'StorageFile'
+
+ # rubocop:disable Nameing/ConstantName
+ StorageFile =
+ if Struct::const_defined?(struct_name)
+ Struct.const_get(struct_name)
+ else
+ Struct.new(
+ struct_name,
+ :id,
+ :name,
+ :file_size,
+ :mime_type,
+ :created_at,
+ :last_modified_at,
+ :created_by_name,
+ :last_modified_by_name,
+ :location
+ )
+ end
+ # rubocop:enable Nameing/ConstantName
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
index dde6f36c54d..47e21595584 100644
--- a/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
@@ -32,7 +32,7 @@ module API::V3::StorageFiles
property :id
property :name
- property :size
+ property :size, getter: ->(*) { file_size }
property :mime_type
date_time_property :created_at
date_time_property :last_modified_at
@@ -41,7 +41,7 @@ module API::V3::StorageFiles
property :location
def _type
- 'StorageFile'
+ Storages::StorageFile.class.to_s
end
end
end