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


PHP IGroupManager::groupExists方法代码示例

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


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

示例1: 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

示例2: addSubAdmin

 /**
  * Creates a subadmin
  *
  * @param array $parameters
  * @return OC_OCS_Result
  */
 public function addSubAdmin($parameters)
 {
     $group = $_POST['groupid'];
     $user = $parameters['userid'];
     // Check if the user exists
     if (!$this->userManager->userExists($user)) {
         return new OC_OCS_Result(null, 101, 'User does not exist');
     }
     // Check if group exists
     if (!$this->groupManager->groupExists($group)) {
         return new OC_OCS_Result(null, 102, 'Group:' . $group . ' does not exist');
     }
     // Check if trying to make subadmin of admin group
     if (strtolower($group) === 'admin') {
         return new OC_OCS_Result(null, 103, 'Cannot create subadmins for admin group');
     }
     // We cannot be subadmin twice
     if (OC_Subadmin::isSubAdminOfGroup($user, $group)) {
         return new OC_OCS_Result(null, 100);
     }
     // Go
     if (OC_Subadmin::createSubAdmin($user, $group)) {
         return new OC_OCS_Result(null, 100);
     } else {
         return new OC_OCS_Result(null, 103, 'Unknown error occured');
     }
 }
开发者ID:jincreator,项目名称:core,代码行数:33,代码来源:users.php

示例3: generalCreateChecks

 /**
  * Check for generic requirements before creating a share
  *
  * @param \OCP\Share\IShare $share
  * @throws \InvalidArgumentException
  * @throws GenericShareException
  */
 protected function generalCreateChecks(\OCP\Share\IShare $share)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         // We expect a valid user as sharedWith for user shares
         if (!$this->userManager->userExists($share->getSharedWith())) {
             throw new \InvalidArgumentException('SharedWith is not a valid user');
         }
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             // We expect a valid group as sharedWith for group shares
             if (!$this->groupManager->groupExists($share->getSharedWith())) {
                 throw new \InvalidArgumentException('SharedWith is not a valid group');
             }
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 if ($share->getSharedWith() !== null) {
                     throw new \InvalidArgumentException('SharedWith should be empty');
                 }
             } else {
                 // We can't handle other types yet
                 throw new \InvalidArgumentException('unkown share type');
             }
         }
     }
     // Verify the initiator of the share is set
     if ($share->getSharedBy() === null) {
         throw new \InvalidArgumentException('SharedBy should be set');
     }
     // Cannot share with yourself
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $share->getSharedBy()) {
         throw new \InvalidArgumentException('Can\'t share with yourself');
     }
     // The path should be set
     if ($share->getNode() === null) {
         throw new \InvalidArgumentException('Path should be set');
     }
     // And it should be a file or a folder
     if (!$share->getNode() instanceof \OCP\Files\File && !$share->getNode() instanceof \OCP\Files\Folder) {
         throw new \InvalidArgumentException('Path should be either a file or a folder');
     }
     // Check if we actually have share permissions
     if (!$share->getNode()->isShareable()) {
         $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
         throw new GenericShareException($message_t, $message_t, 404);
     }
     // Permissions should be set
     if ($share->getPermissions() === null) {
         throw new \InvalidArgumentException('A share requires permissions');
     }
     // Check that we do not share with more permissions than we have
     if ($share->getPermissions() & ~$share->getNode()->getPermissions()) {
         $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]);
         throw new GenericShareException($message_t, $message_t, 404);
     }
     // Check that read permissions are always set
     if (($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
         throw new \InvalidArgumentException('Shares need at least read permissions');
     }
 }
开发者ID:farukuzun,项目名称:core-1,代码行数:66,代码来源:manager.php

示例4: 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

示例5: 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

示例6: getSubAdminsOfGroup

 public function getSubAdminsOfGroup($parameters)
 {
     $group = $parameters['groupid'];
     // Check group exists
     if (!$this->groupManager->groupExists($group)) {
         return new OC_OCS_Result(null, 101, 'Group does not exist');
     }
     // Go
     if (!($subadmins = OC_Subadmin::getGroupsSubAdmins($group))) {
         return new OC_OCS_Result(null, 102, 'Unknown error occured');
     } else {
         return new OC_OCS_Result($subadmins);
     }
 }
