From 90d7737338b93c55ceeac22321015a7fcdb63757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Mon, 16 Jan 2023 12:10:08 +0000 Subject: [PATCH] fix: SA unique token bug (#2901) Fixes a small bug on service account token creation where the tokens the new one was being validated against were not the most up-to-date ones. --- .../ServiceAccountCreateTokenDialog.tsx | 10 ++++------ .../ServiceAccountTokens/ServiceAccountTokens.tsx | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountCreateTokenDialog/ServiceAccountCreateTokenDialog.tsx b/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountCreateTokenDialog/ServiceAccountCreateTokenDialog.tsx index 94e6fcdf48a..be7da49971c 100644 --- a/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountCreateTokenDialog/ServiceAccountCreateTokenDialog.tsx +++ b/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountCreateTokenDialog/ServiceAccountCreateTokenDialog.tsx @@ -7,21 +7,21 @@ import { PersonalAPITokenForm, } from 'component/user/Profile/PersonalAPITokensTab/CreatePersonalAPIToken/PersonalAPITokenForm/PersonalAPITokenForm'; import { ICreatePersonalApiTokenPayload } from 'hooks/api/actions/usePersonalAPITokensApi/usePersonalAPITokensApi'; -import { IServiceAccount } from 'interfaces/service-account'; +import { IPersonalAPIToken } from 'interfaces/personalAPIToken'; const DEFAULT_EXPIRATION = ExpirationOption['30DAYS']; interface IServiceAccountCreateTokenDialogProps { open: boolean; setOpen: React.Dispatch>; - serviceAccount: IServiceAccount; + tokens: IPersonalAPIToken[]; onCreateClick: (newToken: ICreatePersonalApiTokenPayload) => void; } export const ServiceAccountCreateTokenDialog = ({ open, setOpen, - serviceAccount, + tokens, onCreateClick, }: IServiceAccountCreateTokenDialogProps) => { const [patDescription, setPatDescription] = useState(''); @@ -40,9 +40,7 @@ export const ServiceAccountCreateTokenDialog = ({ }, [open]); const isDescriptionUnique = (description: string) => - !serviceAccount.tokens?.some( - token => token.description === description - ); + !tokens?.some(token => token.description === description); const isPATValid = patDescription.length && diff --git a/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountTokens.tsx b/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountTokens.tsx index dfcd74c98e2..112ecbf14a9 100644 --- a/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountTokens.tsx +++ b/frontend/src/component/admin/serviceAccounts/ServiceAccountsTable/ServiceAccountModal/ServiceAccountTokens/ServiceAccountTokens.tsx @@ -322,7 +322,7 @@ export const ServiceAccountTokens = ({