|
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\Deck\Collaboration\Resources; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
use OCA\Deck\Db\Acl; |
|
28
|
|
|
use OCA\Deck\Db\Board; |
|
29
|
|
|
use OCA\Deck\Db\BoardMapper; |
|
30
|
|
|
use OCA\Deck\Service\PermissionService; |
|
31
|
|
|
use OCP\AppFramework\Db\DoesNotExistException; |
|
32
|
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException; |
|
33
|
|
|
use OCP\AppFramework\QueryException; |
|
34
|
|
|
use OCP\Collaboration\Resources\IManager; |
|
35
|
|
|
use OCP\Collaboration\Resources\IProvider; |
|
36
|
|
|
use OCP\Collaboration\Resources\IResource; |
|
37
|
|
|
use OCP\Collaboration\Resources\ResourceException; |
|
38
|
|
|
use OCP\IUser; |
|
39
|
|
|
|
|
40
|
|
|
class ResourceProvider implements IProvider { |
|
41
|
|
|
|
|
42
|
|
|
const RESOURCE_TYPE = 'deck'; |
|
43
|
|
|
|
|
44
|
|
|
private $boardMapper; |
|
45
|
|
|
private $permissionService; |
|
46
|
|
|
|
|
47
|
|
|
/** @var array */ |
|
48
|
|
|
protected $nodes = []; |
|
49
|
|
|
|
|
50
|
|
|
public function __construct(BoardMapper $boardMapper, PermissionService $permissionService) { |
|
51
|
|
|
$this->boardMapper = $boardMapper; |
|
52
|
|
|
$this->permissionService = $permissionService; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Get the type of a resource |
|
57
|
|
|
* |
|
58
|
|
|
* @param IResource $resource |
|
|
|
|
|
|
59
|
|
|
* @return string |
|
60
|
|
|
* @since 15.0.0 |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getType(): string { |
|
63
|
|
|
return self::RESOURCE_TYPE; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the rich object data of a resource |
|
68
|
|
|
* |
|
69
|
|
|
* @param IResource $resource |
|
70
|
|
|
* @return array |
|
71
|
|
|
* @throws \OCP\AppFramework\Db\DoesNotExistException |
|
72
|
|
|
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
|
73
|
|
|
* @since 16.0.0 |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getResourceRichObject(IResource $resource): array { |
|
76
|
|
|
$board = $this->getBoard($resource); |
|
77
|
|
|
$link = \OC::$server->getURLGenerator()->linkToRoute('deck.page.index') . '#!/board/' . $resource->getId(); |
|
78
|
|
|
|
|
79
|
|
|
return [ |
|
80
|
|
|
'type' => self::RESOURCE_TYPE, |
|
81
|
|
|
'id' => $resource->getId(), |
|
82
|
|
|
'name' => $board->getTitle(), |
|
83
|
|
|
'link' => $link, |
|
84
|
|
|
'iconUrl' => \OC::$server->getURLGenerator()->imagePath('deck', 'deck-dark.svg') |
|
85
|
|
|
]; |
|
86
|
|
|
|
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Can a user/guest access the collection |
|
91
|
|
|
* |
|
92
|
|
|
* @param IResource $resource |
|
93
|
|
|
* @param IUser|null $user |
|
94
|
|
|
* @return bool |
|
95
|
|
|
* @since 16.0.0 |
|
96
|
|
|
*/ |
|
97
|
|
|
public function canAccessResource(IResource $resource, ?IUser $user): bool { |
|
98
|
|
|
if ($resource->getType() !== self::RESOURCE_TYPE || !$user instanceof IUser) { |
|
99
|
|
|
return false; |
|
100
|
|
|
} |
|
101
|
|
|
$board = $this->getBoard($resource); |
|
102
|
|
|
if ($board === null) { |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
if ($board->getOwner() === $user->getUID()) { |
|
106
|
|
|
return true; |
|
107
|
|
|
} |
|
108
|
|
|
return $this->permissionService->userCan($board->getAcl(), Acl::PERMISSION_READ, $user->getUID()); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
private function getBoard(IResource $resource) { |
|
112
|
|
|
try { |
|
113
|
|
|
return $this->boardMapper->find($resource->getId(), false, true); |
|
114
|
|
|
} catch (DoesNotExistException $e) { |
|
115
|
|
|
} catch (MultipleObjectsReturnedException $e) { |
|
116
|
|
|
return null; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function invalidateAccessCache($boardId = null) { |
|
121
|
|
|
try { |
|
122
|
|
|
/** @var IManager $resourceManager */ |
|
123
|
|
|
$resourceManager = \OC::$server->query(IManager::class); |
|
124
|
|
|
} catch (QueryException $e) { |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
if ($boardId !== null) { |
|
127
|
|
|
$resource = $resourceManager->getResourceForUser(self::RESOURCE_TYPE, (string)$boardId, null); |
|
128
|
|
|
$resourceManager->invalidateAccessCacheForResource($resource); |
|
129
|
|
|
} else { |
|
130
|
|
|
$resourceManager->invalidateAccessCacheForProvider($this); |
|
131
|
|
|
} |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.