本文整理汇总了PHP中OCP\IGroupManager::getSubAdmin方法的典型用法代码示例。如果您正苦于以下问题:PHP IGroupManager::getSubAdmin方法的具体用法?PHP IGroupManager::getSubAdmin怎么用?PHP IGroupManager::getSubAdmin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\IGroupManager
的用法示例。
在下文中一共展示了IGroupManager::getSubAdmin方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setMailAddress
/**
* Set the mail address of a user
*
* @NoAdminRequired
* @NoSubadminRequired
*
* @param string $id
* @param string $mailAddress
* @return DataResponse
*/
public function setMailAddress($id, $mailAddress)
{
$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 ($mailAddress !== '' && !$this->mailer->validateMailAddress($mailAddress)) {
return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid mail address'))), Http::STATUS_UNPROCESSABLE_ENTITY);
}
if (!$user) {
return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Invalid user'))), Http::STATUS_UNPROCESSABLE_ENTITY);
}
// this is the only permission a backend provides and is also used
// for the permission of setting a email address
if (!$user->canChangeDisplayName()) {
return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Unable to change mail address'))), Http::STATUS_FORBIDDEN);
}
// delete user value if email address is empty
if ($mailAddress === '') {
$this->config->deleteUserValue($id, 'settings', 'email');
} else {
$this->config->setUserValue($id, 'settings', 'email', $mailAddress);
}
return new DataResponse(array('status' => 'success', 'data' => array('username' => $id, 'mailAddress' => $mailAddress, 'message' => (string) $this->l10n->t('Email saved'))), Http::STATUS_OK);
}
示例2: getGroups
/**
* returns the available groups
* @param string $search a search string
* @return \OCP\IGroup[]
*/
protected function getGroups($search = '')
{
if ($this->isAdmin) {
return $this->groupManager->search($search);
} else {
$userObject = $this->userSession->getUser();
if ($userObject !== null) {
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($userObject);
} else {
$groups = [];
}
return $groups;
}
}
示例3: setDisplayName
/**
* Set the displayName of a user
*
* @NoAdminRequired
* @NoSubadminRequired
*
* @param string $username
* @param string $displayName
* @return DataResponse
*/
public function setDisplayName($username, $displayName)
{
$currentUser = $this->userSession->getUser();
if ($username === null) {
$username = $currentUser->getUID();
}
$user = $this->userManager->get($username);
if ($user === null || !$user->canChangeDisplayName() || !$this->groupManager->isAdmin($currentUser->getUID()) && !$this->groupManager->getSubAdmin()->isUserAccessible($currentUser, $user) && $currentUser !== $user) {
return new DataResponse(['status' => 'error', 'data' => ['message' => $this->l10n->t('Authentication error')]]);
}
if ($user->setDisplayName($displayName)) {
return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Your full name has been changed.'), 'username' => $username, 'displayName' => $displayName]]);
} else {
return new DataResponse(['status' => 'error', 'data' => ['message' => $this->l10n->t('Unable to change full name'), 'displayName' => $user->getDisplayName()]]);
}
}
示例4: getSubAdminsOfGroup
/**
* @param array $parameters
* @return OC_OCS_Result
*/
public function getSubAdminsOfGroup($parameters)
{
$group = $parameters['groupid'];
// Check group exists
$targetGroup = $this->groupManager->get($group);
if ($targetGroup === null) {
return new OC_OCS_Result(null, 101, 'Group does not exist');
}
$subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup);
// New class returns IUser[] so convert back
$uids = [];
foreach ($subadmins as $user) {
$uids[] = $user->getUID();
}
return new OC_OCS_Result($uids);
}
示例5: getUserSubAdminGroups
/**
* Get the groups a user is a subadmin of
*
* @param array $parameters
* @return OC_OCS_Result
*/
public function getUserSubAdminGroups($parameters)
{
$user = $this->userManager->get($parameters['userid']);
// Check if the user exists
if ($user === null) {
return new OC_OCS_Result(null, 101, 'User does not exist');
}
// Get the subadmin groups
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
foreach ($groups as $key => $group) {
$groups[$key] = $group->getGID();
}
if (!$groups) {
return new OC_OCS_Result(null, 102, 'Unknown error occurred');
} else {
return new OC_OCS_Result($groups);
}
}
示例6: stats
/**
* Count all unique users visible for the current admin/subadmin.
*
* @NoAdminRequired
*
* @return DataResponse
*/
public function stats()
{
$userCount = 0;
if ($this->isAdmin) {
$countByBackend = $this->userManager->countUsers();
if (!empty($countByBackend)) {
foreach ($countByBackend as $count) {
$userCount += $count;
}
}
} else {
$groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($this->userSession->getUser());
$uniqueUsers = [];
foreach ($groups as $group) {
foreach ($group->getUsers() as $uid => $displayName) {
$uniqueUsers[$uid] = true;
}
}
$userCount = count($uniqueUsers);
}
return new DataResponse(['totalUsers' => $userCount]);
}
示例7: testGetSubAdminsOfGroup
public function testGetSubAdminsOfGroup()
{
$user1 = $this->generateUsers();
$user2 = $this->generateUsers();
$this->userSession->setUser($user1);
$this->groupManager->get('admin')->addUser($user1);
$group1 = $this->groupManager->createGroup($this->getUniqueID());
$this->groupManager->getSubAdmin()->createSubAdmin($user2, $group1);
$result = $this->api->getSubAdminsOfGroup(['groupid' => $group1->getGID()]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertTrue($result->succeeded());
$data = $result->getData();
$this->assertEquals($user2->getUID(), reset($data));
$group1->delete();
$user1 = $this->generateUsers();
$this->userSession->setUser($user1);
$this->groupManager->get('admin')->addUser($user1);
$result = $this->api->getSubAdminsOfGroup(['groupid' => $this->getUniqueID()]);
$this->assertInstanceOf('OC_OCS_Result', $result);
$this->assertFalse($result->succeeded());
$this->assertEquals(101, $result->getStatusCode());
}