当前位置: 首页>>代码示例>>PHP>>正文


PHP IGroupManager::createGroup方法代码示例

本文整理汇总了PHP中OCP\IGroupManager::createGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP IGroupManager::createGroup方法的具体用法?PHP IGroupManager::createGroup怎么用?PHP IGroupManager::createGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OCP\IGroupManager的用法示例。


在下文中一共展示了IGroupManager::createGroup方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

 protected function setUp()
 {
     parent::setUp();
     $this->userManager = \OC::$server->getUserManager();
     $this->groupManager = \OC::$server->getGroupManager();
     $this->groupManager->createGroup('admin');
 }
开发者ID:nem0xff,项目名称:core,代码行数:7,代码来源:testcase.php

示例2: create

 /**
  * @param string $id
  * @return DataResponse
  */
 public function create($id)
 {
     if ($this->groupManager->groupExists($id)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Group already exists.')), Http::STATUS_CONFLICT);
     }
     if ($this->groupManager->createGroup($id)) {
         return new DataResponse(array('groupname' => $id), Http::STATUS_CREATED);
     }
     return new DataResponse(array('status' => 'error', 'data' => array('message' => (string) $this->l10n->t('Unable to add group.'))), Http::STATUS_FORBIDDEN);
 }
开发者ID:heldernl,项目名称:owncloud8-extended,代码行数:14,代码来源:groupscontroller.php

示例3: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $uid = $input->getArgument('uid');
     if ($this->userManager->userExists($uid)) {
         $output->writeln('<error>The user "' . $uid . '" already exists.</error>');
         return 1;
     }
     if ($input->getOption('password-from-env')) {
         $password = getenv('OC_PASS');
         if (!$password) {
             $output->writeln('<error>--password-from-env given, but OC_PASS is empty!</error>');
             return 1;
         }
     } elseif ($input->isInteractive()) {
         /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
         $dialog = $this->getHelperSet()->get('dialog');
         $password = $dialog->askHiddenResponse($output, '<question>Enter password: </question>', false);
         $confirm = $dialog->askHiddenResponse($output, '<question>Confirm password: </question>', false);
         if ($password !== $confirm) {
             $output->writeln("<error>Passwords did not match!</error>");
             return 1;
         }
     } else {
         $output->writeln("<error>Interactive input or --password-from-env is needed for entering a password!</error>");
         return 1;
     }
     $user = $this->userManager->createUser($input->getArgument('uid'), $password);
     if ($user instanceof IUser) {
         $output->writeln('<info>The user "' . $user->getUID() . '" was created successfully</info>');
     } else {
         $output->writeln('<error>An error occurred while creating the user</error>');
         return 1;
     }
     if ($input->getOption('display-name')) {
         $user->setDisplayName($input->getOption('display-name'));
         $output->writeln('Display name set to "' . $user->getDisplayName() . '"');
     }
     foreach ($input->getOption('group') as $groupName) {
         $group = $this->groupManager->get($groupName);
         if (!$group) {
             $this->groupManager->createGroup($groupName);
             $group = $this->groupManager->get($groupName);
             $output->writeln('Created group "' . $group->getGID() . '"');
         }
         $group->addUser($user);
         $output->writeln('User "' . $user->getUID() . '" added to group "' . $group->getGID() . '"');
     }
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:48,代码来源:add.php

示例4: create

 /**
  * @NoAdminRequired
  *
  * @param string $username
  * @param string $password
  * @param array $groups
  * @param string $email
  * @return DataResponse
  */
 public function create($username, $password, array $groups = array(), $email = '')
 {
     if ($email !== '' && !$this->mail->validateAddress($email)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Invalid mail address')), Http::STATUS_UNPROCESSABLE_ENTITY);
     }
     if (!$this->isAdmin) {
         $userId = $this->userSession->getUser()->getUID();
         if (!empty($groups)) {
             foreach ($groups as $key => $group) {
                 if (!$this->subAdminFactory->isGroupAccessible($userId, $group)) {
                     unset($groups[$key]);
                 }
             }
         }
         if (empty($groups)) {
             $groups = $this->subAdminFactory->getSubAdminsOfGroups($userId);
         }
     }
     if ($this->userManager->userExists($username)) {
         return new DataResponse(array('message' => (string) $this->l10n->t('A user with that name already exists.')), Http::STATUS_CONFLICT);
     }
     try {
         $user = $this->userManager->createUser($username, $password);
     } catch (\Exception $exception) {
         return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
     }
     if ($user instanceof User) {
         if ($groups !== null) {
             foreach ($groups as $groupName) {
                 $group = $this->groupManager->get($groupName);
                 if (empty($group)) {
                     $group = $this->groupManager->createGroup($groupName);
                 }
                 $group->addUser($user);
             }
         }
         /**
          * Send new user mail only if a mail is set
          */
         if ($email !== '') {
             $this->config->setUserValue($username, 'settings', 'email', $email);
             // data for the mail template
             $mailData = array('username' => $username, 'url' => $this->urlGenerator->getAbsoluteURL('/'));
             $mail = new TemplateResponse('settings', 'email.new_user', $mailData, 'blank');
             $mailContent = $mail->render();
             $mail = new TemplateResponse('settings', 'email.new_user_plain_text', $mailData, 'blank');
             $plainTextMailContent = $mail->render();
             $subject = $this->l10n->t('Your %s account was created', [$this->defaults->getName()]);
             try {
                 $this->mail->send($email, $username, $subject, $mailContent, $this->fromMailAddress, $this->defaults->getName(), 1, $plainTextMailContent);
             } catch (\Exception $e) {
                 $this->log->error("Can't send new user mail to {$email}: " . $e->getMessage(), array('app' => 'settings'));
             }
         }
         // fetch users groups
         $userGroups = $this->groupManager->getUserGroupIds($user);
         return new DataResponse($this->formatUserForIndex($user, $userGroups), Http::STATUS_CREATED);
     }
     return new DataResponse(array('message' => (string) $this->l10n->t('Unable to create user.')), Http::STATUS_FORBIDDEN);
 }
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:69,代码来源:userscontroller.php