开发者ID:rosarion,项目名称:core,代码行数:14,代码来源:groups.php

示例7: deleteGroup

 /**
  * @param array $parameters
  * @return OC_OCS_Result
  */
 public function deleteGroup($parameters)
 {
     // Check it exists
     if (!$this->groupManager->groupExists($parameters['groupid'])) {
         return new OC_OCS_Result(null, 101);
     } else {
         if ($parameters['groupid'] === 'admin' || !$this->groupManager->get($parameters['groupid'])->delete()) {
             // Cannot delete admin group
             return new OC_OCS_Result(null, 102);
         } else {
             return new OC_OCS_Result(null, 100);
         }
     }
 }
开发者ID:kenwi,项目名称:core,代码行数:18,代码来源:groups.php

示例8: 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

示例9: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $mountId = $input->getArgument('mount_id');
     try {
         $mount = $this->globalService->getStorage($mountId);
     } catch (NotFoundException $e) {
         $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts</error>');
         return 404;
     }
     if ($mount->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
         $output->writeln('<error>Can\'t change applicables on personal mounts</error>');
         return 1;
     }
     $addUsers = $input->getOption('add-user');
     $removeUsers = $input->getOption('remove-user');
     $addGroups = $input->getOption('add-group');
     $removeGroups = $input->getOption('remove-group');
     $applicableUsers = $mount->getApplicableUsers();
     $applicableGroups = $mount->getApplicableGroups();
     if (count($addUsers) + count($removeUsers) + count($addGroups) + count($removeGroups) > 0 || $input->getOption('remove-all')) {
         foreach ($addUsers as $addUser) {
             if (!$this->userManager->userExists($addUser)) {
                 $output->writeln('<error>User "' . $addUser . '" not found</error>');
                 return 404;
             }
         }
         foreach ($addGroups as $addGroup) {
             if (!$this->groupManager->groupExists($addGroup)) {
                 $output->writeln('<error>Group "' . $addGroup . '" not found</error>');
                 return 404;
             }
         }
         if ($input->getOption('remove-all')) {
             $applicableUsers = [];
             $applicableGroups = [];
         } else {
             $applicableUsers = array_unique(array_merge($applicableUsers, $addUsers));
             $applicableUsers = array_values(array_diff($applicableUsers, $removeUsers));
             $applicableGroups = array_unique(array_merge($applicableGroups, $addGroups));
             $applicableGroups = array_values(array_diff($applicableGroups, $removeGroups));
         }
         $mount->setApplicableUsers($applicableUsers);
         $mount->setApplicableGroups($applicableGroups);
         $this->globalService->updateStorage($mount);
     }
     $this->writeArrayInOutputFormat($input, $output, ['users' => $applicableUsers, 'groups' => $applicableGroups]);
 }
开发者ID:GitHubUser4234,项目名称:core,代码行数:47,代码来源:Applicable.php

示例10: addUser

 /**
  * @return OC_OCS_Result
  */
 public function addUser()
 {
     $userId = isset($_POST['userid']) ? $_POST['userid'] : null;
     $password = isset($_POST['password']) ? $_POST['password'] : null;
     $groups = isset($_POST['groups']) ? $_POST['groups'] : null;
     $user = $this->userSession->getUser();
     $isAdmin = $this->groupManager->isAdmin($user->getUID());
     $subAdminManager = $this->groupManager->getSubAdmin();
     if (!$isAdmin && !$subAdminManager->isSubAdmin($user)) {
         return new OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
     }
     if ($this->userManager->userExists($userId)) {
         $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
         return new OC_OCS_Result(null, 102, 'User already exists');
     }
     if (is_array($groups)) {
         foreach ($groups as $group) {
             if (!$this->groupManager->groupExists($group)) {
                 return new OC_OCS_Result(null, 104, 'group ' . $group . ' does not exist');
             }
             if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) {
                 return new OC_OCS_Result(null, 105, 'insufficient privileges for group ' . $group);
             }
         }
     } else {
         if (!$isAdmin) {
             return new OC_OCS_Result(null, 106, 'no group specified (required for subadmins)');
         }
     }
     try {
         $newUser = $this->userManager->createUser($userId, $password);
         $this->logger->info('Successful addUser call with userid: ' . $userId, ['app' => 'ocs_api']);
         if (is_array($groups)) {
             foreach ($groups as $group) {
                 $this->groupManager->get($group)->addUser($newUser);
                 $this->logger->info('Added userid ' . $userId . ' to group ' . $group, ['app' => 'ocs_api']);
             }
         }
         return new OC_OCS_Result(null, 100);
     } catch (\Exception $e) {
         $this->logger->error('Failed addUser attempt with exception: ' . $e->getMessage(), ['app' => 'ocs_api']);
         return new OC_OCS_Result(null, 101, 'Bad request');
     }
 }
