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

Merge remote-tracking branch 'origin/dev' into implementation/45520-show-folder-without-create-permission-as-inactive

Andreas Pfohl735d407f175b
diff --cc modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
index ffdd5d4fd84,ffdd5d4fd84..373632b37dc
--- a/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
+++ b/modules/storages/app/common/storages/peripherals/storage_interaction/nextcloud/files_query.rb
@@@ -75,6 -75,6 +75,7 @@@ module Storages::Peripherals::StorageIn
xml['oc'].size
xml['d'].getcontenttype
xml['d'].getlastmodified
++ xml['oc'].permissions
xml['oc'].send('owner-display-name')
end
end
@@@ -121,7 -121,7 +122,8 @@@
last_modified_at(file_element),
created_by(file_element),
nil,
-- location
++ location,
++ permissions(file_element)
)
end
@@@ -176,5 -176,5 +178,21 @@@
.reject(&:empty?)
.first
end
++
++ def permissions(element)
++ permissions_string =
++ element
++ .xpath('.//oc:permissions')
++ .map(&:inner_text)
++ .reject(&:empty?)
++ .first
++
++ # Nextcloud Dav permissions:
++ # https://github.com/nextcloud/server/blob/66648011c6bc278ace57230db44fd6d63d67b864/lib/public/Files/DavUtil.php
++ result = []
++ result << :readable if permissions_string.include?('G')
++ result << :writeable if %w[CK W].reduce(false) { |s, v| s || permissions_string.include?(v) }
++ result
++ end
end
end
diff --cc modules/storages/app/models/storages/storage_file.rb
index 84c44684dc2,84c44684dc2..c2d3edde008
--- a/modules/storages/app/models/storages/storage_file.rb
+++ b/modules/storages/app/models/storages/storage_file.rb
@@@ -27,9 -27,9 +27,11 @@@
#++
class Storages::StorageFile
-- attr_reader :id, :name, :size, :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, :permissions
-- def initialize(id, name, size, 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, permissions)
@id = id
@name = name
@size = size
@@@ -39,5 -39,5 +41,6 @@@
@created_by_name = created_by_name
@last_modified_by_name = last_modified_by_name
@location = location
++ @permissions = permissions
end
end
diff --cc modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
index 08fd307dcae,08fd307dcae..6f710aebc1d
--- a/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_file_representer.rb
@@@ -43,6 -43,6 +43,7 @@@ module API::V3::StorageFile
property :created_by_name
property :last_modified_by_name
property :location
++ property :permissions
def _type
Storages::StorageFile.name.split('::').last
diff --cc modules/storages/spec/common/peripherals/storage_requests_spec.rb
index 8af4da420e7,efdf53ea1eb..da4fa86596b
--- a/modules/storages/spec/common/peripherals/storage_requests_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_requests_spec.rb
@@@ -37,9 -37,9 +37,9 @@@ describe Storages::Peripherals::Storage
let(:origin_user_id) { 'admin' }
let(:storage) do
-- storage = instance_double(::Storages::Storage)
++ storage = instance_double(Storages::Storage)
allow(storage).to receive(:oauth_client).and_return(instance_double(OAuthClient))
-- allow(storage).to receive(:provider_type).and_return(::Storages::Storage::PROVIDER_TYPE_NEXTCLOUD)
++ allow(storage).to receive(:provider_type).and_return(Storages::Storage::PROVIDER_TYPE_NEXTCLOUD)
allow(storage).to receive(:host).and_return(url)
storage
end
@@@ -52,7 -52,7 +52,7 @@@
end
let(:connection_manager) do
-- connection_manager = instance_double(::OAuthClients::ConnectionManager)
++ connection_manager = instance_double(OAuthClients::ConnectionManager)
allow(connection_manager).to receive(:get_access_token).and_return(ServiceResult.success(result: token))
allow(connection_manager).to receive(:request_with_token_refresh).and_yield(token)
connection_manager
@@@ -92,7 -92,7 +92,7 @@@
end
before do
-- allow(::OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
++ allow(OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
stub_request(:post, "#{url}/ocs/v2.php/apps/dav/api/v1/direct")
.to_return(status: 200, body: json, headers: {})
end
@@@ -187,7 -187,7 +187,7 @@@
let(:xml) { create(:webdav_data) }
before do
-- allow(::OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
++ allow(OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
stub_request(:propfind, "#{url}/remote.php/dav/files/#{origin_user_id}")
.to_return(status: 207, body: xml, headers: {})
end
@@@ -200,7 -200,7 +200,7 @@@
on_success: ->(query) do
result = query.call(nil)
expect(result).to be_success
-- expect(result.result.size).to eq(3)
++ expect(result.result.size).to eq(4)
end,
on_failure: ->(error) do
raise "Files query could not be created: #{error}"
@@@ -225,6 -225,6 +225,50 @@@
)
end
++ it 'must return directories with permissions' do
++ subject
++ .files_query(user:)
++ .match(
++ on_success: ->(query) do
++ result = query.call(nil)
++ expect(result).to be_success
++
++ expect(result.result[0].mime_type).to eq('application/x-op-directory')
++ expect(result.result[0].permissions).to include(:readable)
++ expect(result.result[0].permissions).to include(:writeable)
++
++ expect(result.result[1].mime_type).to eq('application/x-op-directory')
++ expect(result.result[1].permissions).to include(:readable)
++ expect(result.result[1].permissions).not_to include(:writeable)
++ end,
++ on_failure: ->(error) do
++ raise "Files query could not be created: #{error}"
++ end
++ )
++ end
++
++ it 'must return files with permissions' do
++ subject
++ .files_query(user:)
++ .match(
++ on_success: ->(query) do
++ result = query.call(nil)
++ expect(result).to be_success
++
++ expect(result.result[2].mime_type).to eq('text/markdown')
++ expect(result.result[2].permissions).to include(:readable)
++ expect(result.result[2].permissions).to include(:writeable)
++
++ expect(result.result[3].mime_type).to eq('application/pdf')
++ expect(result.result[3].permissions).to include(:readable)
++ expect(result.result[3].permissions).not_to include(:writeable)
++ end,
++ on_failure: ->(error) do
++ raise "Files query could not be created: #{error}"
++ end
++ )
++ end
++
it 'must return a named file' do
subject
.files_query(user:)
@@@ -232,9 -232,9 +276,9 @@@
on_success: ->(query) do
result = query.call(nil)
expect(result).to be_success
-- expect(result.result[1].name).to eq('README.md')
-- expect(result.result[1].mime_type).to eq('text/markdown')
-- expect(result.result[1].id).to eq('12')
++ expect(result.result[2].name).to eq('README.md')
++ expect(result.result[2].mime_type).to eq('text/markdown')
++ expect(result.result[2].id).to eq('12')
end,
on_failure: ->(error) do
raise "Files query could not be created: #{error}"
@@@ -323,7 -323,7 +367,7 @@@
let(:share_id) { 37 }
before do
-- allow(::OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
++ allow(OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)
stub_request(:post, "#{url}/ocs/v2.php/apps/files_sharing/api/v1/shares")
.with(
body: hash_including(
diff --cc modules/storages/spec/factories/webdav_data_factory.rb
index 3667249de56,3667249de56..d1091b848d1
--- a/modules/storages/spec/factories/webdav_data_factory.rb
+++ b/modules/storages/spec/factories/webdav_data_factory.rb
@@@ -45,6 -45,6 +45,7 @@@ FactoryBot.define d
xml['oc'].fileid('6')
xml['oc'].size('20028269')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:27:36 GMT')
++ xml['oc'].permissions('RGDNVCK')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -63,6 -63,6 +64,26 @@@
xml['oc'].fileid('11')
xml['oc'].size('6592')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:31:26 GMT')
++ xml['oc'].permissions('RGDNVCK')
++ xml['oc'].send('owner-display-name', 'admin')
++ end
++ xml['d'].status('HTTP/1.1 200 OK')
++ end
++ xml['d'].propstat do
++ xml['d'].prop do
++ xml['d'].getcontenttype
++ end
++ xml['d'].status('HTTP/1.1 404 Not Found')
++ end
++ end
++ xml['d'].response do
++ xml['d'].href('/remote.php/dav/files/admin/Folder2/')
++ xml['d'].propstat do
++ xml['d'].prop do
++ xml['oc'].fileid('20')
++ xml['oc'].size('8592')
++ xml['d'].getlastmodified('Fri, 28 Oct 2022 14:43:26 GMT')
++ xml['oc'].permissions('RGDNV')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -82,6 -82,6 +103,7 @@@
xml['oc'].size('1024')
xml['d'].getcontenttype('text/markdown')
xml['d'].getlastmodified('Thu, 14 Jul 2022 08:42:15 GMT')
++ xml['oc'].permissions('RGDNVW')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -95,6 -95,6 +117,7 @@@
xml['oc'].size('12706214')
xml['d'].getcontenttype('application/pdf')
xml['d'].getlastmodified('Thu, 14 Jul 2022 08:42:15 GMT')
++ xml['oc'].permissions('RGDNV')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -123,6 -123,6 +146,7 @@@
xml['oc'].fileid('11')
xml['oc'].size('6592')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:31:26 GMT')
++ xml['oc'].permissions('RGDNVCK')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -142,6 -142,6 +166,7 @@@
xml['oc'].size('2048')
xml['d'].getcontenttype('image/png')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:31:26 GMT')
++ xml['oc'].permissions('RGDNVW')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -155,6 -155,6 +180,7 @@@
xml['oc'].size('22736218')
xml['d'].getcontenttype('audio/ogg')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:31:26 GMT')
++ xml['oc'].permissions('RGDNVW')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
@@@ -168,6 -168,6 +194,7 @@@
xml['oc'].size('128')
xml['d'].getcontenttype('text/plain')
xml['d'].getlastmodified('Fri, 28 Oct 2022 14:31:26 GMT')
++ xml['oc'].permissions('RGDNVW')
xml['oc'].send('owner-display-name', 'admin')
end
xml['d'].status('HTTP/1.1 200 OK')
diff --cc modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
index 48f6ba06916,02a1703510b..2bd672de401
--- a/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
+++ b/modules/storages/spec/requests/api/v3/storages/storage_files_spec.rb
@@@ -65,9 -65,9 +65,9 @@@ describe 'API v3 storage files', conten
let(:files) do
[
Storages::StorageFile.new(1, 'new_younglings.md', 4096, 'plain/text', DateTime.now, DateTime.now,
-- 'Obi-Wan Kenobi', 'Obi-Wan Kenobi', '/'),
++ 'Obi-Wan Kenobi', 'Obi-Wan Kenobi', '/', %i[readable]),
Storages::StorageFile.new(2, 'holocron_inventory.md', 4096, 'plain/text', DateTime.now, DateTime.now,
-- 'Obi-Wan Kenobi', 'Obi-Wan Kenobi', '/')
++ 'Obi-Wan Kenobi', 'Obi-Wan Kenobi', '/', %i[readable writeable])
]
end
@@@ -88,6 -88,6 +88,9 @@@
it { is_expected.to be_json_eql(files[0].name.to_json).at_path('_embedded/elements/0/name') }
it { is_expected.to be_json_eql(files[1].id.to_json).at_path('_embedded/elements/1/id') }
it { is_expected.to be_json_eql(files[1].name.to_json).at_path('_embedded/elements/1/name') }
++
++ it { is_expected.to be_json_eql(files[0].permissions.to_json).at_path('_embedded/elements/0/permissions') }
++ it { is_expected.to be_json_eql(files[1].permissions.to_json).at_path('_embedded/elements/1/permissions') }
end
describe 'with files query creation failed' do