diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 7e4c6cfc0..b4dec544f 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -1016,9 +1016,13 @@ public function deleteSubmission(int $id): DataResponse { throw new OCSBadRequestException(); } + // Either the current user needs to be the owner if ($form->getOwnerId() !== $this->currentUser->getUID()) { - $this->logger->debug('This form is not owned by the current user'); - throw new OCSForbiddenException(); + // Or has permissions to remove submissions + if (!$this->formsService->canDeleteResults($form)) { + $this->logger->debug('This form is not owned by the current user and user has no results_delete permission'); + throw new OCSForbiddenException(); + } } // Delete submission (incl. Answers) diff --git a/lib/Controller/ShareApiController.php b/lib/Controller/ShareApiController.php index 75924e4e1..29fffefc0 100644 --- a/lib/Controller/ShareApiController.php +++ b/lib/Controller/ShareApiController.php @@ -313,6 +313,11 @@ protected function validatePermissions(array $permissions, int $shareType): bool return false; } + if (in_array(Constants::PERMISSION_RESULTS_DELETE, $sanitizedPermissions) && !in_array(Constants::PERMISSION_RESULTS, $sanitizedPermissions)) { + $this->logger->debug('Permission results_delete is only allowed when permission results is also set'); + return false; + } + // Make sure only users can have special permissions if (count($sanitizedPermissions) > 1) { switch ($shareType) { diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php index 8a0a8e2ef..0af552978 100644 --- a/lib/Service/FormsService.php +++ b/lib/Service/FormsService.php @@ -252,6 +252,16 @@ public function canSeeResults(Form $form): bool { return in_array(Constants::PERMISSION_RESULTS, $this->getPermissions($form)); } + /** + * Can the current user delete results of a form + * + * @param Form $form + * @return boolean + */ + public function canDeleteResults(Form $form): bool { + return in_array(Constants::PERMISSION_RESULTS_DELETE, $this->getPermissions($form)); + } + /** * Can the user submit a form * @@ -475,7 +485,7 @@ public function notifyNewSubmission(Form $form, string $submitter): void { * * @param int $formId The form to query shares for * @param string $userId The user to check if shared with - * @return array + * @return Share[] */ protected function getSharesWithUser(int $formId, string $userId): array { $shareEntities = $this->shareMapper->findByForm($formId); diff --git a/src/components/SidebarTabs/SharingShareDiv.vue b/src/components/SidebarTabs/SharingShareDiv.vue index 462432c12..32795e70c 100644 --- a/src/components/SidebarTabs/SharingShareDiv.vue +++ b/src/components/SidebarTabs/SharingShareDiv.vue @@ -35,6 +35,9 @@ {{ t('forms', 'View responses') }} + + {{ t('forms', 'Delete responses') }} +