- Rework RsAuthComponent into a card that shows the app, its device, an access summary and the permission status - Group connected apps by app and device, so repeated authorizations for the same app and device (e.g. after a browser update) are shown together, each with its own revoke action - Add RsAuthDetailsModalComponent with the full scope list, device, connected tokens and permission expiry, plus Launch and Revoke actions (built on the existing ModalComponent) - Add RemoteStorageAuthorization#device_name (parsed from the user agent) and #expired? Part of #254
42 lines
879 B
Ruby
42 lines
879 B
Ruby
# frozen_string_literal: true
|
|
|
|
class RsAuthComponent < ViewComponent::Base
|
|
include OauthHelper
|
|
|
|
def initialize(authorizations:)
|
|
@authorizations = authorizations
|
|
@auth = authorizations.first
|
|
@web_app = @auth.web_app
|
|
end
|
|
|
|
def name
|
|
@web_app&.name.presence || @auth.app_name.presence || @auth.client_id
|
|
end
|
|
|
|
def root_access?
|
|
(@auth.permissions & [":r", ":rw"]).any?
|
|
end
|
|
|
|
def scope_summary
|
|
return "All folders and files" if root_access?
|
|
|
|
count = @auth.permissions.size
|
|
"#{count} #{'folder'.pluralize(count)}"
|
|
end
|
|
|
|
def device_name
|
|
@auth.device_name.presence || "Unknown device"
|
|
end
|
|
|
|
def expiry_label
|
|
return "Never expires" if @auth.expire_at.blank?
|
|
return "Expired" if @auth.expired?
|
|
|
|
"Expires #{@auth.expire_at.strftime('%-d %b %Y')}"
|
|
end
|
|
|
|
def multiple_authorizations?
|
|
@authorizations.size > 1
|
|
end
|
|
end
|