Files
akkounts/app/components/rs_auth_component.rb
T
raucao 0b4bb21aa7
CI / Test (pull_request) Successful in 43s
Address review nits in the storage dashboard
- Move the app display name and a root-access helper onto
  RemoteStorageAuthorization, used by both components and the controller,
  removing the duplicated fallback chain and the unused OauthHelper includes
- Summarise the card's categories from the union of the app's authorizations'
  scopes, so an older token with broader access is not understated

Part of #254
2026-11-03 11:44:27 +04:00

35 lines
870 B
Ruby

# frozen_string_literal: true
class RsAuthComponent < ViewComponent::Base
def initialize(authorizations:)
@authorizations = authorizations
@auth = authorizations.first
@web_app = @auth.web_app
end
# The card summarises the app, so reflect the union of its authorizations'
# scopes (an older token may have broader access than the newest one).
def permissions
@authorizations.flat_map(&:permissions).uniq
end
def root_access?
(permissions & [":r", ":rw"]).any?
end
def category_summary
return "All categories and files" if root_access?
count = permissions.size
"#{count} #{'category'.pluralize(count)}"
end
def device_count
@authorizations.map { |auth| auth.device_name.presence || "Unknown device" }.uniq.size
end
def device_summary
"#{device_count} #{'device'.pluralize(device_count)}"
end
end