@@ -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 {
0 commit comments