Skip to content

Commit 4261cfb

Browse files
authored
Merge pull request #20158 from nextcloud/backport/19930/stable18
[stable18] Add app config to disable user flows
2 parents b54b5a5 + aeff8a8 commit 4261cfb

6 files changed

Lines changed: 25 additions & 5 deletions

File tree

apps/workflowengine/lib/Controller/UserWorkflowsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function destroy(int $id): DataResponse {
106106
protected function getScopeContext(): ScopeContext {
107107
if($this->scopeContext === null) {
108108
$user = $this->session->getUser();
109-
if(!$user) {
109+
if(!$user || !$this->manager->isUserScopeEnabled()) {
110110
throw new OCSForbiddenException('User not logged in');
111111
}
112112
$this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());

apps/workflowengine/lib/Manager.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
use Doctrine\DBAL\DBALException;
2525
use OC\Cache\CappedMemoryCache;
26+
use OCA\WorkflowEngine\AppInfo\Application;
2627
use OCA\WorkflowEngine\Check\FileMimeType;
2728
use OCA\WorkflowEngine\Check\FileName;
2829
use OCA\WorkflowEngine\Check\FileSize;
@@ -40,6 +41,7 @@
4041
use OCP\DB\QueryBuilder\IQueryBuilder;
4142
use OCP\EventDispatcher\IEventDispatcher;
4243
use OCP\Files\Storage\IStorage;
44+
use OCP\IConfig;
4345
use OCP\IDBConnection;
4446
use OCP\IL10N;
4547
use OCP\ILogger;
@@ -108,14 +110,18 @@ class Manager implements IManager {
108110
/** @var IEventDispatcher */
109111
private $dispatcher;
110112

113+
/** @var IConfig */
114+
private $config;
115+
111116
public function __construct(
112117
IDBConnection $connection,
113118
IServerContainer $container,
114119
IL10N $l,
115120
LegacyDispatcher $eventDispatcher,
116121
ILogger $logger,
117122
IUserSession $session,
118-
IEventDispatcher $dispatcher
123+
IEventDispatcher $dispatcher,
124+
IConfig $config
119125
) {
120126
$this->connection = $connection;
121127
$this->container = $container;
@@ -125,6 +131,7 @@ public function __construct(
125131
$this->operationsByScope = new CappedMemoryCache(64);
126132
$this->session = $session;
127133
$this->dispatcher = $dispatcher;
134+
$this->config = $config;
128135
}
129136

130137
public function getRuleMatcher(): IRuleMatcher {
@@ -704,4 +711,8 @@ protected function getBuildInChecks(): array {
704711
return [];
705712
}
706713
}
714+
715+
public function isUserScopeEnabled(): bool {
716+
return $this->config->getAppValue(Application::APP_ID, 'user_scope_disabled', 'no') === 'no';
717+
}
707718
}

apps/workflowengine/lib/Service/RuleMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function getFlows(bool $returnFirstMatchingOperationOnly = true): array {
117117
public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array {
118118
$scopes[] = new ScopeContext(IManager::SCOPE_ADMIN);
119119
$user = $this->session->getUser();
120-
if($user !== null) {
120+
if($user !== null && $this->manager->isUserScopeEnabled()) {
121121
$scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
122122
}
123123

apps/workflowengine/lib/Settings/ASettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract class ASettings implements ISettings {
4949
private $eventDispatcher;
5050

5151
/** @var Manager */
52-
private $manager;
52+
protected $manager;
5353

5454
/** @var IInitialStateService */
5555
private $initialStateService;

apps/workflowengine/lib/Settings/Personal.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ class Personal extends ASettings {
3131
function getScope(): int {
3232
return IManager::SCOPE_USER;
3333
}
34+
35+
public function getSection() {
36+
return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
37+
}
3438
}

apps/workflowengine/tests/ManagerTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OCA\WorkflowEngine\Manager;
2929
use OCP\EventDispatcher\IEventDispatcher;
3030
use OCP\Files\IRootFolder;
31+
use OCP\IConfig;
3132
use OCP\IDBConnection;
3233
use OCP\IL10N;
3334
use OCP\ILogger;
@@ -67,6 +68,8 @@ class ManagerTest extends TestCase {
6768
protected $l;
6869
/** @var MockObject|IEventDispatcher */
6970
protected $dispatcher;
71+
/** @var MockObject|IConfig */
72+
protected $config;
7073

7174
protected function setUp(): void {
7275
parent::setUp();
@@ -84,6 +87,7 @@ protected function setUp(): void {
8487
$this->logger = $this->createMock(ILogger::class);
8588
$this->session = $this->createMock(IUserSession::class);
8689
$this->dispatcher = $this->createMock(IEventDispatcher::class);
90+
$this->config = $this->createMock(IConfig::class);
8791

8892
$this->manager = new Manager(
8993
\OC::$server->getDatabaseConnection(),
@@ -92,7 +96,8 @@ protected function setUp(): void {
9296
$this->legacyDispatcher,
9397
$this->logger,
9498
$this->session,
95-
$this->dispatcher
99+
$this->dispatcher,
100+
$this->config
96101
);
97102
$this->clearTables();
98103
}

0 commit comments

Comments
 (0)