Skip to content

Commit 127af09

Browse files
authored
Merge pull request #37139 from nextcloud/share-type-sciencemesh
2 parents 80e12cf + 517b2eb commit 127af09

24 files changed

Lines changed: 172 additions & 21 deletions

apps/admin_audit/lib/Actions/Sharing.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ public function shared(array $params): void {
160160
'id',
161161
]
162162
);
163+
} elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
164+
$this->log(
165+
'The %s "%s" with ID "%s" has been shared to the sciencemesh user "%s" with permissions "%s" (Share ID: %s)',
166+
$params,
167+
[
168+
'itemType',
169+
'path',
170+
'itemSource',
171+
'shareWith',
172+
'permissions',
173+
'id',
174+
]
175+
);
163176
}
164177
}
165178

@@ -276,6 +289,18 @@ public function unshare(array $params): void {
276289
'id',
277290
]
278291
);
292+
} elseif ($params['shareType'] === IShare::TYPE_SCIENCEMESH) {
293+
$this->log(
294+
'The %s "%s" with ID "%s" has been unshared from the sciencemesh user "%s" (Share ID: %s)',
295+
$params,
296+
[
297+
'itemType',
298+
'fileTarget',
299+
'itemSource',
300+
'shareWith',
301+
'id',
302+
]
303+
);
279304
}
280305
}
281306

apps/dav/lib/Connector/Sabre/SharesPlugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private function getShare(Node $node): array {
110110
IShare::TYPE_ROOM,
111111
IShare::TYPE_CIRCLE,
112112
IShare::TYPE_DECK,
113+
IShare::TYPE_SCIENCEMESH,
113114
];
114115
foreach ($requestedShareTypes as $requestedShareType) {
115116
$shares = $this->shareManager->getSharesBy(

apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ public function sharesGetPropertiesDataProvider() {
278278
[[IShare::TYPE_REMOTE]],
279279
[[IShare::TYPE_ROOM]],
280280
[[IShare::TYPE_DECK]],
281+
[[IShare::TYPE_SCIENCEMESH]],
281282
[[IShare::TYPE_USER, IShare::TYPE_GROUP]],
282283
[[IShare::TYPE_USER, IShare::TYPE_GROUP, IShare::TYPE_LINK]],
283284
[[IShare::TYPE_USER, IShare::TYPE_LINK]],

apps/files/lib/Controller/ApiController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ private function getShareTypesForNodes(array $nodes): array {
209209
IShare::TYPE_EMAIL,
210210
IShare::TYPE_ROOM,
211211
IShare::TYPE_DECK,
212+
IShare::TYPE_SCIENCEMESH,
212213
];
213214
$shareTypes = [];
214215

apps/files/lib/Service/OwnershipTransferService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private function collectUsersShares(string $sourceUid,
286286
$shares = [];
287287
$progress = new ProgressBar($output);
288288

289-
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) {
289+
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) {
290290
$offset = 0;
291291
while (true) {
292292
$sharePage = $this->shareManager->getSharesBy($sourceUid, $shareType, null, true, 50, $offset);

apps/files_sharing/lib/Controller/DeletedShareAPIController.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ private function formatShare(IShare $share): array {
159159
$result = array_merge($result, $this->getDeckShareHelper()->formatShare($share));
160160
} catch (QueryException $e) {
161161
}
162+
} elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
163+
$result['share_with'] = $share->getSharedWith();
164+
$result['share_with_displayname'] = '';
165+
166+
try {
167+
$result = array_merge($result, $this->getSciencemeshShareHelper()->formatShare($share));
168+
} catch (QueryException $e) {
169+
}
162170
}
163171

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

175-
$shares = array_merge($groupShares, $roomShares, $deckShares);
184+
$shares = array_merge($groupShares, $roomShares, $deckShares, $sciencemeshShares);
176185

177186
$shares = array_map(function (IShare $share) {
178187
return $this->formatShare($share);
@@ -224,7 +233,7 @@ private function getRoomShareHelper() {
224233
}
225234

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

240249
return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper');
241250
}
251+
252+
/**
253+
* Returns the helper of DeletedShareAPIHelper for sciencemesh shares.
254+
*
255+
* If the sciencemesh application is not enabled or the helper is not available
256+
* a QueryException is thrown instead.
257+
*
258+
* @return \OCA\Deck\Sharing\ShareAPIHelper
259+
* @throws QueryException
260+
*/
261+
private function getSciencemeshShareHelper() {
262+
if (!$this->appManager->isEnabledForUser('sciencemesh')) {
263+
throw new QueryException();
264+
}
265+
266+
return $this->serverContainer->get('\OCA\ScienceMesh\Sharing\ShareAPIHelper');
267+
}
242268
}

apps/files_sharing/lib/Controller/ShareAPIController.php

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,14 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array
320320
$result = array_merge($result, $this->getDeckShareHelper()->formatShare($share));
321321
} catch (QueryException $e) {
322322
}
323+
} elseif ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
324+
$result['share_with'] = $share->getSharedWith();
325+
$result['share_with_displayname'] = '';
326+
327+
try {
328+
$result = array_merge($result, $this->getSciencemeshShareHelper()->formatShare($share));
329+
} catch (QueryException $e) {
330+
}
323331
}
324332

