mirror of
https://github.com/netzbegruenung/user_saml.git
synced 2024-05-02 17:14:53 +02:00
Implement backends add user to groups method
Signed-off-by: Jonathan Treffler <mail@jonathan-treffler.de> Signed-off-by: Giuliano Mele <giuliano.mele@verdigado.com>
This commit is contained in:
parent
993529ed30
commit
c5ff4555a3
30
lib/Exceptions/AddUserToGroupException.php
Normal file
30
lib/Exceptions/AddUserToGroupException.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
||||
*
|
||||
* @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\User_SAML\Exceptions;
|
||||
|
||||
/**
|
||||
* Class AddUserToGroupException is thrown when user could not be added to group
|
||||
*
|
||||
* @package OCA\User_SAML\Exceptions
|
||||
*/
|
||||
class AddUserToGroupException extends \Exception {
|
||||
}
|
|
@ -3,11 +3,13 @@
|
|||
namespace OCA\User_SAML;
|
||||
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use OCA\User_SAML\Exceptions\AddUserToGroupException;
|
||||
use OCP\Group\Backend\ABackend;
|
||||
use OCP\Group\Backend\IAddToGroupBackend;
|
||||
use OCP\Group\Backend\ICreateGroupBackend;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class GroupBackend extends ABackend {
|
||||
class GroupBackend extends ABackend implements IAddToGroupBackend {
|
||||
/** @var IDBConnection */
|
||||
private $dbc;
|
||||
|
||||
|
@ -175,4 +177,17 @@ class GroupBackend extends ABackend {
|
|||
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
public function addToGroup(string $uid, string $gid): bool {
|
||||
try {
|
||||
$qb = $this->dbc->getQueryBuilder();
|
||||
$qb->insert(self::TABLE_MEMBERS)
|
||||
->setValue('uid', $qb->createNamedParameter($uid))
|
||||
->setValue('gid', $qb->createNamedParameter($gid))
|
||||
->execute();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
throw new AddUserToGroupException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace OCA\User_SAML;
|
||||
|
||||
use OCA\User_SAML\Exceptions\AddUserToGroupException;
|
||||
use OCP\Authentication\IApacheBackend;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\Files\NotPermittedException;
|
||||
|
@ -672,9 +673,13 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
|
|||
if ($newGroups === null) {
|
||||
$newGroups = [];
|
||||
}
|
||||
$this->groupManager->replaceGroups($user->getUID(), $newGroups);
|
||||
try {
|
||||
$this->groupManager->replaceGroups($user->getUID(), $newGroups);
|
||||
} catch (AddUserToGroupException $e) {
|
||||
$this->logger->error('Failed to add user to group: {exception}', ['app' => 'user_saml', 'exception' => $e->getMessage()]);
|
||||
}
|
||||
// TODO: drop following line with dropping NC 18 support
|
||||
// $this->groupManager->evaluateGroupMigrations($newGroups);
|
||||
$this->groupManager->evaluateGroupMigrations($newGroups);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue