Skip to content

Commit 10a1afd

Browse files
authored
Merge pull request #404 from nextcloud/backport/403/stable28
[stable28] Change api signature to require etag
2 parents a540e12 + 96ab1c3 commit 10a1afd

3 files changed

Lines changed: 16 additions & 20 deletions

File tree

lib/Controller/ApprovalController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ public function getPendingNodes(?int $since = null): DataResponse {
8181
* Approve a file
8282
*
8383
* @param int $fileId
84-
* @param string|null $etag
84+
* @param string $etag
8585
* @return DataResponse
8686
*/
8787
#[NoAdminRequired]
88-
public function approve(int $fileId, ?string $etag = ''): DataResponse {
88+
public function approve(int $fileId, string $etag): DataResponse {
8989
try {
90-
if ($this->approvalService->approve($fileId, $this->userId, $etag ?? '')) {
90+
if ($this->approvalService->approve($fileId, $this->userId, $etag)) {
9191
return new DataResponse([]);
9292
}
9393
return new DataResponse([], Http::STATUS_BAD_REQUEST);
@@ -103,13 +103,13 @@ public function approve(int $fileId, ?string $etag = ''): DataResponse {
103103
* Reject a file
104104
*
105105
* @param int $fileId
106-
* @param string|null $etag
106+
* @param string $etag
107107
* @return DataResponse
108108
*/
109109
#[NoAdminRequired]
110-
public function reject(int $fileId, ?string $etag = ''): DataResponse {
110+
public function reject(int $fileId, string $etag): DataResponse {
111111
try {
112-
if ($this->approvalService->reject($fileId, $this->userId, $etag ?? '')) {
112+
if ($this->approvalService->reject($fileId, $this->userId, $etag)) {
113113
return new DataResponse([]);
114114
}
115115
return new DataResponse([], Http::STATUS_BAD_REQUEST);

lib/Service/ApprovalService.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ public function getApprovalState(int $fileId, ?string $userId, bool $userHasAcce
351351
*
352352
* @param int $fileId
353353
* @param string|null $userId
354-
* @param string $etag optional etag of the file to check if it has changed since approval was requested
354+
* @param string $etag
355355
* @return bool success
356356
* @throws OutdatedEtagException
357357
*/
358-
public function approve(int $fileId, ?string $userId, string $etag = ''): bool {
358+
public function approve(int $fileId, ?string $userId, string $etag): bool {
359359
$fileState = $this->getApprovalState($fileId, $userId);
360-
if ($etag !== '' && $etag !== $this->getEtag($fileId)) {
360+
if ($etag !== $this->getEtag($fileId)) {
361361
throw new OutdatedEtagException();
362362
}
363363
// if file has pending tag and user is authorized to approve it
@@ -393,13 +393,13 @@ public function approve(int $fileId, ?string $userId, string $etag = ''): bool {
393393
*
394394
* @param int $fileId
395395
* @param string|null $userId
396-
* @param string $etag optional etag of the file to check if it has changed since approval was requested
396+
* @param string $etag
397397
* @return bool success
398398
* @throws OutdatedEtagException
399399
*/
400-
public function reject(int $fileId, ?string $userId, string $etag = ''): bool {
400+
public function reject(int $fileId, ?string $userId, string $etag): bool {
401401
$fileState = $this->getApprovalState($fileId, $userId);
402-
if ($etag !== '' && $etag !== $this->getEtag($fileId)) {
402+
if ($etag !== $this->getEtag($fileId)) {
403403
throw new OutdatedEtagException();
404404
}
405405
// if file has pending tag and user is authorized to approve it

tests/unit/Service/ApprovalServiceTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,11 @@
3535
use OCP\IL10N;
3636
use OCP\IUserManager;
3737
use OCP\Notification\IManager as INotificationManager;
38-
3938
use OCP\Security\ICrypto;
4039
use OCP\Share\IManager as IShareManager;
41-
4240
use OCP\Share\IShare;
43-
4441
use OCP\SystemTag\ISystemTagManager;
4542
use OCP\SystemTag\ISystemTagObjectMapper;
46-
4743
use Psr\Log\LoggerInterface;
4844

4945
class ApprovalServiceTest extends TestCase {
@@ -410,24 +406,24 @@ public function testApproval() {
410406
// approve failures
411407
// tag does not exist
412408
$this->ruleService->saveRule($idRule3, $idTagPending3, -1, $idTagRejected3, $approvers, $requesters, $description);
413-
$result = $this->approvalService->approve($fileToReject->getId(), 'user1');
409+
$result = $this->approvalService->approve($fileToReject->getId(), 'user1', $fileToReject->getEtag());
414410
$this->assertFalse($result);
415411
$this->ruleService->saveRule($idRule3, $idTagPending3, $idTagApproved3, $idTagRejected3, $approvers, $requesters, $description);
416412

417413
// approve
418-
$this->approvalService->approve($fileToApprove->getId(), 'user1');
414+
$this->approvalService->approve($fileToApprove->getId(), 'user1', $fileToApprove->getEtag());
419415
$stateForUser1 = $this->approvalService->getApprovalState($fileToApprove->getId(), 'user1');
420416
$this->assertEquals(Application::STATE_APPROVED, $stateForUser1['state']);
421417

422418
// reject failures
423419
// tag does not exist
424420
$this->ruleService->saveRule($idRule3, $idTagPending3, $idTagApproved3, -1, $approvers, $requesters, $description);
425-
$result = $this->approvalService->reject($fileToReject->getId(), 'user1');
421+
$result = $this->approvalService->reject($fileToReject->getId(), 'user1', $fileToReject->getEtag());
426422
$this->assertFalse($result);
427423
$this->ruleService->saveRule($idRule3, $idTagPending3, $idTagApproved3, $idTagRejected3, $approvers, $requesters, $description);
428424

429425
// reject
430-
$this->approvalService->reject($fileToReject->getId(), 'user1');
426+
$this->approvalService->reject($fileToReject->getId(), 'user1', $fileToReject->getEtag());
431427
$stateForUser1 = $this->approvalService->getApprovalState($fileToReject->getId(), 'user1');
432428
$this->assertEquals(Application::STATE_REJECTED, $stateForUser1['state']);
433429
}

0 commit comments

Comments
 (0)