demarches-normaliennes/app/components/profile/api_token_component.rb
simon lehericey b635c940ae refactor(UI api token): add more information to api token list
- network filtering
- validity
- last used

remove creation logic
2024-01-25 11:17:43 +01:00

32 lines
1,019 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Profile::APITokenComponent < ApplicationComponent
def initialize(api_token:)
@api_token = api_token
end
private
def recently_used?
@api_token.last_used_at&.> 2.weeks.ago
end
def autorizations
right = @api_token.write_access? ? 'lecture et écriture sur' : 'lecture seule sur'
scope = @api_token.full_access? ? 'toutes les démarches' : @api_token.procedures.map(&:libelle).join(', ')
sanitize("#{right} #{tag.b(scope)}")
end
def network_filtering
if @api_token.authorized_networks.present?
"filtrage : #{@api_token.authorized_networks_for_ui}"
else
tag.span('aucun filtrage réseau', class: 'fr-text-default--warning')
end
end
def use_and_expiration
use = @api_token.last_used_at.present? ? "utilisé il y a #{time_ago_in_words(@api_token.last_used_at)} - " : ""
expiration = @api_token.expires_at.present? ? "valable jusquʼau #{l(@api_token.expires_at, format: :long)}" : "valable indéfiniment"
"#{use} #{expiration}"
end
end