Merge pull request #1234 from nextcloud/rebase-413-by-faldon
Disabling users in WebUI
This commit is contained in:
commit
854dfef199
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1792 1792">
|
||||||
|
<path d="m576 896q-159 0-271.5-112.5t-112.5-271.5 112.5-271.5 271.5-112.5 271.5 112.5 112.5 271.5-112.5 271.5-271.5 112.5zm960 128h352q13 0 22.5 9.5t9.5 22.5v192q0 13-9.5 22.5t-22.5 9.5h-352v352q0 13-9.5 22.5t-22.5 9.5h-192q-13 0-22.5-9.5t-9.5-22.5v-352h-352q-13 0-22.5-9.5t-9.5-22.5v-192q0-13 9.5-22.5t22.5-9.5h352v-352q0-13 9.5-22.5t22.5-9.5h192q13 0 22.5 9.5t9.5 22.5v352zm-736 224q0 52 38 90t90 38h256v238q-68 50-171 50h-874q-121 0-194-69t-73-190q0-53 3.5-103.5t14-109 26.5-108.5 43-97.5 62-81 85.5-53.5 111.5-20q19 0 39 17 79 61 154.5 91.5t164.5 30.5 164.5-30.5 154.5-91.5q20-17 39-17 132 0 217 96h-223q-52 0-90 38t-38 90v192z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 777 B |
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1792 1792">
|
||||||
|
<path d="m576 896q-159 0-271.5-112.5t-112.5-271.5 112.5-271.5 271.5-112.5 271.5 112.5 112.5 271.5-112.5 271.5-271.5 112.5zm1077 320l249 249q9 9 9 23 0 13-9 22l-136 136q-9 9-22 9-14 0-23-9l-249-249-249 249q-9 9-23 9-13 0-22-9l-136-136q-9-9-9-22 0-14 9-23l249-249-249-249q-9-9-9-23 0-13 9-22l136-136q9-9 22-9 14 0 23 9l249 249 249-249q9-9 23-9 13 0 22 9l136 136q9 9 9 22 0 14-9 23zm-498 0l-181 181q-37 37-37 91 0 53 37 90l83 83q-21 3-44 3h-874q-121 0-194-69t-73-190q0-53 3.5-103.5t14-109 26.5-108.5 43-97.5 62-81 85.5-53.5 111.5-20q19 0 39 17 154 122 319 122t319-122q20-17 39-17 28 0 57 6-28 27-41 50t-13 56q0 54 37 91z"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 763 B |
|
@ -408,6 +408,28 @@ class Manager extends PublicEmitter implements IUserManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns how many users have logged in once
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* @since 12.0.0
|
||||||
|
*/
|
||||||
|
public function countDisabledUsers() {
|
||||||
|
$queryBuilder = \OC::$server->getDatabaseConnection()->getQueryBuilder();
|
||||||
|
$queryBuilder->select($queryBuilder->createFunction('COUNT(*)'))
|
||||||
|
->from('preferences')
|
||||||
|
->where($queryBuilder->expr()->eq('appid', $queryBuilder->createNamedParameter('core')))
|
||||||
|
->andWhere($queryBuilder->expr()->eq('configkey', $queryBuilder->createNamedParameter('enabled')))
|
||||||
|
->andWhere($queryBuilder->expr()->eq('configvalue', $queryBuilder->createNamedParameter('false')));
|
||||||
|
|
||||||
|
$query = $queryBuilder->execute();
|
||||||
|
|
||||||
|
$result = (int)$query->fetchColumn();
|
||||||
|
$query->closeCursor();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns how many users have logged in once
|
* returns how many users have logged in once
|
||||||
*
|
*
|
||||||
|
|
|
@ -154,6 +154,14 @@ interface IUserManager {
|
||||||
*/
|
*/
|
||||||
public function callForAllUsers(\Closure $callback, $search = '');
|
public function callForAllUsers(\Closure $callback, $search = '');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns how many users have logged in once
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
* @since 11.0.0
|
||||||
|
*/
|
||||||
|
public function countDisabledUsers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns how many users have logged in once
|
* returns how many users have logged in once
|
||||||
*
|
*
|
||||||
|
|
|
@ -225,6 +225,7 @@ class UsersController extends Controller {
|
||||||
'email' => $displayName,
|
'email' => $displayName,
|
||||||
'isRestoreDisabled' => !$restorePossible,
|
'isRestoreDisabled' => !$restorePossible,
|
||||||
'isAvatarAvailable' => $avatarAvailable,
|
'isAvatarAvailable' => $avatarAvailable,
|
||||||
|
'isEnabled' => $user->isEnabled(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,11 +254,6 @@ class UsersController extends Controller {
|
||||||
* TODO: Tidy up and write unit tests - code is mainly static method calls
|
* TODO: Tidy up and write unit tests - code is mainly static method calls
|
||||||
*/
|
*/
|
||||||
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
|
public function index($offset = 0, $limit = 10, $gid = '', $pattern = '', $backend = '') {
|
||||||
// FIXME: The JS sends the group '_everyone' instead of no GID for the "all users" group.
|
|
||||||
if($gid === '_everyone') {
|
|
||||||
$gid = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove backends
|
// Remove backends
|
||||||
if(!empty($backend)) {
|
if(!empty($backend)) {
|
||||||
$activeBackends = $this->userManager->getBackends();
|
$activeBackends = $this->userManager->getBackends();
|
||||||
|
@ -272,16 +268,19 @@ class UsersController extends Controller {
|
||||||
|
|
||||||
$users = [];
|
$users = [];
|
||||||
if ($this->isAdmin) {
|
if ($this->isAdmin) {
|
||||||
|
if($gid !== '' && $gid !== '_disabledUsers') {
|
||||||
if($gid !== '') {
|
|
||||||
$batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
|
$batch = $this->getUsersForUID($this->groupManager->displayNamesInGroup($gid, $pattern, $limit, $offset));
|
||||||
} else {
|
} else {
|
||||||
$batch = $this->userManager->search($pattern, $limit, $offset);
|
$batch = $this->userManager->search($pattern, $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($batch as $user) {
|
foreach ($batch as $user) {
|
||||||
|
if( ($gid !== '_disabledUsers' && $user->isEnabled()) ||
|
||||||
|
($gid === '_disabledUsers' && !$user->isEnabled())
|
||||||
|
) {
|
||||||
$users[] = $this->formatUserForIndex($user);
|
$users[] = $this->formatUserForIndex($user);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
|
$subAdminOfGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
|
||||||
|
@ -293,7 +292,7 @@ class UsersController extends Controller {
|
||||||
$subAdminOfGroups = $gids;
|
$subAdminOfGroups = $gids;
|
||||||
|
|
||||||
// Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
|
// Set the $gid parameter to an empty value if the subadmin has no rights to access a specific group
|
||||||
if($gid !== '' && !in_array($gid, $subAdminOfGroups)) {
|
if($gid !== '' && $gid !== '_disabledUsers' && !in_array($gid, $subAdminOfGroups)) {
|
||||||
$gid = '';
|
$gid = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,9 +317,13 @@ class UsersController extends Controller {
|
||||||
$this->groupManager->getUserGroupIds($user),
|
$this->groupManager->getUserGroupIds($user),
|
||||||
$subAdminOfGroups
|
$subAdminOfGroups
|
||||||
));
|
));
|
||||||
|
if( ($gid !== '_disabledUsers' && $user->isEnabled()) ||
|
||||||
|
($gid === '_disabledUsers' && !$user->isEnabled())
|
||||||
|
) {
|
||||||
$users[] = $this->formatUserForIndex($user, $userGroups);
|
$users[] = $this->formatUserForIndex($user, $userGroups);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new DataResponse($users);
|
return new DataResponse($users);
|
||||||
}
|
}
|
||||||
|
@ -335,12 +338,12 @@ class UsersController extends Controller {
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function create($username, $password, array $groups=array(), $email='') {
|
public function create($username, $password, array $groups=[], $email='') {
|
||||||
if($email !== '' && !$this->mailer->validateMailAddress($email)) {
|
if($email !== '' && !$this->mailer->validateMailAddress($email)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'message' => (string)$this->l10n->t('Invalid mail address')
|
'message' => (string)$this->l10n->t('Invalid mail address')
|
||||||
),
|
],
|
||||||
Http::STATUS_UNPROCESSABLE_ENTITY
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -364,9 +367,9 @@ class UsersController extends Controller {
|
||||||
|
|
||||||
if (empty($groups)) {
|
if (empty($groups)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'message' => $this->l10n->t('No valid group selected'),
|
'message' => $this->l10n->t('No valid group selected'),
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -374,9 +377,9 @@ class UsersController extends Controller {
|
||||||
|
|
||||||
if ($this->userManager->userExists($username)) {
|
if ($this->userManager->userExists($username)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'message' => (string)$this->l10n->t('A user with that name already exists.')
|
'message' => (string)$this->l10n->t('A user with that name already exists.')
|
||||||
),
|
],
|
||||||
Http::STATUS_CONFLICT
|
Http::STATUS_CONFLICT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -385,9 +388,9 @@ class UsersController extends Controller {
|
||||||
if ($password === '') {
|
if ($password === '') {
|
||||||
if ($email === '') {
|
if ($email === '') {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.')
|
'message' => (string)$this->l10n->t('To send a password link to the user an email address is required.')
|
||||||
),
|
],
|
||||||
Http::STATUS_UNPROCESSABLE_ENTITY
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -404,9 +407,9 @@ class UsersController extends Controller {
|
||||||
$message = $this->l10n->t('Unable to create user.');
|
$message = $this->l10n->t('Unable to create user.');
|
||||||
}
|
}
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'message' => (string) $message,
|
'message' => (string) $message,
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -431,7 +434,7 @@ class UsersController extends Controller {
|
||||||
$emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken);
|
$emailTemplate = $this->newUserMailHelper->generateTemplate($user, $generatePasswordResetToken);
|
||||||
$this->newUserMailHelper->sendMail($user, $emailTemplate);
|
$this->newUserMailHelper->sendMail($user, $emailTemplate);
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->log->error("Can't send new user mail to $email: " . $e->getMessage(), array('app' => 'settings'));
|
$this->log->error("Can't send new user mail to $email: " . $e->getMessage(), ['app' => 'settings']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fetch users groups
|
// fetch users groups
|
||||||
|
@ -444,9 +447,9 @@ class UsersController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'message' => (string) $this->l10n->t('Unable to create user.')
|
'message' => (string) $this->l10n->t('Unable to create user.')
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -465,24 +468,24 @@ class UsersController extends Controller {
|
||||||
|
|
||||||
if($userId === $id) {
|
if($userId === $id) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Unable to delete user.')
|
'message' => (string) $this->l10n->t('Unable to delete user.')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
|
if(!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string)$this->l10n->t('Authentication error')
|
'message' => (string)$this->l10n->t('Authentication error')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -490,29 +493,97 @@ class UsersController extends Controller {
|
||||||
if($user) {
|
if($user) {
|
||||||
if($user->delete()) {
|
if($user->delete()) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'username' => $id
|
'username' => $id
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_NO_CONTENT
|
Http::STATUS_NO_CONTENT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string)$this->l10n->t('Unable to delete user.')
|
'message' => (string)$this->l10n->t('Unable to delete user.')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param string $id
|
||||||
|
* @param int $enabled
|
||||||
|
* @return DataResponse
|
||||||
|
*/
|
||||||
|
public function setEnabled($id, $enabled) {
|
||||||
|
$enabled = (bool)$enabled;
|
||||||
|
if($enabled) {
|
||||||
|
$errorMsgGeneral = (string) $this->l10n->t('Error while enabling user.');
|
||||||
|
} else {
|
||||||
|
$errorMsgGeneral = (string) $this->l10n->t('Error while disabling user.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$userId = $this->userSession->getUser()->getUID();
|
||||||
|
$user = $this->userManager->get($id);
|
||||||
|
|
||||||
|
if ($userId === $id) {
|
||||||
|
return new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => $errorMsgGeneral
|
||||||
|
]
|
||||||
|
], Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($user) {
|
||||||
|
if (!$this->isAdmin && !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) {
|
||||||
|
return new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => (string) $this->l10n->t('Authentication error')
|
||||||
|
]
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->setEnabled($enabled);
|
||||||
|
return new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'username' => $id,
|
||||||
|
'enabled' => $enabled
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => $errorMsgGeneral
|
||||||
|
]
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the mail address of a user
|
||||||
|
*
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoSubadminRequired
|
* @NoSubadminRequired
|
||||||
* @PasswordConfirmationRequired
|
* @PasswordConfirmationRequired
|
||||||
|
@ -637,12 +708,12 @@ class UsersController extends Controller {
|
||||||
|
|
||||||
if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
|
if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Invalid mail address')
|
'message' => (string) $this->l10n->t('Invalid mail address')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_UNPROCESSABLE_ENTITY
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -662,9 +733,9 @@ class UsersController extends Controller {
|
||||||
try {
|
try {
|
||||||
$this->saveUserSettings($user, $data);
|
$this->saveUserSettings($user, $data);
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'userId' => $user->getUID(),
|
'userId' => $user->getUID(),
|
||||||
'avatarScope' => $avatarScope,
|
'avatarScope' => $avatarScope,
|
||||||
'displayname' => $displayname,
|
'displayname' => $displayname,
|
||||||
|
@ -676,8 +747,8 @@ class UsersController extends Controller {
|
||||||
'address' => $address,
|
'address' => $address,
|
||||||
'addressScope' => $addressScope,
|
'addressScope' => $addressScope,
|
||||||
'message' => (string) $this->l10n->t('Settings saved')
|
'message' => (string) $this->l10n->t('Settings saved')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_OK
|
Http::STATUS_OK
|
||||||
);
|
);
|
||||||
} catch (ForbiddenException $e) {
|
} catch (ForbiddenException $e) {
|
||||||
|
@ -843,36 +914,36 @@ class UsersController extends Controller {
|
||||||
&& !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
|
&& !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)
|
||||||
) {
|
) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Forbidden')
|
'message' => (string) $this->l10n->t('Forbidden')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
|
if($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Invalid mail address')
|
'message' => (string) $this->l10n->t('Invalid mail address')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_UNPROCESSABLE_ENTITY
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Invalid user')
|
'message' => (string) $this->l10n->t('Invalid user')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_UNPROCESSABLE_ENTITY
|
Http::STATUS_UNPROCESSABLE_ENTITY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -880,12 +951,12 @@ class UsersController extends Controller {
|
||||||
// for the permission of setting a email address
|
// for the permission of setting a email address
|
||||||
if (!$user->canChangeDisplayName()) {
|
if (!$user->canChangeDisplayName()) {
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'message' => (string) $this->l10n->t('Unable to change mail address')
|
'message' => (string) $this->l10n->t('Unable to change mail address')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -896,14 +967,14 @@ class UsersController extends Controller {
|
||||||
try {
|
try {
|
||||||
$this->saveUserSettings($user, $userData);
|
$this->saveUserSettings($user, $userData);
|
||||||
return new DataResponse(
|
return new DataResponse(
|
||||||
array(
|
[
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'data' => array(
|
'data' => [
|
||||||
'username' => $id,
|
'username' => $id,
|
||||||
'mailAddress' => $mailAddress,
|
'mailAddress' => $mailAddress,
|
||||||
'message' => (string) $this->l10n->t('Email saved')
|
'message' => (string) $this->l10n->t('Email saved')
|
||||||
)
|
]
|
||||||
),
|
],
|
||||||
Http::STATUS_OK
|
Http::STATUS_OK
|
||||||
);
|
);
|
||||||
} catch (ForbiddenException $e) {
|
} catch (ForbiddenException $e) {
|
||||||
|
|
|
@ -458,15 +458,16 @@ table.grid th, table.grid td {
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
}
|
}
|
||||||
td.name, td.password { padding-left:.8em; }
|
td.name, td.password { padding-left:.8em; }
|
||||||
td.password>img,td.displayName>img, td.remove>a, td.quota>img { visibility:hidden; vertical-align: middle;}
|
td.password>img,td.displayName>img, td.quota>img { visibility:hidden; }
|
||||||
td.password, td.quota, td.displayName { width:12em; cursor:pointer; }
|
td.password, td.quota, td.displayName { width:12em; cursor:pointer; }
|
||||||
td.password>span, td.quota>span, rd.displayName>span { margin-right: 1.2em; color: #C7C7C7; }
|
td.password>span, td.quota>span { margin-right: 1.2em; color: #C7C7C7; }
|
||||||
span.usersLastLoginTooltip { white-space: nowrap; }
|
span.usersLastLoginTooltip { white-space: nowrap; }
|
||||||
|
|
||||||
/* dropdowns will be relative to this element */
|
/* dropdowns will be relative to this element */
|
||||||
#userlist {
|
#userlist {
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
#userlist .mailAddress,
|
#userlist .mailAddress,
|
||||||
#userlist .storageLocation,
|
#userlist .storageLocation,
|
||||||
#userlist .userBackend,
|
#userlist .userBackend,
|
||||||
|
@ -501,13 +502,51 @@ span.usersLastLoginTooltip { white-space: nowrap; }
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr:hover>td.password>span, tr:hover>td.displayName>span { margin:0; cursor:pointer; }
|
.bubble {
|
||||||
tr:hover>td.remove>a, tr:hover>td.password>img,tr:hover>td.displayName>img, tr:hover>td.quota>img { visibility:visible; cursor:pointer; }
|
z-index:1;
|
||||||
td.remove {
|
right: -6px;
|
||||||
width: 25px;
|
top: auto;
|
||||||
}
|
}
|
||||||
tr:hover>td.remove>a {
|
.bubble:after {
|
||||||
float: left;
|
right: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popovermenu a.menuitem {
|
||||||
|
height: 20px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
line-height: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
#userlist .popovermenu {
|
||||||
|
margin-top: 4px;
|
||||||
|
border-top-right-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#userlist .popovermenu>ul.userActionsMenu {
|
||||||
|
right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#userlist .popovermenu>ul.userActionsMenu a span {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#userlist .popovermenu {
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:hover>td.password>span, tr:hover>td.displayName>span { margin:0; cursor:pointer; }
|
||||||
|
tr:hover>td.password>img,tr:hover>td.displayName>img, tr:hover>td.quota>img { visibility:visible; cursor:pointer; }
|
||||||
|
td.userActions {
|
||||||
|
width: 25px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
td.userActions .action {
|
||||||
|
position: relative;
|
||||||
|
top: 3px;
|
||||||
|
}
|
||||||
|
td.userActions .action:hover {
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.recoveryPassword { left:50em; display:block; position:absolute; top:-1px; }
|
div.recoveryPassword { left:50em; display:block; position:absolute; top:-1px; }
|
||||||
|
|
|
@ -48,7 +48,8 @@ GroupList = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getUserCount: function ($groupLiElement) {
|
getUserCount: function ($groupLiElement) {
|
||||||
return parseInt($groupLiElement.data('usercount'), 10);
|
var count = parseInt($groupLiElement.data('usercount'), 10);
|
||||||
|
return isNaN(count) ? 0 : count;
|
||||||
},
|
},
|
||||||
|
|
||||||
modGroupCount: function(gid, diff) {
|
modGroupCount: function(gid, diff) {
|
||||||
|
@ -208,10 +209,17 @@ GroupList = {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
showDisabledUsers: function () {
|
||||||
|
UserList.empty();
|
||||||
|
UserList.update('_disabledUsers');
|
||||||
|
$userGroupList.find('li').removeClass('active');
|
||||||
|
GroupList.getGroupLI('_disabledUsers').addClass('active');
|
||||||
|
},
|
||||||
|
|
||||||
showGroup: function (gid) {
|
showGroup: function (gid) {
|
||||||
GroupList.activeGID = gid;
|
GroupList.activeGID = gid;
|
||||||
UserList.empty();
|
UserList.empty();
|
||||||
UserList.update(gid);
|
UserList.update(gid === '_everyone' ? '' : gid);
|
||||||
$userGroupList.find('li').removeClass('active');
|
$userGroupList.find('li').removeClass('active');
|
||||||
if (gid !== undefined) {
|
if (gid !== undefined) {
|
||||||
//TODO: treat Everyone properly
|
//TODO: treat Everyone properly
|
||||||
|
@ -364,6 +372,11 @@ $(document).ready( function () {
|
||||||
GroupList.showGroup(GroupList.getElementGID(this));
|
GroupList.showGroup(GroupList.getElementGID(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// show disabled users
|
||||||
|
$userGroupList.on('click', '.disabledusers', function () {
|
||||||
|
GroupList.showDisabledUsers();
|
||||||
|
});
|
||||||
|
|
||||||
$('#newgroupname').on('input', function(){
|
$('#newgroupname').on('input', function(){
|
||||||
GroupList.handleAddGroupInput(this.value);
|
GroupList.handleAddGroupInput(this.value);
|
||||||
});
|
});
|
||||||
|
|
|
@ -48,11 +48,12 @@ var UserList = {
|
||||||
* 'backend': 'LDAP',
|
* 'backend': 'LDAP',
|
||||||
* 'email': 'username@example.org'
|
* 'email': 'username@example.org'
|
||||||
* 'isRestoreDisabled':false
|
* 'isRestoreDisabled':false
|
||||||
|
* 'isEnabled': true
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
add: function (user) {
|
add: function (user) {
|
||||||
if (this.currentGid && this.currentGid !== '_everyone' && _.indexOf(user.groups, this.currentGid) < 0) {
|
if (this.currentGid && this.currentGid !== '_everyone' && this.currentGid !== '_disabledUsers' && _.indexOf(user.groups, this.currentGid) < 0) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var $tr = $userListBody.find('tr:first-child').clone();
|
var $tr = $userListBody.find('tr:first-child').clone();
|
||||||
|
@ -77,6 +78,7 @@ var UserList = {
|
||||||
$tr.data('displayname', user.displayname);
|
$tr.data('displayname', user.displayname);
|
||||||
$tr.data('mailAddress', user.email);
|
$tr.data('mailAddress', user.email);
|
||||||
$tr.data('restoreDisabled', user.isRestoreDisabled);
|
$tr.data('restoreDisabled', user.isRestoreDisabled);
|
||||||
|
$tr.data('userEnabled', user.isEnabled);
|
||||||
$tr.find('.name').text(user.name);
|
$tr.find('.name').text(user.name);
|
||||||
$tr.find('td.displayName > span').text(user.displayname);
|
$tr.find('td.displayName > span').text(user.displayname);
|
||||||
$tr.find('td.mailAddress > span').text(user.email);
|
$tr.find('td.mailAddress > span').text(user.email);
|
||||||
|
@ -97,18 +99,17 @@ var UserList = {
|
||||||
$tdSubadmins.find('.action').tooltip({placement: 'top'});
|
$tdSubadmins.find('.action').tooltip({placement: 'top'});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove action
|
* user actions menu
|
||||||
*/
|
*/
|
||||||
if ($tr.find('td.remove img').length === 0 && OC.currentUser !== user.name) {
|
if ($tr.find('td.userActions > span > img').length === 0 && OC.currentUser !== user.name) {
|
||||||
var deleteImage = $('<img class="action">').attr({
|
var menuImage = $('<img class="svg action">').attr({
|
||||||
src: OC.imagePath('core', 'actions/delete')
|
src: OC.imagePath('core', 'actions/more')
|
||||||
});
|
});
|
||||||
var deleteLink = $('<a class="action delete">')
|
var menuLink = $('<span class="toggleUserActions"></span>')
|
||||||
.attr({ href: '#', 'original-title': t('settings', 'Delete')})
|
.append(menuImage);
|
||||||
.append(deleteImage);
|
$tr.find('td.userActions > span').replaceWith(menuLink);
|
||||||
$tr.find('td.remove').append(deleteLink);
|
|
||||||
} else if (OC.currentUser === user.name) {
|
} else if (OC.currentUser === user.name) {
|
||||||
$tr.find('td.remove a').remove();
|
$tr.find('td.userActions').empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,14 +161,6 @@ var UserList = {
|
||||||
* append generated row to user list
|
* append generated row to user list
|
||||||
*/
|
*/
|
||||||
$tr.appendTo($userList);
|
$tr.appendTo($userList);
|
||||||
if(UserList.isEmpty === true) {
|
|
||||||
//when the list was emptied, one row was left, necessary to keep
|
|
||||||
//add working and the layout unbroken. We need to remove this item
|
|
||||||
$tr.show();
|
|
||||||
$userListBody.find('tr:first').remove();
|
|
||||||
UserList.isEmpty = false;
|
|
||||||
UserList.checkUsersToLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
$quotaSelect.on('change', UserList.onQuotaSelect);
|
$quotaSelect.on('change', UserList.onQuotaSelect);
|
||||||
|
|
||||||
|
@ -338,6 +331,9 @@ var UserList = {
|
||||||
getRestoreDisabled: function(element) {
|
getRestoreDisabled: function(element) {
|
||||||
return ($(element).closest('tr').data('restoreDisabled') || '');
|
return ($(element).closest('tr').data('restoreDisabled') || '');
|
||||||
},
|
},
|
||||||
|
getUserEnabled: function(element) {
|
||||||
|
return ($(element).closest('tr').data('userEnabled') || '');
|
||||||
|
},
|
||||||
initDeleteHandling: function() {
|
initDeleteHandling: function() {
|
||||||
//set up handler
|
//set up handler
|
||||||
UserDeleteHandler = new DeleteHandler('/settings/users/users', 'username',
|
UserDeleteHandler = new DeleteHandler('/settings/users/users', 'username',
|
||||||
|
@ -351,7 +347,7 @@ var UserList = {
|
||||||
UserList.undoRemove);
|
UserList.undoRemove);
|
||||||
|
|
||||||
//when to mark user for delete
|
//when to mark user for delete
|
||||||
$userListBody.on('click', '.delete', function () {
|
$userListBody.on('click', '.action-remove', function () {
|
||||||
// Call function for handling delete/undo
|
// Call function for handling delete/undo
|
||||||
var uid = UserList.getUID(this);
|
var uid = UserList.getUID(this);
|
||||||
|
|
||||||
|
@ -908,6 +904,62 @@ $(document).ready(function () {
|
||||||
UserList._triggerGroupEdit($td, isSubadminSelect);
|
UserList._triggerGroupEdit($td, isSubadminSelect);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$userListBody.on('click', '.toggleUserActions', function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
var $td = $(this).closest('td');
|
||||||
|
var $tr = $($td).closest('tr');
|
||||||
|
var menudiv = $td.find('.popovermenu');
|
||||||
|
|
||||||
|
if(menudiv.is(':visible')) {
|
||||||
|
menudiv.fadeOut(100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
menudiv.find('.action-togglestate').empty();
|
||||||
|
if($tr.data('userEnabled')) {
|
||||||
|
$('.action-togglestate', $td).html('<span class="icon icon-close"></span><span>'+t('settings', 'Disable')+'</span>');
|
||||||
|
} else {
|
||||||
|
$('.action-togglestate', $td).html('<span class="icon icon-add"></span><span>'+t('settings', 'Enable')+'</span>');
|
||||||
|
}
|
||||||
|
menudiv.click(function() { menudiv.fadeOut(100); });
|
||||||
|
menudiv.hover('', function() { menudiv.fadeOut(100); });
|
||||||
|
menudiv.fadeIn(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
$userListBody.on('click', '.action-togglestate', function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
var $td = $(this).closest('td');
|
||||||
|
var $tr = $td.closest('tr');
|
||||||
|
var uid = UserList.getUID($td);
|
||||||
|
var setEnabled = UserList.getUserEnabled($td) ? 0 : 1;
|
||||||
|
$.post(
|
||||||
|
OC.generateUrl('/settings/users/{id}/setEnabled', {id: uid}),
|
||||||
|
{username: uid, enabled: setEnabled},
|
||||||
|
function (result) {
|
||||||
|
if (result && result.status==='success'){
|
||||||
|
var count = GroupList.getUserCount(GroupList.getGroupLI('_disabledUsers'));
|
||||||
|
$tr.remove();
|
||||||
|
if(result.data.enabled == 1) {
|
||||||
|
$tr.data('userEnabled', true);
|
||||||
|
GroupList.setUserCount(GroupList.getGroupLI('_disabledUsers'), count-1);
|
||||||
|
} else {
|
||||||
|
$tr.data('userEnabled', false);
|
||||||
|
GroupList.setUserCount(GroupList.getGroupLI('_disabledUsers'), count+1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
OC.dialogs.alert(result.data.message, t('settings', 'Error while changing status of {user}', {user: uid}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).fail(function(result){
|
||||||
|
var message = 'Unknown error';
|
||||||
|
if( result.responseJSON &&
|
||||||
|
result.responseJSON.data &&
|
||||||
|
result.responseJSON.data.message) {
|
||||||
|
message = result.responseJSON.data.message;
|
||||||
|
}
|
||||||
|
OC.dialogs.alert(message, t('settings', 'Error while changing status of {user}', {user: uid}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// init the quota field select box after it is shown the first time
|
// init the quota field select box after it is shown the first time
|
||||||
$('#app-settings').one('show', function() {
|
$('#app-settings').one('show', function() {
|
||||||
$(this).find('#default_quota').singleSelect().on('change', UserList.onQuotaSelect);
|
$(this).find('#default_quota').singleSelect().on('change', UserList.onQuotaSelect);
|
||||||
|
|
|
@ -53,6 +53,7 @@ $application->registerRoutes($this, [
|
||||||
['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],
|
['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],
|
||||||
['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
|
['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
|
||||||
['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
|
['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
|
||||||
|
['name' => 'Users#setEnabled', 'url' => '/settings/users/{id}/setEnabled', 'verb' => 'POST'],
|
||||||
['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'],
|
['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'],
|
||||||
['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
|
['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
|
||||||
['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
|
['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
|
||||||
|
|
|
@ -37,6 +37,15 @@
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<!-- Disabled Users -->
|
||||||
|
<?php $disabledUsersGroup = $_["disabledUsersGroup"] ?>
|
||||||
|
<li data-gid="_disabledUsers" data-usercount="<?php if($disabledUsersGroup['usercount'] > 0) { p($disabledUsersGroup['usercount']); } ?>" class="isgroup">
|
||||||
|
<a href="#"><span class="groupname"><?php p($l->t('Disabled')); ?></span></a>
|
||||||
|
<span class="utils">
|
||||||
|
<span class="usercount"><?php if($disabledUsersGroup['usercount'] > 0) { p($disabledUsersGroup['usercount']); } ?></span>
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
|
||||||
<!--List of Groups-->
|
<!--List of Groups-->
|
||||||
<?php foreach($_["groups"] as $group): ?>
|
<?php foreach($_["groups"] as $group): ?>
|
||||||
<li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['usercount']) ?>" class="isgroup">
|
<li data-gid="<?php p($group['name']) ?>" data-usercount="<?php p($group['usercount']) ?>" class="isgroup">
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
<th class="storageLocation" scope="col"><?php p($l->t('Storage location')); ?></th>
|
<th class="storageLocation" scope="col"><?php p($l->t('Storage location')); ?></th>
|
||||||
<th class="userBackend" scope="col"><?php p($l->t('User backend')); ?></th>
|
<th class="userBackend" scope="col"><?php p($l->t('User backend')); ?></th>
|
||||||
<th class="lastLogin" scope="col"><?php p($l->t('Last login')); ?></th>
|
<th class="lastLogin" scope="col"><?php p($l->t('Last login')); ?></th>
|
||||||
<th id="headerRemove"> </th>
|
<th class="userActions"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -63,7 +63,21 @@
|
||||||
<td class="storageLocation"></td>
|
<td class="storageLocation"></td>
|
||||||
<td class="userBackend"></td>
|
<td class="userBackend"></td>
|
||||||
<td class="lastLogin"></td>
|
<td class="lastLogin"></td>
|
||||||
<td class="remove"></td>
|
<td class="userActions"><span></span>
|
||||||
|
<div class="popovermenu bubble open menu">
|
||||||
|
<ul class="userActionsMenu">
|
||||||
|
<li>
|
||||||
|
<a href="#" class="menuitem action-togglestate permanent" data-action="togglestate"></a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#" class="menuitem action-remove permanent" data-action="remove">
|
||||||
|
<span class="icon icon-delete"></span>
|
||||||
|
<span><?php p($l->t('Delete')); ?></span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -45,6 +45,7 @@ $groupManager = \OC::$server->getGroupManager();
|
||||||
// Set the sort option: SORT_USERCOUNT or SORT_GROUPNAME
|
// Set the sort option: SORT_USERCOUNT or SORT_GROUPNAME
|
||||||
$sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
|
$sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
|
||||||
|
|
||||||
|
$isLDAPUsed = false;
|
||||||
if (\OC_App::isEnabled('user_ldap')) {
|
if (\OC_App::isEnabled('user_ldap')) {
|
||||||
$isLDAPUsed =
|
$isLDAPUsed =
|
||||||
$groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
|
$groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
|
||||||
|
@ -59,12 +60,15 @@ $config = \OC::$server->getConfig();
|
||||||
|
|
||||||
$isAdmin = OC_User::isAdminUser(OC_User::getUser());
|
$isAdmin = OC_User::isAdminUser(OC_User::getUser());
|
||||||
|
|
||||||
|
$isDisabled = !OC_User::isEnabled(OC_User::getUser());
|
||||||
|
|
||||||
$groupsInfo = new \OC\Group\MetaData(
|
$groupsInfo = new \OC\Group\MetaData(
|
||||||
OC_User::getUser(),
|
OC_User::getUser(),
|
||||||
$isAdmin,
|
$isAdmin,
|
||||||
$groupManager,
|
$groupManager,
|
||||||
\OC::$server->getUserSession()
|
\OC::$server->getUserSession()
|
||||||
);
|
);
|
||||||
|
|
||||||
$groupsInfo->setSorting($sortGroupsBy);
|
$groupsInfo->setSorting($sortGroupsBy);
|
||||||
list($adminGroup, $groups) = $groupsInfo->get();
|
list($adminGroup, $groups) = $groupsInfo->get();
|
||||||
|
|
||||||
|
@ -93,6 +97,13 @@ if($isAdmin) {
|
||||||
$subAdmins = false;
|
$subAdmins = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$disabledUsers = $isLDAPUsed ? 0 : $userManager->countDisabledUsers();
|
||||||
|
$disabledUsersGroup = [
|
||||||
|
'id' => '_disabledUsers',
|
||||||
|
'name' => '_disabledUsers',
|
||||||
|
'usercount' => $disabledUsers
|
||||||
|
];
|
||||||
|
|
||||||
// load preset quotas
|
// load preset quotas
|
||||||
$quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
|
$quotaPreset=$config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
|
||||||
$quotaPreset=explode(',', $quotaPreset);
|
$quotaPreset=explode(',', $quotaPreset);
|
||||||
|
@ -111,6 +122,7 @@ $tmpl = new OC_Template("settings", "users/main", "user");
|
||||||
$tmpl->assign('groups', $groups);
|
$tmpl->assign('groups', $groups);
|
||||||
$tmpl->assign('sortGroups', $sortGroupsBy);
|
$tmpl->assign('sortGroups', $sortGroupsBy);
|
||||||
$tmpl->assign('adminGroup', $adminGroup);
|
$tmpl->assign('adminGroup', $adminGroup);
|
||||||
|
$tmpl->assign('disabledUsersGroup', $disabledUsersGroup);
|
||||||
$tmpl->assign('isAdmin', (int)$isAdmin);
|
$tmpl->assign('isAdmin', (int)$isAdmin);
|
||||||
$tmpl->assign('subadmins', $subAdmins);
|
$tmpl->assign('subadmins', $subAdmins);
|
||||||
$tmpl->assign('numofgroups', count($groups) + count($adminGroup));
|
$tmpl->assign('numofgroups', count($groups) + count($adminGroup));
|
||||||
|
|
|
@ -211,6 +211,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('OC_User_Database'));
|
->will($this->returnValue('OC_User_Database'));
|
||||||
|
$foo->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$admin = $this->createMock(User::class);
|
$admin = $this->createMock(User::class);
|
||||||
$admin
|
$admin
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
|
@ -240,6 +243,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn(Dummy::class);
|
->willReturn(Dummy::class);
|
||||||
|
$admin->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$bar = $this->createMock(User::class);
|
$bar = $this->createMock(User::class);
|
||||||
$bar
|
$bar
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
|
@ -267,6 +273,15 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn(Dummy::class);
|
->willReturn(Dummy::class);
|
||||||
|
$bar->expects($this->at(0))
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
$bar->expects($this->at(1))
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
$bar->expects($this->at(2))
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(false);
|
||||||
|
|
||||||
$this->groupManager
|
$this->groupManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -330,6 +345,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'foo@bar.com',
|
'email' => 'foo@bar.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
1 => array(
|
1 => array(
|
||||||
'name' => 'admin',
|
'name' => 'admin',
|
||||||
|
@ -343,6 +359,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'admin@bar.com',
|
'email' => 'admin@bar.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => false,
|
'isAvatarAvailable' => false,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
2 => array(
|
2 => array(
|
||||||
'name' => 'bar',
|
'name' => 'bar',
|
||||||
|
@ -356,6 +373,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'bar@dummy.com',
|
'email' => 'bar@dummy.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -399,6 +417,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('OC_User_Database'));
|
->will($this->returnValue('OC_User_Database'));
|
||||||
|
$foo->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$admin = $this->createMock(User::class);
|
$admin = $this->createMock(User::class);
|
||||||
$admin
|
$admin
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
|
@ -428,6 +449,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn(Dummy::class);
|
->willReturn(Dummy::class);
|
||||||
|
$admin->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$bar = $this->createMock(User::class);
|
$bar = $this->createMock(User::class);
|
||||||
$bar
|
$bar
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
|
@ -455,6 +479,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn(Dummy::class);
|
->willReturn(Dummy::class);
|
||||||
|
$bar->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
$this->groupManager
|
$this->groupManager
|
||||||
->expects($this->at(2))
|
->expects($this->at(2))
|
||||||
|
@ -532,6 +559,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'bar@dummy.com',
|
'email' => 'bar@dummy.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
],
|
],
|
||||||
1=> [
|
1=> [
|
||||||
'name' => 'foo',
|
'name' => 'foo',
|
||||||
|
@ -545,6 +573,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'foo@bar.com',
|
'email' => 'foo@bar.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
],
|
],
|
||||||
2 => [
|
2 => [
|
||||||
'name' => 'admin',
|
'name' => 'admin',
|
||||||
|
@ -558,6 +587,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'admin@bar.com',
|
'email' => 'admin@bar.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => false,
|
'isAvatarAvailable' => false,
|
||||||
|
'isEnabled' => true,
|
||||||
],
|
],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -600,6 +630,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('OC_User_Database'));
|
->will($this->returnValue('OC_User_Database'));
|
||||||
|
$foo->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$admin = $this->createMock(User::class);
|
$admin = $this->createMock(User::class);
|
||||||
$admin
|
$admin
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
|
@ -629,6 +662,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn(Dummy::class);
|
->willReturn(Dummy::class);
|
||||||
|
$admin->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$bar = $this->createMock(User::class);
|
$bar = $this->createMock(User::class);
|
||||||
$bar
|
$bar
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
|
@ -656,6 +692,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn(Dummy::class);
|
->willReturn(Dummy::class);
|
||||||
|
$bar->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
$this->userManager
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -692,6 +731,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'foo@bar.com',
|
'email' => 'foo@bar.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
1 => array(
|
1 => array(
|
||||||
'name' => 'admin',
|
'name' => 'admin',
|
||||||
|
@ -705,6 +745,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'admin@bar.com',
|
'email' => 'admin@bar.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => false,
|
'isAvatarAvailable' => false,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
2 => array(
|
2 => array(
|
||||||
'name' => 'bar',
|
'name' => 'bar',
|
||||||
|
@ -718,6 +759,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'bar@dummy.com',
|
'email' => 'bar@dummy.com',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -755,6 +797,10 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('OC_User_Database'));
|
->will($this->returnValue('OC_User_Database'));
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
$this->userManager
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackends')
|
->method('getBackends')
|
||||||
|
@ -793,6 +839,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => null,
|
'email' => null,
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -832,6 +879,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('bar'));
|
->will($this->returnValue('bar'));
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
$this->userManager
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -864,6 +914,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => null,
|
'email' => null,
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
Http::STATUS_CREATED
|
Http::STATUS_CREATED
|
||||||
);
|
);
|
||||||
|
@ -888,6 +939,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('bar'));
|
->will($this->returnValue('bar'));
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$existingGroup = $this->getMockBuilder('\OCP\IGroup')
|
$existingGroup = $this->getMockBuilder('\OCP\IGroup')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$existingGroup
|
$existingGroup
|
||||||
|
@ -946,6 +1000,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => null,
|
'email' => null,
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
Http::STATUS_CREATED
|
Http::STATUS_CREATED
|
||||||
);
|
);
|
||||||
|
@ -975,6 +1030,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue('bar'));
|
->will($this->returnValue('bar'));
|
||||||
$subGroup1 = $this->createMock(IGroup::class);
|
$subGroup1 = $this->createMock(IGroup::class);
|
||||||
|
$newUser->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
$subGroup1
|
$subGroup1
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
->method('getGID')
|
->method('getGID')
|
||||||
|
@ -1034,6 +1092,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => null,
|
'email' => null,
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
),
|
),
|
||||||
Http::STATUS_CREATED
|
Http::STATUS_CREATED
|
||||||
);
|
);
|
||||||
|
@ -1463,7 +1522,8 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mockUser($userId = 'foo', $displayName = 'M. Foo',
|
private function mockUser($userId = 'foo', $displayName = 'M. Foo',
|
||||||
$lastLogin = 500, $home = '/home/foo', $backend = 'OC_User_Database') {
|
$lastLogin = 500, $home = '/home/foo',
|
||||||
|
$backend = 'OC_User_Database', $enabled = true) {
|
||||||
$user = $this->createMock(User::class);
|
$user = $this->createMock(User::class);
|
||||||
$user
|
$user
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
|
@ -1483,6 +1543,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->will($this->returnValue($backend));
|
->will($this->returnValue($backend));
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn($enabled);
|
||||||
|
|
||||||
$result = [
|
$result = [
|
||||||
'name' => $userId,
|
'name' => $userId,
|
||||||
|
@ -1496,6 +1559,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => null,
|
'email' => null,
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => $enabled,
|
||||||
];
|
];
|
||||||
|
|
||||||
return [$user, $result];
|
return [$user, $result];
|
||||||
|
@ -2159,6 +2223,11 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
/**
|
/**
|
||||||
* @dataProvider setEmailAddressData
|
* @dataProvider setEmailAddressData
|
||||||
*
|
*
|
||||||
|
* @param string $mailAddress
|
||||||
|
* @param bool $isValid
|
||||||
|
* @param bool $expectsUpdate
|
||||||
|
* @param bool $canChangeDisplayName
|
||||||
|
* @param int $responseCode
|
||||||
*/
|
*/
|
||||||
public function testSetEMailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
|
public function testSetEMailAddress($mailAddress, $isValid, $expectsUpdate, $canChangeDisplayName, $responseCode) {
|
||||||
$user = $this->createMock(User::class);
|
$user = $this->createMock(User::class);
|
||||||
|
@ -2230,6 +2299,9 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('getBackendClassName')
|
->method('getBackendClassName')
|
||||||
->willReturn('bar');
|
->willReturn('bar');
|
||||||
|
$user
|
||||||
|
->method('isEnabled')
|
||||||
|
->willReturn(true);
|
||||||
|
|
||||||
$this->userManager
|
$this->userManager
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
|
@ -2279,6 +2351,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
'email' => 'abc@example.org',
|
'email' => 'abc@example.org',
|
||||||
'isRestoreDisabled' => false,
|
'isRestoreDisabled' => false,
|
||||||
'isAvatarAvailable' => true,
|
'isAvatarAvailable' => true,
|
||||||
|
'isEnabled' => true,
|
||||||
],
|
],
|
||||||
Http::STATUS_CREATED
|
Http::STATUS_CREATED
|
||||||
);
|
);
|
||||||
|
@ -2370,6 +2443,427 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$result = $controller->getVerificationCode('account', false);
|
$result = $controller->getVerificationCode('account', false);
|
||||||
|
|
||||||
$this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
|
$this->assertSame(Http::STATUS_BAD_REQUEST, $result->getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableUserFailsDueSameUser() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('abc'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Error while disabling user.',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(true)->setEnabled('abc', false);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableUserFailsDueNoAdminAndNoSubadmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$user2 = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user2->expects($this->never())
|
||||||
|
->method('setEnabled');
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn($user2);
|
||||||
|
|
||||||
|
$subadmin = $this->createMock('\OC\SubAdmin');
|
||||||
|
$subadmin->expects($this->once())
|
||||||
|
->method('isUserAccessible')
|
||||||
|
->will($this->returnValue(false));
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getSubAdmin')
|
||||||
|
->willReturn($subadmin);
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Authentication error',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(false)->setEnabled('abc', false);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableUserFailsDueNoUser() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn(null);
|
||||||
|
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getSubAdmin');
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Error while disabling user.',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(true)->setEnabled('abc', false);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableUserFailsDueNoUserForSubAdmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn(null);
|
||||||
|
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getSubAdmin');
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Error while disabling user.',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(false)->setEnabled('abc', false);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableUserSuccessForAdmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$user2 = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user2->expects($this->once())
|
||||||
|
->method('setEnabled')
|
||||||
|
->with(false);
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn($user2);
|
||||||
|
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getSubAdmin');
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'username' => 'abc',
|
||||||
|
'enabled' => 0,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$response = $this->getController(true)->setEnabled('abc', false);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDisableUserSuccessForSubAdmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$user2 = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user2->expects($this->once())
|
||||||
|
->method('setEnabled');
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn($user2);
|
||||||
|
|
||||||
|
$subadmin = $this->createMock('\OC\SubAdmin');
|
||||||
|
$subadmin->expects($this->once())
|
||||||
|
->method('isUserAccessible')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getSubAdmin')
|
||||||
|
->willReturn($subadmin);
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'username' => 'abc',
|
||||||
|
'enabled' => 0,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$response = $this->getController(false)->setEnabled('abc', false);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableUserFailsDueSameUser() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('abc'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Error while enabling user.',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(true)->setEnabled('abc', true);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableUserFailsDueNoAdminAndNoSubadmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$user2 = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user2->expects($this->never())
|
||||||
|
->method('setEnabled');
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn($user2);
|
||||||
|
|
||||||
|
$subadmin = $this->createMock('\OC\SubAdmin');
|
||||||
|
$subadmin->expects($this->once())
|
||||||
|
->method('isUserAccessible')
|
||||||
|
->will($this->returnValue(false));
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getSubAdmin')
|
||||||
|
->willReturn($subadmin);
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Authentication error',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(false)->setEnabled('abc', true);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableUserFailsDueNoUser() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn(null);
|
||||||
|
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getSubAdmin');
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Error while enabling user.',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(true)->setEnabled('abc', true);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableUserFailsDueNoUserForSubAdmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn(null);
|
||||||
|
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getSubAdmin');
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'error',
|
||||||
|
'data' => [
|
||||||
|
'message' => 'Error while enabling user.',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
Http::STATUS_FORBIDDEN
|
||||||
|
);
|
||||||
|
$response = $this->getController(false)->setEnabled('abc', true);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableUserSuccessForAdmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(1))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$user2 = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user2->expects($this->once())
|
||||||
|
->method('setEnabled');
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn($user2);
|
||||||
|
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->never())
|
||||||
|
->method('getSubAdmin');
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'username' => 'abc',
|
||||||
|
'enabled' => 1,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$response = $this->getController(true)->setEnabled('abc', true);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEnableUserSuccessForSubAdmin() {
|
||||||
|
$user = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user->expects($this->once())
|
||||||
|
->method('getUID')
|
||||||
|
->will($this->returnValue('def'));
|
||||||
|
$this->userSession
|
||||||
|
->expects($this->exactly(2))
|
||||||
|
->method('getUser')
|
||||||
|
->will($this->returnValue($user));
|
||||||
|
$user2 = $this->getMockBuilder('\OC\User\User')
|
||||||
|
->disableOriginalConstructor()->getMock();
|
||||||
|
$user2->expects($this->once())
|
||||||
|
->method('setEnabled')
|
||||||
|
->with(true);
|
||||||
|
$this->userManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('abc')
|
||||||
|
->willReturn($user2);
|
||||||
|
|
||||||
|
$subadmin = $this->createMock('\OC\SubAdmin');
|
||||||
|
$subadmin->expects($this->once())
|
||||||
|
->method('isUserAccessible')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
$this->groupManager
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getSubAdmin')
|
||||||
|
->willReturn($subadmin);
|
||||||
|
|
||||||
|
$expectedResponse = new DataResponse(
|
||||||
|
[
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => [
|
||||||
|
'username' => 'abc',
|
||||||
|
'enabled' => 1,
|
||||||
|
],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$response = $this->getController(false)->setEnabled('abc', true);
|
||||||
|
$this->assertEquals($expectedResponse, $response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,6 +510,31 @@ class ManagerTest extends TestCase {
|
||||||
$this->assertEquals(7 + 16, $users);
|
$this->assertEquals(7 + 16, $users);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCountUsersOnlyDisabled() {
|
||||||
|
$manager = \OC::$server->getUserManager();
|
||||||
|
// count other users in the db before adding our own
|
||||||
|
$countBefore = $manager->countDisabledUsers();
|
||||||
|
|
||||||
|
//Add test users
|
||||||
|
$user1 = $manager->createUser('testdisabledcount1', 'testdisabledcount1');
|
||||||
|
|
||||||
|
$user2 = $manager->createUser('testdisabledcount2', 'testdisabledcount2');
|
||||||
|
$user2->setEnabled(false);
|
||||||
|
|
||||||
|
$user3 = $manager->createUser('testdisabledcount3', 'testdisabledcount3');
|
||||||
|
|
||||||
|
$user4 = $manager->createUser('testdisabledcount4', 'testdisabledcount4');
|
||||||
|
$user4->setEnabled(false);
|
||||||
|
|
||||||
|
$this->assertEquals($countBefore + 2, $manager->countDisabledUsers());
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
$user1->delete();
|
||||||
|
$user2->delete();
|
||||||
|
$user3->delete();
|
||||||
|
$user4->delete();
|
||||||
|
}
|
||||||
|
|
||||||
public function testCountUsersOnlySeen() {
|
public function testCountUsersOnlySeen() {
|
||||||
$manager = \OC::$server->getUserManager();
|
$manager = \OC::$server->getUserManager();
|
||||||
// count other users in the db before adding our own
|
// count other users in the db before adding our own
|
||||||
|
|
Loading…
Reference in New Issue