开发者ID:kenwi,项目名称:core,代码行数:47,代码来源:users.php

示例11: generalCreateChecks

 /**
  * Check for generic requirements before creating a share
  *
  * @param \OCP\Share\IShare $share
  * @throws \InvalidArgumentException
  * @throws GenericShareException
  */
 protected function generalCreateChecks(\OCP\Share\IShare $share)
 {
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
         // We expect a valid user as sharedWith for user shares
         if (!$this->userManager->userExists($share->getSharedWith())) {
             throw new \InvalidArgumentException('SharedWith is not a valid user');
         }
     } else {
         if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
             // We expect a valid group as sharedWith for group shares
             if (!$this->groupManager->groupExists($share->getSharedWith())) {
                 throw new \InvalidArgumentException('SharedWith is not a valid group');
             }
         } else {
             if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
                 if ($share->getSharedWith() !== null) {
                     throw new \InvalidArgumentException('SharedWith should be empty');
                 }
             } else {
                 if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) {
                     if ($share->getSharedWith() === null) {
                         throw new \InvalidArgumentException('SharedWith should not be empty');
                     }
                 } else {
                     // We can't handle other types yet
                     throw new \InvalidArgumentException('unkown share type');
                 }
             }
         }
     }
     // Verify the initiator of the share is set
     if ($share->getSharedBy() === null) {
         throw new \InvalidArgumentException('SharedBy should be set');
     }
     // Cannot share with yourself
     if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER && $share->getSharedWith() === $share->getSharedBy()) {
         throw new \InvalidArgumentException('Can\'t share with yourself');
     }
     // The path should be set
     if ($share->getNode() === null) {
         throw new \InvalidArgumentException('Path should be set');
     }
     // And it should be a file or a folder
     if (!$share->getNode() instanceof \OCP\Files\File && !$share->getNode() instanceof \OCP\Files\Folder) {
         throw new \InvalidArgumentException('Path should be either a file or a folder');
     }
     // And you can't share your rootfolder
     if ($this->userManager->userExists($share->getSharedBy())) {
         $sharedPath = $this->rootFolder->getUserFolder($share->getSharedBy())->getPath();
     } else {
         $sharedPath = $this->rootFolder->getUserFolder($share->getShareOwner())->getPath();
     }
     if ($sharedPath === $share->getNode()->getPath()) {
         throw new \InvalidArgumentException('You can\'t share your root folder');
     }
     // Check if we actually have share permissions
     if (!$share->getNode()->isShareable()) {
         $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
         throw new GenericShareException($message_t, $message_t, 404);
     }
     // Permissions should be set
     if ($share->getPermissions() === null) {
         throw new \InvalidArgumentException('A share requires permissions');
     }
     /*
      * Quick fix for #23536
      * Non moveable mount points do not have update and delete permissions
      * while we 'most likely' do have that on the storage.
      */
     $permissions = $share->getNode()->getPermissions();
     $mount = $share->getNode()->getMountPoint();
     if (!$mount instanceof MoveableMount) {
         $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE;
     }
     // Check that we do not share with more permissions than we have
     if ($share->getPermissions() & ~$permissions) {
         $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]);
         throw new GenericShareException($message_t, $message_t, 404);
     }
     // Check that read permissions are always set
     if (($share->getPermissions() & \OCP\Constants::PERMISSION_READ) === 0) {
         throw new \InvalidArgumentException('Shares need at least read permissions');
     }
     if ($share->getNode() instanceof \OCP\Files\File) {
         if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
             $message_t = $this->l->t('Files can\'t be shared with delete permissions');
             throw new GenericShareException($message_t);
         }
         if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
             $message_t = $this->l->t('Files can\'t be shared with create permissions');
             throw new GenericShareException($message_t);
         }
     }
