Skip to content

Commit

Permalink
Check if user can update node
Browse files Browse the repository at this point in the history
...and change to an alternative user if not.

Signed-off-by: XueSheng-GIT <[email protected]>
  • Loading branch information
XueSheng-GIT committed Dec 14, 2024
1 parent 56be914 commit 6643768
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace OCA\WorkflowOcr;

use OC\Core\Command\Info\FileUtils;
use OCA\WorkflowEngine\Entity\File;
use OCA\WorkflowOcr\AppInfo\Application;
use OCA\WorkflowOcr\BackgroundJobs\ProcessFileJob;
Expand Down Expand Up @@ -58,20 +59,24 @@ class Operation implements ISpecificOperation {
private $processingFileAccessor;
/** @var IRootFolder */
private $rootFolder;
/** @var fileUtils */

Check failure on line 62 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.1

UndefinedDocblockClass

lib/Operation.php:62:11: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/200)

Check failure on line 62 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.2

UndefinedDocblockClass

lib/Operation.php:62:11: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/200)

Check failure on line 62 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.3

UndefinedDocblockClass

lib/Operation.php:62:11: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/200)
private $fileUtils;

public function __construct(
IJobList $jobList,
IL10N $l,
LoggerInterface $logger,
IURLGenerator $urlGenerator,
IProcessingFileAccessor $processingFileAccessor,
IRootFolder $rootFolder) {
IRootFolder $rootFolder,
FileUtils $fileUtils) {

Check failure on line 72 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.1

UndefinedClass

lib/Operation.php:72:3: UndefinedClass: Class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/019)

Check failure on line 72 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.2

UndefinedClass

lib/Operation.php:72:3: UndefinedClass: Class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/019)

Check failure on line 72 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.3

UndefinedClass

lib/Operation.php:72:3: UndefinedClass: Class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/019)
$this->jobList = $jobList;
$this->l = $l;
$this->logger = $logger;
$this->urlGenerator = $urlGenerator;
$this->processingFileAccessor = $processingFileAccessor;
$this->rootFolder = $rootFolder;
$this->fileUtils = $fileUtils;
}

/**
Expand Down Expand Up @@ -215,6 +220,22 @@ private function tryGetJobArgs(Node $node, $operation, & $argsArray) : bool {
return false;
}

// Change to an alternative user if node is not updateable
if (!$node->isUpdateable()) {
$originalUser = $user;

$filesPerUser = $this->fileUtils->getFilesByUser($node);

Check failure on line 227 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.1

UndefinedDocblockClass

lib/Operation.php:227:20: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/200)

Check failure on line 227 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.2

UndefinedDocblockClass

lib/Operation.php:227:20: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/200)

Check failure on line 227 in lib/Operation.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master PHP8.3

UndefinedDocblockClass

lib/Operation.php:227:20: UndefinedDocblockClass: Docblock-defined class, interface or enum named OC\Core\Command\Info\FileUtils does not exist (see https://psalm.dev/200)
foreach ($filesPerUser as $uid => $files) {
foreach ($files as $userFile) {
if ($userFile->isUpdateable()) {
$user = $uid;
break;
}
}
}
$this->logger->debug('User \'{originalUser}\' has no update permissions for node. Thus, changing to user \'{user}\'.', ['originalUser' => $originalUser, 'user' => $user]);
}

$argsArray = [
'uid' => $user,
'fileId' => $node->getId(),
Expand Down

0 comments on commit 6643768

Please sign in to comment.