Skip to content

Commit

Permalink
drop function canDeleteSubmission. it is unrelated to this PR
Browse files Browse the repository at this point in the history
Signed-off-by: Timotheus Pokorra <[email protected]>
  • Loading branch information
tpokorra committed Jan 9, 2025
1 parent 9f5d187 commit 395e687
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 80 deletions.
6 changes: 3 additions & 3 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1289,9 +1289,9 @@ public function deleteSubmission(int $formId, int $submissionId): DataResponse {
throw new OCSBadRequestException('Submission doesn\'t belong to given form');
}

// The current user has permissions to remove own submission
if (!$this->formsService->canDeleteSubmission($form, $submission)) {
$this->logger->debug('The user cannot delete own submission because AllowEdit is not set');
// The current user 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();
}

Expand Down
22 changes: 0 additions & 22 deletions lib/Service/FormsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,28 +374,6 @@ public function canDeleteResults(Form $form): bool {
return !$this->isFormArchived($form);
}

/**
* Can the current user delete own submission
*
* @param Form $form
* @param Submission $submission
* @return boolean
*/
public function canDeleteSubmission(Form $form, Submission $submission): bool {

// Do not allow deleting results on archived forms
if ($this->isFormArchived($form)) {
return false;
}

// if AllowEdit then the current user can delete own submission
if ($form->getAllowEdit() && $submission->getUserId() == $this->currentUser->getUID()) {
return true;
}

return false;
}

/**
* Can the user submit a form
*
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Controller/ApiControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ public function testDeleteSubmissionNoPermission($submissionData, $formData) {

$this->formsService
->expects($this->once())
->method('canDeleteSubmission')
->method('canDeleteResults')
->with($form)
->willReturn(false);

Expand All @@ -1009,7 +1009,7 @@ public function testDeleteSubmission($submissionData, $formData) {

$this->formsService
->expects($this->once())
->method('canDeleteSubmission')
->method('canDeleteResults')
->with($form)
->willReturn(true);

Expand Down
53 changes: 0 additions & 53 deletions tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,59 +959,6 @@ public function testCanDeleteResults(string $ownerId, array $sharesArray, bool $
$this->assertEquals($expected, $this->formsService->canDeleteResults($form));
}

public function dataCanDeleteSubmission() {
return [
'disallowNoAllowEdit' => [
'formArchived' => false,
'submissionUserId' => 'currentUser',
'allowEdit' => false,
'expected' => false
],
'disallowArchivedForm' => [
'formArchived' => true,
'submissionUserId' => 'currentUser',
'allowEdit' => false,
'expected' => false
],
'allowAllowEdit' => [
'formArchived' => false,
'submissionUserId' => 'currentUser',
'allowEdit' => true,
'expected' => true
],
'disallowAllowEditOtherUser' => [
'formArchived' => false,
'submissionUserId' => 'otherUser',
'allowEdit' => true,
'expected' => false
],
];
}
/**
* @dataProvider dataCanDeleteSubmission
*
* @param bool $formArchived
* @param string $submissionUserId,
* @param bool $allowEdit
* @param bool $expected
*/
public function testCanDeleteSubmission(bool $formArchived, string $submissionUserId, bool $allowEdit, bool $expected) {
$form = new Form();
$form->setId(42);
$form->setAccess([
'permitAllUsers' => false,
'showToAllUsers' => false,
]);
$form->setState($formArchived?Constants::FORM_STATE_ARCHIVED:Constants::FORM_STATE_ACTIVE);
$form->setAllowEdit($allowEdit);

$submission = new Submission();
$submission->setFormId(42);
$submission->setUserId($submissionUserId);

$this->assertEquals($expected, $this->formsService->canDeleteSubmission($form, $submission));
}

public function dataCanSubmit() {
return [
'allowFormOwner' => [
Expand Down

0 comments on commit 395e687

Please sign in to comment.