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 missing properties for storage file query
Andreas Pfohl17b33d699b00
diff --git a/docs/api/apiv3/paths/storage_files.yml b/docs/api/apiv3/paths/storage_files.ymlindex 24fae906cb2..61f4a3e25b3 100644--- a/docs/api/apiv3/paths/storage_files.yml+++ b/docs/api/apiv3/paths/storage_files.yml@@ -7,11 +7,11 @@ get:- File linksdescription: |-Gets a collection of files from a storage.-- If no `root` context is given, the result is the content of the document root. With `root` context given, the- result contains the collections of files from within the given root file id.-- If given `root` context is no directory, but a file, the collection contains this file as a single element.++ If no `parent` context is given, the result is the content of the document root. With `parent` context given, the+ result contains the collections of files/directories from within the given parent file id.++ If given `parent` context is no directory, `400 Bad Request` is returned.parameters:- name: iddescription: Storage id@@ -20,8 +20,8 @@ get:schema:type: integerexample: 1337- - name: root- description: Root file identification+ - name: parent+ description: Parent file identificationin: queryrequired: falseschema:@@ -34,6 +34,16 @@ get:application/hal+json:schema:$ref: '../components/schemas/file_collection_model.yml'+ '400':+ description: Returned if the given parent parameter value does not refer to a directory.+ content:+ application/hal+json:+ schema:+ $ref: '../components/schemas/error_response.yml'+ example:+ _type: Error+ errorIdentifier: urn:openproject-org:api:v3:errors:InvalidQuery+ message: The given parent is not a directory.'404':content:application/hal+json:diff --git a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.tsindex 0d51ea7f816..efdb14d42c0 100644--- a/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts+++ b/frontend/src/app/shared/components/file-links/storage-file-list-item/storage-file-list-item.component.ts@@ -87,10 +87,10 @@ export class StorageFileListItemComponent implements OnInit, AfterViewInit {return;}- if (this.storageFile.lastModifiedByName) {+ if (this.storageFile.createdByName) {this.principalRendererService.render(this.avatar.nativeElement,- { name: this.storageFile.lastModifiedByName, href: '/external_users/1' },+ { name: this.storageFile.createdByName, href: '/external_users/1' },{ hide: true, link: false },{ hide: false, size: 'mini' },);diff --git a/modules/storages/app/models/storages/storage_file.rb b/modules/storages/app/models/storages/storage_file.rbindex eca5853eacf..24e258d6deb 100644--- a/modules/storages/app/models/storages/storage_file.rb+++ b/modules/storages/app/models/storages/storage_file.rb@@ -1,9 +1,10 @@class Storages::StorageFile- attr_reader :id, :name, :mime_type, :created_at, :last_modified_at, :created_by_name, :last_modified_by_name, :location+ attr_reader :id, :name, :size, :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)+ 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@@ -11,48 +12,4 @@ class Storages::StorageFile@last_modified_by_name = last_modified_by_name@location = locationend-- 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 do |obj|- ::Storages::StorageFile.new(- obj[:id],- obj[:name],- obj[:mimeType],- nil,- obj[:lastModifiedAt],- nil,- obj[:lastModifiedByName],- obj[:location]- )- end- endenddiff --git a/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb b/modules/storages/lib/api/v3/storage_files/storage_file_representer.rbindex 37f25322c89..dde6f36c54d 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,6 +32,7 @@ module API::V3::StorageFilesproperty :idproperty :name+ property :sizeproperty :mime_typedate_time_property :created_atdate_time_property :last_modified_atdiff --git a/modules/storages/lib/api/v3/utilities/storage_interaction/nextcloud_storage_query.rb b/modules/storages/lib/api/v3/utilities/storage_interaction/nextcloud_storage_query.rbindex e4b804b7782..5f18441fa1f 100644--- a/modules/storages/lib/api/v3/utilities/storage_interaction/nextcloud_storage_query.rb+++ b/modules/storages/lib/api/v3/utilities/storage_interaction/nextcloud_storage_query.rb@@ -4,7 +4,7 @@ module API::V3::Utilities::StorageInteraction@uri = base_uri@token = token@token_refresh = token_refresh- @base_path = "/remote.php/dav/files/#{@token.origin_user_id}/"+ @base_path = "/remote.php/dav/files/#{@token.send('origin_user_id')}/"enddef files@@ -14,7 +14,7 @@ module API::V3::Utilities::StorageInteractionresult = @token_refresh.call doresponse = http.propfind(@base_path,- nil,+ requested_properties,{'Depth' => '1','Authorization' => "Bearer #{@token.access_token}"@@ -33,6 +33,23 @@ module API::V3::Utilities::StorageInteractionprivate+ def requested_properties+ Nokogiri::XML::Builder.new do |xml|+ xml['d'].propfind(+ 'xmlns:d' => 'DAV:',+ 'xmlns:oc' => 'http://owncloud.org/ns'+ ) do+ xml['d'].send('prop') do+ xml['oc'].send('fileid')+ xml['oc'].send('size')+ xml['d'].send('getcontenttype')+ xml['d'].send('getlastmodified')+ xml['oc'].send('owner-display-name')+ end+ end+ end.to_xml+ end+def parse_response(response)return response unless response.success@@ -46,40 +63,64 @@ module API::V3::Utilities::StorageInteractionname = name(file_element)::Storages::StorageFile.new(- nil,+ id(file_element),CGI.unescape(name),+ size(file_element),mime_type(file_element),nil,last_modified_at(file_element),- nil,+ created_by(file_element),nil,"/#{name}")end- def name(response)- response+ def id(element)+ element+ .xpath('.//oc:fileid')+ .map(&:inner_text)+ .reject(&:empty?)+ .first+ end++ def name(element)+ element.xpath('d:href')+ .map(&:inner_text).first- .inner_text.delete_prefix(@base_path).delete_suffix('/')end- def mime_type(response)- response- .xpath('.//d:getcontenttype')+ def size(element)+ element+ .xpath('.//oc:size')+ .map(&:inner_text)+ .map { |e| Integer(e) }.first- .inner_text- rescue NoMethodError- 'application/x-op-directory'end- def last_modified_at(response)- response+ def mime_type(element)+ element+ .xpath('.//d:getcontenttype')+ .map(&:inner_text)+ .reject(&:empty?)+ .first || 'application/x-op-directory'+ end++ def last_modified_at(element)+ element.xpath('.//d:getlastmodified').map { |e| DateTime.parse(e) }.firstend++ def created_by(element)+ element+ .xpath('.//oc:owner-display-name')+ .map(&:inner_text)+ .reject(&:empty?)+ .first+ endendend