//.........这里部分代码省略.........
开发者ID:GitHubUser4234,项目名称:core,代码行数:101,代码来源:Manager.php

示例12: createShare

 /**
  * @return \OC_OCS_Result
  */
 public function createShare()
 {
     $share = $this->shareManager->newShare();
     // Verify path
     $path = $this->request->getParam('path', null);
     if ($path === null) {
         return new \OC_OCS_Result(null, 404, 'please specify a file or folder path');
     }
     $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID());
     try {
         $path = $userFolder->get($path);
     } catch (\OCP\Files\NotFoundException $e) {
         return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist');
     }
     $share->setNode($path);
     // Parse permissions (if available)
     $permissions = $this->request->getParam('permissions', null);
     if ($permissions === null) {
         $permissions = \OCP\Constants::PERMISSION_ALL;
     } else {
         $permissions = (int) $permissions;
     }
     if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
         return new \OC_OCS_Result(null, 404, 'invalid permissions');
     }
     // Shares always require read permissions
     $permissions |= \OCP\Constants::PERMISSION_READ;
     if ($path instanceof \OCP\Files\File) {
         // Single file shares should never have delete or create permissions
         $permissions &= ~\OCP\Constants::PERMISSION_DELETE;
         $permissions &= ~\OCP\Constants::PERMISSION_CREATE;
     }
     /*
      * Hack for https://github.com/owncloud/core/issues/22587
      * We check the permissions via webdav. But the permissions of the mount point
      * do not equal the share permissions. Here we fix that for federated mounts.
      */
     if ($path->getStorage()->instanceOfStorage('OCA\\Files_Sharing\\External\\Storage')) {
         $permissions &= ~($permissions & ~$path->getPermissions());
     }
     $shareWith = $this->request->getParam('shareWith', null);
     $shareType = (int) $this->request->getParam('shareType', '-1');
     if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
         // Valid user is required to share
         if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
             return new \OC_OCS_Result(null, 404, 'please specify a valid user');
         }
         $share->setSharedWith($shareWith);
         $share->setPermissions($permissions);
     } else {
         if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
             // Valid group is required to share
             if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
                 return new \OC_OCS_Result(null, 404, 'please specify a valid group');
             }
             $share->setSharedWith($shareWith);
             $share->setPermissions($permissions);
         } else {
             if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
                 //Can we even share links?
                 if (!$this->shareManager->shareApiAllowLinks()) {
                     return new \OC_OCS_Result(null, 404, 'public link sharing is disabled by the administrator');
                 }
                 /*
                  * For now we only allow 1 link share.
                  * Return the existing link share if this is a duplicate
                  */
                 $existingShares = $this->shareManager->getSharesBy($this->currentUser->getUID(), \OCP\Share::SHARE_TYPE_LINK, $path, false, 1, 0);
                 if (!empty($existingShares)) {
                     return new \OC_OCS_Result($this->formatShare($existingShares[0]));
                 }
                 $publicUpload = $this->request->getParam('publicUpload', null);
                 if ($publicUpload === 'true') {
                     // Check if public upload is allowed
                     if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
                         return new \OC_OCS_Result(null, 403, 'public upload disabled by the administrator');
                     }
                     // Public upload can only be set for folders
                     if ($path instanceof \OCP\Files\File) {
                         return new \OC_OCS_Result(null, 404, 'public upload is only possible for public shared folders');
                     }
                     $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
                 } else {
                     $share->setPermissions(\OCP\Constants::PERMISSION_READ);
                 }
                 // Set password
                 $password = $this->request->getParam('password', '');
                 if ($password !== '') {
                     $share->setPassword($password);
                 }
                 //Expire date
                 $expireDate = $this->request->getParam('expireDate', '');
                 if ($expireDate !== '') {
                     try {
                         $expireDate = $this->parseDate($expireDate);
                         $share->setExpirationDate($expireDate);
                     } catch (\Exception $e) {
//.........这里部分代码省略.........
开发者ID:gvde,项目名称:core,代码行数:101,代码来源:share20ocs.php

示例13: createShare

 /**
  * @return \OC_OCS_Result
  */
 public function createShare()
 {
     $share = $this->shareManager->newShare();
     // Verify path
     $path = $this->request->getParam('path', null);
     if ($path === null) {
         return new \OC_OCS_Result(null, 404, 'please specify a file or folder path');
     }
     $userFolder = $this->rootFolder->getUserFolder($this->currentUser->getUID());
     try {
         $path = $userFolder->get($path);
     } catch (\OCP\Files\NotFoundException $e) {
         return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist');
     }
     $share->setPath($path);
     // Parse permissions (if available)
     $permissions = $this->request->getParam('permissions', null);
     if ($permissions === null) {
         $permissions = \OCP\Constants::PERMISSION_ALL;
     } else {
         $permissions = (int) $permissions;
     }
     if ($permissions < 0 || $permissions > \OCP\Constants::PERMISSION_ALL) {
         return new \OC_OCS_Result(null, 404, 'invalid permissions');
     }
     // Shares always require read permissions
     $permissions |= \OCP\Constants::PERMISSION_READ;
     if ($path instanceof \OCP\Files\File) {
         // Single file shares should never have delete or create permissions
         $permissions &= ~\OCP\Constants::PERMISSION_DELETE;
         $permissions &= ~\OCP\Constants::PERMISSION_CREATE;
     }
     $shareWith = $this->request->getParam('shareWith', null);
     $shareType = (int) $this->request->getParam('shareType', '-1');
     if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
         // Valid user is required to share
         if ($shareWith === null || !$this->userManager->userExists($shareWith)) {
             return new \OC_OCS_Result(null, 404, 'please specify a valid user');
         }
         $share->setSharedWith($this->userManager->get($shareWith));
         $share->setPermissions($permissions);
     } else {
         if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
             // Valid group is required to share
             if ($shareWith === null || !$this->groupManager->groupExists($shareWith)) {
                 return new \OC_OCS_Result(null, 404, 'please specify a valid group');
             }
             $share->setSharedWith($this->groupManager->get($shareWith));
             $share->setPermissions($permissions);
         } else {
             if ($shareType === \OCP\Share::SHARE_TYPE_LINK) {
                 //Can we even share links?
                 if (!$this->shareManager->shareApiAllowLinks()) {
                     return new \OC_OCS_Result(null, 404, 'public link sharing is disabled by the administrator');
                 }
                 $publicUpload = $this->request->getParam('publicUpload', null);
                 if ($publicUpload === 'true') {
                     // Check if public upload is allowed
                     if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
                         return new \OC_OCS_Result(null, 403, '"public upload disabled by the administrator');
                     }
                     // Public upload can only be set for folders
                     if ($path instanceof \OCP\Files\File) {
                         return new \OC_OCS_Result(null, 404, '"public upload is only possible for public shared folders');
                     }
                     $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE);
                 } else {
                     $share->setPermissions(\OCP\Constants::PERMISSION_READ);
                 }
                 // Set password
                 $share->setPassword($this->request->getParam('password', null));
                 //Expire date
                 $expireDate = $this->request->getParam('expireDate', null);
                 if ($expireDate !== null) {
                     try {
                         $expireDate = $this->parseDate($expireDate);
                         $share->setExpirationDate($expireDate);
                     } catch (\Exception $e) {
                         return new \OC_OCS_Result(null, 404, 'Invalid Date. Format must be YYYY-MM-DD.');
                     }
                 }
             } else {
                 if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
                     //fixme Remote shares are handled by old code path for now
                     return \OCA\Files_Sharing\API\Local::createShare([]);
                 } else {
                     return new \OC_OCS_Result(null, 400, "unknown share type");
                 }
             }
         }
     }
     $share->setShareType($shareType);
     $share->setSharedBy($this->currentUser);
     try {
         $share = $this->shareManager->createShare($share);
     } catch (\OC\HintException $e) {
         $code = $e->getCode() === 0 ? 403 : $e->getCode();
//.........这里部分代码省略.........
开发者ID:matt407,项目名称:core,代码行数:101,代码来源:share20ocs.php


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