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


PHP OC_Group::inGroup方法代码示例

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


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

示例1: checkGroupRightsForPrincipal

 public static function checkGroupRightsForPrincipal($uid)
 {
     $appConfig = \OC::$server->getAppConfig();
     $isEnabled = $appConfig->getValue(self::$appname, 'enabled');
     $bEnabled = false;
     if ($isEnabled === 'yes') {
         $bEnabled = true;
     } else {
         if ($isEnabled === 'no') {
             $bEnabled = false;
         } else {
             if ($isEnabled !== 'no') {
                 $groups = json_decode($isEnabled);
                 if (is_array($groups)) {
                     foreach ($groups as $group) {
                         if (\OC_Group::inGroup($uid, $group)) {
                             $bEnabled = true;
                             break;
                         }
                     }
                 }
             }
         }
     }
     if ($bEnabled == false) {
         throw new \Sabre\DAV\Exception\Forbidden();
         return false;
     } else {
         return true;
     }
 }
开发者ID:ViToni,项目名称:contactsplus,代码行数:31,代码来源:app.php

示例2: checkAdminUser

 /**
  * Check if the user is a admin, send json error msg if not
  */
 public static function checkAdminUser()
 {
     self::checkLoggedIn();
     if (!OC_Group::inGroup(OC_User::getUser(), 'admin')) {
         $l = new OC_L10N('core');
         self::error(array('data' => array('message' => $l->t('Authentication error'))));
         exit;
     }
 }
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:12,代码来源:owncloud_lib_json.php

示例3: checkSubAdminUser

	/**
	* Check if the user is a subadmin, send json error msg if not
	*/
	public static function checkSubAdminUser() {
		self::checkLoggedIn();
		self::verifyUser();
		if(!OC_Group::inGroup(OC_User::getUser(), 'admin') && !OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
			$l = OC_L10N::get('lib');
			self::error(array( 'data' => array( 'message' => $l->t('Authentication error') )));
			exit();
		}
	}
开发者ID:ryanshoover,项目名称:core,代码行数:12,代码来源:json.php

示例4: testSingleBackend

 function testSingleBackend()
 {
     OC_Group::useBackend(new OCA\user_ldap\GROUP_LDAP());
     $group_ldap = new OCA\user_ldap\GROUP_LDAP();
     $this->assertIsA(OC_Group::getGroups(), gettype(array()));
     $this->assertIsA($group_ldap->getGroups(), gettype(array()));
     $this->assertFalse(OC_Group::inGroup('john', 'dosers'), gettype(false));
     $this->assertFalse($group_ldap->inGroup('john', 'dosers'), gettype(false));
     //TODO: check also for expected true result. This backend won't be able to do any modifications, maybe use a dummy for this.
     $this->assertIsA(OC_Group::getUserGroups('john doe'), gettype(array()));
     $this->assertIsA($group_ldap->getUserGroups('john doe'), gettype(array()));
     $this->assertIsA(OC_Group::usersInGroup('campers'), gettype(array()));
     $this->assertIsA($group_ldap->usersInGroup('campers'), gettype(array()));
 }
开发者ID:ryanshoover,项目名称:core,代码行数:14,代码来源:group_ldap.php

示例5: update_groups

/**
* Gets an array of groups and will try to add the group to OC and then add the user to the groups.
* 
*/
function update_groups($uid, $groups, $protected_groups = array(), $just_created = false)
{
    if (!$just_created) {
        $old_groups = OC_Group::getUserGroups($uid);
        foreach ($old_groups as $group) {
            if (!in_array($group, $protected_groups) && !in_array($group, $groups)) {
                \OC_Group::removeFromGroup($uid, $group);
                \OCP\Util::writeLog('cas', 'Removed "' . $uid . '" from the group "' . $group . '"', \OCP\Util::DEBUG);
            }
        }
    }
    foreach ($groups as $group) {
        if (preg_match('/[^a-zA-Z0-9 _\\.@\\-]/', $group)) {
            \OCP\Util::writeLog('cas', 'Invalid group "' . $group . '", allowed chars "a-zA-Z0-9" and "_.@-" ', \OCP\Util::DEBUG);
        } else {
            if (!\OC_Group::inGroup($uid, $group)) {
                if (!OC_Group::groupExists($group)) {
                    \OC_Group::createGroup($group);
                    \OCP\Util::writeLog('cas', 'New group created: ' . $group, \OCP\Util::DEBUG);
                }
                \OC_Group::addToGroup($uid, $group);
                \OCP\Util::writeLog('cas', 'Added "' . $uid . '" to the group "' . $group . '"', \OCP\Util::DEBUG);
            }
        }
    }
}
开发者ID:felixrupp,项目名称:user_cas,代码行数:30,代码来源:hooks.php

