Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…agement into feat/1179-bceid-login
  • Loading branch information
MCatherine1994 committed Mar 6, 2024
2 parents 0b5dc12 + 469c1e9 commit 61f6374
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 23 deletions.
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test-coverage": "vitest run --coverage"
},
"dependencies": {
"@bcgov-nr/nr-theme": "^1.8.4",
"@bcgov-nr/nr-theme": "^1.8.5",
"@carbon/icons-vue": "^10.72.1",
"aws-amplify": "^5.3.6",
"axios": "1.6.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ const props = defineProps({
userName: {
type: String,
required: true
},
customMsg: {
type: String,
required: false,
default: 'access'
}
});
</script>

<template>
<p>
Are you sure you want to remove
<strong>{{ props.role }}</strong> access to
<strong>{{ props.role }}</strong> {{ props.customMsg }} from
<strong>{{ props.userName }}</strong> in
<strong>{{ selectedApplicationDisplayText }}</strong>
</p>
Expand Down
30 changes: 27 additions & 3 deletions frontend/src/components/managePermissions/ManagePermissions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import type {
FamAppAdminGetResponse,
} from 'fam-admin-mgmt-api/model';
import {
deletAndRefreshUserRoleAssignments,
deleteAndRefreshUserRoleAssignments,
deleteAndRefreshApplicationAdmin,
fetchUserRoleAssignments,
fetchApplicationAdmins,
fetchDelegatedAdmins,
deleteAndRefreshDelegatedAdmin,
} from '@/services/fetchData';
import { Severity } from '@/enum/SeverityEnum';
import { IconSize } from '@/enum/IconEnum';
Expand Down Expand Up @@ -94,14 +95,14 @@ const deleteUserRoleAssignment = async (
assignment: FamApplicationUserRoleAssignmentGet
) => {
try {
userRoleAssignments.value = await deletAndRefreshUserRoleAssignments(
userRoleAssignments.value = await deleteAndRefreshUserRoleAssignments(
assignment.user_role_xref_id,
assignment.role.application_id
);
setNotificationMsg(
Severity.Success,
`You removed ${assignment.role.role_name} access to ${assignment.user.user_name}`
`You removed ${assignment.role.role_name} access from ${assignment.user.user_name}`
);
} catch (error: any) {
setNotificationMsg(
Expand All @@ -128,6 +129,26 @@ const deleteAppAdmin = async (admin: FamAppAdminGetResponse) => {
);
}
};
const deleteDelegatedAdminAssignment = async (
delegatedAdminAssignment: FamAccessControlPrivilegeGetResponse
) => {
try {
delegatedAdmins.value = await deleteAndRefreshDelegatedAdmin(
delegatedAdminAssignment.access_control_privilege_id
);
setNotificationMsg(
Severity.Success,
`You removed ${delegatedAdminAssignment.role.role_name} privilege from ${delegatedAdminAssignment.user.user_name}`
);
} catch (error: any) {
setNotificationMsg(
Severity.Error,
`An error has occured. ${error.response.data.detail.description}`
);
}
};
</script>

<template>
Expand Down Expand Up @@ -211,6 +232,9 @@ const deleteAppAdmin = async (admin: FamAppAdminGetResponse) => {
<DelegatedAdminTable
:loading="isLoading()"
:delegatedAdmins="delegatedAdmins || []"
@deleteDelegatedAdminAssignment="
deleteDelegatedAdminAssignment
"
/>
</TabPanel>
</TabView>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script setup lang="ts">
import { ref, type PropType } from 'vue';
import { ref, reactive, type PropType } from 'vue';
import { FilterMatchMode } from 'primevue/api';
import Column from 'primevue/column';
import DataTable from 'primevue/datatable';
import { useConfirm } from 'primevue/useconfirm';
import ConfirmDialog from 'primevue/confirmdialog';
import { routeItems } from '@/router/routeItem';
import {
Expand All @@ -11,8 +13,14 @@ import {
TABLE_ROWS_PER_PAGE,
} from '@/store/Constants';
import DataTableHeader from '@/components/managePermissions/table/DataTableHeader.vue';
import { IconSize } from '@/enum/IconEnum';
import type { FamAccessControlPrivilegeGetResponse } from 'fam-admin-mgmt-api/model';
type emit = (
e: 'deleteDelegatedAdminAssignment',
item: FamAccessControlPrivilegeGetResponse
) => void;
const props = defineProps({
loading: {
type: Boolean,
Expand Down Expand Up @@ -50,18 +58,45 @@ const delegatedAdminFilters = ref({
const delegatedAdminSearchChange = (newvalue: string) => {
delegatedAdminFilters.value.global.value = newvalue;
};
const confirm = useConfirm();
const emit = defineEmits<emit>();
const confirmDeleteData = reactive({
adminName: '',
role: '',
});
const deleteDelegatedAdmin = (
delegatedAdmin: FamAccessControlPrivilegeGetResponse
) => {
confirmDeleteData.adminName = delegatedAdmin.user.user_name;
confirmDeleteData.role = delegatedAdmin.role.parent_role
? delegatedAdmin.role.parent_role.role_name
: delegatedAdmin.role.role_name;
confirm.require({
group: 'deleteDelegatedAdmin',
header: 'Remove Privilege',
rejectLabel: 'Cancel',
acceptLabel: 'Remove',
accept: () => {
emit('deleteDelegatedAdminAssignment', delegatedAdmin);
},
});
};
</script>

<template>
<!-- Hidden until functionality is available
<ConfirmDialog group="deleteAdmin">
<ConfirmDialog group="deleteDelegatedAdmin">
<template #message>
<ConfirmDialogtext
:userName=""
:role=""
<ConfirmDialogText
:userName="confirmDeleteData.adminName"
:role="confirmDeleteData.role"
customMsg="privilege"
/>
</template>
</ConfirmDialog> -->
</ConfirmDialog>
<div class="data-table-container">
<div class="custom-data-table">
<DataTableHeader
Expand Down Expand Up @@ -127,12 +162,15 @@ const delegatedAdminSearchChange = (newvalue: string) => {
</Column>
<Column header="Action">
<template #body="{ data }">
<!-- Hidden until functionality is available
<button
class="btn btn-icon"
>
<Icon icon="edit" :size="IconSize.small"/>
</button> -->
<button
class="btn btn-icon"
@click="deleteDelegatedAdmin(data)"
>
<Icon
icon="trash-can"
:size="IconSize.small"
/>
</button>
</template>
</Column>
</DataTable>
Expand Down
19 changes: 18 additions & 1 deletion frontend/src/services/fetchData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AdminMgmtApiService,
} from '@/services/ApiServiceFactory';
import FamLoginUserState from '@/store/FamLoginUserState';
import { selectedApplicationId } from '@/store/ApplicationState';

// --- Fetching data (from backend)

Expand Down Expand Up @@ -43,7 +44,7 @@ export const fetchUserRoleAssignments = async (
* @param userRoleXrefId id to delete fam_user_role_assignment record.
* @param applicationId id to fetch and refresh fam_user_role_assignment records with the applicationId.
*/
export const deletAndRefreshUserRoleAssignments = async (
export const deleteAndRefreshUserRoleAssignments = async (
userRoleXrefId: number,
applicationId: number
): Promise<FamApplicationUserRoleAssignmentGet[]> => {
Expand Down Expand Up @@ -125,3 +126,19 @@ export const fetchDelegatedAdmins = async (
return delegatedAdmins;

};

/**
* This will call api to delete delegatedAdminPrivilege record from backend and fetch again
* to refresh the state.
* @param accessPrivilegegId id to delete delegated admin accesss record.
*/
export const deleteAndRefreshDelegatedAdmin = async (
accessPrivilegegId: number
): Promise<FamAccessControlPrivilegeGetResponse[]> => {
await AdminMgmtApiService.delegatedAdminApi.deleteAccessControlPrivilege(
accessPrivilegegId
);
// When deletion is successful, refresh (fetch) for frontend state.
return fetchDelegatedAdmins(selectedApplicationId.value);
};

0 comments on commit 61f6374

Please sign in to comment.