325333

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

734-
$shares = array_merge($userShares, $groupShares, $circleShares, $roomShares, $deckShares);
749+
$shares = array_merge($userShares, $groupShares, $circleShares, $roomShares, $deckShares, $sciencemeshShares);
735750

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

1432+
if ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
1433+
try {
1434+
return $this->getSciencemeshShareHelper()->canAccessShare($share, $this->currentUser);
1435+
} catch (QueryException $e) {
1436+
return false;
1437+
}
1438+
}
1439+
14171440
return false;
14181441
}
14191442

@@ -1490,7 +1513,8 @@ protected function canDeleteShare(\OCP\Share\IShare $share): bool {
14901513
protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool {
14911514
if ($share->getShareType() !== IShare::TYPE_GROUP &&
14921515
$share->getShareType() !== IShare::TYPE_ROOM &&
1493-
$share->getShareType() !== IShare::TYPE_DECK
1516+
$share->getShareType() !== IShare::TYPE_DECK &&
1517+
$share->getShareType() !== IShare::TYPE_SCIENCEMESH
14941518
) {
14951519
return false;
14961520
}
@@ -1527,6 +1551,14 @@ protected function canDeleteShareFromSelf(\OCP\Share\IShare $share): bool {
15271551
}
15281552
}
15291553

1554+
if ($share->getShareType() === IShare::TYPE_SCIENCEMESH) {
1555+
try {
1556+
return $this->getSciencemeshShareHelper()->canAccessShare($share, $this->currentUser);
1557+
} catch (QueryException $e) {
1558+
return false;
1559+
}
1560+
}
1561+
15301562
return false;
15311563
}
15321564

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

1641+
try {
1642+
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
1643+
$share = $this->shareManager->getShareById('sciencemesh:' . $id, $this->currentUser);
1644+
return $share;
1645+
}
1646+
} catch (ShareNotFound $e) {
1647+
// Do nothing, just try the other share type
1648+
}
1649+
16091650
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
16101651
throw new ShareNotFound();
16111652
}
@@ -1669,6 +1710,23 @@ private function getDeckShareHelper() {
16691710
return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper');
16701711
}
16711712