示例6: __construct

 /**
  * Share an item, adds an entry into the database
  * @param $source The source location of the item
  * @param $uid_shared_with The user or group to share the item with
  * @param $permissions The permissions, use the constants WRITE and DELETE
  */
 public function __construct($source, $uid_shared_with, $permissions)
 {
     $uid_owner = OCP\USER::getUser();
     $query = OCP\DB::prepare("INSERT INTO *PREFIX*sharing VALUES(?,?,?,?,?)");
     // Check if this is a reshare and use the original source
     if ($result = OC_Share::getSource($source)) {
         $source = $result;
     }
     if ($uid_shared_with == self::PUBLICLINK) {
         $token = sha1("{$uid_shared_with}-{$source}");
         $query->execute(array($uid_owner, self::PUBLICLINK, $source, $token, $permissions));
         $this->token = $token;
     } else {
         if (OC_Group::groupExists($uid_shared_with)) {
             $gid = $uid_shared_with;
             $uid_shared_with = OC_Group::usersInGroup($gid);
             // Remove the owner from the list of users in the group
             $uid_shared_with = array_diff($uid_shared_with, array($uid_owner));
         } else {
             if (OCP\User::userExists($uid_shared_with)) {
                 $userGroups = OC_Group::getUserGroups($uid_owner);
                 // Check if the user is in one of the owner's groups
                 foreach ($userGroups as $group) {
                     if ($inGroup = OC_Group::inGroup($uid_shared_with, $group)) {
                         $gid = null;
                         $uid_shared_with = array($uid_shared_with);
                         break;
                     }
                 }
                 if (!$inGroup) {
                     throw new Exception("You can't share with " . $uid_shared_with);
                 }
             } else {
                 throw new Exception($uid_shared_with . " is not a user");
             }
         }
         foreach ($uid_shared_with as $uid) {
             // Check if this item is already shared with the user
             $checkSource = OCP\DB::prepare("SELECT source FROM *PREFIX*sharing WHERE source = ? AND uid_shared_with " . self::getUsersAndGroups($uid, false));
             $resultCheckSource = $checkSource->execute(array($source))->fetchAll();
             // TODO Check if the source is inside a folder
             if (count($resultCheckSource) > 0) {
                 if (!isset($gid)) {
                     throw new Exception("This item is already shared with " . $uid);
                 } else {
                     // Skip this user if sharing with a group
                     continue;
                 }
             }
             // Check if the target already exists for the user, if it does append a number to the name
             $sharedFolder = '/' . $uid . '/files/Shared';
             $target = $sharedFolder . "/" . basename($source);
             $checkTarget = OCP\DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with " . self::getUsersAndGroups($uid, false) . " LIMIT 1");
             $result = $checkTarget->execute(array($target))->fetchAll();
             if (count($result) > 0) {
                 if ($pos = strrpos($target, ".")) {
                     $name = substr($target, 0, $pos);
                     $ext = substr($target, $pos);
                 } else {
                     $name = $target;
                     $ext = "";
                 }
                 $counter = 1;
                 while (count($result) > 0) {
                     $target = $name . "_" . $counter . $ext;
                     $result = $checkTarget->execute(array($target))->fetchAll();
                     $counter++;
                 }
             }
             if (isset($gid)) {
                 $uid = $uid . "@" . $gid;
             }
             $query->execute(array($uid_owner, $uid, $source, $target, $permissions));
             // Update mtime of shared folder to invoke a file cache rescan
             $rootView = new OC_FilesystemView('/');
             if (!$rootView->is_dir($sharedFolder)) {
                 if (!$rootView->is_dir('/' . $uid . '/files')) {
                     OC_Util::tearDownFS();
                     OC_Util::setupFS($uid);
                     OC_Util::tearDownFS();
                 }
                 $rootView->mkdir($sharedFolder);
             }
             $rootView->touch($sharedFolder);
         }
     }
 }
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:93,代码来源:lib_share.php

