Skip to content

Commit

Permalink
Add results_delete permission
Browse files Browse the repository at this point in the history
Check permission on frontend to show delete buttons

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jan 25, 2023
1 parent 98dd2f4 commit 703f2a7
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
11 changes: 6 additions & 5 deletions docs/DataStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,12 @@ The actual answers of users on submission.

## Permissions
Array of permissions, the user has on the form. Permissions are named by resp. routes on frontend.
| Permission | Description |
| -----------|-------------|
| edit | User is allowed to edit the form |
| results | User is allowed to access the form results |
| submit | User is allowed to submit to the form |
| Permission | Description |
| ---------------|-------------|
| edit | User is allowed to edit the form |
| results | User is allowed to access the form results |
| results_delete | User is allowed to delete form submissions |
| submit | User is allowed to submit to the form |

## Access Object
Defines some extended options of sharing / access
Expand Down
2 changes: 2 additions & 0 deletions lib/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ class Constants {
// Define Form Permissions
public const PERMISSION_EDIT = 'edit';
public const PERMISSION_RESULTS = 'results';
public const PERMISSION_RESULTS_DELETE = 'results_delete';
public const PERMISSION_SUBMIT = 'submit';

public const PERMISSION_ALL = [
self::PERMISSION_EDIT,
self::PERMISSION_RESULTS,
self::PERMISSION_RESULTS_DELETE,
self::PERMISSION_SUBMIT
];

Expand Down
6 changes: 5 additions & 1 deletion src/components/Results/Submission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="submission-head">
<h3>{{ submission.userDisplayName }}</h3>
<NcActions class="submission-menu" :force-menu="true">
<NcActionButton @click="onDelete">
<NcActionButton v-if="canDeleteSubmission" @click="onDelete">
<template #icon>
<IconDelete :size="20" />
</template>
Expand Down Expand Up @@ -71,6 +71,10 @@ export default {
type: Array,
required: true,
},
canDeleteSubmission: {
type: Boolean,
required: true,
},
},
computed: {
Expand Down
3 changes: 2 additions & 1 deletion src/mixins/PermissionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export default {
PERMISSION_TYPES: {
PERMISSION_EDIT: 'edit',
PERMISSION_RESULTS: 'results',
PERMISSION_RESULTS_DELETE: 'results_delete',
PERMISSION_SUBMIT: 'submit',
PERMISSION_ALL: [this.PERMISSION_EDIT, this.PERMISSION_RESULTS, this.PERMISSION_SUBMIT],
PERMISSION_ALL: [this.PERMISSION_EDIT, this.PERMISSION_RESULTS, this.PERMISSION_RESULTS_DELETE, this.PERMISSION_SUBMIT],
},
}
},
Expand Down
10 changes: 8 additions & 2 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</template>
{{ t('forms', 'Download CSV') }}
</NcActionButton>
<NcActionButton @click="deleteAllSubmissions">
<NcActionButton v-if="canDeleteSubmissions" @click="deleteAllSubmissions">
<template #icon>
<IconDelete :size="20" />
</template>
Expand Down Expand Up @@ -123,6 +123,7 @@
:key="submission.id"
:submission="submission"
:questions="form.questions"
:can-delete-submission="canDeleteSubmissions"
@delete="deleteSubmission(submission.id)" />
</section>
</NcAppContent>
Expand Down Expand Up @@ -155,6 +156,7 @@ import answerTypes from '../models/AnswerTypes.js'
import logger from '../utils/Logger.js'
import SetWindowTitle from '../utils/SetWindowTitle.js'
import OcsResponse2Data from '../utils/OcsResponse2Data.js'
import PermissionTypes from '../mixins/PermissionTypes.js'
const picker = getFilePickerBuilder(t('forms', 'Save CSV to Files'))
.setMultiSelect(false)
Expand Down Expand Up @@ -183,7 +185,7 @@ export default {
TopBar,
},
mixins: [ViewsMixin],
mixins: [PermissionTypes, ViewsMixin],
data() {
return {
Expand All @@ -193,6 +195,10 @@ export default {
},
computed: {
canDeleteSubmissions() {
return this.form.permissions.includes(this.PERMISSION_TYPES.PERMISSION_RESULTS_DELETE)
},
noSubmissions() {
return this.form.submissions?.length === 0
},
Expand Down
20 changes: 4 additions & 16 deletions tests/Integration/Api/ApiV2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
namespace OCA\Forms\Tests\Integration\Api;

use OCA\Forms\Db\Form;
use OCA\Forms\Constants;
use OCA\Forms\Db\FormMapper;

use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -356,11 +356,7 @@ public function dataGetForms() {
'hash' => 'abcdefg',
'title' => 'Title of a Form',
'expires' => 0,
'permissions' => [
'edit',
'results',
'submit'
],
'permissions' => Constants::PERMISSION_ALL,
'partial' => true,
'submissionCount' => 3
]]
Expand Down Expand Up @@ -460,11 +456,7 @@ public function dataGetNewForm() {
'submitMultiple' => false,
'showExpiration' => false,
'canSubmit' => true,
'permissions' => [
'edit',
'results',
'submit'
],
'permissions' => Constants::PERMISSION_ALL,
'questions' => [],
'shares' => [],
'submissionCount' => 0,
Expand Down Expand Up @@ -515,11 +507,7 @@ public function dataGetFullForm() {
'submitMultiple' => false,
'showExpiration' => false,
'canSubmit' => true,
'permissions' => [
'edit',
'results',
'submit'
],
'permissions' => Constants::PERMISSION_ALL,
'questions' => [
[
'type' => 'short',
Expand Down
10 changes: 3 additions & 7 deletions tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,7 @@ public function dataGetForm() {
'displayName' => 'Some User'
]
],
'permissions' => [
'edit',
'results',
'submit'
]
'permissions' => Constants::PERMISSION_ALL
]]
];
}
Expand Down Expand Up @@ -319,7 +315,7 @@ public function dataGetPartialForm() {
'hash' => 'abcdefg',
'title' => 'Form 1',
'expires' => 0,
'permissions' => ['edit', 'results', 'submit'],
'permissions' => Constants::PERMISSION_ALL,
'submissionCount' => 123,
'partial' => true
]]
Expand Down Expand Up @@ -494,7 +490,7 @@ public function dataGetPermissions() {
'showToAllUsers' => false,
],
'shares' => [],
'expected' => ['edit', 'results', 'submit'],
'expected' => Constants::PERMISSION_ALL,
],
'allUsersCanSubmit' => [
'ownerId' => 'someOtherUser',
Expand Down

0 comments on commit 703f2a7

Please sign in to comment.