|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2019 Julius Härtl <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @author Julius Härtl <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OCA\Richdocuments\Service; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
use OCP\IUserManager; |
|
28
|
|
|
use OCP\IUserSession; |
|
29
|
|
|
|
|
30
|
|
|
class UserScopeService { |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(IUserSession $userSession, IUserManager $userManager) { |
|
33
|
|
|
$this->userSession = $userSession; |
|
|
|
|
|
|
34
|
|
|
$this->userManager = $userManager; |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Set a valid user in IUserSession since lots of server logic is relying on obtaining |
|
39
|
|
|
* the current acting user from that |
|
40
|
|
|
* |
|
41
|
|
|
* @param $uid |
|
42
|
|
|
* @throws \InvalidArgumentException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function setUserScope(string $uid = null) { |
|
45
|
|
|
if ($uid === null) { |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$user = $this->userManager->get($uid); |
|
50
|
|
|
if ($user === null) { |
|
51
|
|
|
throw new \InvalidArgumentException('No user found for the uid ' . $uid); |
|
52
|
|
|
} |
|
53
|
|
|
$this->userSession->setUser($user); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Setup the FS which is needed to emit hooks |
|
58
|
|
|
* |
|
59
|
|
|
* This is required for versioning/activity as the legacy filesystem hooks |
|
60
|
|
|
* are not emitted if filesystem operations are executed though \OCP\Files\Node\File |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $owner |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setFilesystemScope(string $owner): void { |
|
65
|
|
|
\OC_Util::tearDownFS(); |
|
66
|
|
|
\OC_Util::setupFS($owner); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: