Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for room shares #10255

Merged
merged 16 commits into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 25 additions & 0 deletions apps/admin_audit/lib/Actions/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ public function shared(array $params) {
'id',
]
);
} elseif($params['shareType'] === Share::SHARE_TYPE_ROOM) {
$this->log(
'The %s "%s" with ID "%s" has been shared to the room "%s" with permissions "%s" (Share ID: %s)',
$params,
[
'itemType',
'itemTarget',
'itemSource',
'shareWith',
'permissions',
'id',
]
);
}
}

Expand Down Expand Up @@ -122,6 +135,18 @@ public function unshare(array $params) {
'id',
]
);
} elseif($params['shareType'] === Share::SHARE_TYPE_ROOM) {
$this->log(
'The %s "%s" with ID "%s" has been unshared from the room "%s" (Share ID: %s)',
$params,
[
'itemType',
'fileTarget',
'itemSource',
'shareWith',
'id',
]
);
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/dav/lib/Connector/Sabre/SharesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private function getShareTypes(\OCP\Files\Node $node) {
\OCP\Share::SHARE_TYPE_LINK,
\OCP\Share::SHARE_TYPE_REMOTE,
\OCP\Share::SHARE_TYPE_EMAIL,
\OCP\Share::SHARE_TYPE_ROOM,
];
foreach ($requestedShareTypes as $requestedShareType) {
// one of each type is enough to find out about the types
Expand Down
1 change: 1 addition & 0 deletions apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function sharesGetPropertiesDataProvider() {
[[\OCP\Share::SHARE_TYPE_GROUP]],
[[\OCP\Share::SHARE_TYPE_LINK]],
[[\OCP\Share::SHARE_TYPE_REMOTE]],
[[\OCP\Share::SHARE_TYPE_ROOM]],
[[\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP]],
[[\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_LINK]],
[[\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK]],
Expand Down
2 changes: 1 addition & 1 deletion apps/files/lib/Command/TransferOwnership.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private function collectUsersShares(OutputInterface $output) {
$output->writeln("Collecting all share information for files and folder of $this->sourceUser ...");

$progress = new ProgressBar($output, count($this->shares));
foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) {
foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE, \OCP\Share::SHARE_TYPE_ROOM] as $shareType) {
$offset = 0;
while (true) {
$sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset);
Expand Down
3 changes: 2 additions & 1 deletion apps/files/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ private function getShareTypes(Node $node) {
\OCP\Share::SHARE_TYPE_GROUP,
\OCP\Share::SHARE_TYPE_LINK,
\OCP\Share::SHARE_TYPE_REMOTE,
\OCP\Share::SHARE_TYPE_EMAIL
\OCP\Share::SHARE_TYPE_EMAIL,
\OCP\Share::SHARE_TYPE_ROOM
];
foreach ($requestedShareTypes as $requestedShareType) {
// one of each type is enough to find out about the types
Expand Down
2 changes: 2 additions & 0 deletions apps/files_sharing/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
hasShares = true;
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
hasShares = true;
} else if (shareType === OC.Share.SHARE_TYPE_ROOM) {
hasShares = true;
}
});
OCA.Sharing.Util._updateFileActionIcon($tr, hasShares, hasLink);
Expand Down
56 changes: 51 additions & 5 deletions apps/files_sharing/lib/Controller/DeletedShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@

namespace OCA\Files_Sharing\Controller;

use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\QueryException;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\IUserManager;
use OCP\Share\Exceptions\GenericShareException;
use OCP\Share\Exceptions\ShareNotFound;
Expand All @@ -57,22 +60,35 @@ class DeletedShareAPIController extends OCSController {
/** @var IRootFolder */
private $rootFolder;

/** @var IAppManager */
private $appManager;

/** @var IServerContainer */
private $serverContainer;

public function __construct(string $appName,
IRequest $request,
ShareManager $shareManager,
string $UserId,
IUserManager $userManager,
IGroupManager $groupManager,
IRootFolder $rootFolder) {
IRootFolder $rootFolder,
IAppManager $appManager,
IServerContainer $serverContainer) {
parent::__construct($appName, $request);

$this->shareManager = $shareManager;
$this->userId = $UserId;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->rootFolder = $rootFolder;
$this->appManager = $appManager;
$this->serverContainer = $serverContainer;
}

/**
* @suppress PhanUndeclaredClassMethod
*/
private function formatShare(IShare $share): array {

$result = [
Expand Down Expand Up @@ -120,9 +136,19 @@ private function formatShare(IShare $share): array {
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
}

$group = $this->groupManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$group = $this->groupManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_ROOM) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = '';

try {
$result = array_merge($result, $this->getRoomShareHelper()->formatShare($share));
} catch (QueryException $e) {
}
}

return $result;

Expand All @@ -132,7 +158,10 @@ private function formatShare(IShare $share): array {
* @NoAdminRequired
*/
public function index(): DataResponse {
$shares = $this->shareManager->getDeletedSharedWith($this->userId, \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
$groupShares = $this->shareManager->getDeletedSharedWith($this->userId, \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
$roomShares = $this->shareManager->getDeletedSharedWith($this->userId, \OCP\Share::SHARE_TYPE_ROOM, null, -1, 0);

$shares = array_merge($groupShares, $roomShares);

$shares = array_map(function (IShare $share) {
return $this->formatShare($share);
Expand Down Expand Up @@ -165,4 +194,21 @@ public function undelete(string $id): DataResponse {

return new DataResponse([]);
}

/**
* Returns the helper of DeletedShareAPIController for room shares.
*
* If the Talk application is not enabled or the helper is not available
* a QueryException is thrown instead.
*
* @return \OCA\Spreed\Share\Helper\DeletedShareAPIController
* @throws QueryException
*/
private function getRoomShareHelper() {
if (!$this->appManager->isEnabledForUser('spreed')) {
throw new QueryException();
}

return $this->serverContainer->query('\OCA\Spreed\Share\Helper\DeletedShareAPIController');
}
}
71 changes: 67 additions & 4 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\QueryException;
use OCP\Constants;
use OCP\Files\Folder;
use OCP\Files\Node;
Expand All @@ -46,6 +47,7 @@
use OCP\IL10N;
use OCP\IUserManager;
use OCP\IRequest;
use OCP\IServerContainer;
use OCP\IURLGenerator;
use OCP\Files\IRootFolder;
use OCP\Lock\LockedException;
Expand Down Expand Up @@ -84,6 +86,8 @@ class ShareAPIController extends OCSController {
private $config;
/** @var IAppManager */
private $appManager;
/** @var IServerContainer */
private $serverContainer;

/**
* Share20OCS constructor.
Expand All @@ -99,6 +103,7 @@ class ShareAPIController extends OCSController {
* @param IL10N $l10n
* @param IConfig $config
* @param IAppManager $appManager
* @param IServerContainer $serverContainer
*/
public function __construct(
string $appName,
Expand All @@ -111,7 +116,8 @@ public function __construct(
string $userId,
IL10N $l10n,
IConfig $config,
IAppManager $appManager
IAppManager $appManager,
IServerContainer $serverContainer
) {
parent::__construct($appName, $request);

Expand All @@ -125,6 +131,7 @@ public function __construct(
$this->l = $l10n;
$this->config = $config;
$this->appManager = $appManager;
$this->serverContainer = $serverContainer;
}

/**
Expand All @@ -134,6 +141,8 @@ public function __construct(
* @param Node|null $recipientNode
* @return array
* @throws NotFoundException In case the node can't be resolved.
*
* @suppress PhanUndeclaredClassMethod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

*/
protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array {
$sharedBy = $this->userManager->get($share->getSharedBy());
Expand Down Expand Up @@ -231,6 +240,14 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n
$shareWithStart = ($hasCircleId? strrpos($share->getSharedWith(), '[') + 1: 0);
$shareWithLength = ($hasCircleId? -1: strpos($share->getSharedWith(), ' '));
$result['share_with'] = substr($share->getSharedWith(), $shareWithStart, $shareWithLength);
} else if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = '';

try {
$result = array_merge($result, $this->getRoomShareHelper()->formatShare($share));
} catch (QueryException $e) {
}
}


Expand Down Expand Up @@ -315,7 +332,8 @@ public function deleteShare(string $id): DataResponse {
throw new OCSNotFoundException($this->l->t('Could not delete share'));
}

if ($share->getShareType() === Share::SHARE_TYPE_GROUP &&
if (($share->getShareType() === Share::SHARE_TYPE_GROUP ||
$share->getShareType() === Share::SHARE_TYPE_ROOM) &&
$share->getShareOwner() !== $this->currentUser &&
$share->getSharedBy() !== $this->currentUser) {
$this->shareManager->deleteFromSelf($share, $this->currentUser);
Expand Down Expand Up @@ -515,6 +533,12 @@ public function createShare(
}
$share->setSharedWith($shareWith);
$share->setPermissions($permissions);
} else if ($shareType === Share::SHARE_TYPE_ROOM) {
try {
$this->getRoomShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
} catch (QueryException $e) {
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$path->getPath()]));
}
} else {
throw new OCSBadRequestException($this->l->t('Unknown share type'));
}
Expand Down Expand Up @@ -546,8 +570,9 @@ private function getSharedWithMe($node = null, bool $includeTags): DataResponse
$userShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $node, -1, 0);
$groupShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $node, -1, 0);
$circleShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_CIRCLE, $node, -1, 0);
$roomShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $node, -1, 0);

$shares = array_merge($userShares, $groupShares, $circleShares);
$shares = array_merge($userShares, $groupShares, $circleShares, $roomShares);

$shares = array_filter($shares, function (IShare $share) {
return $share->getShareOwner() !== $this->currentUser;
Expand Down Expand Up @@ -594,6 +619,7 @@ private function getSharesInDir(Node $folder): DataResponse {
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $node, false, -1, 0));
}
$shares = array_merge($shares, $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $node, false, -1, 0));
}

$formatted = [];
Expand Down Expand Up @@ -679,8 +705,9 @@ public function getShares(
} else {
$circleShares = [];
}
$roomShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_ROOM, $path, $reshares, -1, 0);

