-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add support for room shares #10255
Changes from all commits
7292a98
857bb45
4ee839d
d9458b3
4ed7131
382b27d
de403f2
8084ba5
1ccc99e
523fdb6
30d8e3e
0fab46c
2d062da
e1561f0
e2e6f23
4b7fa4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -84,6 +86,8 @@ class ShareAPIController extends OCSController { | |
private $config; | ||
/** @var IAppManager */ | ||
private $appManager; | ||
/** @var IServerContainer */ | ||
private $serverContainer; | ||
|
||
/** | ||
* Share20OCS constructor. | ||
|
@@ -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, | ||
|
@@ -111,7 +116,8 @@ public function __construct( | |
string $userId, | ||
IL10N $l10n, | ||
IConfig $config, | ||
IAppManager $appManager | ||
IAppManager $appManager, | ||
IServerContainer $serverContainer | ||
) { | ||
parent::__construct($appName, $request); | ||
|
||
|
@@ -125,6 +131,7 @@ public function __construct( | |
$this->l = $l10n; | ||
$this->config = $config; | ||
$this->appManager = $appManager; | ||
$this->serverContainer = $serverContainer; | ||
} | ||
|
||
/** | ||
|
@@ -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 | ||
*/ | ||
protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = null): array { | ||
$sharedBy = $this->userManager->get($share->getSharedBy()); | ||
|
@@ -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) { | ||
} | ||
} | ||
|
||
|
||
|
@@ -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); | ||
|
@@ -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')); | ||
} | ||
|
@@ -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; | ||
|
@@ -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 = []; | ||
|
@@ -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); | ||
|
@@ -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)) { | ||
|
@@ -888,6 +916,9 @@ public function updateShare( | |
return new DataResponse($this->formatShare($share)); | ||
} | ||
|
||
/** | ||
* @suppress PhanUndeclaredClassMethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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(); | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaah it is because this is returned or? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, see #10255 (comment) or the commit message |
||
* @throws QueryException | ||
*/ | ||
private function getRoomShareHelper() { | ||
if (!$this->appManager->isEnabledForUser('spreed')) { | ||
throw new QueryException(); | ||
} | ||
|
||
return $this->serverContainer->query('\OCA\Spreed\Share\Helper\ShareAPIController'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this?