-
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
Add occ commands to enable and disable a user + a disabled user can n… #23844
Changes from all commits
9c9fec3
8486926
0eed6b5
271ba6d
9b875db
661ab1a
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 |
---|---|---|
|
@@ -31,32 +31,36 @@ | |
use \OC_OCS_Result; | ||
use \OC_Helper; | ||
use OCP\Files\NotFoundException; | ||
use OCP\IConfig; | ||
use OCP\IGroupManager; | ||
use OCP\ILogger; | ||
use OCP\IUserManager; | ||
use OCP\IUserSession; | ||
|
||
class Users { | ||
|
||
/** @var \OCP\IUserManager */ | ||
/** @var IUserManager */ | ||
private $userManager; | ||
/** @var \OCP\IConfig */ | ||
/** @var IConfig */ | ||
private $config; | ||
/** @var \OCP\IGroupManager */ | ||
/** @var IGroupManager */ | ||
private $groupManager; | ||
/** @var \OCP\IUserSession */ | ||
/** @var IUserSession */ | ||
private $userSession; | ||
/** @var ILogger */ | ||
private $logger; | ||
|
||
/** | ||
* @param \OCP\IUserManager $userManager | ||
* @param \OCP\IConfig $config | ||
* @param \OCP\IGroupManager $groupManager | ||
* @param \OCP\IUserSession $userSession | ||
* @param IUserManager $userManager | ||
* @param IConfig $config | ||
* @param IGroupManager $groupManager | ||
* @param IUserSession $userSession | ||
* @param ILogger $logger | ||
*/ | ||
public function __construct(\OCP\IUserManager $userManager, | ||
\OCP\IConfig $config, | ||
\OCP\IGroupManager $groupManager, | ||
\OCP\IUserSession $userSession, | ||
public function __construct(IUserManager $userManager, | ||
IConfig $config, | ||
IGroupManager $groupManager, | ||
IUserSession $userSession, | ||
ILogger $logger) { | ||
$this->userManager = $userManager; | ||
$this->config = $config; | ||
|
@@ -329,6 +333,50 @@ public function deleteUser($parameters) { | |
} | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return OC_OCS_Result | ||
*/ | ||
public function disableUser($parameters) { | ||
return $this->setEnabled($parameters, false); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return OC_OCS_Result | ||
*/ | ||
public function enableUser($parameters) { | ||
return $this->setEnabled($parameters, true); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @param bool $value | ||
* @return OC_OCS_Result | ||
*/ | ||
private function setEnabled($parameters, $value) { | ||
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. I'd like some integration tests on this covering the following scenarios:
cc @owncloud/qa 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. \3. is not covered by the code? 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. It is. Check L370 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. Ah. Bloody GitHub, if I click on edit it shows "3." instead of "1." Yes. 3, is not covered yet. 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. @SergioBertolinSG do we have this covered now ? 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. Yes it works fine. |
||
// Check if user is logged in | ||
$currentLoggedInUser = $this->userSession->getUser(); | ||
if ($currentLoggedInUser === null) { | ||
return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED); | ||
} | ||
|
||
$targetUser = $this->userManager->get($parameters['userid']); | ||
if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { | ||
return new OC_OCS_Result(null, 101); | ||
} | ||
|
||
// If not permitted | ||
$subAdminManager = $this->groupManager->getSubAdmin(); | ||
if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { | ||
return new OC_OCS_Result(null, 997); | ||
} | ||
|
||
// enable/disable the user now | ||
$targetUser->setEnabled($value); | ||
return new OC_OCS_Result(null, 100); | ||
} | ||
|
||
/** | ||
* @param array $parameters | ||
* @return OC_OCS_Result | ||
|
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.
In general to be more RESTful another idea would be to still do a "PUT" on "/cloud/users/{userid}" and set the "enabled" attribute to true or false. (PUT being an "edit" operation)
This also means that the GET operation would return the "enabled" flag as well with the user's properties.
I'm ok with keeping in that way if that's too much to rework.
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.
I see that GET already returns the flag. So intuitively as an API consumer, I'd be tempted to try and set it the way I described.
However now I see that it says "displayName" in the response but the PUT value is "display" 😞
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.
Well - true restful would be to have only one GET to retrieve a json object holding all information and one PUT where we can push a full json object to store the new state.
But the whole provisioning api is not REST - so nothing to worry about - in the scope for v1.
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.
🙈 agreed