Skip to content

Commit

Permalink
feat(user): ajout last_login, documents_quota, documents_use, keys_qu…
Browse files Browse the repository at this point in the history
…ota et keys_use
  • Loading branch information
ocruze committed Dec 20, 2024
1 parent 833c514 commit cc5b0e6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
8 changes: 6 additions & 2 deletions assets/@types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ export type CartesUser = {
last_name?: string | null;
roles: string[];
communities_member: CommunityMemberDto[];
account_creation_date: string;
last_api_call_date: string;
account_creation_date?: string;
last_login_date?: string;
documents_quota?: number;
documents_use?: number;
keys_quota?: number;
keys_use?: number;
};

/** datastore */
Expand Down
2 changes: 1 addition & 1 deletion assets/entrepot/pages/users/me/Me.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Me = () => {
<p>{t("lastname", { lastName: user?.last_name ?? "" })}</p>
<p>{t("username", { userName: user?.user_name ?? "" })}</p>
<p>{t("email", { email: user.email })}</p>
<p>{t("registration_date", { date: formatDateFromISO(user.account_creation_date) })}</p>
{user.account_creation_date !== undefined && <p>{t("registration_date", { date: formatDateFromISO(user.account_creation_date) })}</p>}
<div className={fr.cx("fr-grid-row", "fr-grid-row--middle", "fr-mb-6v")}>
{t("id", { id: user.id })}
<Button
Expand Down
64 changes: 57 additions & 7 deletions src/Security/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class User implements UserInterface
/** @var array<mixed> */
private array $communitiesMember = [];

private \DateTimeInterface $accountCreationDate;
private \DateTimeInterface $lastApiCallDate;
private ?\DateTimeInterface $accountCreationDate;
private ?\DateTimeInterface $lastLoginDate;

private ?int $documentsQuota;
private ?int $documentsUse;
private ?int $keysQuota;
private ?int $keysUse;

/**
* @param array<mixed> $keycloakUserInfo
Expand All @@ -34,8 +39,29 @@ public function __construct(array $keycloakUserInfo = [], array $apiUserInfo = [
$this->lastName = $keycloakUserInfo['family_name'] ?? null;
$this->userName = $keycloakUserInfo['preferred_username'];

$this->accountCreationDate = new \DateTime($apiUserInfo['creation']);
$this->lastApiCallDate = new \DateTime($apiUserInfo['last_call']);
if (array_key_exists('creation', $apiUserInfo)) {
$this->accountCreationDate = new \DateTime($apiUserInfo['creation']);
}

if (array_key_exists('last_login', $apiUserInfo)) {
$this->lastLoginDate = new \DateTime($apiUserInfo['last_login']);
}

if (array_key_exists('documents_quota', $apiUserInfo)) {
$this->documentsQuota = $apiUserInfo['documents_quota'];
}

if (array_key_exists('documents_use', $apiUserInfo)) {
$this->documentsUse = $apiUserInfo['documents_use'];
}

if (array_key_exists('keys_quota', $apiUserInfo)) {
$this->keysQuota = $apiUserInfo['keys_quota'];
}

if (array_key_exists('keys_use', $apiUserInfo)) {
$this->keysUse = $apiUserInfo['keys_use'];
}

if (array_key_exists('communities_member', $apiUserInfo)) {
$this->communitiesMember = $apiUserInfo['communities_member'];
Expand Down Expand Up @@ -121,9 +147,29 @@ public function getAccountCreationDate(): ?\DateTimeInterface
return $this->accountCreationDate;
}

public function getLastApiCallDate(): ?\DateTimeInterface
public function getLastLoginDate(): ?\DateTimeInterface
{
return $this->lastLoginDate;
}

public function getDocumentsQuota(): ?int
{
return $this->documentsQuota;
}

public function getDocumentsUse(): ?int
{
return $this->documentsUse;
}

public function getKeysQuota(): ?int
{
return $this->keysQuota;
}

public function getKeysUse(): ?int
{
return $this->lastApiCallDate;
return $this->keysUse;
}

public static function getTestUser(): User
Expand All @@ -136,7 +182,7 @@ public static function getTestUser(): User
], [
'_id' => 'fc5a7948-142a-4dae-b24e-5550fe7183f9',
'creation' => '2023-06-26T11:52:25.924679Z',
'last_call' => '2023-08-01T14:09:41.074381Z',
'last_login' => '2023-08-01T14:09:41.074381Z',
'communities_member' => [[
'rights' => ['ANNEX', 'BROADCAST', 'PROCESSING', 'UPLOAD'],
'community' => [
Expand All @@ -148,6 +194,10 @@ public static function getTestUser(): User
'_id' => 'a0f47300-4c9b-464a-b23f-639ccfa6a673',
],
]],
'documents_quota' => 50000000,
'documents_use' => 0,
'keys_quota' => 1000,
'keys_use' => 3,
]);
}
}

0 comments on commit cc5b0e6

Please sign in to comment.