Fixed translation lookup for StorageRepresenter

pull/10772/head
Andreas Pfohl 2 years ago
parent 278f907d24
commit 0acfcfd9eb
No known key found for this signature in database
GPG Key ID: FF58F3B771328EB4
  1. 17
      modules/storages/lib/api/v3/storages/storage_authorizer.rb
  2. 17
      modules/storages/lib/api/v3/storages/storage_representer.rb
  3. 2
      modules/storages/spec/features/show_file_links_spec.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

@ -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

@ -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

Loading…
Cancel
Save