Skip to content

Commit

Permalink
fix: fixing bugs from previous 1059 task (#1192)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Saglioni <[email protected]>
Co-authored-by: catherine meng <[email protected]>
  • Loading branch information
3 people authored Feb 9, 2024
1 parent dee5998 commit bef0ca3
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 134 deletions.
57 changes: 15 additions & 42 deletions frontend/src/components/grantaccess/GrantAccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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: {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
);
Expand All @@ -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 '';
};
</script>

<template>
<PageTitle
title="Add user permission"
subtitle="Add a new permission to a user. All fields are mandatory unless noted"
:subtitle="`Adding user permission to ${selectedApplicationDisplayText}. All fields are mandatory`"
/>
<VeeForm
ref="form"
Expand All @@ -234,10 +212,7 @@ const composeAndPushNotificationMessages = (
>
<div class="page-body">
<form id="grantAccessForm" class="form-container">
<StepContainer
title="User information"
:subtitle="`Enter the user information to add a new user to ${selectedApplicationDisplayText}`"
>
<StepContainer title="User information">
<UserDomainSelect
:domain="formData.domain"
@change="userDomainChange"
Expand All @@ -252,7 +227,6 @@ const composeAndPushNotificationMessages = (

<StepContainer
title="Add user roles"
subtitle="Enter a specific role for this user"
:divider="isAbstractRoleSelected()"
>
<label>Assign a role to the user</label>
Expand Down Expand Up @@ -328,4 +302,3 @@ const composeAndPushNotificationMessages = (
</div>
</VeeForm>
</template>
<style lang="scss" scoped></style>
33 changes: 14 additions & 19 deletions frontend/src/components/grantaccess/GrantApplicationAdmin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
}`
Expand All @@ -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}`
);
}
})
Expand All @@ -101,7 +103,7 @@ const handleSubmit = async () => {
<template>
<PageTitle
title="Add application admin"
subtitle="Add a new application admin. All fields are mandatory unless noted"
subtitle="All fields are mandatory"
/>
<VeeForm
ref="form"
Expand All @@ -111,18 +113,11 @@ const handleSubmit = async () => {
>
<div class="page-body">
<form id="grantAdminForm" class="form-container">
<StepContainer
title="User information"
:subtitle="`Enter the user information to add a new admin ${
formData.application
? 'to ' + formData.application.application_name
: ''
}`"
>
<StepContainer title="User information">
<UserNameInput
:domain="UserType.I"
:userId="formData.userId"
helper-text="Only IDIR usernames are allowed"
helper-text="Only IDIR users are allowed to be added as application admins"
@change="userIdChange"
@setVerifyResult="setVerifyUserIdPassed"
/>
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/grantaccess/StepContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const props = defineProps({
},
subtitle: {
type: String,
required: true,
required: false,
},
divider: {
type: Boolean,
Expand All @@ -18,8 +18,8 @@ const props = defineProps({
<template>
<div>
<h1 class="title">{{ props.title }}</h1>
<h2 class="subtitle">{{ props.subtitle }}</h2>
<div class="step-content">
<h2 v-if="subtitle" class="subtitle">{{ props.subtitle }}</h2>
<div :class="subtitle ? 'step-content' : ''">
<slot />
</div>
<Divider v-if="props.divider" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ const computedDomain = computed({
</div>
</div>
</template>
<style lang="scss" scoped></style>
<style lang="scss" scoped>
label {
margin-bottom: 0px;
}
</style>
8 changes: 2 additions & 6 deletions frontend/src/components/grantaccess/form/UserNameInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ const props = defineProps({
domain: { type: String, required: true },
userId: { type: String, default: '' },
fieldId: { type: String, default: 'userId' },
helperText: {
type: String,
default: 'Enter and verify the username for this user',
},
helperText: { type: String },
});
const emit = defineEmits(['change', 'setVerifyResult']);
Expand Down Expand Up @@ -58,7 +55,6 @@ watch(
resetVerifiedUserIdentity();
}
);
</script>

<template>
Expand Down Expand Up @@ -89,7 +85,7 @@ watch(
<small
id="userIdInput-helper"
class="helper-text"
v-if="!errorMessage"
v-if="helperText && !errorMessage"
>{{ helperText }}</small
>
<ErrorMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ const deleteUserRoleAssignment = async (
);
setNotificationMsg(
Severity.success,
Severity.Success,
`You removed ${assignment.role.role_name} access to ${assignment.user.user_name}`
);
} catch (error: any) {
setNotificationMsg(
Severity.error,
Severity.Error,
`An error has occured. ${error.response.data.detail.description}`
);
}
Expand All @@ -93,12 +93,12 @@ const deleteAppAdmin = async (admin: FamAppAdminGetResponse) => {
);
setNotificationMsg(
Severity.success,
Severity.Success,
`You removed ${admin.user.user_name}'s admin privilege`
);
} catch (error: any) {
setNotificationMsg(
Severity.error,
Severity.Error,
`An error has occured. ${error.response.data.detail.description}`
);
}
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/enum/SeverityEnum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
export enum Severity {
success = 'success',
warning = 'warn',
error = 'error',
}
Success = 'success',
Warning = 'warn',
Error = 'error',
}

export enum ErrorCode {
Conflict = 'Conflict',
SelfGrantProhibited = 'SelfGrantProhibited',
Default = 'Default',
}

export const ErrorDescription = {
SelfGrantProhibited: 'Granting admin privilege to self is not allowed.',
Default: 'An error has occured.',
}
4 changes: 2 additions & 2 deletions frontend/src/errors/FamCustomError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class FamCustomError extends Error {
export enum RouteErrorName {
NOT_AUTHENTICATED_ERROR = 'NOT_AUTHENTICATED_ERROR',
NO_APPLICATION_SELECTED_ERROR = 'NO_APPLICATION_SELECTED_ERROR',
NOT_FAM_ADMIN = "NOT_FAM_ADMIN"
ACCESS_RESTRICTED = "ACCESS_RESTRICTED"
}

type RouteInfo = {to: any, from: any};
type RouteInfo = { to: any, from: any };
/**
* FAM custom route error.
* For use only when needing to throw during router transition.
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import GrantAccessView from '@/views/GrantAccessView.vue';
import GrantApplicationAdminView from '@/views/GrantApplicationAdminView.vue';
import LandingView from '@/views/LandingView.vue';
import ManagePermissionsView from '@/views/ManagePermissionsView.vue';
import { FAM_ADMIN_ROLE } from '@/store/Constants';

// WARNING: any components referenced below that themselves reference the router cannot be automatically hot-reloaded in local development due to circular dependency
// See vitejs issue https://github.com/vitejs/vite/issues/3033 for discussion.
Expand Down Expand Up @@ -91,6 +92,7 @@ const routes = [
meta: {
requiresAuth: true,
requiresAppSelected: true,
requiredPrivileges: [FAM_ADMIN_ROLE],
title: routeItems.grantAppAdmin.label,
layout: 'ProtectedLayout',
hasBreadcrumb: true,
Expand Down
Loading

0 comments on commit bef0ca3

Please sign in to comment.