Passed
Push — master ( 2187f8...15d39c )
by Joas
11:45 queued 12s
created

UserWorkflowsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 9
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]>
5
 *
6
 * @author Arthur Schiwon <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\WorkflowEngine\Controller;
26
27
use OCA\WorkflowEngine\Helper\ScopeContext;
28
use OCA\WorkflowEngine\Manager;
29
use OCP\AppFramework\Http\DataResponse;
30
use OCP\AppFramework\OCS\OCSBadRequestException;
31
use OCP\AppFramework\OCS\OCSForbiddenException;
32
use OCP\IRequest;
33
use OCP\IUserSession;
34
use OCP\WorkflowEngine\IManager;
35
36
class UserWorkflowsController extends AWorkflowController {
37
38
	/** @var IUserSession */
39
	private $session;
40
41
	/** @var ScopeContext */
42
	private $scopeContext;
43
44
	public function __construct(
45
		$appName,
46
		IRequest $request,
47
		Manager $manager,
48
		IUserSession $session
49
	) {
50
		parent::__construct($appName, $request, $manager);
51
52
		$this->session = $session;
53
	}
54
55
	/**
56
	 * Retrieve all configured workflow rules
57
	 *
58
	 * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user?format=json"
59
	 *
60
	 * @NoAdminRequired
61
	 * @throws OCSForbiddenException
62
	 */
63
	public function index(): DataResponse {
64
		return parent::index();
65
	}
66
67
	/**
68
	 * @NoAdminRequired
69
	 *
70
	 * Example: curl -u joann -H "OCS-APIREQUEST: true" "http://my.nc.srvr/ocs/v2.php/apps/workflowengine/api/v1/workflows/user/OCA\\Workflow_DocToPdf\\Operation?format=json"
71
	 * @throws OCSForbiddenException
72
	 */
73
	public function show(string $id): DataResponse {
74
		return parent::show($id);
75
	}
76
77
	/**
78
	 * @NoAdminRequired
79
	 * @throws OCSBadRequestException
80
	 * @throws OCSForbiddenException
81
	 */
82
	public function create(string $class, string $name, array $checks, string $operation): DataResponse {
83
		return parent::create($class, $name, $checks, $operation);
0 ignored issues
show
Bug introduced by
The call to OCA\WorkflowEngine\Contr...lowController::create() has too few arguments starting with entity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
		return parent::/** @scrutinizer ignore-call */ create($class, $name, $checks, $operation);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
84
	}
85
86
	/**
87
	 * @NoAdminRequired
88
	 * @throws OCSBadRequestException
89
	 * @throws OCSForbiddenException
90
	 */
91
	public function update(int $id, string $name, array $checks, string $operation): DataResponse {
92
		return parent::update($id, $name, $checks, $operation);
0 ignored issues
show
Bug introduced by
The call to OCA\WorkflowEngine\Contr...lowController::update() has too few arguments starting with entity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

92
		return parent::/** @scrutinizer ignore-call */ update($id, $name, $checks, $operation);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
93
	}
94
95
	/**
96
	 * @NoAdminRequired
97
	 * @throws OCSForbiddenException
98
	 */
99
	public function destroy(int $id): DataResponse {
100
		return parent::destroy($id);
101
	}
102
103
	/**
104
	 * @throws OCSForbiddenException
105
	 */
106
	protected function getScopeContext(): ScopeContext {
107
		if($this->scopeContext === null) {
108
			$user = $this->session->getUser();
109
			if(!$user) {
110
				throw new OCSForbiddenException('User not logged in');
111
			}
112
			$this->scopeContext = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
113
		}
114
		return $this->scopeContext;
115
	}
116
117
}
118