示例7: isUserAccessible

 /**
  * checks if a user is a accessible by a subadmin
  * @param string $subadmin uid of the subadmin
  * @param string $user uid of the user
  * @return bool
  */
 public static function isUserAccessible($subadmin, $user)
 {
     if (!self::isSubAdmin($subadmin)) {
         return false;
     }
     if (OC_User::isAdminUser($user)) {
         return false;
     }
     $accessiblegroups = self::getSubAdminsGroups($subadmin);
     foreach ($accessiblegroups as $accessiblegroup) {
         if (OC_Group::inGroup($user, $accessiblegroup)) {
             return true;
         }
     }
     return false;
 }
开发者ID:adolfo2103,项目名称:hcloudfilem,代码行数:22,代码来源:subadmin.php

示例8: getEnabledApps

 /**
  * Returns apps enabled for the current user.
  *
  * @param bool $forceRefresh whether to refresh the cache
  * @param bool $all whether to return apps for all users, not only the
  * currently logged in one
  * @return array
  */
 public static function getEnabledApps($forceRefresh = false, $all = false)
 {
     if (!OC_Config::getValue('installed', false)) {
         return array();
     }
     // in incognito mode or when logged out, $user will be false,
     // which is also the case during an upgrade
     $user = null;
     if (!$all) {
         $user = \OC_User::getUser();
     }
     if (is_string($user) && !$forceRefresh && !empty(self::$enabledAppsCache)) {
         return self::$enabledAppsCache;
     }
     $apps = array();
     $appConfig = \OC::$server->getAppConfig();
     $appStatus = $appConfig->getValues(false, 'enabled');
     foreach ($appStatus as $app => $enabled) {
         if ($app === 'files') {
             continue;
         }
         if ($enabled === 'yes') {
             $apps[] = $app;
         } else {
             if ($enabled !== 'no') {
                 $groups = json_decode($enabled);
                 if (is_array($groups)) {
                     if (is_string($user)) {
                         foreach ($groups as $group) {
                             if (\OC_Group::inGroup($user, $group)) {
                                 $apps[] = $app;
                                 break;
                             }
                         }
                     } else {
                         // global, consider app as enabled
                         $apps[] = $app;
                     }
                 }
             }
         }
     }
     sort($apps);
     array_unshift($apps, 'files');
     // Only cache the app list, when the user is logged in.
     // Otherwise we cache the list with disabled apps, although
     // the apps are enabled for the user after he logged in.
     if ($user) {
         self::$enabledAppsCache = $apps;
     }
     return $apps;
 }
开发者ID:kebenxiaoming,项目名称:owncloudRedis,代码行数:60,代码来源:app.php

