本文整理汇总了PHP中OCP\Share::unshareFromSelf方法的典型用法代码示例。如果您正苦于以下问题:PHP Share::unshareFromSelf方法的具体用法?PHP Share::unshareFromSelf怎么用?PHP Share::unshareFromSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OCP\Share
的用法示例。
在下文中一共展示了Share::unshareFromSelf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unshareStorage
/**
* unshare complete storage, also the grouped shares
*
* @return bool
*/
public function unshareStorage()
{
$result = true;
if (!empty($this->share['grouped'])) {
foreach ($this->share['grouped'] as $share) {
$result = $result && \OCP\Share::unshareFromSelf($share['item_type'], $share['file_target']);
}
}
$result = $result && \OCP\Share::unshareFromSelf($this->getItemType(), $this->getMountPoint());
return $result;
}
示例2: testShareWithUser
//.........这里部分代码省略.........
}
// Unshare
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2));
// Attempt reshare without share permission
$this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user2);
$message = 'Sharing test.txt failed, because resharing is not allowed';
try {
\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ);
$this->fail('Exception was expected: ' . $message);
} catch (\Exception $exception) {
$this->assertEquals($message, $exception->getMessage());
}
// Owner grants share and update permission
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE));
// Attempt reshare with escalated permissions
\OC_User::setUserId($this->user2);
$message = 'Sharing test.txt failed, because the permissions exceed permissions granted to ' . $this->user2;
try {
\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE);
$this->fail('Exception was expected: ' . $message);
} catch (\Exception $exception) {
$this->assertEquals($message, $exception->getMessage());
}
// Valid reshare
$this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE));
$this->assertEquals(array('test.txt'), \OCP\Share::getItemShared('test', 'test.txt', Backend::FORMAT_SOURCE));
\OC_User::setUserId($this->user3);
$this->assertEquals(array('test.txt'), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_SOURCE));
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS));
// Attempt to escalate permissions
\OC_User::setUserId($this->user2);
$message = 'Setting permissions for test.txt failed, because the permissions exceed permissions granted to ' . $this->user2;
try {
\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE);
$this->fail('Exception was expected: ' . $message);
} catch (\Exception $exception) {
$this->assertEquals($message, $exception->getMessage());
}
// Remove update permission
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE));
\OC_User::setUserId($this->user2);
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS));
\OC_User::setUserId($this->user3);
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS));
// Remove share permission
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user2);
$this->assertEquals(array(\OCP\Constants::PERMISSION_READ), \OCP\Share::getItemSharedWith('test', 'test.txt', Backend::FORMAT_PERMISSIONS));
\OC_User::setUserId($this->user3);
$this->assertSame(array(), \OCP\Share::getItemSharedWith('test', 'test.txt'));
// Reshare again, and then have owner unshare
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::setPermissions('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE));
\OC_User::setUserId($this->user2);
$this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user3, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2));
\OC_User::setUserId($this->user2);
$this->assertSame(array(), \OCP\Share::getItemSharedWith('test', 'test.txt'));
\OC_User::setUserId($this->user3);
$this->assertSame(array(), \OCP\Share::getItemSharedWith('test', 'test.txt'));
// Attempt target conflict
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user3);
$this->assertTrue(\OCP\Share::shareItem('test', 'share.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user2);
$to_test = \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET);
$this->assertEquals(2, count($to_test));
$this->assertTrue(in_array('test.txt', $to_test));
$this->assertTrue(in_array('test1.txt', $to_test));
// Unshare from self
$this->assertTrue(\OCP\Share::unshareFromSelf('test', 'test.txt'));
$this->assertEquals(array('test1.txt'), \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET));
// Unshare from self via source
$this->assertTrue(\OCP\Share::unshareFromSelf('test', 'share.txt', true));
$this->assertEquals(array(), \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET));
\OC_User::setUserId($this->user1);
$this->assertTrue(\OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user3);
$this->assertTrue(\OCP\Share::shareItem('test', 'share.txt', \OCP\Share::SHARE_TYPE_USER, $this->user2, \OCP\Constants::PERMISSION_READ));
\OC_User::setUserId($this->user2);
$to_test = \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET);
$this->assertEquals(2, count($to_test));
$this->assertTrue(in_array('test.txt', $to_test));
$this->assertTrue(in_array('test1.txt', $to_test));
// Remove user
\OC_User::setUserId($this->user1);
$user = \OC::$server->getUserManager()->get($this->user1);
if ($user !== null) {
$user->delete();
}
\OC_User::setUserId($this->user2);
$this->assertEquals(array('test1.txt'), \OCP\Share::getItemsSharedWith('test', Backend::FORMAT_TARGET));
}
示例3: delete
/**
* {@inheritDoc}
*/
public function delete($privateUri, $userId)
{
list($itemType, $itemTarget) = explode('::', $privateUri, 1);
if ($itemType === 'calendar') {
return Share::unshareFromSelf('calendar', $itemTarget);
} elseif ($itemType === 'object') {
$calendars = Share::getItemsShared($itemType, ShareTypes::GROUPED);
/** @var ICalendar $calendar */
foreach ($calendars as $calendar) {
if ($calendar->getPrivateUri() !== $privateUri) {
continue;
}
$objects = $calendar['objects'];
foreach ($objects as $object) {
Share::unshareFromSelf('object', $object['shareItem']['item_source']);
}
}
return true;
} else {
throw new BackendUtils\DoesNotExistException();
}
}
示例4: unlink
public function unlink($path)
{
// Delete the file if DELETE permission is granted
if ($source = $this->getSourcePath($path)) {
if ($this->isDeletable($path)) {
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
return $storage->unlink($internalPath);
} else {
if (dirname($path) == '/' || dirname($path) == '.') {
// Unshare the file from the user if in the root of the Shared folder
if ($this->is_dir($path)) {
$itemType = 'folder';
} else {
$itemType = 'file';
}
return \OCP\Share::unshareFromSelf($itemType, $path);
}
}
}
return false;
}
示例5: removeMount
/**
* Remove the mount points
*
* @return bool
*/
public function removeMount()
{
$mountManager = \OC\Files\Filesystem::getMountManager();
$storage = $this->getStorage();
$result = \OCP\Share::unshareFromSelf($storage->getItemType(), $storage->getMountPoint());
$mountManager->removeMount($this->mountPoint);
return $result;
}