-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable / Disable user from web application #27333
Changes from 7 commits
5896a5a
9bbaeea
fc22600
9438b3a
da08773
f0fb0e6
c25d379
c0c08d4
eeefa58
becc59d
4aa1dd6
48c9bfa
aa3590b
ce4d369
6d8dfae
ef59718
d31f7e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,7 @@ private function formatUserForIndex(IUser $user, array $userGroups = null) { | |
'displayname' => $user->getDisplayName(), | ||
'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups, | ||
'subadmin' => $subAdminGroups, | ||
'isEnabled' => $user->isEnabled(), | ||
'quota' => $user->getQuota(), | ||
'storageLocation' => $user->getHome(), | ||
'lastLogin' => $user->getLastLogin() * 1000, | ||
|
@@ -661,4 +662,68 @@ public function setDisplayName($username, $displayName) { | |
]); | ||
} | ||
} | ||
|
||
/** | ||
* @NoAdminRequired | ||
* | ||
* @param string $id | ||
* @return DataResponse | ||
*/ | ||
public function setEnabled($id, $enabled) { | ||
$userId = $this->userSession->getUser()->getUID(); | ||
$user = $this->userManager->get($id); | ||
|
||
if($userId === $id | ||
&& !$this->isAdmin | ||
&& !$this->groupManager->getSubAdmin()->isUserAccessible($this->userSession->getUser(), $user)) { | ||
return new DataResponse( | ||
array( | ||
'status' => 'error', | ||
'data' => array( | ||
'message' => (string)$this->l10n->t('Forbidden') | ||
) | ||
), | ||
Http::STATUS_FORBIDDEN | ||
); | ||
} | ||
|
||
|
||
if(!$user){ | ||
return new DataResponse( | ||
array( | ||
'status' => 'error', | ||
'data' => array( | ||
'message' => (string)$this->l10n->t('Invalid user') | ||
) | ||
), | ||
Http::STATUS_UNPROCESSABLE_ENTITY | ||
); | ||
} | ||
|
||
if($enabled !== 'true' && $enabled !== 'false') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe convert this to a boolean directly at the beginning of the function ? |
||
{ | ||
return new DataResponse( | ||
array( | ||
'status' => 'error', | ||
'data' => array( | ||
'message' => (string)$this->l10n->t('Unable to enable/disable user.') | ||
) | ||
), | ||
Http::STATUS_FORBIDDEN | ||
); | ||
} | ||
|
||
$user->setEnabled($enabled === 'true' ? true : false); | ||
|
||
return new DataResponse( | ||
[ | ||
'status' => 'success', | ||
'data' => [ | ||
'username' => $id, | ||
'enabled' => $enabled | ||
] | ||
], | ||
Http::STATUS_OK | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ var UserList = { | |
|
||
// initially the list might already contain user entries (not fully ajaxified yet) | ||
// initialize these entries | ||
this.$el.find('#isEnabled').on('change', this.onEnabledChange); | ||
this.$el.find('.quota-user').singleSelect().on('change', this.onQuotaSelect); | ||
}, | ||
|
||
|
@@ -39,6 +40,7 @@ var UserList = { | |
* 'displayname': 'Users display name', | ||
* 'groups': ['group1', 'group2'], | ||
* 'subadmin': ['group4', 'group5'], | ||
* 'enabled' 'true' | ||
* 'quota': '10 GB', | ||
* 'storageLocation': '/srv/www/owncloud/data/username', | ||
* 'lastLogin': '1418632333' | ||
|
@@ -95,6 +97,13 @@ var UserList = { | |
this._updateGroupListLabel($tdSubadmins, user.subadmin); | ||
$tdSubadmins.find('.action').tooltip({placement: 'top'}); | ||
|
||
/** | ||
* enabled | ||
*/ | ||
var $tdEnabled = $tr.find('#isEnabled'); | ||
$tdEnabled.attr("checked", user.isEnabled); | ||
$tdEnabled.on('change', UserList.onEnabledChange); | ||
|
||
/** | ||
* remove action | ||
*/ | ||
|
@@ -558,6 +567,44 @@ var UserList = { | |
); | ||
}, | ||
|
||
/** | ||
* Event handler for when a enabled value has been changed. | ||
* This will save the value. | ||
*/ | ||
onEnabledChange: function() { | ||
var $select = $(this); | ||
var uid = UserList.getUID($select); | ||
var enabled = $select.attr('checked') ? 'true' : 'false'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use the boolean |
||
UserList._updateEnabled(uid, enabled, function(returnedEnabled){ | ||
if (enabled !== returnedEnabled) { | ||
$select.find('#isEnabled').attr("checked", user.isEnabled); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
} | ||
}); | ||
}, | ||
|
||
|
||
/** | ||
* Saves the enabled value for the given user | ||
* @param {String} [uid] optional user id, sets default quota if empty | ||
* @param {String} enabled value | ||
* @param {Function} ready callback after save | ||
*/ | ||
_updateEnabled: function(uid, enabled, ready) { | ||
$.post( | ||
OC.generateUrl('/settings/users/{id}/enabled', {id: uid}), | ||
{username: uid, enabled: enabled}, | ||
function (result) { | ||
if(result.status == 'success') { | ||
var msg = 'User have been ' + (result.data.enabled === 'true' ? 'enabled' : 'disabled') + '!'; | ||
OC.Notification.showTemporary(t('admin', msg)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the message directly inside the Also use a placeholder for the state: |
||
} else { | ||
OC.Notification.showTemporary(t('admin', result.data.message)); | ||
} | ||
} | ||
); | ||
}, | ||
|
||
|
||
/** | ||
* Creates a temporary jquery.multiselect selector on the given group field | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
<?php if(is_array($_['subadmins']) || $_['subadmins']): ?> | ||
<th id="headerSubAdmins" scope="col"><?php p($l->t('Group Admin for')); ?></th> | ||
<?php endif;?> | ||
<th id="headerIsEnabled" scope="col"><?php p($l->t('Enabled')); ?></th> | ||
<th id="headerQuota" scope="col"><?php p($l->t('Quota')); ?></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> | ||
|
@@ -46,6 +47,9 @@ | |
><span class="title groupsList"></span><span class="icon-triangle-s"></span></div> | ||
</td> | ||
<?php endif;?> | ||
<td class="enabled"> | ||
<input type="checkbox" id="isEnabled" checked="checked"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a |
||
</td> | ||
<td class="quota"> | ||
<select class="quota-user" data-inputtitle="<?php p($l->t('Please enter storage quota (ex: "512 MB" or "12 GB")')) ?>"> | ||
<option value='default'> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, prevent disabling yourself, but it seems this doesn't work correctly