Skip to content
Snippets Groups Projects
Unverified Commit dcdbea54 authored by Joas Schilling's avatar Joas Schilling
Browse files

Respect the accepted flag for group and user shares

parent 6f8c7885
No related branches found
No related tags found
Loading
...@@ -44,6 +44,7 @@ use OCP\IUserManager; ...@@ -44,6 +44,7 @@ use OCP\IUserManager;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\OCS\IDiscoveryService; use OCP\OCS\IDiscoveryService;
use OCP\Share; use OCP\Share;
use OCP\Share\IShare;
class Manager { class Manager {
const STORAGE = '\OCA\Files_Sharing\External\Storage'; const STORAGE = '\OCA\Files_Sharing\External\Storage';
...@@ -151,7 +152,7 @@ class Manager { ...@@ -151,7 +152,7 @@ class Manager {
public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) { public function addShare($remote, $token, $password, $name, $owner, $shareType, $accepted=false, $user = null, $remoteId = -1, $parent = -1) {
$user = $user ? $user : $this->uid; $user = $user ? $user : $this->uid;
$accepted = $accepted ? 1 : 0; $accepted = $accepted ? IShare::STATUS_ACCEPTED : IShare::STATUS_PENDING;
$name = Filesystem::normalizePath('/' . $name); $name = Filesystem::normalizePath('/' . $name);
if (!$accepted) { if (!$accepted) {
......
...@@ -35,6 +35,7 @@ use OCP\IConfig; ...@@ -35,6 +35,7 @@ use OCP\IConfig;
use OCP\ILogger; use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\Share\IManager; use OCP\Share\IManager;
use OCP\Share\IShare;
class MountProvider implements IMountProvider { class MountProvider implements IMountProvider {
/** /**
...@@ -94,6 +95,11 @@ class MountProvider implements IMountProvider { ...@@ -94,6 +95,11 @@ class MountProvider implements IMountProvider {
try { try {
/** @var \OCP\Share\IShare $parentShare */ /** @var \OCP\Share\IShare $parentShare */
$parentShare = $share[0]; $parentShare = $share[0];
if ($parentShare->getStatus() !== IShare::STATUS_ACCEPTED) {
continue;
}
$owner = $parentShare->getShareOwner(); $owner = $parentShare->getShareOwner();
if (!isset($ownerViews[$owner])) { if (!isset($ownerViews[$owner])) {
$ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files'); $ownerViews[$owner] = new View('/' . $parentShare->getShareOwner() . '/files');
...@@ -188,8 +194,11 @@ class MountProvider implements IMountProvider { ...@@ -188,8 +194,11 @@ class MountProvider implements IMountProvider {
// use most permissive permissions // use most permissive permissions
$permissions = 0; $permissions = 0;
$status = IShare::STATUS_PENDING;
foreach ($shares as $share) { foreach ($shares as $share) {
$permissions |= $share->getPermissions(); $permissions |= $share->getPermissions();
$status = max($status, $share->getStatus());
if ($share->getTarget() !== $superShare->getTarget()) { if ($share->getTarget() !== $superShare->getTarget()) {
// adjust target, for database consistency // adjust target, for database consistency
$share->setTarget($superShare->getTarget()); $share->setTarget($superShare->getTarget());
...@@ -216,7 +225,8 @@ class MountProvider implements IMountProvider { ...@@ -216,7 +225,8 @@ class MountProvider implements IMountProvider {
} }
} }
$superShare->setPermissions($permissions); $superShare->setPermissions($permissions)
->setStatus($status);
$result[] = [$superShare, $shares]; $result[] = [$superShare, $shares];
} }
......
...@@ -142,6 +142,7 @@ class DefaultShareProvider implements IShareProvider { ...@@ -142,6 +142,7 @@ class DefaultShareProvider implements IShareProvider {
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
//Set the UID of the user we share with //Set the UID of the user we share with
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); $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) { } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
//Set the GID of the group we share with //Set the GID of the group we share with
$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
...@@ -932,6 +933,7 @@ class DefaultShareProvider implements IShareProvider { ...@@ -932,6 +933,7 @@ class DefaultShareProvider implements IShareProvider {
->setTarget($data['file_target']) ->setTarget($data['file_target'])
->setNote($data['note']) ->setNote($data['note'])
->setMailSend((bool)$data['mail_send']) ->setMailSend((bool)$data['mail_send'])
->setStatus((int)$data['accepted'])
->setLabel($data['label']); ->setLabel($data['label']);
$shareTime = new \DateTime(); $shareTime = new \DateTime();
...@@ -1020,6 +1022,7 @@ class DefaultShareProvider implements IShareProvider { ...@@ -1020,6 +1022,7 @@ class DefaultShareProvider implements IShareProvider {
while($data = $stmt->fetch()) { while($data = $stmt->fetch()) {
$shareMap[$data['parent']]->setPermissions((int)$data['permissions']); $shareMap[$data['parent']]->setPermissions((int)$data['permissions']);
$shareMap[$data['parent']]->setStatus((int)$data['accepted']);
$shareMap[$data['parent']]->setTarget($data['file_target']); $shareMap[$data['parent']]->setTarget($data['file_target']);
$shareMap[$data['parent']]->setParent($data['parent']); $shareMap[$data['parent']]->setParent($data['parent']);
} }
......
...@@ -58,6 +58,8 @@ class Share implements \OCP\Share\IShare { ...@@ -58,6 +58,8 @@ class Share implements \OCP\Share\IShare {
private $shareOwner; private $shareOwner;
/** @var int */ /** @var int */
private $permissions; private $permissions;
/** @var int */
private $status;
/** @var string */ /** @var string */
private $note = ''; private $note = '';
/** @var \DateTime */ /** @var \DateTime */
...@@ -318,6 +320,21 @@ class Share implements \OCP\Share\IShare { ...@@ -318,6 +320,21 @@ class Share implements \OCP\Share\IShare {
return $this->permissions; return $this->permissions;
} }
/**
* @inheritdoc
*/
public function setStatus(int $status): IShare {
$this->status = $status;
return $this;
}
/**
* @inheritdoc
*/
public function getStatus(): int {
return $this->status;
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
......
...@@ -96,6 +96,21 @@ interface IShare { ...@@ -96,6 +96,21 @@ interface IShare {
*/ */
// const TYPE_USERROOM = 11; // 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 * Set the internal id of the share
* It is only allowed to set the internal id of a share once. * It is only allowed to set the internal id of a share once.
...@@ -279,6 +294,25 @@ interface IShare { ...@@ -279,6 +294,25 @@ interface IShare {
*/ */
public function getPermissions(); 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 * Attach a note to a share
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment