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

- WIP - processed some ToDos

Frank Bergmannf150be551064
diff --git a/modules/storages/app/models/storages/file_link.rb b/modules/storages/app/models/storages/file_link.rb
index e3eec7ba579..84d90c9bd8e 100644
--- a/modules/storages/app/models/storages/file_link.rb
+++ b/modules/storages/app/models/storages/file_link.rb
@@ -38,9 +38,6 @@
# Additional attributes and constraints are defined in
# db/migrate/20220113144759_create_file_links.rb migration.
class Storages::FileLink < ApplicationRecord
- # Is this file shared with me in Nextcloud? This attribute is _not_ stored in the DB
- attr_accessor :origin_permission
-
# Every FileLink references its Storage. A "on delete cascade" is defined in
# the migration, so this FileLink will be deleted when deleting the Storage.
belongs_to :storage
@@ -59,6 +56,13 @@ class Storages::FileLink < ApplicationRecord
# origin_id is the Nextcloud ID of the file and should be valid.
validates :origin_id, presence: true
+ # Is this file shared with me in Nextcloud?
+ # This attribute is _not_ to be stored in the DB
+ attr_writer :origin_permission
+ def origin_permission
+ @origin_permission || nil
+ end
+
# A standard Rails custom query:
# https://www.rubyguides.com/2019/10/scopes-in-ruby-on-rails/
# Purpose: limit to FileLink visible by given user.
diff --git a/modules/storages/app/services/storages/file_link_sync_service.rb b/modules/storages/app/services/storages/file_link_sync_service.rb
index 6745491c1a4..9efc6d4ebde 100644
--- a/modules/storages/app/services/storages/file_link_sync_service.rb
+++ b/modules/storages/app/services/storages/file_link_sync_service.rb
@@ -41,13 +41,7 @@ class Storages::FileLinkSyncService
# @return ServiceResult with FileLinks in the result
def call(file_links)
@file_links = file_links
- # Reset permissions to nil (undefined) by default.
- # ToDo: Make nil default on the level of the model
- @file_links.each { |file_link| file_link.origin_permission = nil }
-
- # Group by storage_id, creating a hash { storage_id => [file_links] }
storage_file_link_hash = @file_links.group_by(&:storage_id)
-
storage_file_link_hash.each do |storage_id, storage_file_links|
# Add new types of storages here. We currently only support Nextcloud
sync_nextcloud(storage_id, storage_file_links)
@@ -101,7 +95,6 @@ class Storages::FileLinkSyncService
# "24" => { "status" => "Forbidden", "statuscode" => 403 }
# In case of completely deleted file or other errors we might also get:
# "24" = { "status" => "Not Found", "statuscode" => 404 }
- # ToDo: What happens if nothing at all or an empty hash comes back for an origin_file_id
def sync_single_file(file_link, origin_file_info_hash)
file_link.origin_mime_type = origin_file_info_hash["mimetype"]
file_link.origin_created_by_name = origin_file_info_hash["owner_name"]
diff --git a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb
index 37c82027cb8..fdebbdc83f6 100644
--- a/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb
+++ b/modules/storages/lib/api/v3/file_links/work_packages_file_links_api.rb
@@ -42,15 +42,11 @@ module API
reply_with_not_found_if_module_inactive
end
- # ToDo: Check race condition if two users try to get the same WP file_links?
-
# The `:resources` keyword defines the API namespace -> /api/v3/work_packages/:id/file_links/...
resources :file_links do
# Get the list of FileLinks related to a work package, with updated information from Nextcloud.
get do
- # API supports query filters on storages:
- # storage: { operator: '=', values: [storage_id]
- # ToDo: Check if ParamsToQueryService raises condition?
+ # API supports query filters on storages, for example { storage: { operator: '=', values: [storage_id] }
query = ParamsToQueryService
.new(::Storages::Storage,
current_user,
@@ -61,7 +57,6 @@ module API
message = I18n.t('api_v3.errors.missing_or_malformed_parameter')
raise ::API::Errors::InvalidQuery.new(message)
end
- # ToDo: Double-check that I've got this tested
# Get the list of all FileLinks for the work package.
# This could be a huge array in some cases...
@@ -84,8 +79,7 @@ module API
current_user:
)
rescue StandardError => e
- # ToDo: Check if API response handles exceptions like the one below (API.root)
- # There was an error during the SyncService, which should normally not occur.
+ # Example case: invalid oauth_client for storage raises invalid operation => 500
message = "#{I18n.t('api_v3.errors.code_500')}: #{e.message}"
raise ::API::Errors::InternalError.new(message)
end
diff --git a/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb b/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb
index 98c6d3b7e08..bcb1e3fc51a 100644
--- a/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb
+++ b/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb
@@ -136,7 +136,7 @@ describe 'API v3 file links resource', with_flag: { storages_module_active: true
file_link_trashed
file_link_deleted
- # FileLinks on host-unauth and host-error that we'll see in the result list with origin_permission=:error
+ # FileLinks on host-unauth and host-error that we'll see in the result list with origin_permission=:error
file_link_unauth_happy
file_link_error_happy
file_link_timeout_happy
@@ -173,13 +173,11 @@ describe 'API v3 file links resource', with_flag: { storages_module_active: true
.to_return(status: 200, headers: { 'Content-Type': 'application/json' }, body: response_host_happy)
# https://host-error/: Simulates a Nextcloud with network timeout
- stub_request(:post, host_error)
- .to_timeout
+ stub_request(:post, host_error).to_return(status: 500)
# ToDo: get_access_token against a timeout server produces a OAuth URL response, that's not really correct.
# https://host-timeout/: Simulates a Nextcloud with network timeout
- stub_request(:post, host_timeout)
- .to_timeout
+ stub_request(:post, host_timeout).to_timeout
# https://host-notoken/: Simulate a Nextcloud with no oauth_token yet
stub_request(:post, File.join(host_notoken, '/ocs/v1.php/apps/integration_openproject/filesinfo'))
@@ -225,17 +223,14 @@ describe 'API v3 file links resource', with_flag: { storages_module_active: true
expect(deleted_file_link).to be_nil
expect(::Storages::FileLink.where(origin_id: '27').any?).to be_falsey
- # The FileLink from a Nextcloud with timeout should have origin_permission=:error
+ # The FileLink from a Nextcloud with error should have origin_permission=:error
error_file_link = elements.detect { |e| e["originData"]["id"] == "29" }
expect(error_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_ERROR
- # ToDo: Check origin_error of #28, #29
-
- # ToDo: Search in elements for file_link with origin_id = '25' and check origin_permission = :not_authenticated
- # ToDo: Search for '24' and check for perms = :view
- # ToDo: Add trashed file_link
- # ToDo: Add deleted file_link (404)
+ # The FileLink from a Nextcloud with timeout should have origin_permission=:error
+ error_file_link = elements.detect { |e| e["originData"]["id"] == "30" }
+ expect(error_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_ERROR
end
- # it 'returns file_link1 with updated mtime' do expect(subject.status).to be 200 end
+ # ToDo: it 'returns file_link1 with updated mtime' do expect(subject.status).to be 200 end
end
end