示例5: testDeleteGroup

 public function testDeleteGroup()
 {
     $group = $this->groupManager->createGroup($this->getUniqueId());
     $result = $this->api->deleteGroup(['groupid' => $group->getGID()]);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $this->assertFalse($this->groupManager->groupExists($group->getGID()));
 }
开发者ID:rosarion,项目名称:core,代码行数:8,代码来源:groupstest.php

示例6: setup

 public function setup()
 {
     $this->users = [];
     $this->groups = [];
     $this->userManager = \OC::$server->getUserManager();
     $this->groupManager = \OC::$server->getGroupManager();
     $this->dbConn = \OC::$server->getDatabaseConnection();
     // Create 3 users and 3 groups
     for ($i = 0; $i < 3; $i++) {
         $this->users[] = $this->userManager->createUser('user' . $i, 'user');
         $this->groups[] = $this->groupManager->createGroup('group' . $i);
     }
     // Create admin group
     if (!$this->groupManager->groupExists('admin')) {
         $this->groupManager->createGroup('admin');
     }
 }
开发者ID:nem0xff,项目名称:core,代码行数:17,代码来源:subadmin.php

示例7: setup

 public function setup()
 {
     $this->users = [];
     $this->groups = [];
     $this->userManager = \OC::$server->getUserManager();
     $this->groupManager = \OC::$server->getGroupManager();
     $this->dbConn = \OC::$server->getDatabaseConnection();
     // Create 3 users and 3 groups
     for ($i = 0; $i < 3; $i++) {
         $this->users[] = $this->userManager->createUser('user' . $i, 'user');
         $this->groups[] = $this->groupManager->createGroup('group' . $i);
     }
     // Create admin group
     if (!$this->groupManager->groupExists('admin')) {
         $this->groupManager->createGroup('admin');
     }
     // Create "orphaned" users and groups (scenario: temporarily disabled
     // backend)
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('group_admin')->values(['gid' => $qb->createNamedParameter($this->groups[0]->getGID()), 'uid' => $qb->createNamedParameter('orphanedUser')])->execute();
     $qb->insert('group_admin')->values(['gid' => $qb->createNamedParameter('orphanedGroup'), 'uid' => $qb->createNamedParameter('orphanedUser')])->execute();
     $qb->insert('group_admin')->values(['gid' => $qb->createNamedParameter('orphanedGroup'), 'uid' => $qb->createNamedParameter($this->users[0]->getUID())])->execute();
 }
开发者ID:rchicoli,项目名称:owncloud-core,代码行数:23,代码来源:SubAdminTest.php

示例8: addGroup

 /**
  * creates a new group
  */
 public function addGroup($parameters)
 {
     // Validate name
     $groupid = isset($_POST['groupid']) ? $_POST['groupid'] : '';
     if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $groupid) || empty($groupid)) {
         \OCP\Util::writeLog('provisioning_api', 'Attempt made to create group using invalid characters.', \OCP\Util::ERROR);
         return new OC_OCS_Result(null, 101, 'Invalid group name');
     }
     // Check if it exists
     if ($this->groupManager->groupExists($groupid)) {
         return new OC_OCS_Result(null, 102);
     }
     $this->groupManager->createGroup($groupid);
     return new OC_OCS_Result(null, 100);
 }
开发者ID:rosarion,项目名称:core,代码行数:18,代码来源:groups.php

示例9: addGroup

 /**
  * creates a new group
  *
  * @param array $parameters
  * @return OC_OCS_Result
  */
 public function addGroup($parameters)
 {
     // Validate name
     $groupId = $this->request->getParam('groupid', '');
     if (empty($groupId)) {
         \OCP\Util::writeLog('provisioning_api', 'Group name not supplied', \OCP\Util::ERROR);
         return new OC_OCS_Result(null, 101, 'Invalid group name');
     }
     // Check if it exists
     if ($this->groupManager->groupExists($groupId)) {
         return new OC_OCS_Result(null, 102);
     }
     $this->groupManager->createGroup($groupId);
     return new OC_OCS_Result(null, 100);
 }
开发者ID:kenwi,项目名称:core,代码行数:21,代码来源:groups.php

示例10: testSubAdminOfGroupAlreadySubAdmin

 public function testSubAdminOfGroupAlreadySubAdmin()
 {
     $user1 = $this->generateUsers();
     $user2 = $this->generateUsers();
     $this->userSession->setUser($user1);
     $this->groupManager->get('admin')->addUser($user1);
     $group1 = $this->groupManager->createGroup($this->getUniqueID());
     //Make user2 subadmin of group1
     $_POST['groupid'] = $group1->getGID();
     $result = $this->api->addSubAdmin(['userid' => $user2->getUID()]);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     //Make user2 subadmin of group1 again
     $_POST['groupid'] = $group1->getGID();
     $result = $this->api->addSubAdmin(['userid' => $user2->getUID()]);
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $group1->delete();
 }
开发者ID:jincreator,项目名称:core,代码行数:19,代码来源:userstest.php


注:本文中的OCP\IGroupManager::createGroup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。