$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares);
$shares = array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares);

if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
$federatedShares = $this->shareManager->getSharesBy($this->currentUser, Share::SHARE_TYPE_REMOTE, $path, $reshares, -1, 0);
Expand Down Expand Up @@ -864,6 +891,7 @@ public function updateShare(
/* Check if this is an incomming share */
$incomingShares = $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_USER, $share->getNode(), -1, 0);
$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_GROUP, $share->getNode(), -1, 0));
$incomingShares = array_merge($incomingShares, $this->shareManager->getSharedWith($this->currentUser, Share::SHARE_TYPE_ROOM, $share->getNode(), -1, 0));

/** @var \OCP\Share\IShare[] $incomingShares */
if (!empty($incomingShares)) {
Expand All @@ -888,6 +916,9 @@ public function updateShare(
return new DataResponse($this->formatShare($share));
}

/**
* @suppress PhanUndeclaredClassMethod
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which class is undeclared here?

*/
protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups = true): bool {
// A file with permissions 0 can't be accessed by us. So Don't show it
if ($share->getPermissions() === 0) {
Expand Down Expand Up @@ -921,6 +952,14 @@ protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups =
return true;
}

if ($share->getShareType() === Share::SHARE_TYPE_ROOM) {
try {
return $this->getRoomShareHelper()->canAccessShare($share, $this->currentUser);
} catch (QueryException $e) {
return false;
}
}

return false;
}

