Delete all submissions
Signed-off-by: Jonas Rittershofer <jotoeri@users.noreply.github.com>
This commit is contained in:
parent
8b92d52b2e
commit
a9400b440f
|
@ -54,7 +54,10 @@ return [
|
|||
['name' => 'api#updateOption', 'url' => '/api/v1/option/update', 'verb' => 'POST'],
|
||||
['name' => 'api#deleteOption', 'url' => '/api/v1/option/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
// Submissions
|
||||
['name' => 'api#getSubmissions', 'url' => '/api/v1/submissions/{hash}', 'verb' => 'GET'],
|
||||
['name' => 'api#deleteAllSubmissions', 'url' => '/api/v1/submissions/{formId}', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'api#insertSubmission', 'url' => '/api/v1/submission/insert', 'verb' => 'POST'],
|
||||
['name' => 'api#deleteSubmission', 'url' => '/api/v1/submission/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
|
|
|
@ -741,4 +741,30 @@ class ApiController extends Controller {
|
|||
|
||||
return new Http\JSONResponse($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function deleteAllSubmissions(int $formId): Http\JSONResponse {
|
||||
$this->logger->debug('Delete all submissions to form: {formId}', [
|
||||
'formId' => $formId,
|
||||
]);
|
||||
|
||||
try {
|
||||
$form = $this->formMapper->findById($formId);
|
||||
} catch (IMapperException $e) {
|
||||
$this->logger->debug('Could not find form');
|
||||
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 all submissions (incl. Answers)
|
||||
$this->submissionMapper->deleteByForm($formId);
|
||||
|
||||
return new Http\JSONResponse($id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,14 @@
|
|||
|
||||
<header v-if="!noSubmissions">
|
||||
<h2>{{ t('forms', 'Responses for {title}', { title: form.title }) }}</h2>
|
||||
<button id="exportButton" @click="download">
|
||||
<span class="icon-download" role="img" />
|
||||
{{ t('forms', 'Export to CSV') }}
|
||||
</button>
|
||||
<Actions class="submission-menu" :force-menu="true">
|
||||
<ActionButton icon="icon-download" @click="download">
|
||||
{{ t('forms', 'Export to CSV') }}
|
||||
</ActionButton>
|
||||
<ActionButton icon="icon-delete" @click="deleteAllSubmissions">
|
||||
{{ t('forms', 'Delete all Submissions') }}
|
||||
</ActionButton>
|
||||
</Actions>
|
||||
</header>
|
||||
|
||||
<!-- No submissions -->
|
||||
|
@ -71,6 +75,8 @@
|
|||
import { generateUrl } from '@nextcloud/router'
|
||||
import { Parser } from 'json2csv'
|
||||
import { showError } from '@nextcloud/dialogs'
|
||||
import Actions from '@nextcloud/vue/dist/Components/Actions'
|
||||
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
|
||||
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
|
||||
import axios from '@nextcloud/axios'
|
||||
import moment from '@nextcloud/moment'
|
||||
|
@ -84,6 +90,8 @@ export default {
|
|||
name: 'Results',
|
||||
|
||||
components: {
|
||||
Actions,
|
||||
ActionButton,
|
||||
AppContent,
|
||||
EmptyContent,
|
||||
Submission,
|
||||
|
@ -154,6 +162,23 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
async deleteAllSubmissions() {
|
||||
if (!confirm(t('forms', 'Are you sure you want to delete all submissions from this form?'))) {
|
||||
return
|
||||
}
|
||||
|
||||
this.loadingResults = true
|
||||
try {
|
||||
await axios.delete(generateUrl('/apps/forms/api/v1/submissions/{formId}', { formId: this.form.id }))
|
||||
this.submissions = []
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
showError(t('forms', 'There was an error while removing the submissions'))
|
||||
} finally {
|
||||
this.loadingResults = false
|
||||
}
|
||||
},
|
||||
|
||||
download() {
|
||||
this.loadingResults = true
|
||||
|
||||
|
|
Loading…
Reference in a new issue