示例9: getAbsoluteMountPoints

 /**
  * Returns the mount points for the given user.
  * The mount point is relative to the data directory.
  *
  * @param string $user user
  * @return array of mount point string as key, mountpoint config as value
  */
 public static function getAbsoluteMountPoints($user)
 {
     $mountPoints = array();
     $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data");
     $mount_file = \OC_Config::getValue("mount_file", $datadir . "/mount.json");
     $backends = self::getBackends();
     //move config file to it's new position
     if (is_file(\OC::$SERVERROOT . '/config/mount.json')) {
         rename(\OC::$SERVERROOT . '/config/mount.json', $mount_file);
     }
     // Load system mount points
     $mountConfig = self::readData();
     // Global mount points (is this redundant?)
     if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
         foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
             $options['personal'] = false;
             $options['options'] = self::decryptPasswords($options['options']);
             if (!isset($options['priority'])) {
                 $options['priority'] = $backends[$options['class']]['priority'];
             }
             // Override if priority greater
             if (!isset($mountPoints[$mountPoint]) || $options['priority'] >= $mountPoints[$mountPoint]['priority']) {
                 $options['priority_type'] = self::MOUNT_TYPE_GLOBAL;
                 $options['backend'] = $backends[$options['class']]['backend'];
                 $mountPoints[$mountPoint] = $options;
             }
         }
     }
     // All user mount points
     if (isset($mountConfig[self::MOUNT_TYPE_USER]) && isset($mountConfig[self::MOUNT_TYPE_USER]['all'])) {
         $mounts = $mountConfig[self::MOUNT_TYPE_USER]['all'];
         foreach ($mounts as $mountPoint => $options) {
             $mountPoint = self::setUserVars($user, $mountPoint);
             foreach ($options as &$option) {
                 $option = self::setUserVars($user, $option);
             }
             $options['personal'] = false;
             $options['options'] = self::decryptPasswords($options['options']);
             if (!isset($options['priority'])) {
                 $options['priority'] = $backends[$options['class']]['priority'];
             }
             // Override if priority greater
             if (!isset($mountPoints[$mountPoint]) || $options['priority'] >= $mountPoints[$mountPoint]['priority']) {
                 $options['priority_type'] = self::MOUNT_TYPE_GLOBAL;
                 $options['backend'] = $backends[$options['class']]['backend'];
                 $mountPoints[$mountPoint] = $options;
             }
         }
     }
     // Group mount points
     if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
         foreach ($mountConfig[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
             if (\OC_Group::inGroup($user, $group)) {
                 foreach ($mounts as $mountPoint => $options) {
                     $mountPoint = self::setUserVars($user, $mountPoint);
                     foreach ($options as &$option) {
                         $option = self::setUserVars($user, $option);
                     }
                     $options['personal'] = false;
                     $options['options'] = self::decryptPasswords($options['options']);
                     if (!isset($options['priority'])) {
                         $options['priority'] = $backends[$options['class']]['priority'];
                     }
                     // Override if priority greater or if priority type different
                     if (!isset($mountPoints[$mountPoint]) || $options['priority'] >= $mountPoints[$mountPoint]['priority'] || $mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_GROUP) {
                         $options['priority_type'] = self::MOUNT_TYPE_GROUP;
                         $options['backend'] = $backends[$options['class']]['backend'];
                         $mountPoints[$mountPoint] = $options;
                     }
                 }
             }
         }
     }
     // User mount points
     if (isset($mountConfig[self::MOUNT_TYPE_USER])) {
         foreach ($mountConfig[self::MOUNT_TYPE_USER] as $mountUser => $mounts) {
             if (strtolower($mountUser) === strtolower($user)) {
                 foreach ($mounts as $mountPoint => $options) {
                     $mountPoint = self::setUserVars($user, $mountPoint);
                     foreach ($options as &$option) {
                         $option = self::setUserVars($user, $option);
                     }
                     $options['personal'] = false;
                     $options['options'] = self::decryptPasswords($options['options']);
                     if (!isset($options['priority'])) {
                         $options['priority'] = $backends[$options['class']]['priority'];
                     }
                     // Override if priority greater or if priority type different
                     if (!isset($mountPoints[$mountPoint]) || $options['priority'] >= $mountPoints[$mountPoint]['priority'] || $mountPoints[$mountPoint]['priority_type'] !== self::MOUNT_TYPE_USER) {
                         $options['priority_type'] = self::MOUNT_TYPE_USER;
                         $options['backend'] = $backends[$options['class']]['backend'];
                         $mountPoints[$mountPoint] = $options;
                     }
//.........这里部分代码省略.........
开发者ID:Romua1d,项目名称:core,代码行数:101,代码来源:config.php

示例10: delete

 /**
  * @brief deletes a card
  * @param integer $id id of card
  * @return boolean true on success, otherwise an exception will be thrown
  */
 public static function delete($id)
 {
     $contact = self::find($id);
     if (!$contact) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', id: ' . $id . ' not found.', \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('Could not find the vCard with ID: ' . $id, 404));
     }
     $addressbook = Addressbook::find($contact['addressbookid']);
     if (!$addressbook) {
         throw new \Exception(App::$l10n->t('Could not find the Addressbook with ID: ' . $contact['addressbookid'], 404));
     }
     if ($addressbook['userid'] != \OCP\User::getUser() && !\OC_Group::inGroup(\OCP\User::getUser(), 'admin')) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ', ' . $addressbook['userid'] . ' != ' . \OCP\User::getUser(), \OCP\Util::DEBUG);
         $sharedAddressbook = \OCP\Share::getItemSharedWithBySource(App::SHAREADDRESSBOOK, App::SHAREADDRESSBOOKPREFIX . $contact['addressbookid'], \OCP\Share::FORMAT_NONE, null, true);
         $sharedContact = \OCP\Share::getItemSharedWithBySource(App::SHARECONTACT, App::SHARECONTACTPREFIX . $id, \OCP\Share::FORMAT_NONE, null, true);
         $addressbook_permissions = 0;
         $contact_permissions = 0;
         if ($sharedAddressbook) {
             $addressbook_permissions = $sharedAddressbook['permissions'];
         }
         if ($sharedContact) {
             $contact_permissions = $sharedEvent['permissions'];
         }
         $permissions = max($addressbook_permissions, $contact_permissions);
         if (!($permissions & \OCP\PERMISSION_DELETE)) {
             throw new \Exception(App::$l10n->t('You do not have the permissions to delete this contact.', 403));
         }
     }
     $aid = $contact['addressbookid'];
     //	\OC_Hook::emit('\OCA\ContactsPlus\VCard', 'pre_deleteVCard',
     //		array('aid' => null, 'id' => $id, 'uri' => null)
     //	);
     $favorites = \OC::$server->getTagManager()->load(App::$appname)->getFavorites();
     if (count($favorites) > 0) {
         $favorites = \OC::$server->getTagManager()->load(App::$appname)->removeFromFavorites($id);
     }
     $stmt = \OCP\DB::prepare('DELETE FROM `' . App::ContactsTable . '` WHERE `id` = ?');
     try {
         $stmt->execute(array($id));
     } catch (\Exception $e) {
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', exception: ' . $e->getMessage(), \OCP\Util::ERROR);
         \OCP\Util::writeLog(App::$appname, __METHOD__ . ', id: ' . $id, \OCP\Util::DEBUG);
         throw new \Exception(App::$l10n->t('There was an error deleting this contact.'));
     }
     App::updateDBProperties($id);
     //App::getVCategories()->purgeObject($id);
     Addressbook::touch($addressbook['id']);
     \OCP\Share::unshareAll(App::SHARECONTACT, $id);
     return true;
 }