Expand Down Expand Up @@ -988,6 +1027,13 @@ private function getShareById(string $id): IShare {
// Do nothing, just try the other share type
}

try {
$share = $this->shareManager->getShareById('ocRoomShare:' . $id, $this->currentUser);
return $share;
} catch (ShareNotFound $e) {
// Do nothing, just try the other share type
}

if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
throw new ShareNotFound();
}
Expand Down Expand Up @@ -1016,4 +1062,21 @@ public function cleanup() {
$this->lockedNode->unlock(ILockingProvider::LOCK_SHARED);
}
}

/**
* Returns the helper of ShareAPIController for room shares.
*
* If the Talk application is not enabled or the helper is not available
* a QueryException is thrown instead.
*
* @return \OCA\Spreed\Share\Helper\ShareAPIController
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah it is because this is returned or?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* @throws QueryException
*/
private function getRoomShareHelper() {
if (!$this->appManager->isEnabledForUser('spreed')) {
throw new QueryException();
}

return $this->serverContainer->query('\OCA\Spreed\Share\Helper\ShareAPIController');
}
}
1 change: 1 addition & 0 deletions apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $storageFactory) {
$shares = $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_USER, null, -1);
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_GROUP, null, -1));
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_CIRCLE, null, -1));
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), \OCP\Share::SHARE_TYPE_ROOM, null, -1));

// filter out excluded shares and group shares that includes self
$shares = array_filter($shares, function (\OCP\Share\IShare $share) use ($user) {
Expand Down
Loading