Skip to content

Commit a0ebec1

Browse files
authored
Merge pull request #3028 from nextcloud/fix/permissionChecks
fix: Update permission checks for archiving forms and transfer ownership
2 parents 255662c + a332532 commit a0ebec1

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

lib/Controller/ApiController.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,25 +1786,31 @@ private function checkAccessUpdate(array $keyValuePairs): void {
17861786
* Checks if the current user is allowed to archive/unarchive the form
17871787
*/
17881788
private function checkArchivePermission(Form $form, string $currentUserId, array $keyValuePairs): void {
1789+
// Only check if the request is trying to change the archived state
1790+
if (!array_key_exists('state', $keyValuePairs)) {
1791+
return;
1792+
}
1793+
17891794
$isArchived = $this->formsService->isFormArchived($form);
1790-
$owner = $currentUserId === $form->getOwnerId();
1791-
$onlyState = sizeof($keyValuePairs) === 1 && key_exists('state', $keyValuePairs);
1795+
$isOwner = $currentUserId === $form->getOwnerId();
17921796

1793-
// Only check if the request is trying to change the archived state
1794-
if ($onlyState && $keyValuePairs['state'] === Constants::FORM_STATE_ARCHIVED) {
1797+
// If the request contains 'state' it must be the only key
1798+
if (sizeof($keyValuePairs) !== 1) {
1799+
$this->logger->debug('State may only be changed on its own');
1800+
throw new OCSForbiddenException('State may only be changed on its own');
1801+
}
1802+
1803+
$state = $keyValuePairs['state'];
1804+
1805+
if ($state === Constants::FORM_STATE_ARCHIVED && !$isArchived && !$isOwner) {
17951806
// Trying to archive
1796-
if (!$owner || $isArchived) {
1797-
$this->logger->debug('Only the form owner can archive the form, and only if it is not already archived');
1798-
throw new OCSForbiddenException('Only the form owner can archive the form, and only if it is not already archived');
1799-
}
1800-
} elseif ($onlyState && $keyValuePairs['state'] === Constants::FORM_STATE_CLOSED) {
1807+
$this->logger->debug('Only the form owner can archive the form, and only if it is not already archived');
1808+
throw new OCSForbiddenException('Only the form owner can archive the form, and only if it is not already archived');
1809+
} elseif ($state === Constants::FORM_STATE_CLOSED && $isArchived && !$isOwner) {
18011810
// Trying to unarchive
1802-
if (!$owner || !$isArchived) {
1803-
$this->logger->debug('Only the form owner can unarchive the form, and only if it is currently archived');
1804-
throw new OCSForbiddenException('Only the form owner can unarchive the form, and only if it is currently archived');
1805-
}
1811+
$this->logger->debug('Only the form owner can unarchive the form, and only if it is currently archived');
1812+
throw new OCSForbiddenException('Only the form owner can unarchive the form, and only if it is currently archived');
18061813
}
1807-
// All other updates are allowed (including updates that do not touch the state)
18081814
}
18091815

18101816
private function isLockingRequest(array $keyValuePairs): bool {

src/components/SidebarTabs/SettingsSidebarTab.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<NcCheckboxRadioSwitch
104104
:model-value="formArchived"
105105
aria-describedby="forms-settings__archive-form"
106-
:disabled="locked"
106+
:disabled="locked || !isCurrentUserOwner"
107107
type="switch"
108108
@update:model-value="onFormArchivedChange">
109109
{{ t('forms', 'Archive form') }}
@@ -168,7 +168,10 @@
168168
</div>
169169
</div>
170170

171-
<TransferOwnership :locked="locked" :form="form" />
171+
<TransferOwnership
172+
:locked="locked"
173+
:is-owner="isCurrentUserOwner"
174+
:form="form" />
172175
</div>
173176
</template>
174177

src/components/SidebarTabs/TransferOwnership.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
alignment="start"
1111
variant="tertiary"
1212
wide
13-
:disabled="locked"
13+
:disabled="locked || !isOwner"
1414
@click="openModal">
1515
<span class="transfer-button__text">{{
1616
t('forms', 'Transfer ownership')
@@ -119,6 +119,11 @@ export default {
119119
required: true,
120120
},
121121
122+
isOwner: {
123+
type: Boolean,
124+
required: true,
125+
},
126+
122127
locked: {
123128
type: Boolean,
124129
required: true,

0 commit comments

Comments
 (0)