Skip to content

Commit

Permalink
Merge pull request #21044 from owncloud/group-propagation-82
Browse files Browse the repository at this point in the history
[8.2] Group share etag propagation
  • Loading branch information
Vincent Petry committed Dec 10, 2015
2 parents e1809db + 63a2e36 commit c023812
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 116 deletions.
4 changes: 3 additions & 1 deletion apps/files_sharing/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ function() use ($c) {
$server = $c->query('ServerContainer');
return new PropagationManager(
$server->getUserSession(),
$server->getConfig()
$server->getConfig(),
$server->getGroupManager(),
$server->getUserManager()
);
});

Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/lib/mountprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(IConfig $config, PropagationManager $propagationMana
*/
public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
$shares = \OCP\Share::getItemsSharedWithUser('file', $user->getUID());
$propagator = $this->propagationManager->getSharePropagator($user->getUID());
$propagator = $this->propagationManager->getSharePropagator($user);
$propagator->propagateDirtyMountPoints($shares);
$shares = array_filter($shares, function ($share) {
return $share['permissions'] > 0;
Expand Down
32 changes: 25 additions & 7 deletions apps/files_sharing/lib/propagation/propagationmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use OC\Files\Filesystem;
use OC\Files\View;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Util;

Expand Down Expand Up @@ -56,9 +59,21 @@ class PropagationManager {
*/
private $sharePropagators = [];

public function __construct(IUserSession $userSession, IConfig $config) {
/**
* @var IGroupManager
*/
private $groupManager;

/**
* @var IUserManager
*/
private $userManager;

public function __construct(IUserSession $userSession, IConfig $config, IGroupManager $groupManager, IUserManager $userManager) {
$this->userSession = $userSession;
$this->config = $config;
$this->groupManager = $groupManager;
$this->userManager = $userManager;
}

/**
Expand Down Expand Up @@ -97,15 +112,18 @@ public function propagateSharesToUser($shares, $user) {
}

/**
* @param string $user
* @param IUser|string $user
* @return \OCA\Files_Sharing\Propagation\RecipientPropagator
*/
public function getSharePropagator($user) {
if (isset($this->sharePropagators[$user])) {
return $this->sharePropagators[$user];
if (!$user instanceof IUser) {
$user = $this->userManager->get($user);
}
if (isset($this->sharePropagators[$user->getUID()])) {
return $this->sharePropagators[$user->getUID()];
}
$this->sharePropagators[$user] = new RecipientPropagator($user, $this->getChangePropagator($user), $this->config, $this);
return $this->sharePropagators[$user];
$this->sharePropagators[$user->getUID()] = new RecipientPropagator($user, $this->getChangePropagator($user->getUID()), $this->config, $this, $this->groupManager);
return $this->sharePropagators[$user->getUID()];
}

/**
Expand All @@ -130,7 +148,7 @@ public function globalSetup() {
if (!$user) {
return;
}
$recipientPropagator = $this->getSharePropagator($user->getUID());
$recipientPropagator = $this->getSharePropagator($user);
$watcher = new ChangeWatcher(Filesystem::getView(), $recipientPropagator);

// for marking shares owned by the active user as dirty when a file inside them changes
Expand Down
40 changes: 36 additions & 4 deletions apps/files_sharing/lib/propagation/recipientpropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use OC\Files\Cache\ChangePropagator;
use OC\Files\View;
use OC\Share\Share;
use OCP\IGroupManager;
use OCP\IUser;

/**
* Propagate etags for share recipients
Expand All @@ -51,18 +53,31 @@ class RecipientPropagator {
private $manager;

/**
* @param string $userId current user, must match the propagator's
* @var IGroupManager
*/
private $groupManager;

/**
* @var IUser
*/
private $user;

/**
* @param IUser $user current user, must match the propagator's
* user
* @param \OC\Files\Cache\ChangePropagator $changePropagator change propagator
* initialized with a view for $user
* @param \OCP\IConfig $config
* @param PropagationManager $manager
* @param IGroupManager $groupManager
*/
public function __construct($userId, $changePropagator, $config, PropagationManager $manager) {
$this->userId = $userId;
public function __construct(IUser $user, $changePropagator, $config, PropagationManager $manager, IGroupManager $groupManager) {
$this->userId = $user->getUID();
$this->user = $user;
$this->changePropagator = $changePropagator;
$this->config = $config;
$this->manager = $manager;
$this->groupManager = $groupManager;
}

/**
Expand Down Expand Up @@ -139,7 +154,7 @@ public function propagateById($id) {
$this->markDirty($share, microtime(true));

// propagate up the share tree
if ($share['share_with'] === $this->userId) {
if ($this->isRecipientOfShare($share)) {
$user = $share['uid_owner'];
$view = new View('/' . $user . '/files');
$path = $view->getPath($share['file_source']);
Expand All @@ -150,4 +165,21 @@ public function propagateById($id) {

unset($this->propagatingIds[$id]);
}

/**
* Check if the user for this recipient propagator is the recipient of a share
*
* @param array $share
* @return bool
*/
private function isRecipientOfShare($share) {
if ($share['share_with'] === $this->userId && $share['share_type'] == \OCP\Share::SHARE_TYPE_USER) { // == since 'share_type' is a string
return true;
}
if ($share['share_type'] == \OCP\Share::SHARE_TYPE_GROUP) {
$groups = $this->groupManager->getUserGroupIds($this->user);
return in_array($share['share_with'], $groups);
}
return false;
}
}
Loading

0 comments on commit c023812

Please sign in to comment.