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

Fixed translation lookup for StorageRepresenter

Andreas Pfohl0acfcfd9eb54
diff --git a/modules/storages/lib/api/v3/storages/storage_authorizer.rb b/modules/storages/lib/api/v3/storages/storage_authorizer.rb
index 6d0a59c0d14..8bbb0328b01 100644
--- a/modules/storages/lib/api/v3/storages/storage_authorizer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_authorizer.rb
@@ -26,30 +26,15 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-# This class provides definitions for API routes and endpoints for the storages namespace. It inherits the
-# functionality from the Grape REST API framework. It is mounted in lib/api/v3/root.rb.
-# `modules/storages/lib/` is a defined root directory for grape, providing a root level look up for the namespaces.
-# Hence, the modules of the class have to be represented in the directory structure.
module API
module V3
module Storages
- URN_CONNECTION_CONNECTED = "#{::API::V3::URN_PREFIX}storages:authorization:Connected".freeze
- URN_CONNECTION_AUTH_FAILED = "#{::API::V3::URN_PREFIX}storages:authorization:FailedAuthorization".freeze
- URN_CONNECTION_ERROR = "#{::API::V3::URN_PREFIX}storages:authorization:Error".freeze
-
class StorageAuthorizer
class << self
def authorize(storage)
oauth_client = storage.oauth_client
connection_manager = ::OAuthClients::ConnectionManager.new(user: User.current, oauth_client:)
- case connection_manager.authorization_state
- when :connected
- URN_CONNECTION_CONNECTED
- when :failed_authorization
- URN_CONNECTION_AUTH_FAILED
- else
- URN_CONNECTION_ERROR
- end
+ connection_manager.authorization_state
end
end
end
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index 269140263af..ca3f3528ea9 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -33,6 +33,10 @@
module API
module V3
module Storages
+ URN_CONNECTION_CONNECTED = "#{::API::V3::URN_PREFIX}storages:authorization:Connected".freeze
+ URN_CONNECTION_AUTH_FAILED = "#{::API::V3::URN_PREFIX}storages:authorization:FailedAuthorization".freeze
+ URN_CONNECTION_ERROR = "#{::API::V3::URN_PREFIX}storages:authorization:Error".freeze
+
class StorageRepresenter < ::API::Decorators::Single
# LinkedResource module defines helper methods to describe attributes
include API::Decorators::LinkedResource
@@ -61,9 +65,18 @@ module API
link :authorizationState do
state = ::API::V3::Storages::StorageAuthorizer.authorize represented
- title = I18n.t(:"oauth_client.urn_connection_status.#{state.split(':').last}")
- { href: state, title: }
+ urn = case state
+ when :connected
+ URN_CONNECTION_CONNECTED
+ when :failed_authorization
+ URN_CONNECTION_AUTH_FAILED
+ else
+ URN_CONNECTION_ERROR
+ end
+ title = I18n.t(:"oauth_client.urn_connection_status.#{state}")
+
+ { href: urn, title: }
end
def _type
diff --git a/modules/storages/spec/features/show_file_links_spec.rb b/modules/storages/spec/features/show_file_links_spec.rb
index c18ffbd3d89..1ee03fd2db3 100644
--- a/modules/storages/spec/features/show_file_links_spec.rb
+++ b/modules/storages/spec/features/show_file_links_spec.rb
@@ -42,7 +42,7 @@ describe 'Showing of file links in work package', with_flag: { storages_module_a
before do
allow(::API::V3::Storages::StorageAuthorizer)
- .to receive(:authorize).and_return(::API::V3::Storages::URN_CONNECTION_CONNECTED)
+ .to receive(:authorize).and_return(:connected)
project_storage
file_link