Skip to content

Commit

Permalink
Add SHARE_TYPE_SCIENCEMESH
Browse files Browse the repository at this point in the history
Signed-off-by: Michiel de Jong <michiel@unhosted.org>
  • Loading branch information
michielbdejong committed Feb 14, 2023
1 parent a705132 commit 1a9037d
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 12 deletions.
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 @@ -160,6 +160,19 @@ public function shared(array $params): void {
'id',
]
);
} elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
$this->log(
'The %s "%s" with ID "%s" has been shared to the sciencemesh user "%s" with permissions "%s" (Share ID: %s)',
$params,
[
'itemType',
'path',
'itemSource',
'shareWith',
'permissions',
'id',
]
);
}
}

Expand Down Expand Up @@ -276,6 +289,18 @@ public function unshare(array $params): void {
'id',
]
);
} elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
$this->log(
'The %s "%s" with ID "%s" has been unshared from the sciencemesh user "%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 @@ -110,6 +110,7 @@ private function getShare(Node $node): array {
IShare::TYPE_ROOM,
IShare::TYPE_CIRCLE,
IShare::TYPE_DECK,
IShare::TYPE_SCIENCEMESH,
];
foreach ($requestedShareTypes as $requestedShareType) {
$shares = $this->shareManager->getSharesBy(
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 @@ -278,6 +278,7 @@ public function sharesGetPropertiesDataProvider() {
[[IShare::TYPE_REMOTE]],
[[IShare::TYPE_ROOM]],
[[IShare::TYPE_DECK]],
[[IShare::TYPE_SCIENCEMESH]],
[[IShare::TYPE_USER, IShare::TYPE_GROUP]],
[[IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK]],
[[IShare::TYPE_USER, IShare::TYPE_LINK]],
Expand Down
1 change: 1 addition & 0 deletions apps/files/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ private function getShareTypesForNodes(array $nodes): array {
IShare::TYPE_EMAIL,
IShare::TYPE_ROOM,
IShare::TYPE_DECK,
IShare::TYPE_SCIENCEMESH,
];
$shareTypes = [];

Expand Down
2 changes: 1 addition & 1 deletion apps/files/lib/Service/OwnershipTransferService.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function collectUsersShares(string $sourceUid,
$shares = [];
$progress = new ProgressBar($output);

foreach ([IShare::TYPE_GROUP, IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_ROOM, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE, IShare::TYPE_DECK] as $shareType) {
foreach ([IShare::TYPE_GROUP, IShare::TYPE_USER, IShare::TYPE_LINK, IShare::TYPE_REMOTE, IShare::TYPE_ROOM, IShare::TYPE_EMAIL, IShare::TYPE_CIRCLE, IShare::TYPE_DECK, IShare::TYPE_SCIENCEMESH] as $shareType) {
$offset = 0;
while (true) {
$sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset);
Expand Down
30 changes: 28 additions & 2 deletions apps/files_sharing/lib/Controller/DeletedShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ private function formatShare(IShare $share): array {
$result = array_merge($result, $this->getDeckShareHelper()->formatShare($share));
} catch (QueryException $e) {
}
} elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = '';

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

return $result;
Expand All @@ -171,8 +179,9 @@ public function index(): DataResponse {
$groupShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_GROUP, null, -1, 0);
$roomShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_ROOM, null, -1, 0);
$deckShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_DECK, null, -1, 0);
$sciencemeshShares = $this->shareManager->getDeletedSharedWith($this->userId, IShare::TYPE_SCIENCEMESH, null, -1, 0);

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

$shares = array_map(function (IShare $share) {
return $this->formatShare($share);
Expand Down Expand Up @@ -224,7 +233,7 @@ private function getRoomShareHelper() {
}

/**
* Returns the helper of ShareAPIHelper for deck shares.
* Returns the helper of DeletedShareAPIHelper for deck shares.
*
* If the Deck application is not enabled or the helper is not available
* a QueryException is thrown instead.
Expand All @@ -239,4 +248,21 @@ private function getDeckShareHelper() {

return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper');
}

/**
* Returns the helper of DeletedShareAPIHelper for sciencemesh shares.
*
* If the sciencemesh application is not enabled or the helper is not available
* a QueryException is thrown instead.
*
* @return \OCA\Deck\Sharing\ShareAPIHelper
* @throws QueryException
*/
private function getSciencemeshShareHelper() {
if (!$this->appManager->isEnabledForUser('sciencemesh')) {
throw new QueryException();
}

return $this->serverContainer->get('\OCA\ScienceMesh\Sharing\ShareAPIHelper');
}
}
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 @@ -320,6 +320,14 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
$result = array_merge($result, $this->getDeckShareHelper()->formatShare($share));
} catch (QueryException $e) {
}
} elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = '';

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


Expand Down Expand Up @@ -692,6 +700,12 @@ public function createShare(
} catch (QueryException $e) {
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support room shares', [$node->getPath()]));
}
} elseif ($shareType === IShare::TYPE_SCIENCEMESH) {
try {
$this->getSciencemeshShareHelper()->createShare($share, $shareWith, $permissions, $expireDate);
} catch (QueryException $e) {
throw new OCSForbiddenException($this->l->t('Sharing %s failed because the back end does not support sciencemesh shares', [$node->getPath()]));
}
} else {
throw new OCSBadRequestException($this->l->t('Unknown share type'));
}
Expand Down Expand Up @@ -730,8 +744,9 @@ private function getSharedWithMe($node, bool $includeTags): array {
$circleShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_CIRCLE, $node, -1, 0);
$roomShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_ROOM, $node, -1, 0);
$deckShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_DECK, $node, -1, 0);
$sciencemeshShares = $this->shareManager->getSharedWith($this->currentUser, IShare::TYPE_SCIENCEMESH, $node, -1, 0);

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

