Skip to content

Commit

Permalink
Showing submission subsets based on IDP
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle1morel committed Nov 22, 2023
1 parent 558cafa commit 7620356
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
7 changes: 7 additions & 0 deletions app/src/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@ export const DEFAULTCORS = Object.freeze({
/** Set true to dynamically set Access-Control-Allow-Origin based on Origin */
origin: true
});

/** Current user authentication type */
export const IdentityProvider = Object.freeze({
IDIR: 'idir',
BCEID: 'bceidbasic',
BCEIDBUSINESS: 'bceidbusiness'
});
11 changes: 8 additions & 3 deletions app/src/controllers/chefs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { chefsService } from '../services';
import { isTruthy } from '../components/utils';
import { IdentityProvider } from '../components/constants';

import type { NextFunction, Request, Response } from 'express';
import type { JwtPayload } from 'jsonwebtoken';

const controller = {
exportSubmissions: async (req: Request, res: Response, next: NextFunction) => {
Expand All @@ -17,14 +19,17 @@ const controller = {
try {
const response = await chefsService.getFormSubmissions(req.params.formId);

if (isTruthy(req.query.filterToUser)) {
// IDIR users should be able to see all submissions
const filterToUser = (req.currentUser?.tokenPayload as JwtPayload).identity_provider !== IdentityProvider.IDIR;

if (isTruthy(filterToUser)) {
res
.status(200)
.send(
response.filter(
(x: any) =>
(x: { createdBy: string }) =>
x.createdBy.toUpperCase().substring(0, x.createdBy.indexOf('@idir')) ===
(req.currentUser?.tokenPayload as any).idir_username.toUpperCase()
(req.currentUser?.tokenPayload as JwtPayload).idir_username.toUpperCase()
)
);
} else {
Expand Down
1 change: 0 additions & 1 deletion app/src/services/chefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const service = {
exportSubmissions: async (formId: string) => {
try {
const response = await chefsAxios().get(`forms/${formId}/export`);
console.log(response);
return response.data;
} catch (e: unknown) {
throw e;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/services/chefsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export default {
* @function getFormSubmissions
* @returns {Promise} An axios response
*/
getFormSubmissions(formId: string, filterToUser: boolean = true) {
return appAxios().get(`chefs/forms/${formId}/submissions`, { params: { filterToUser } });
getFormSubmissions(formId: string) {
return appAxios().get(`chefs/forms/${formId}/submissions`);
},

/**
Expand Down
26 changes: 2 additions & 24 deletions frontend/src/views/SubmissionsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type { Ref } from 'vue';
const { getConfig } = storeToRefs(useConfigStore());
// State
const filterToUser: Ref<boolean> = ref(true);
const submissions: Ref<Array<any>> = ref([]);
// Datatable filter(s)
const filters = ref({
Expand All @@ -25,34 +24,13 @@ const filters = ref({
// Actions
onMounted(async () => {
const chefsConfig = getConfig.value.chefs;
submissions.value = (await chefsService.getFormSubmissions(chefsConfig.formId, filterToUser.value)).data;
});
watch(filterToUser, async () => {
const chefsConfig = getConfig.value.chefs;
submissions.value = (await chefsService.getFormSubmissions(chefsConfig.formId, filterToUser.value)).data;
submissions.value = (await chefsService.getFormSubmissions(chefsConfig.formId)).data;
});
</script>

<template>
<h1>Submissions</h1>

<div class="justify-content-left">
<div class="flex align-items-center">
<Checkbox
v-model="filterToUser"
input-id="filterToUser"
:binary="true"
/>
<label
for="filterToUser"
class="ml-2"
>
Filter to self
</label>
</div>
</div>

<div class="flex">
<div class="flex-grow-1">
<DataTable
Expand All @@ -67,7 +45,7 @@ watch(filterToUser, async () => {
paginator-template="RowsPerPageDropdown CurrentPageReport PrevPageLink NextPageLink "
current-page-report-template="{first}-{last} of {totalRecords}"
:rows-per-page-options="[10, 20, 50]"
:global-filter-fields="['name', 'value']"
:global-filter-fields="['confirmationId', 'createdBy']"
>
<template #empty>
<div class="flex justify-content-center">
Expand Down

0 comments on commit 7620356

Please sign in to comment.