开发者ID:ViToni,项目名称:contactsplus,代码行数:55,代码来源:vcard.php

示例11: testRemoveFromGroupAsIrelevantSubAdmin

 public function testRemoveFromGroupAsIrelevantSubAdmin()
 {
     $user1 = $this->generateUsers();
     self::loginAsUser($user1);
     $user2 = $this->generateUsers();
     $group1 = $this->getUniqueID();
     $group2 = $this->getUniqueID();
     \OC_Group::createGroup($group1);
     \OC_Group::createGroup($group2);
     \OC_Group::addToGroup($user1, $group1);
     \OC_Group::addToGroup($user2, $group2);
     \OC_SubAdmin::createSubAdmin($user1, $group1);
     $result = \OCA\provisioning_api\Users::removeFromGroup(array('userid' => $user2, '_delete' => array('groupid' => $group2)));
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertFalse($result->succeeded());
     $this->assertTrue(\OC_Group::inGroup($user2, $group2));
     \OC_Group::deleteGroup($group1);
     \OC_Group::deleteGroup($group2);
 }
开发者ID:samj1912,项目名称:repo,代码行数:19,代码来源:userstest.php

示例12: checkSubAdminUser

 /**
  * Check if the user is a subadmin, redirects to home if not
  * @return array $groups where the current user is subadmin
  */
 public static function checkSubAdminUser()
 {
     // Check if we are a user
     self::checkLoggedIn();
     self::verifyUser();
     if (OC_Group::inGroup(OC_User::getUser(), 'admin')) {
         return true;
     }
     if (!OC_SubAdmin::isSubAdmin(OC_User::getUser())) {
         header('Location: ' . OC_Helper::linkToAbsolute('', 'index.php'));
         exit;
     }
     return true;
 }
开发者ID:ryanshoover,项目名称:core,代码行数:18,代码来源:util.php

示例13: array

<?php

