From bef0ca3effaf2675cce93b4fe221a38d7f6a34ae Mon Sep 17 00:00:00 2001 From: NickSaglioni <117364634+NickSaglioni@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:08:17 -0300 Subject: [PATCH] fix: fixing bugs from previous 1059 task (#1192) Co-authored-by: Nicola Saglioni Co-authored-by: catherine meng --- .../components/grantaccess/GrantAccess.vue | 57 ++++----------- .../grantaccess/GrantApplicationAdmin.vue | 33 ++++----- .../components/grantaccess/StepContainer.vue | 6 +- .../grantaccess/form/UserDomainSelect.vue | 6 +- .../grantaccess/form/UserNameInput.vue | 8 +-- .../managePermissions/ManagePermissions.vue | 8 +-- frontend/src/enum/SeverityEnum.ts | 19 +++-- frontend/src/errors/FamCustomError.ts | 4 +- frontend/src/router/index.ts | 2 + frontend/src/router/routeHandlers.ts | 33 ++++++--- frontend/src/services/AuthService.ts | 30 +++++--- frontend/src/store/Constants.ts | 3 +- frontend/src/store/NotificationState.ts | 72 +++++++++++-------- frontend/src/store/ToastState.ts | 2 +- .../admin_management/api/app/utils/utils.py | 2 +- 15 files changed, 151 insertions(+), 134 deletions(-) diff --git a/frontend/src/components/grantaccess/GrantAccess.vue b/frontend/src/components/grantaccess/GrantAccess.vue index 8b1ce7941..887ba52a7 100644 --- a/frontend/src/components/grantaccess/GrantAccess.vue +++ b/frontend/src/components/grantaccess/GrantAccess.vue @@ -7,9 +7,8 @@ import { number, object, string } from 'yup'; import Button from '@/components/common/Button.vue'; import { IconSize } from '@/enum/IconEnum'; -import { Severity } from '@/enum/SeverityEnum'; +import { Severity, ErrorCode } from '@/enum/SeverityEnum'; import { AppActlApiService } from '@/services/ApiServiceFactory'; -import { selectedApplicationDisplayText } from '@/store/ApplicationState'; import { isLoading } from '@/store/LoadingState'; import { setGrantAccessNotificationMsg } from '@/store/NotificationState'; import { FOREST_CLIENT_INPUT_MAX_LENGTH } from '@/store/Constants'; @@ -21,6 +20,7 @@ import { import UserDomainSelect from '@/components/grantaccess/form/UserDomainSelect.vue'; import UserNameInput from '@/components/grantaccess/form/UserNameInput.vue'; import ForestClientInput from '@/components/grantaccess/form/ForestClientInput.vue'; +import { selectedApplicationDisplayText } from '@/store/ApplicationState'; const props = defineProps({ applicationRoleOptions: { @@ -120,11 +120,10 @@ const areVerificationsPassed = () => { const handleSubmit = async () => { const successForestClientIdList: string[] = []; - const warningForestClientIdList: string[] = []; // msg override the default error notification message const errorNotification = { - msg: '', + code: ErrorCode.Default, errorForestClientIdList: [] as string[], }; do { @@ -137,23 +136,20 @@ const handleSubmit = async () => { }) .catch((error) => { if (error.response?.status === 409) { - warningForestClientIdList.push(forestClientNumber || ''); + errorNotification.code = ErrorCode.Conflict; } else if ( error.response.data.detail.code === 'self_grant_prohibited' ) { - errorNotification.msg = - 'Granting roles to self is not allowed.'; - } else { - errorNotification.errorForestClientIdList.push( - forestClientNumber || '' - ); + errorNotification.code = ErrorCode.SelfGrantProhibited; } + errorNotification.errorForestClientIdList.push( + forestClientNumber || '' + ); }); } while (formData.value.verifiedForestClients.length > 0); composeAndPushNotificationMessages( successForestClientIdList, - warningForestClientIdList, errorNotification ); @@ -179,52 +175,34 @@ function toRequestPayload(formData: any, forestClientNumber: string) { const composeAndPushNotificationMessages = ( successIdList: string[], - warningIdList: string[], - errorMsg: { msg: string; errorForestClientIdList: string[] } + errorMsg: { code: string; errorForestClientIdList: string[] } ) => { const username = formData.value.userId.toUpperCase(); if (successIdList.length > 0) { setGrantAccessNotificationMsg( successIdList, username, - Severity.success, - getSelectedRole()?.role_name - ); - } - if (warningIdList.length > 0) { - setGrantAccessNotificationMsg( - warningIdList, - username, - Severity.warning, + Severity.Success, getSelectedRole()?.role_name ); } - - if (errorMsg.msg) { + if (errorMsg.errorForestClientIdList.length > 0) { setGrantAccessNotificationMsg( errorMsg.errorForestClientIdList, username, - Severity.error, + Severity.Error, getSelectedRole()?.role_name, - `An error has occured. ${errorMsg.msg}` - ); - } else if (errorMsg.errorForestClientIdList.length > 0) { - setGrantAccessNotificationMsg( - errorMsg.errorForestClientIdList, - username, - Severity.error, - getSelectedRole()?.role_name + errorMsg.code ); } return ''; }; - - diff --git a/frontend/src/components/grantaccess/GrantApplicationAdmin.vue b/frontend/src/components/grantaccess/GrantApplicationAdmin.vue index d6bee7cb0..97f135201 100644 --- a/frontend/src/components/grantaccess/GrantApplicationAdmin.vue +++ b/frontend/src/components/grantaccess/GrantApplicationAdmin.vue @@ -10,14 +10,14 @@ import type { FamAppAdminCreateRequest } from 'fam-admin-mgmt-api/model/fam-app- import type { FamApplicationGetResponse } from 'fam-admin-mgmt-api/model/fam-application-get-response'; import Button from '@/components/common/Button.vue'; import { IconSize } from '@/enum/IconEnum'; -import { Severity } from '@/enum/SeverityEnum'; +import { Severity, ErrorDescription } from '@/enum/SeverityEnum'; import { isLoading } from '@/store/LoadingState'; import { setNotificationMsg } from '@/store/NotificationState'; const defaultFormData = { userId: '', - application: Number, + application: null, }; const formData = ref(JSON.parse(JSON.stringify(defaultFormData))); // clone default input const formValidationSchema = object({ @@ -67,7 +67,7 @@ const handleSubmit = async () => { .createApplicationAdmin(data) .then(() => { setNotificationMsg( - Severity.success, + Severity.Success, `Admin privilege has been added to ${formData.value.userId.toUpperCase()} for application ${ formData.value.application.application_name }` @@ -76,20 +76,22 @@ const handleSubmit = async () => { .catch((error) => { if (error.response?.status === 409) { setNotificationMsg( - Severity.warning, - error.response.data.detail + Severity.Error, + `User ${formData.value.userId.toUpperCase()} is already a ${ + formData.value.application.application_name + } admin` ); } else if ( error.response.data.detail.code === 'self_grant_prohibited' ) { setNotificationMsg( - Severity.error, - 'Granting admin privilege to self is not allowed.' + Severity.Error, + ErrorDescription.SelfGrantProhibited ); } else { setNotificationMsg( - Severity.success, - `An error has occured. ${error.response.data.detail.description}` + Severity.Error, + `${ErrorDescription.Default} ${error.response.data.detail.description}` ); } }) @@ -101,7 +103,7 @@ const handleSubmit = async () => {