Skip to content

Commit

Permalink
Add Sciencemesh share type where Deck share type exists
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 Jan 18, 2023
1 parent 7375884 commit 29fe154
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 6 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
11 changes: 10 additions & 1 deletion 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
54 changes: 50 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 room 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 @@ -1684,7 +1725,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 +1879,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 +1897,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
5 changes: 5 additions & 0 deletions apps/files_sharing/tests/MountProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ public function testExcludeShares() {
['user1', IShare::TYPE_CIRCLE, null, -1],
['user1', IShare::TYPE_ROOM, null, -1],
['user1', IShare::TYPE_DECK, null, -1],
['user1', IShare::TYPE_SCIENCEMESH, null, -1],
)->willReturnOnConsecutiveCalls(
$userShares,
$groupShares,
$circleShares,
$roomShares,
$deckShares,
$sciencemeshShares
);
$this->shareManager->expects($this->any())
->method('newShare')
Expand Down Expand Up @@ -386,6 +388,7 @@ public function testMergeShares($userShares, $groupShares, $expectedShares, $mov
$circleShares = [];
$roomShares = [];
$deckShares = [];
$sciencemeshShares = [];
$this->shareManager->expects($this->exactly(5))
->method('getSharedWith')
->withConsecutive(
Expand All @@ -394,12 +397,14 @@ public function testMergeShares($userShares, $groupShares, $expectedShares, $mov
['user1', IShare::TYPE_CIRCLE, null, -1],
['user1', IShare::TYPE_ROOM, null, -1],
['user1', IShare::TYPE_DECK, null, -1],
['user1', IShare::TYPE_SCIENCEMESH, null, -1],
)->willReturnOnConsecutiveCalls(
$userShares,
$groupShares,
$circleShares,
$roomShares,
$deckShares,
$sciencemeshShares
);
$this->shareManager->expects($this->any())
->method('newShare')
Expand Down
1 change: 1 addition & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ protected function generalCreateChecks(IShare $share) {
}
} elseif ($share->getShareType() === IShare::TYPE_ROOM) {
} elseif ($share->getShareType() === IShare::TYPE_DECK) {
} elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
} else {
// We cannot handle other types yet
throw new \InvalidArgumentException('unknown share type');
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ public function getProviderForType($shareType) {
$provider = $this->getRoomShareProvider();
} elseif ($shareType === IShare::TYPE_DECK) {
$provider = $this->getProvider('deck');
} elseif ($shareType === IShare::TYPE_SCIENCEMESH) {
$provider = $this->getProvider('sciencemesh');
}


Expand Down
5 changes: 5 additions & 0 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ interface IShare {
*/
public const TYPE_DECK_USER = 13;

/**
* @since 26.0.0
*/
public const TYPE_SCIENCEMESH = 15;

/**
* @since 18.0.0
*/
Expand Down

0 comments on commit 29fe154

Please sign in to comment.