Skip to content

Commit

Permalink
Fix related logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rullzer committed Apr 19, 2016
1 parent 6123bad commit afa37d3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/connector/sabre/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function getSharePermissions() {

if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
/** @var \OC\Files\Storage\Shared $storage */
$permissions = (int)$storage->getShare()['permissions'];
$permissions = (int)$storage->getShare()->getPermissions();
} else {
$permissions = $storage->getPermissions($path);
}
Expand Down
51 changes: 31 additions & 20 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ protected function generalCreateChecks(\OCP\Share\IShare $share) {
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);
}
}
}

/**
Expand Down Expand Up @@ -505,6 +516,24 @@ public function createShare(\OCP\Share\IShare $share) {

$this->generalCreateChecks($share);

// Verify if there are any issues with the path
$this->pathCreateChecks($share->getNode());

/*
* On creation of a share the owner is always the owner of the path
* Except for mounted federated shares.
*/
$storage = $share->getNode()->getStorage();
if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
$parent = $share->getNode()->getParent();
while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
$parent = $parent->getParent();
}
$share->setShareOwner($parent->getOwner()->getUID());
} else {
$share->setShareOwner($share->getNode()->getOwner()->getUID());
}

//Verify share type
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$this->userCreateChecks($share);
Expand Down Expand Up @@ -538,24 +567,6 @@ public function createShare(\OCP\Share\IShare $share) {
}
}

// Verify if there are any issues with the path
$this->pathCreateChecks($share->getNode());

/*
* On creation of a share the owner is always the owner of the path
* Except for mounted federated shares.
*/
$storage = $share->getNode()->getStorage();
if ($storage->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
$parent = $share->getNode()->getParent();
while($parent->getStorage()->instanceOfStorage('OCA\Files_Sharing\External\Storage')) {
$parent = $parent->getParent();
}
$share->setShareOwner($parent->getOwner()->getUID());
} else {
$share->setShareOwner($share->getNode()->getOwner()->getUID());
}

// Cannot share with the owner
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER &&
$share->getSharedWith() === $share->getShareOwner()) {
Expand Down Expand Up @@ -818,7 +829,7 @@ public function deleteShare(\OCP\Share\IShare $share) {
* @param string $recipientId
*/
public function deleteFromSelf(\OCP\Share\IShare $share, $recipientId) {
list($providerId, ) = $this->splitFullId($share->getId());
list($providerId, ) = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);

$provider->deleteFromSelf($share, $recipientId);
Expand All @@ -844,7 +855,7 @@ public function moveShare(\OCP\Share\IShare $share, $recipientId) {
}
}

list($providerId, ) = $this->splitFullId($share->getId());
list($providerId, ) = $this->splitFullId($share->getFullId());
$provider = $this->factory->getProvider($providerId);

$provider->move($share, $recipientId);
Expand Down
2 changes: 1 addition & 1 deletion lib/private/files/config/usermountcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function registerMounts(IUser $user, array $mounts) {
$newMounts = array_map(function (IMountPoint $mount) use ($user) {
$storage = $mount->getStorage();
if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
$rootId = (int)$storage->getShare()['file_source'];
$rootId = (int)$storage->getShare()->getNodeId();
} else {
$rootId = (int)$storage->getCache()->getId('');
}
Expand Down
15 changes: 14 additions & 1 deletion lib/private/files/storage/wrapper/jail.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct($arguments) {
$this->rootPath = $arguments['root'];
}

protected function getSourcePath($path) {
public function getSourcePath($path) {
if ($path === '') {
return $this->rootPath;
} else {
Expand Down Expand Up @@ -415,6 +415,14 @@ public function getETag($path) {
return $this->storage->getETag($this->getSourcePath($path));
}

/**
* @param string $path
* @return array
*/
public function getMetaData($path) {
return $this->storage->getMetaData($this->getSourcePath($path));
}

/**
* @param string $path
* @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE
Expand Down Expand Up @@ -442,4 +450,9 @@ public function releaseLock($path, $type, ILockingProvider $provider) {
public function changeLock($path, $type, ILockingProvider $provider) {
$this->storage->changeLock($this->getSourcePath($path), $type, $provider);
}

public function resolvePath($path) {
$path = $this->getSourcePath($path);
return \OC\Files\Filesystem::resolvePath($path);
}
}
2 changes: 1 addition & 1 deletion lib/private/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public static function getStorageInfo($path, $rootInfo = null) {
/** @var \OC\Files\Storage\Wrapper\Quota $storage */
$quota = $sourceStorage->getQuota();
}
$free = $storage->free_space('');
$free = $sourceStorage->free_space('');
if ($free >= 0) {
$total = $free + $used;
} else {
Expand Down

0 comments on commit afa37d3

Please sign in to comment.