Skip to content

Commit

Permalink
Added filter for self submissions
Browse files Browse the repository at this point in the history
User can view specifically their own submissions

Resolves: #462
  • Loading branch information
jasonchung1871 authored and bcgov-citz-ccft committed Nov 25, 2022
1 parent 5d8c750 commit b3fa38a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
18 changes: 16 additions & 2 deletions app/frontend/src/components/forms/SubmissionsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@

<v-row no-gutters>
<v-spacer />
<v-col cols="12" sm="8">
<v-col cols="4" sm="4">
<v-checkbox
class="pl-3"
v-model="deletedOnly"
label="Show deleted submissions"
@click="refreshSubmissions"
/>
</v-col>
<v-col cols="4" sm="4">
<v-checkbox
class="pl-3"
v-model="currentUserOnly"
label="Show my submissions"
@click="refreshSubmissions"
/>
</v-col>
<v-col cols="12" sm="4">
<!-- search input -->
<div class="submissions-search">
Expand All @@ -57,6 +65,8 @@
</div>
</v-col>
</v-row>
<v-row no-gutters>
</v-row>

<!-- table header -->
<v-data-table
Expand Down Expand Up @@ -153,6 +163,7 @@ export default {
data() {
return {
deletedOnly: false,
currentUserOnly: false,
loading: true,
restoreItem: {},
search: '',
Expand All @@ -168,6 +179,9 @@ export default {
'submissionList',
'userFormPreferences',
]),
...mapGetters('auth', [
'user'
]),
checkFormManage() {
return this.permissions.some((p) => FormManagePermissions.includes(p));
Expand Down Expand Up @@ -249,7 +263,7 @@ export default {
// Get user prefs for this form
await this.getFormPreferencesForCurrentUser(this.formId);
// Get the submissions for this form
await this.fetchSubmissions({ formId: this.formId, deletedOnly: this.deletedOnly });
await this.fetchSubmissions({ formId: this.formId, deletedOnly: this.deletedOnly, createdBy: (this.currentUserOnly) ? `${this.user.username}@${this.user.idp}` : '' });
// Build up the list of forms for the table
if (this.submissionList) {
const tableRows = this.submissionList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export default {
},
computed: {
...mapGetters('form', ['form', 'submissionList', 'permissions']),
...mapGetters('auth', [
'user'
]),
headers() {
let headers = [
{ text: 'Confirmation Id', align: 'start', value: 'confirmationId' },
Expand Down Expand Up @@ -179,7 +182,7 @@ export default {
async populateSubmissionsTable() {
this.loading = true;
// Get the submissions for this form
await this.fetchSubmissions({ formId: this.formId, userView: true });
await this.fetchSubmissions({ formId: this.formId, userView: true, createdBy: `${this.user.username}@${this.user.idp}` });
// Build up the list of forms for the table
if (this.submissionList) {
const tableRows = this.submissionList.map((s) => {
Expand Down
4 changes: 2 additions & 2 deletions app/frontend/src/store/modules/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,15 @@ export default {
}, { root: true });
}
},
async fetchSubmissions({ commit, dispatch, state }, { formId, userView, deletedOnly = false }) {
async fetchSubmissions({ commit, dispatch, state }, { formId, userView, deletedOnly = false, createdBy = '' }) {
try {
commit('SET_SUBMISSIONLIST', []);
// Get list of active submissions for this form (for either all submissions, or just single user)
const fields = state.userFormPreferences &&
state.userFormPreferences.preferences ? state.userFormPreferences.preferences.columnList : undefined;
const response = userView
? await rbacService.getUserSubmissions({ formId: formId })
: await formService.listSubmissions(formId, { deleted: deletedOnly, fields: fields });
: await formService.listSubmissions(formId, { deleted: deletedOnly, fields: fields, createdBy: createdBy });
commit('SET_SUBMISSIONLIST', response.data);
} catch (error) {
dispatch('notifications/addNotification', {
Expand Down
6 changes: 3 additions & 3 deletions app/frontend/tests/unit/store/modules/form.actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('form actions', () => {
expect(mockStore.commit).toHaveBeenCalledTimes(2);
expect(mockStore.commit).toHaveBeenCalledWith('SET_SUBMISSIONLIST', expect.any(Array));
expect(formService.listSubmissions).toHaveBeenCalledTimes(1);
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false });
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false, 'createdBy': '' });
expect(rbacService.getUserSubmissions).toHaveBeenCalledTimes(0);
});

Expand All @@ -211,7 +211,7 @@ describe('form actions', () => {
expect(mockStore.commit).toHaveBeenCalledTimes(2);
expect(mockStore.commit).toHaveBeenCalledWith('SET_SUBMISSIONLIST', expect.any(Array));
expect(formService.listSubmissions).toHaveBeenCalledTimes(1);
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false });
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false, 'createdBy': '' });
expect(rbacService.getUserSubmissions).toHaveBeenCalledTimes(0);
});

Expand All @@ -235,7 +235,7 @@ describe('form actions', () => {
expect(mockStore.dispatch).toHaveBeenCalledTimes(1);
expect(mockStore.dispatch).toHaveBeenCalledWith('notifications/addNotification', expect.any(Object), expect.any(Object));
expect(formService.listSubmissions).toHaveBeenCalledTimes(1);
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false });
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false, 'createdBy': '' });
expect(rbacService.getUserSubmissions).toHaveBeenCalledTimes(0);
});

Expand Down
5 changes: 5 additions & 0 deletions app/src/forms/common/models/tables/formSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class FormSubmission extends Timestamps(Model) {

static get modifiers() {
return {
filterCreatedBy(query, value) {
if (value) {
query.where('createdBy', 'ilike', `%${value}%`);
}
},
filterFormVersionId(query, value) {
if (value !== undefined) {
query.where('formVersionId', value);
Expand Down
2 changes: 1 addition & 1 deletion app/src/forms/form/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
},
listSubmissions: async (req, res, next) => {
try {
const response = await service.listSubmissions(req.params.formVersionId);
const response = await service.listSubmissions(req.params.formVersionId, req.query);
res.status(200).json(response);
} catch (error) {
next(error);
Expand Down
3 changes: 2 additions & 1 deletion app/src/forms/form/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ const service = {
return schema.components.flatMap(c => findFields(c));
},

listSubmissions: async (formVersionId) => {
listSubmissions: async (formVersionId, params) => {
return FormSubmission.query()
.where('formVersionId', formVersionId)
.modify('filterCreatedBy', params.createdBy)
.modify('orderDescending');
},

Expand Down

0 comments on commit b3fa38a

Please sign in to comment.