Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Respect the accepted flag for group and user shares
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Nov 12, 2019
commit dcdbea54e60d13d2508b71ebdcb7992f2ae5ef34
3 changes: 2 additions & 1 deletion apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService;
use OCP\Share;
use OCP\Share\IShare;

class Manager {
const STORAGE = '\OCA\Files_Sharing\External\Storage';
Expand Down Expand Up @@ -151,7 +152,7 @@ public function __construct(IDBConnection $connection,
public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) {

$user = $user ? $user : $this->uid;
$accepted = $accepted ? 1 : 0;
$accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING;
$name = Filesystem::normalizePath('/' . $name);

if (!$accepted) {
Expand Down
12 changes: 11 additions & 1 deletion apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\ILogger;
use OCP\IUser;
use OCP\Share\IManager;
use OCP\Share\IShare;

class MountProvider implements IMountProvider {
/**
Expand Down Expand Up @@ -94,6 +95,11 @@ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
try {
/** @var \OCP\Share\IShare $parentShare */
$parentShare = $share[0];

if ($parentShare->getStatus() !== IShare::STATUS_ACCEPTED) {
continue;
}

$owner = $parentShare->getShareOwner();
if (!isset($ownerViews[$owner])) {
$ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files');
Expand Down Expand Up @@ -188,8 +194,11 @@ private function buildSuperShares(array $allShares, \OCP\IUser $user) {

// use most permissive permissions
$permissions = 0;
$status = IShare::STATUS_PENDING;
foreach ($shares as $share) {
$permissions |= $share->getPermissions();
$status = max($status, $share->getStatus());

if ($share->getTarget() !== $superShare->getTarget()) {
// adjust target, for database consistency
$share->setTarget($superShare->getTarget());
Expand All @@ -216,7 +225,8 @@ private function buildSuperShares(array $allShares, \OCP\IUser $user) {
}
}

$superShare->setPermissions($permissions);
$superShare->setPermissions($permissions)
->setStatus($status);

$result[] = [$superShare, $shares];
}
Expand Down
3 changes: 3 additions & 0 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function create(\OCP\Share\IShare $share) {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
//Set the UID of the user we share with
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
$qb->setValue('accepted', $qb->createNamedParameter(IShare::STATUS_PENDING));
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
//Set the GID of the group we share with
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
Expand Down Expand Up @@ -932,6 +933,7 @@ private function createShare($data) {
->setTarget($data['file_target'])
->setNote($data['note'])
->setMailSend((bool)$data['mail_send'])
->setStatus((int)$data['accepted'])
->setLabel($data['label']);

$shareTime = new \DateTime();
Expand Down Expand Up @@ -1020,6 +1022,7 @@ private function resolveGroupShares($shares, $userId) {

while($data = $stmt->fetch()) {
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
$shareMap[$data['parent']]->setStatus((int)$data['accepted']);
$shareMap[$data['parent']]->setTarget($data['file_target']);
$shareMap[$data['parent']]->setParent($data['parent']);
}
Expand Down
17 changes: 17 additions & 0 deletions lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Share implements \OCP\Share\IShare {
private $shareOwner;
/** @var int */
private $permissions;
/** @var int */
private $status;
/** @var string */
private $note = '';
/** @var \DateTime */
Expand Down Expand Up @@ -318,6 +320,21 @@ public function getPermissions() {
return $this->permissions;
}

/**
* @inheritdoc
*/
public function setStatus(int $status): IShare {
$this->status = $status;
return $this;
}

/**
* @inheritdoc
*/
public function getStatus(): int {
return $this->status;
}

/**
* @inheritdoc
*/
Expand Down
34 changes: 34 additions & 0 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ interface IShare {
*/
// const TYPE_USERROOM = 11;

/**
* @since 18.0.0
*/
public const STATUS_PENDING = 0;

/**
* @since 18.0.0
*/
public const STATUS_ACCEPTED = 1;

/**
* @since 18.0.0
*/
public const STATUS_REJECTED = 2;

/**
* Set the internal id of the share
* It is only allowed to set the internal id of a share once.
Expand Down Expand Up @@ -279,6 +294,25 @@ public function setPermissions($permissions);
*/
public function getPermissions();

/**
* Set the accepted status
* See self::STATUS_*
*
* @param int $status
* @return IShare The modified object
* @since 18.0.0
*/
public function setStatus(int $status): IShare;

/**
* Get the accepted status
* See self::STATUS_*
*
* @return int
* @since 18.0.0
*/
public function getStatus(): int;

/**
* Attach a note to a share
*
Expand Down