Skip to content

Commit b3fa38a

Browse files
jasonchung1871bcgov-citz-ccft
authored andcommitted
Added filter for self submissions
User can view specifically their own submissions Resolves: #462
1 parent 5d8c750 commit b3fa38a

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

app/frontend/src/components/forms/SubmissionsTable.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,22 @@
3535

3636
<v-row no-gutters>
3737
<v-spacer />
38-
<v-col cols="12" sm="8">
38+
<v-col cols="4" sm="4">
3939
<v-checkbox
4040
class="pl-3"
4141
v-model="deletedOnly"
4242
label="Show deleted submissions"
4343
@click="refreshSubmissions"
4444
/>
4545
</v-col>
46+
<v-col cols="4" sm="4">
47+
<v-checkbox
48+
class="pl-3"
49+
v-model="currentUserOnly"
50+
label="Show my submissions"
51+
@click="refreshSubmissions"
52+
/>
53+
</v-col>
4654
<v-col cols="12" sm="4">
4755
<!-- search input -->
4856
<div class="submissions-search">
@@ -57,6 +65,8 @@
5765
</div>
5866
</v-col>
5967
</v-row>
68+
<v-row no-gutters>
69+
</v-row>
6070

6171
<!-- table header -->
6272
<v-data-table
@@ -153,6 +163,7 @@ export default {
153163
data() {
154164
return {
155165
deletedOnly: false,
166+
currentUserOnly: false,
156167
loading: true,
157168
restoreItem: {},
158169
search: '',
@@ -168,6 +179,9 @@ export default {
168179
'submissionList',
169180
'userFormPreferences',
170181
]),
182+
...mapGetters('auth', [
183+
'user'
184+
]),
171185
172186
checkFormManage() {
173187
return this.permissions.some((p) => FormManagePermissions.includes(p));
@@ -249,7 +263,7 @@ export default {
249263
// Get user prefs for this form
250264
await this.getFormPreferencesForCurrentUser(this.formId);
251265
// Get the submissions for this form
252-
await this.fetchSubmissions({ formId: this.formId, deletedOnly: this.deletedOnly });
266+
await this.fetchSubmissions({ formId: this.formId, deletedOnly: this.deletedOnly, createdBy: (this.currentUserOnly) ? `${this.user.username}@${this.user.idp}` : '' });
253267
// Build up the list of forms for the table
254268
if (this.submissionList) {
255269
const tableRows = this.submissionList

app/frontend/src/components/forms/submission/MySubmissionsTable.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export default {
108108
},
109109
computed: {
110110
...mapGetters('form', ['form', 'submissionList', 'permissions']),
111+
...mapGetters('auth', [
112+
'user'
113+
]),
111114
headers() {
112115
let headers = [
113116
{ text: 'Confirmation Id', align: 'start', value: 'confirmationId' },
@@ -179,7 +182,7 @@ export default {
179182
async populateSubmissionsTable() {
180183
this.loading = true;
181184
// Get the submissions for this form
182-
await this.fetchSubmissions({ formId: this.formId, userView: true });
185+
await this.fetchSubmissions({ formId: this.formId, userView: true, createdBy: `${this.user.username}@${this.user.idp}` });
183186
// Build up the list of forms for the table
184187
if (this.submissionList) {
185188
const tableRows = this.submissionList.map((s) => {

app/frontend/src/store/modules/form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ export default {
350350
}, { root: true });
351351
}
352352
},
353-
async fetchSubmissions({ commit, dispatch, state }, { formId, userView, deletedOnly = false }) {
353+
async fetchSubmissions({ commit, dispatch, state }, { formId, userView, deletedOnly = false, createdBy = '' }) {
354354
try {
355355
commit('SET_SUBMISSIONLIST', []);
356356
// Get list of active submissions for this form (for either all submissions, or just single user)
357357
const fields = state.userFormPreferences &&
358358
state.userFormPreferences.preferences ? state.userFormPreferences.preferences.columnList : undefined;
359359
const response = userView
360360
? await rbacService.getUserSubmissions({ formId: formId })
361-
: await formService.listSubmissions(formId, { deleted: deletedOnly, fields: fields });
361+
: await formService.listSubmissions(formId, { deleted: deletedOnly, fields: fields, createdBy: createdBy });
362362
commit('SET_SUBMISSIONLIST', response.data);
363363
} catch (error) {
364364
dispatch('notifications/addNotification', {

app/frontend/tests/unit/store/modules/form.actions.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ describe('form actions', () => {
200200
expect(mockStore.commit).toHaveBeenCalledTimes(2);
201201
expect(mockStore.commit).toHaveBeenCalledWith('SET_SUBMISSIONLIST', expect.any(Array));
202202
expect(formService.listSubmissions).toHaveBeenCalledTimes(1);
203-
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false });
203+
expect(formService.listSubmissions).toHaveBeenCalledWith('fId', { 'deleted': false, 'createdBy': '' });
204204
expect(rbacService.getUserSubmissions).toHaveBeenCalledTimes(0);
205205
});
206206

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

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

app/src/forms/common/models/tables/formSubmission.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ class FormSubmission extends Timestamps(Model) {
1010

1111
static get modifiers() {
1212
return {
13+
filterCreatedBy(query, value) {
14+
if (value) {
15+
query.where('createdBy', 'ilike', `%${value}%`);
16+
}
17+
},
1318
filterFormVersionId(query, value) {
1419
if (value !== undefined) {
1520
query.where('formVersionId', value);

app/src/forms/form/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ module.exports = {
113113
},
114114
listSubmissions: async (req, res, next) => {
115115
try {
116-
const response = await service.listSubmissions(req.params.formVersionId);
116+
const response = await service.listSubmissions(req.params.formVersionId, req.query);
117117
res.status(200).json(response);
118118
} catch (error) {
119119
next(error);

app/src/forms/form/service.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ const service = {
313313
return schema.components.flatMap(c => findFields(c));
314314
},
315315

316-
listSubmissions: async (formVersionId) => {
316+
listSubmissions: async (formVersionId, params) => {
317317
return FormSubmission.query()
318318
.where('formVersionId', formVersionId)
319+
.modify('filterCreatedBy', params.createdBy)
319320
.modify('orderDescending');
320321
},
321322

0 commit comments

Comments
 (0)