1713+
/**
1714+
* Returns the helper of ShareAPIHelper for sciencemesh shares.
1715+
*
1716+
* If the sciencemesh application is not enabled or the helper is not available
1717+
* a QueryException is thrown instead.
1718+
*
1719+
* @return \OCA\Deck\Sharing\ShareAPIHelper
1720+
* @throws QueryException
1721+
*/
1722+
private function getSciencemeshShareHelper() {
1723+
if (!$this->appManager->isEnabledForUser('sciencemesh')) {
1724+
throw new QueryException();
1725+
}
1726+
1727+
return $this->serverContainer->get('\OCA\ScienceMesh\Sharing\ShareAPIHelper');
1728+
}
1729+
16721730
/**
16731731
* @param string $viewer
16741732
* @param Node $node
@@ -1684,7 +1742,8 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
16841742
IShare::TYPE_EMAIL,
16851743
IShare::TYPE_CIRCLE,
16861744
IShare::TYPE_ROOM,
1687-
IShare::TYPE_DECK
1745+
IShare::TYPE_DECK,
1746+
IShare::TYPE_SCIENCEMESH
16881747
];
16891748

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

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

1902+
// SCIENCEMESH SHARES
1903+
$sciencemeshShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_SCIENCEMESH, $path, $reshares, -1, 0);
1904+
18421905
// FEDERATION
18431906
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
18441907
$federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0);
@@ -1851,7 +1914,7 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
18511914
$federatedGroupShares = [];
18521915
}
18531916

1854-
return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $federatedShares, $federatedGroupShares);
1917+
return array_merge($userShares, $groupShares, $linkShares, $mailShares, $circleShares, $roomShares, $deckShares, $sciencemeshShares, $federatedShares, $federatedGroupShares);
18551918
}
18561919

18571920

apps/files_sharing/lib/Controller/ShareesAPIController.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ public function search(string $search = '', string $itemType = null, int $page =
186186
if ($this->shareManager->shareProviderExists(IShare::TYPE_ROOM)) {
187187
$shareTypes[] = IShare::TYPE_ROOM;
188188
}
189+
190+
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
191+
$shareTypes[] = IShare::TYPE_SCIENCEMESH;
192+
}
189193
} else {
190194
if ($this->shareManager->allowGroupSharing()) {
191195
$shareTypes[] = IShare::TYPE_GROUP;
@@ -198,6 +202,10 @@ public function search(string $search = '', string $itemType = null, int $page =
198202
$shareTypes[] = IShare::TYPE_CIRCLE;
199203
}
200204

205+
if ($this->shareManager->shareProviderExists(IShare::TYPE_SCIENCEMESH)) {
206+
$shareTypes[] = IShare::TYPE_SCIENCEMESH;
207+
}
208+
201209
if ($shareType !== null && is_array($shareType)) {
202210
$shareTypes = array_intersect($shareTypes, $shareType);
203211
} elseif (is_numeric($shareType)) {

apps/files_sharing/lib/MountProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
9797
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_CIRCLE, null, -1));
9898
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_ROOM, null, -1));
9999
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_DECK, null, -1));
100+
$shares = array_merge($shares, $this->shareManager->getSharedWith($user->getUID(), IShare::TYPE_SCIENCEMESH, null, -1));
100101

101102

102103
// filter out excluded shares and group shares that includes self

apps/files_sharing/src/components/SharingInput.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export default {
194194
this.SHARE_TYPES.SHARE_TYPE_ROOM,
195195
this.SHARE_TYPES.SHARE_TYPE_GUEST,
196196
this.SHARE_TYPES.SHARE_TYPE_DECK,
197+
this.SHARE_TYPES.SHARE_TYPE_SCIENCEMESH,
197198
]
198199
199200
if (OC.getCapabilities().files_sharing.public.enabled === true) {
@@ -420,6 +421,11 @@ export default {
420421
icon: 'icon-deck',
421422
iconTitle: t('files_sharing', 'Deck board'),
422423
}
424+
case this.SHARE_TYPES.SHARE_TYPE_SCIENCEMESH:
425+
return {
426+
icon: 'icon-sciencemesh',
427+
iconTitle: t('files_sharing', 'Science Mesh'),
428+
}
423429
default:
424430
return {}
425431
}

0 commit comments

Comments
 (0)