Allow user creation with subadmins and quota

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-04-06 15:07:04 +02:00
parent 4a6e31c91d
commit 18ec4ddd2b
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF

View file

@ -196,10 +196,17 @@ class UsersController extends AUserData {
* @param string $password
* @param string $email
* @param array $groups
* @param array $subadmins
* @param string $quota
* @return DataResponse
* @throws OCSException
*/
public function addUser(string $userid, string $password = '', string $email='', array $groups = []): DataResponse {
public function addUser(string $userid,
string $password = '',
string $email = '',
array $groups = [],
array $subadmin = [],
string $quota = ''): DataResponse {
$user = $this->userSession->getUser();
$isAdmin = $this->groupManager->isAdmin($user->getUID());
$subAdminManager = $this->groupManager->getSubAdmin();
@ -224,6 +231,26 @@ class UsersController extends AUserData {
}
}
$subadminGroups = [];
if ($subadmin !== []) {
foreach ($subadmin as $groupid) {
$group = $this->groupManager->get($groupid);
// Check if group exists
if ($group === null) {
throw new OCSException('Subadmin group does not exist', 102);
}
// Check if trying to make subadmin of admin group
if ($group->getGID() === 'admin') {
throw new OCSException('Cannot create subadmins for admin group', 103);
}
// Check if has permission to promote subadmins
if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) {
throw new OCSForbiddenException('No permissions to promote subadmins');
}
$subadminGroups[] = $group;
}
}
$generatePasswordResetToken = false;
if ($password === '') {
if ($email === '') {
@ -244,6 +271,13 @@ class UsersController extends AUserData {
$this->groupManager->get($group)->addUser($newUser);
$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
}
foreach ($subadminGroups as $group) {
$subAdminManager->createSubAdmin($newUser, $group);
}
if ($quota !== '') {
$this->editUser($userid, 'quota', $quota);
}
// Send new user mail only if a mail is set
if ($email !== '') {