// Init owncloud
require_once '../../lib/base.php';
// Check if we are a user
if (!OC_User::isLoggedIn() || !OC_Group::inGroup(OC_User::getUser(), 'admin')) {
    OC_JSON::error(array("data" => array("message" => "Authentication error")));
    exit;
}
$groups = array();
if (isset($_POST["groups"])) {
    $groups = $_POST["groups"];
}
$username = $_POST["username"];
$password = $_POST["password"];
// Does the group exist?
if (in_array($username, OC_User::getUsers())) {
    OC_JSON::error(array("data" => array("message" => "User already exists")));
    exit;
}
// Return Success story
try {
    OC_User::createUser($username, $password);
    foreach ($groups as $i) {
        if (!OC_Group::groupExists($i)) {
            OC_Group::createGroup($i);
        }
        OC_Group::addToGroup($username, $i);
    }
    OC_JSON::success(array("data" => array("username" => $username, "groups" => implode(", ", OC_Group::getUserGroups($username)))));
} catch (Exception $exception) {
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:31,代码来源:createuser.php

示例14: import

 /**
  * @brief imports a user, or owncloud instance
  * @param $path string path to zip
  * @param optional $type type of import (user or instance)
  * @param optional $uid userid of new user
  */
 public static function import($path, $type = 'user', $uid = null)
 {
     $datadir = OC_Config::getValue('datadirectory');
     // Extract the zip
     if (!($extractpath = self::extractZip($path))) {
         return json_encode(array('success' => false));
     }
     // Get export_info.json
     $scan = scandir($extractpath);
     // Check for export_info.json
     if (!in_array('export_info.json', $scan)) {
         OC_Log::write('migration', 'Invalid import file, export_info.json not found', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     $json = json_decode(file_get_contents($extractpath . 'export_info.json'));
     if ($json->exporttype != $type) {
         OC_Log::write('migration', 'Invalid import file', OC_Log::ERROR);
         return json_encode(array('success' => false));
     }
     self::$exporttype = $type;
     $currentuser = OC_User::getUser();
     // Have we got a user if type is user
     if (self::$exporttype == 'user') {
         self::$uid = !is_null($uid) ? $uid : $currentuser;
     }
     // We need to be an admin if we are not importing our own data
     if ($type == 'user' && self::$uid != $currentuser || $type != 'user') {
         if (!OC_Group::inGroup(OC_User::getUser(), 'admin')) {
             // Naughty.
             OC_Log::write('migration', 'Import not permitted.', OC_Log::ERROR);
             return json_encode(array('success' => false));
         }
     }
     // Handle export types
     switch (self::$exporttype) {
         case 'user':
             // Check user availability
             if (!OC_User::userExists(self::$uid)) {
                 OC_Log::write('migration', 'User doesn\'t exist', OC_Log::ERROR);
                 return json_encode(array('success' => false));
             }
             // Copy data
             $userfolder = $extractpath . $json->exporteduser;
             $newuserfolder = $datadir . '/' . self::$uid;
             foreach (scandir($userfolder) as $file) {
                 if ($file !== '.' && $file !== '..' && is_dir($file)) {
                     // Then copy the folder over
                     OC_Helper::copyr($userfolder . '/' . $file, $newuserfolder . '/' . $file);
                 }
             }
             // Import user app data
             if (file_exists($extractpath . $json->exporteduser . '/migration.db')) {
                 if (!($appsimported = self::importAppData($extractpath . $json->exporteduser . '/migration.db', $json, self::$uid))) {
                     return json_encode(array('success' => false));
                 }
             }
             // All done!
             if (!self::unlink_r($extractpath)) {
                 OC_Log::write('migration', 'Failed to delete the extracted zip', OC_Log::ERROR);
             }
             return json_encode(array('success' => true, 'data' => $appsimported));
             break;
         case 'instance':
             /*
              * EXPERIMENTAL
             // Check for new data dir and dbexport before doing anything
             // TODO
             
             // Delete current data folder.
             OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO );
             if( !self::unlink_r( $datadir, false ) ) {
             	OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR );
             	return json_encode( array( 'success' => false ) );
             }
             
             // Copy over data
             if( !self::copy_r( $extractpath . 'userdata', $datadir ) ) {
             	OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR );
             	return json_encode( array( 'success' => false ) );
             }
             
             // Import the db
             if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ) {
             	return json_encode( array( 'success' => false ) );
             }
             // Done
             return json_encode( array( 'success' => true ) );
             */
             break;
     }
 }
开发者ID:ryanshoover,项目名称:core,代码行数:97,代码来源:migrate.php

示例15: shareItem

 /**
  * Share an item with a user, group, or via private link
  * @param string $itemType
  * @param string $itemSource
  * @param int $shareType SHARE_TYPE_USER, SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @param string $shareWith User or group the item is being shared with
  * @param int $permissions CRUDS
  * @param null $itemSourceName
  * @throws \Exception
  * @internal param \OCP\Item $string type
  * @internal param \OCP\Item $string source
  * @internal param \OCP\SHARE_TYPE_USER $int , SHARE_TYPE_GROUP, or SHARE_TYPE_LINK
  * @internal param \OCP\User $string or group the item is being shared with
  * @internal param \OCP\CRUDS $int permissions
  * @return bool|string Returns true on success or false on failure, Returns token on success for links
  */
 public static function shareItem($itemType, $itemSource, $shareType, $shareWith, $permissions, $itemSourceName = null)
 {
     $uidOwner = \OC_User::getUser();
     $sharingPolicy = \OC_Appconfig::getValue('core', 'shareapi_share_policy', 'global');
     if (is_null($itemSourceName)) {
         $itemSourceName = $itemSource;
     }
     // verify that the file exists before we try to share it
     if ($itemType === 'file' or $itemType === 'folder') {
         $path = \OC\Files\Filesystem::getPath($itemSource);
         if (!$path) {
             $message = 'Sharing ' . $itemSourceName . ' failed, because the file does not exist';
             \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
             throw new \Exception($message);
         }
     }
     // Verify share type and sharing conditions are met
     if ($shareType === self::SHARE_TYPE_USER) {
         if ($shareWith == $uidOwner) {
             $message = 'Sharing ' . $itemSourceName . ' failed, because the user ' . $shareWith . ' is the item owner';
             \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
             throw new \Exception($message);
         }
         if (!\OC_User::userExists($shareWith)) {
             $message = 'Sharing ' . $itemSourceName . ' failed, because the user ' . $shareWith . ' does not exist';
             \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
             throw new \Exception($message);
         }
         if ($sharingPolicy == 'groups_only') {
             $inGroup = array_intersect(\OC_Group::getUserGroups($uidOwner), \OC_Group::getUserGroups($shareWith));
             if (empty($inGroup)) {
                 $message = 'Sharing ' . $itemSourceName . ' failed, because the user ' . $shareWith . ' is not a member of any groups that ' . $uidOwner . ' is a member of';
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
         }
         // Check if the item source is already shared with the user, either from the same owner or a different user
         if ($checkExists = self::getItems($itemType, $itemSource, self::$shareTypeUserAndGroups, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
             // Only allow the same share to occur again if it is the same
             // owner and is not a user share, this use case is for increasing
             // permissions for a specific user
             if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
                 $message = 'Sharing ' . $itemSourceName . ' failed, because this item is already shared with ' . $shareWith;
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
         }
     } else {
         if ($shareType === self::SHARE_TYPE_GROUP) {
             if (!\OC_Group::groupExists($shareWith)) {
                 $message = 'Sharing ' . $itemSourceName . ' failed, because the group ' . $shareWith . ' does not exist';
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
             if ($sharingPolicy == 'groups_only' && !\OC_Group::inGroup($uidOwner, $shareWith)) {
                 $message = 'Sharing ' . $itemSourceName . ' failed, because ' . $uidOwner . ' is not a member of the group ' . $shareWith;
                 \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                 throw new \Exception($message);
             }
             // Check if the item source is already shared with the group, either from the same owner or a different user
             // The check for each user in the group is done inside the put() function
             if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_GROUP, $shareWith, null, self::FORMAT_NONE, null, 1, true, true)) {
                 // Only allow the same share to occur again if it is the same
                 // owner and is not a group share, this use case is for increasing
                 // permissions for a specific user
                 if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
                     $message = 'Sharing ' . $itemSourceName . ' failed, because this item is already shared with ' . $shareWith;
                     \OC_Log::write('OCP\\Share', $message, \OC_Log::ERROR);
                     throw new \Exception($message);
                 }
             }
             // Convert share with into an array with the keys group and users
             $group = $shareWith;
             $shareWith = array();
             $shareWith['group'] = $group;
             $shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
         } else {
             if ($shareType === self::SHARE_TYPE_LINK) {
                 if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
                     // when updating a link share
                     if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null, $uidOwner, self::FORMAT_NONE, null, 1)) {
                         // remember old token
                         $oldToken = $checkExists['token'];
                         $oldPermissions = $checkExists['permissions'];
//.........这里部分代码省略.........
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:101,代码来源:share.php


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