Files
deck/lib/AppInfo/Application.php
Julius Härtl a6b6842e2b No not fail on nonexisting acl users/groups
Signed-off-by: Julius Härtl <jus@bitgrid.net>
2017-05-03 13:25:58 +02:00

97 lines
3.0 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\AppInfo;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper;
use OCP\AppFramework\App;
use OCA\Deck\Middleware\SharingMiddleware;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
class Application extends App {
/**
* Application constructor.
*
* @param array $urlParams
*/
public function __construct(array $urlParams = array()) {
parent::__construct('deck', $urlParams);
$container = $this->getContainer();
$server = $container->getServer();
$container->registerService('SharingMiddleware', function($container) use ($server) {
return new SharingMiddleware(
$server->getLogger(),
$server->getConfig()
);
});
$container->registerMiddleware('SharingMiddleware');
// Delete user/group acl entries when they get deleted
/** @var IUserManager $userManager */
$userManager = $server->getUserManager();
$userManager->listen('\OC\User', 'postDelete', function(IUser $user) use ($container) {
/** @var AclMapper $aclMapper */
$aclMapper = $container->query(AclMapper::class);
$acls = $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_USER, $user->getUID());
foreach ($acls as $acl) {
$aclMapper->delete($acl);
}
});
/** @var IUserManager $userManager */
$groupManager = $server->getGroupManager();
$groupManager->listen('\OC\Group', 'postDelete', function(IGroup $group) use ($container) {
/** @var AclMapper $aclMapper */
$aclMapper = $container->query(AclMapper::class);
$aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID());
$acls = $aclMapper->findByParticipant(Acl::PERMISSION_TYPE_GROUP, $group->getGID());
foreach ($acls as $acl) {
$aclMapper->delete($acl);
}
});
}
public function registerNavigationEntry() {
$container = $this->getContainer();
$container->query('OCP\INavigationManager')->add(function() use ($container) {
$urlGenerator = $container->query('OCP\IURLGenerator');
$l10n = $container->query('OCP\IL10N');
return [
'id' => 'deck',
'order' => 10,
'href' => $urlGenerator->linkToRoute('deck.page.index'),
'icon' => $urlGenerator->imagePath('deck', 'app.svg'),
'name' => $l10n->t('Deck'),
];
});
}
}