2022-11-30 10:13:17 +01:00
|
|
|
|
class Profile::APITokenComponent < ApplicationComponent
|
2024-01-17 10:44:09 +01:00
|
|
|
|
def initialize(api_token:)
|
2022-11-30 10:13:17 +01:00
|
|
|
|
@api_token = api_token
|
|
|
|
|
end
|
2023-02-28 16:33:22 +01:00
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
2024-01-17 10:44:09 +01:00
|
|
|
|
def recently_used?
|
|
|
|
|
@api_token.last_used_at&.> 2.weeks.ago
|
2023-02-28 16:33:22 +01:00
|
|
|
|
end
|
|
|
|
|
|
2024-01-17 10:44:09 +01:00
|
|
|
|
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}"
|
2023-02-28 16:33:22 +01:00
|
|
|
|
end
|
2022-11-30 10:13:17 +01:00
|
|
|
|
end
|