|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016 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\AppInfo; |
|
25
|
|
|
|
|
26
|
|
|
use Exception; |
|
27
|
|
|
use InvalidArgumentException; |
|
28
|
|
|
use OC_Util; |
|
29
|
|
|
use OCA\Deck\Activity\CommentEventHandler; |
|
30
|
|
|
use OCA\Deck\Capabilities; |
|
31
|
|
|
use OCA\Deck\Collaboration\Resources\ResourceProvider; |
|
32
|
|
|
use OCA\Deck\Collaboration\Resources\ResourceProviderCard; |
|
33
|
|
|
use OCA\Deck\Db\Acl; |
|
34
|
|
|
use OCA\Deck\Db\AclMapper; |
|
35
|
|
|
use OCA\Deck\Db\AssignedUsersMapper; |
|
36
|
|
|
use OCA\Deck\Db\CardMapper; |
|
37
|
|
|
use OCA\Deck\Middleware\DefaultBoardMiddleware; |
|
38
|
|
|
use OCA\Deck\Middleware\ExceptionMiddleware; |
|
39
|
|
|
use OCA\Deck\Notification\Notifier; |
|
40
|
|
|
use OCA\Deck\Service\FullTextSearchService; |
|
41
|
|
|
use OCP\AppFramework\App; |
|
42
|
|
|
use OCP\Collaboration\Resources\IManager; |
|
43
|
|
|
use OCP\Collaboration\Resources\IProviderManager; |
|
44
|
|
|
use OCP\Comments\CommentsEntityEvent; |
|
45
|
|
|
use OCP\FullTextSearch\IFullTextSearchManager; |
|
46
|
|
|
use OCP\IGroup; |
|
47
|
|
|
use OCP\IServerContainer; |
|
48
|
|
|
use OCP\IUser; |
|
49
|
|
|
use OCP\IUserManager; |
|
50
|
|
|
use OCP\IURLGenerator; |
|
51
|
|
|
use OCP\Util; |
|
52
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
53
|
|
|
|
|
54
|
|
|
class Application extends App { |
|
55
|
|
|
|
|
56
|
|
|
public const APP_ID = 'deck'; |
|
57
|
|
|
|
|
58
|
|
|
/** @var IServerContainer */ |
|
59
|
|
|
private $server; |
|
60
|
|
|
|
|
61
|
|
|
/** @var FullTextSearchService */ |
|
62
|
|
|
private $fullTextSearchService; |
|
63
|
|
|
|
|
64
|
|
|
/** @var IFullTextSearchManager */ |
|
65
|
|
|
private $fullTextSearchManager; |
|
66
|
|
|
|
|
67
|
|
|
public function __construct(array $urlParams = array()) { |
|
68
|
|
|
parent::__construct('deck', $urlParams); |
|
69
|
|
|
|
|
70
|
|
|
$container = $this->getContainer(); |
|
71
|
|
|
$server = $this->getContainer()->getServer(); |
|
72
|
|
|
|
|
73
|
|
|
$this->server = $server; |
|
74
|
|
|
|
|
75
|
|
|
$container->registerCapability(Capabilities::class); |
|
76
|
|
|
$container->registerMiddleWare(ExceptionMiddleware::class); |
|
77
|
|
|
$container->registerMiddleWare(DefaultBoardMiddleware::class); |
|
78
|
|
|
|
|
79
|
|
|
$container->registerService('databaseType', static function() use ($server) { |
|
80
|
|
|
return $server->getConfig()->getSystemValue('dbtype', 'sqlite'); |
|
81
|
|
|
}); |
|
82
|
|
|
$container->registerService('database4ByteSupport', static function() use ($server) { |
|
83
|
|
|
return $server->getDatabaseConnection()->supports4ByteText(); |
|
84
|
|
|
}); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function register(): void { |
|
88
|
|
|
$this->registerNavigationEntry(); |
|
89
|
|
|
$this->registerUserGroupHooks(); |
|
90
|
|
|
$this->registerNotifications(); |
|
91
|
|
|
$this->registerCommentsEntity(); |
|
92
|
|
|
$this->registerFullTextSearch(); |
|
93
|
|
|
$this->registerCollaborationResources(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function registerNavigationEntry(): void { |
|
97
|
|
|
$container = $this->getContainer(); |
|
98
|
|
|
$this->server->getNavigationManager()->add(static function() use ($container) { |
|
99
|
|
|
$urlGenerator = $container->query(IURLGenerator::class); |
|
100
|
|
|
return [ |
|
101
|
|
|
'id' => 'deck', |
|
102
|
|
|
'order' => 10, |
|
103
|
|
|
'href' => $urlGenerator->linkToRoute('deck.page.index'), |
|
104
|
|
|
'icon' => $urlGenerator->imagePath('deck', 'deck.svg'), |
|
105
|
|
|
'name' => 'Deck', |
|
106
|
|
|
]; |
|
107
|
|
|
}); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
private function registerUserGroupHooks(): void { |
|
111
|
|
|
$container = $this->getContainer(); |
|
112
|
|
|
// Delete user/group acl entries when they get deleted |
|
113
|
|
|
/** @var IUserManager $userManager */ |
|
114
|
|
|
$userManager = $this->server->getUserManager(); |
|
115
|
|
|
$userManager->listen('\OC\User', 'postDelete', static function(IUser $user) use ($container) { |
|
|
|
|
|
|
116
|
|
|
// delete existing acl entries for deleted user |
|
117
|
|
|
/** @var AclMapper $aclMapper */ |
|
118
|
|
|
$aclMapper = $container->query(AclMapper::class); |
|
119
|
|
|
$acls = $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_USER, $user->getUID()); |
|
120
|
|
|
foreach ($acls as $acl) { |
|
121
|
|
|
$aclMapper->delete($acl); |
|
122
|
|
|
} |
|
123
|
|
|
// delete existing user assignments |
|
124
|
|
|
$assignmentMapper = $container->query(AssignedUsersMapper::class); |
|
125
|
|
|
$assignments = $assignmentMapper->findByUserId($user->getUID()); |
|
126
|
|
|
foreach ($assignments as $assignment) { |
|
127
|
|
|
$assignmentMapper->delete($assignment); |
|
128
|
|
|
} |
|
129
|
|
|
}); |
|
130
|
|
|
|
|
131
|
|
|
/** @var IUserManager $userManager */ |
|
132
|
|
|
$groupManager = $this->server->getGroupManager(); |
|
133
|
|
|
$groupManager->listen('\OC\Group', 'postDelete', static function(IGroup $group) use ($container) { |
|
|
|
|
|
|
134
|
|
|
/** @var AclMapper $aclMapper */ |
|
135
|
|
|
$aclMapper = $container->query(AclMapper::class); |
|
136
|
|
|
$aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID()); |
|
137
|
|
|
$acls = $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID()); |
|
138
|
|
|
foreach ($acls as $acl) { |
|
139
|
|
|
$aclMapper->delete($acl); |
|
140
|
|
|
} |
|
141
|
|
|
}); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function registerNotifications(): void { |
|
145
|
|
|
$notificationManager = $this->server->getNotificationManager(); |
|
146
|
|
|
$notificationManager->registerNotifierService(Notifier::class); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function registerCommentsEntity(): void { |
|
150
|
|
|
$this->server->getEventDispatcher()->addListener(CommentsEntityEvent::EVENT_ENTITY, function(CommentsEntityEvent $event) { |
|
151
|
|
|
$event->addEntityCollection('deckCard', function($name) { |
|
152
|
|
|
/** @var CardMapper */ |
|
153
|
|
|
$service = $this->getContainer()->query(CardMapper::class); |
|
154
|
|
|
try { |
|
155
|
|
|
$service->find((int) $name); |
|
156
|
|
|
} catch (InvalidArgumentException $e) { |
|
157
|
|
|
return false; |
|
158
|
|
|
} |
|
159
|
|
|
return true; |
|
160
|
|
|
}); |
|
161
|
|
|
}); |
|
162
|
|
|
$this->registerCommentsEventHandler(); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
*/ |
|
167
|
|
|
protected function registerCommentsEventHandler(): void { |
|
168
|
|
|
$this->server->getCommentsManager()->registerEventHandler(function () { |
|
169
|
|
|
return $this->getContainer()->query(CommentEventHandler::class); |
|
170
|
|
|
}); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
protected function registerCollaborationResources(): void { |
|
174
|
|
|
$version = OC_Util::getVersion()[0]; |
|
175
|
|
|
if ($version < 16) { |
|
176
|
|
|
return; |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* Register Collaboration ResourceProvider |
|
181
|
|
|
* |
|
182
|
|
|
* @Todo: Remove if min-version is 18 |
|
183
|
|
|
*/ |
|
184
|
|
|
if ($version < 18) { |
|
185
|
|
|
/** @var IManager $resourceManager */ |
|
186
|
|
|
$resourceManager = $this->getContainer()->query(IManager::class); |
|
187
|
|
|
} else { |
|
188
|
|
|
/** @var IProviderManager $resourceManager */ |
|
189
|
|
|
$resourceManager = $this->getContainer()->query(IProviderManager::class); |
|
190
|
|
|
} |
|
191
|
|
|
$resourceManager->registerResourceProvider(ResourceProvider::class); |
|
192
|
|
|
$resourceManager->registerResourceProvider(ResourceProviderCard::class); |
|
193
|
|
|
|
|
194
|
|
|
$this->server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () { |
|
195
|
|
|
Util::addScript('deck', 'collections'); |
|
196
|
|
|
}); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
public function registerFullTextSearch(): void { |
|
200
|
|
|
if (Util::getVersion()[0] < 16) { |
|
201
|
|
|
return; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
$c = $this->getContainer(); |
|
205
|
|
|
try { |
|
206
|
|
|
$this->fullTextSearchService = $c->query(FullTextSearchService::class); |
|
207
|
|
|
$this->fullTextSearchManager = $c->query(IFullTextSearchManager::class); |
|
208
|
|
|
} catch (Exception $e) { |
|
209
|
|
|
return; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
if (!$this->fullTextSearchManager->isAvailable()) { |
|
213
|
|
|
return; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
$eventDispatcher = $this->server->getEventDispatcher(); |
|
217
|
|
|
$eventDispatcher->addListener( |
|
218
|
|
|
'\OCA\Deck\Card::onCreate', function(GenericEvent $e) { |
|
219
|
|
|
$this->fullTextSearchService->onCardCreated($e); |
|
220
|
|
|
} |
|
221
|
|
|
); |
|
222
|
|
|
$eventDispatcher->addListener( |
|
223
|
|
|
'\OCA\Deck\Card::onUpdate', function(GenericEvent $e) { |
|
224
|
|
|
$this->fullTextSearchService->onCardUpdated($e); |
|
225
|
|
|
} |
|
226
|
|
|
); |
|
227
|
|
|
$eventDispatcher->addListener( |
|
228
|
|
|
'\OCA\Deck\Card::onDelete', function(GenericEvent $e) { |
|
229
|
|
|
$this->fullTextSearchService->onCardDeleted($e); |
|
230
|
|
|
} |
|
231
|
|
|
); |
|
232
|
|
|
$eventDispatcher->addListener( |
|
233
|
|
|
'\OCA\Deck\Board::onShareNew', function(GenericEvent $e) { |
|
234
|
|
|
$this->fullTextSearchService->onBoardShares($e); |
|
235
|
|
|
} |
|
236
|
|
|
); |
|
237
|
|
|
$eventDispatcher->addListener( |
|
238
|
|
|
'\OCA\Deck\Board::onShareEdit', function(GenericEvent $e) { |
|
239
|
|
|
$this->fullTextSearchService->onBoardShares($e); |
|
240
|
|
|
} |
|
241
|
|
|
); |
|
242
|
|
|
$eventDispatcher->addListener( |
|
243
|
|
|
'\OCA\Deck\Board::onShareDelete', function(GenericEvent $e) { |
|
244
|
|
|
$this->fullTextSearchService->onBoardShares($e); |
|
245
|
|
|
} |
|
246
|
|
|
); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
} |
|
250
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.