Merge pull request #9108 from nextcloud/ocs-api-subadmins-quota-adduser
Allow user creation with subadmins and quota
This commit is contained in:
commit
0327ef1044
|
@ -196,10 +196,17 @@ class UsersController extends AUserData {
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @param array $groups
|
* @param array $groups
|
||||||
|
* @param array $subadmins
|
||||||
|
* @param string $quota
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
* @throws OCSException
|
* @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();
|
$user = $this->userSession->getUser();
|
||||||
$isAdmin = $this->groupManager->isAdmin($user->getUID());
|
$isAdmin = $this->groupManager->isAdmin($user->getUID());
|
||||||
$subAdminManager = $this->groupManager->getSubAdmin();
|
$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;
|
$generatePasswordResetToken = false;
|
||||||
if ($password === '') {
|
if ($password === '') {
|
||||||
if ($email === '') {
|
if ($email === '') {
|
||||||
|
@ -244,6 +271,13 @@ class UsersController extends AUserData {
|
||||||
$this->groupManager->get($group)->addUser($newUser);
|
$this->groupManager->get($group)->addUser($newUser);
|
||||||
$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
|
$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
|
// Send new user mail only if a mail is set
|
||||||
if ($email !== '') {
|
if ($email !== '') {
|
||||||
|
|
Loading…
Reference in New Issue