$filteredShares = array_filter($shares, function (IShare $share) {
return $share->getShareOwner() !== $this->currentUser;
Expand Down Expand Up @@ -1414,6 +1429,14 @@ protected function canAccessShare(\OCP\Share\IShare $share, bool $checkGroups =
}
}

if ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
try {
return $this->getSciencemeshShareHelper()->canAccessShare($share, $this->currentUser);
} catch (QueryException $e) {
return false;
}
}

return false;
}

Expand Down Expand Up @@ -1490,7 +1513,8 @@ protected function canDeleteShare(\OCP\Share\IShare $share): bool {
protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool {
if ($share->getShareType() !== IShare::TYPE_GROUP &&
$share->getShareType() !== IShare::TYPE_ROOM &&
$share->getShareType() !== IShare::TYPE_DECK
$share->getShareType() !== IShare::TYPE_DECK &&
$share->getShareType() !== IShare::TYPE_SCIENCEMESH
) {
return false;
}
Expand Down Expand Up @@ -1527,6 +1551,14 @@ protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool {
}
}

if ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
try {
return $this->getSciencemeshShareHelper()->canAccessShare($share, $this->currentUser);
} catch (QueryException $e) {
return false;
}
}

return false;
}

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

try {
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
$share = $this->shareManager->getShareById('sciencemesh:' . $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 @@ -1669,6 +1710,23 @@ private function getDeckShareHelper() {
return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper');
}

/**
* Returns the helper of ShareAPIHelper for sciencemesh shares.
*
* If the sciencemesh application is not enabled or the helper is not available
* a QueryException is thrown instead.
*
* @return \OCA\Deck\Sharing\ShareAPIHelper
* @throws QueryException
*/
private function getSciencemeshShareHelper() {
if (!$this->appManager->isEnabledForUser('sciencemesh')) {
throw new QueryException();
}

return $this->serverContainer->get('\OCA\ScienceMesh\Sharing\ShareAPIHelper');
}

/**
* @param string $viewer
* @param Node $node
Expand All @@ -1684,7 +1742,8 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
IShare::TYPE_EMAIL,
IShare::TYPE_CIRCLE,
IShare::TYPE_ROOM,
IShare::TYPE_DECK
IShare::TYPE_DECK,
IShare::TYPE_SCIENCEMESH
];

// Should we assume that the (currentUser) viewer is the owner of the node !?
Expand Down Expand Up @@ -1837,8 +1896,12 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
// TALK SHARES
$roomShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_ROOM, $path, $reshares, -1, 0);

// DECK SHARES
$deckShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_DECK, $path, $reshares, -1, 0);

// SCIENCEMESH SHARES
$sciencemeshShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_SCIENCEMESH, $path, $reshares, -1, 0);

// FEDERATION
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
$federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0);
Expand All @@ -1851,7 +1914,7 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
$federatedGroupShares = [];
}

return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $federatedShares, $federatedGroupShares);
return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $sciencemeshShares, $federatedShares, $federatedGroupShares);
}


Expand Down
7 changes: 7 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ public function search(string $search = '', string $itemType = null, int $page =
if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) {
$shareTypes[] = IShare::TYPE_DECK;
}

if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
$shareTypes[] = IShare::TYPE_SCIENCEMESH;
}
} else {
if ($this->shareManager->allowGroupSharing()) {
$shareTypes[] = IShare::TYPE_GROUP;
Expand All @@ -206,6 +210,9 @@ public function search(string $search = '', string $itemType = null, int $page =
if ($this->shareManager->shareProviderExists(IShare::TYPE_DECK)) {
$shareTypes[] = IShare::TYPE_DECK;
}
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
$shareTypes[] = IShare::TYPE_SCIENCEMESH;
}

if ($shareType !== null && is_array($shareType)) {
$shareTypes = array_intersect($shareTypes, $shareType);
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/lib/MountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_CIRCLE, null, -1));
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_ROOM, null, -1));
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_DECK, null, -1));
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_SCIENCEMESH, null, -1));


// filter out excluded shares and group shares that includes self
Expand Down
6 changes: 6 additions & 0 deletions apps/files_sharing/src/components/SharingInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default {
this.SHARE_TYPES.SHARE_TYPE_ROOM,
this.SHARE_TYPES.SHARE_TYPE_GUEST,
this.SHARE_TYPES.SHARE_TYPE_DECK,
this.SHARE_TYPES.SHARE_TYPE_SCIENCEMESH,
]

if (OC.getCapabilities().files_sharing.public.enabled === true) {
Expand Down Expand Up @@ -413,6 +414,11 @@ export default {
icon: 'icon-deck',
iconTitle: t('files_sharing', 'Deck board'),
}
case this.SHARE_TYPES.SHARE_TYPE_SCIENCEMESH:
return {
icon: 'icon-sciencemesh',
iconTitle: t('files_sharing', 'Science Mesh'),
}
default:
return {}
}
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ Object.assign(OC, {
SHARE_TYPE_REMOTE_GROUP: 9,
SHARE_TYPE_ROOM: 10,
SHARE_TYPE_DECK: 12,
SHARE_TYPE_SCIENCEMESH: 15,
},
})
2 changes: 2 additions & 0 deletions apps/files_sharing/src/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ import { getCapabilities } from '@nextcloud/capabilities'
hasShares = true
} else if (shareType === ShareTypes.SHARE_TYPE_DECK) {
hasShares = true
} else if (shareType === ShareTypes.SHARE_TYPE_SCIENCEMESH) {
hasShares = true
}
})
OCA.Sharing.Util._updateFileActionIcon($tr, hasShares, hasLink)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ public function testDeleteShareShareNotFound() {
$this->expectExceptionMessage('Wrong share ID, share does not exist');

$this->shareManager
->expects($this->exactly(6))
->expects($this->exactly(7))
->method('getShareById')
->willReturnCallback(function ($id) {
if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42' || $id === 'deck:42') {
if ($id === 'ocinternal:42' || $id === 'ocRoomShare:42' || $id === 'ocFederatedSharing:42' || $id === 'ocCircleShare:42' || $id === 'ocMailShare:42' || $id === 'deck:42' || $id === 'sciencemesh:42') {
throw new \OCP\Share\Exceptions\ShareNotFound();
} else {
throw new \Exception();
Expand Down
Loading

0 comments on commit 1a9037d

Please sign in to comment.