Delete Submission
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
parent
bb9bca3667
commit
8a96e16413
|
@ -55,7 +55,8 @@ return [
|
|||
['name' => 'api#deleteOption', 'url' => '/api/v1/option/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'api#getSubmissions', 'url' => '/api/v1/submissions/{hash}', 'verb' => 'GET'],
|
||||
['name' => 'api#insertSubmission', 'url' => '/api/v1/submissions/insert', 'verb' => 'POST'],
|
||||
['name' => 'api#insertSubmission', 'url' => '/api/v1/submission/insert', 'verb' => 'POST'],
|
||||
['name' => 'api#deleteSubmission', 'url' => '/api/v1/submission/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'system#get_site_users_and_groups', 'url' => '/get/siteusers', 'verb' => 'POST'],
|
||||
]
|
||||
|
|
|
@ -714,4 +714,31 @@ class ApiController extends Controller {
|
|||
|
||||
return new Http\JSONResponse([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteSubmission(int $id): Http\JSONResponse {
|
||||
$this->logger->debug('Delete Submission: {id}', [
|
||||
'id' => $id,
|
||||
]);
|
||||
|
||||
try {
|
||||
$submission = $this->submissionMapper->findById($id);
|
||||
$form = $this->formMapper->findById($submission->getFormId());
|
||||
} catch (IMapperException $e) {
|
||||
$this->logger->debug('Could not find form or submission');
|
||||
return new Http\JSONResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ($form->getOwnerId() !== $this->userId) {
|
||||
$this->logger->debug('This form is not owned by the current user');
|
||||
return new Http\JSONResponse([], Http::STATUS_FORBIDDEN);
|
||||
}
|
||||
|
||||
// Delete submission (incl. Answers)
|
||||
$this->submissionMapper->delete($submission);
|
||||
|
||||
return new Http\JSONResponse($id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,24 @@ class SubmissionMapper extends QBMapper {
|
|||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Integer $id
|
||||
* @return Submission
|
||||
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
|
||||
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
|
||||
*/
|
||||
public function findById(int $id): Submission {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where(
|
||||
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
|
||||
);
|
||||
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $formId
|
||||
* @throws DoesNotExistException if not found
|
||||
|
|
|
@ -22,9 +22,16 @@
|
|||
|
||||
<template>
|
||||
<div class="table submission section">
|
||||
<h3 class="submission-title">
|
||||
Response by {{ userDisplayName }}
|
||||
</h3>
|
||||
<div class="submission-head">
|
||||
<h3 class="submission-title">
|
||||
Response by {{ userDisplayName }}
|
||||
</h3>
|
||||
<Actions class="submission-menu" :force-menu="true">
|
||||
<ActionButton icon="icon-delete" @click="onDelete">
|
||||
{{ t('forms', 'Delete submission') }}
|
||||
</ActionButton>
|
||||
</Actions>
|
||||
</div>
|
||||
<p class="submission-date">
|
||||
{{ submissionDateTime }}
|
||||
</p>
|
||||
|
@ -39,13 +46,18 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import Actions from '@nextcloud/vue/dist/Components/Actions'
|
||||
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
|
||||
import moment from '@nextcloud/moment'
|
||||
|
||||
import Answer from './Answer'
|
||||
|
||||
export default {
|
||||
name: 'Submission',
|
||||
|
||||
components: {
|
||||
Actions,
|
||||
ActionButton,
|
||||
Answer,
|
||||
},
|
||||
|
||||
|
@ -73,6 +85,10 @@ export default {
|
|||
questionToAnswer(questionId) {
|
||||
return this.questions.find(question => question.id === questionId)
|
||||
},
|
||||
|
||||
onDelete() {
|
||||
this.$emit('delete')
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
v-for="submission in submissions"
|
||||
:key="submission.id"
|
||||
:submission="submission"
|
||||
:questions="questions" />
|
||||
:questions="questions"
|
||||
@delete="deleteSubmission(submission.id)" />
|
||||
|
||||
<!-- <transition-group
|
||||
name="list"
|
||||
|
@ -150,6 +151,21 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
async deleteSubmission(id) {
|
||||
this.loadingResults = true
|
||||
|
||||
try {
|
||||
await axios.delete(generateUrl('/apps/forms/api/v1/submission/{id}', { id }))
|
||||
const index = this.submissions.findIndex(search => search.id === id)
|
||||
this.submissions.splice(index, 1)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
showError(t('forms', 'There was an error while removing the submission'))
|
||||
} finally {
|
||||
this.loadingResults = false
|
||||
}
|
||||
},
|
||||
|
||||
/* download() {
|
||||
this.loading = true
|
||||
axios.get(OC.generateUrl('apps/forms/get/form/' + this.$route.params.hash))
|
||||
|
|
|
@ -131,7 +131,7 @@ export default {
|
|||
this.loading = true
|
||||
|
||||
try {
|
||||
await axios.post(generateUrl('/apps/forms/api/v1/submissions/insert'), {
|
||||
await axios.post(generateUrl('/apps/forms/api/v1/submission/insert'), {
|
||||
formId: this.form.id,
|
||||
answers: this.answers,
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue