Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function destroy(int $id): DataResponse {
protected function getScopeContext(): ScopeContext {
if($this->scopeContext === null) {
$user = $this->session->getUser();
if(!$user) {
if(!$user || !$this->manager->isUserScopeEnabled()) {
throw new OCSForbiddenException('User not logged in');
}
$this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
Expand Down
13 changes: 12 additions & 1 deletion apps/workflowengine/lib/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

use Doctrine\DBAL\DBALException;
use OC\Cache\CappedMemoryCache;
use OCA\WorkflowEngine\AppInfo\Application;
use OCA\WorkflowEngine\Check\FileMimeType;
use OCA\WorkflowEngine\Check\FileName;
use OCA\WorkflowEngine\Check\FileSize;
Expand All @@ -40,6 +41,7 @@
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
Expand Down Expand Up @@ -108,14 +110,18 @@ class Manager implements IManager {
/** @var IEventDispatcher */
private $dispatcher;

/** @var IConfig */
private $config;

public function __construct(
IDBConnection $connection,
IServerContainer $container,
IL10N $l,
LegacyDispatcher $eventDispatcher,
ILogger $logger,
IUserSession $session,
IEventDispatcher $dispatcher
IEventDispatcher $dispatcher,
IConfig $config
) {
$this->connection = $connection;
$this->container = $container;
Expand All @@ -125,6 +131,7 @@ public function __construct(
$this->operationsByScope = new CappedMemoryCache(64);
$this->session = $session;
$this->dispatcher = $dispatcher;
$this->config = $config;
}

public function getRuleMatcher(): IRuleMatcher {
Expand Down Expand Up @@ -708,4 +715,8 @@ protected function getBuildInChecks(): array {
return [];
}
}

public function isUserScopeEnabled(): bool {
return $this->config->getAppValue(Application::APP_ID, 'user_scope_disabled', 'no') === 'no';
}
}
2 changes: 1 addition & 1 deletion apps/workflowengine/lib/Service/RuleMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getFlows(bool $returnFirstMatchingOperationOnly = true): array {
public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array {
$scopes[] = new ScopeContext(IManager::SCOPE_ADMIN);
$user = $this->session->getUser();
if($user !== null) {
if($user !== null && $this->manager->isUserScopeEnabled()) {
$scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
}

Expand Down
2 changes: 1 addition & 1 deletion apps/workflowengine/lib/Settings/ASettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ abstract class ASettings implements ISettings {
private $eventDispatcher;

/** @var Manager */
private $manager;
protected $manager;

/** @var IInitialStateService */
private $initialStateService;
Expand Down
4 changes: 4 additions & 0 deletions apps/workflowengine/lib/Settings/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ class Personal extends ASettings {
function getScope(): int {
return IManager::SCOPE_USER;
}

public function getSection() {
return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
}
}
7 changes: 6 additions & 1 deletion apps/workflowengine/tests/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\WorkflowEngine\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
Expand Down Expand Up @@ -67,6 +68,8 @@ class ManagerTest extends TestCase {
protected $l;
/** @var MockObject|IEventDispatcher */
protected $dispatcher;
/** @var MockObject|IConfig */
protected $config;

protected function setUp(): void {
parent::setUp();
Expand All @@ -84,6 +87,7 @@ protected function setUp(): void {
$this->logger = $this->createMock(ILogger::class);
$this->session = $this->createMock(IUserSession::class);
$this->dispatcher = $this->createMock(IEventDispatcher::class);
$this->config = $this->createMock(IConfig::class);

$this->manager = new Manager(
\OC::$server->getDatabaseConnection(),
Expand All @@ -92,7 +96,8 @@ protected function setUp(): void {
$this->legacyDispatcher,
$this->logger,
$this->session,
$this->dispatcher
$this->dispatcher,
$this->config
);
$this->clearTables();
}
Expand Down