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 new share type for federated groups #34132

Closed
Closed
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
11 changes: 9 additions & 2 deletions apps/cloud_federation_api/lib/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,15 @@ public function __construct(ICloudFederationProviderManager $cloudFederationProv
*/
public function getSupportedShareTypes($resourceType) {
try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
return $provider->getSupportedShareTypes();
$supportedShareTypes = [];
$cloudFederationProviders = $this->cloudFederationProviderManager->getAllCloudFederationProviders();
foreach ($cloudFederationProviders as $providerWrapper) {
if ($providerWrapper['resourceType'] === $resourceType) {
$providerSupportedShareTypes = $providerWrapper['provider']->getSupportedShareTypes();
$supportedShareTypes = array_merge($supportedShareTypes, $providerSupportedShareTypes);
}
}
return array_unique($supportedShareTypes);
} catch (\Exception $e) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Bjoern Schiessle <bjoern@schiessle.org>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
*
* @license GNU AGPL version 3 or any later version
*
Expand Down Expand Up @@ -177,6 +178,10 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
}
}

if ($shareType === 'federation') {
// Allow creation of pending shares by federation provider
}

// if no explicit display name is given, we use the uid as display name
$ownerDisplayName = $ownerDisplayName === null ? $owner : $ownerDisplayName;
$sharedByDisplayName = $sharedByDisplayName === null ? $sharedBy : $sharedByDisplayName;
Expand All @@ -188,7 +193,7 @@ public function addShare($shareWith, $name, $description, $providerId, $owner, $
}

try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType, $shareType);
$share = $this->factory->getCloudFederationShare($shareWith, $name, $description, $providerId, $owner, $ownerDisplayName, $sharedBy, $sharedByDisplayName, '', $shareType, $resourceType);
$share->setProtocol($protocol);
$provider->shareReceived($share);
Expand Down Expand Up @@ -249,7 +254,7 @@ public function receiveNotification($notificationType, $resourceType, $providerI
}

try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType, $notification['shareType']);
$result = $provider->notificationReceived($notificationType, $providerId, $notification);
} catch (ProviderDoesNotExistsException $e) {
return new JSONResponse(
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
'OCA\\Files_Sharing\\Migration\\Version22000Date20210216084241' => $baseDir . '/../lib/Migration/Version22000Date20210216084241.php',
'OCA\\Files_Sharing\\Migration\\Version24000Date20220208195521' => $baseDir . '/../lib/Migration/Version24000Date20220208195521.php',
'OCA\\Files_Sharing\\Migration\\Version24000Date20220404142216' => $baseDir . '/../lib/Migration/Version24000Date20220404142216.php',
'OCA\\Files_Sharing\\Migration\\Version26000Date20230117143027' => $baseDir . '/../lib/Migration/Version26000Date20230117143027.php',
'OCA\\Files_Sharing\\MountProvider' => $baseDir . '/../lib/MountProvider.php',
'OCA\\Files_Sharing\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
'OCA\\Files_Sharing\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class ComposerStaticInitFiles_Sharing
'OCA\\Files_Sharing\\Migration\\Version22000Date20210216084241' => __DIR__ . '/..' . '/../lib/Migration/Version22000Date20210216084241.php',
'OCA\\Files_Sharing\\Migration\\Version24000Date20220208195521' => __DIR__ . '/..' . '/../lib/Migration/Version24000Date20220208195521.php',
'OCA\\Files_Sharing\\Migration\\Version24000Date20220404142216' => __DIR__ . '/..' . '/../lib/Migration/Version24000Date20220404142216.php',
'OCA\\Files_Sharing\\Migration\\Version26000Date20230117143027' => __DIR__ . '/..' . '/../lib/Migration/Version26000Date20230117143027.php',
'OCA\\Files_Sharing\\MountProvider' => __DIR__ . '/..' . '/../lib/MountProvider.php',
'OCA\\Files_Sharing\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
'OCA\\Files_Sharing\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
Expand Down
60 changes: 51 additions & 9 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @author Richard Steinmetz <richard@steinmetz.cloud>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
* @author Valdnet <47037905+Valdnet@users.noreply.github.com>
* @author Vincent Petry <vincent@nextcloud.com>
* @author waleczny <michal@walczak.xyz>
Expand Down Expand Up @@ -320,7 +321,15 @@ 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_FEDERATED_GROUP) {
$group = $this->groupManager->get($share->getSharedWith());
$result['share_with'] = $share->getSharedWith();
$result['share_with_displayname'] = $group !== null ? $group->getDisplayName() : $share->getSharedWith();
try {
$result = array_merge($result, $this->getFederatedGroupShareHelper()->formatShare($share));

Check failure

Code scanning / Psalm

UndefinedDocblockClass

Docblock-defined class, interface or enum named OCA\VO_Federation\Sharing\ShareAPIHelper does not exist
} catch (QueryException $e) {
}
}


$result['mail_send'] = $share->getMailSend() ? 1 : 0;
Expand Down Expand Up @@ -648,7 +657,7 @@ public function createShare(
throw new OCSNotFoundException($this->l->t('Invalid date, date format must be YYYY-MM-DD'));
}
}
} elseif ($shareType === IShare::TYPE_REMOTE_GROUP) {
} elseif ($shareType === IShare::TYPE_REMOTE_GROUP || $shareType === IShare::TYPE_FEDERATED_GROUP) {
if (!$this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
throw new OCSForbiddenException($this->l->t('Sharing %1$s failed because the back end does not allow shares from type %2$s', [$node->getPath(), $shareType]));
}
Expand Down Expand Up @@ -1609,6 +1618,16 @@ private function getShareById(string $id): IShare {
if (!$this->shareManager->outgoingServer2ServerSharesAllowed()) {
throw new ShareNotFound();
}

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

$share = $this->shareManager->getShareById('ocFederatedSharing:' . $id, $this->currentUser);

return $share;
Expand Down Expand Up @@ -1669,6 +1688,23 @@ private function getDeckShareHelper() {
return $this->serverContainer->get('\OCA\Deck\Sharing\ShareAPIHelper');
}

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

Check failure

Code scanning / Psalm

UndefinedDocblockClass

Docblock-defined class, interface or enum named OCA\VO_Federation\Sharing\ShareAPIHelper does not exist
}

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

Check notice

Code scanning / Psalm

DeprecatedClass

OCP\AppFramework\QueryException is marked deprecated
/**
* @param string $viewer
* @param Node $node
Expand Down Expand Up @@ -1710,6 +1746,12 @@ private function getSharesFromNode(string $viewer, $node, bool $reShares): array
$federatedShares = $this->shareManager->getSharesBy(
$this->currentUser, IShare::TYPE_REMOTE_GROUP, $node, $reShares, -1, 0
);
if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) {
$federatedGroupShares = $this->shareManager->getSharesBy(
$this->currentUser, IShare::TYPE_FEDERATED_GROUP, $node, $reShares, -1, 0
);
$federatedShares = array_merge($federatedShares, $federatedGroupShares);
}
$shares = array_merge($shares, $federatedShares);
}

Expand Down Expand Up @@ -1840,18 +1882,18 @@ private function getAllShares(?Node $path = null, bool $reshares = false) {
$deckShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_DECK, $path, $reshares, -1, 0);

// FEDERATION
$federatedShares = [];
if ($this->shareManager->outgoingServer2ServerSharesAllowed()) {
$federatedShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0);
} else {
$federatedShares = [];
$remoteShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE, $path, $reshares, -1, 0);
$federatedShares = array_merge($federatedShares, $remoteShares);
}
if ($this->shareManager->outgoingServer2ServerGroupSharesAllowed()) {
$federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
} else {
$federatedGroupShares = [];
$remoteGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_REMOTE_GROUP, $path, $reshares, -1, 0);
$federatedGroupShares = $this->shareManager->getSharesBy($this->currentUser, IShare::TYPE_FEDERATED_GROUP, $path, $reshares, -1, 0);
$federatedShares = array_merge($federatedShares, $remoteGroupShares, $federatedGroupShares);
}

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


Expand Down
12 changes: 12 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
*
* @license AGPL-3.0
*
Expand Down Expand Up @@ -82,6 +83,7 @@ class ShareesAPIController extends OCSController {
'groups' => [],
'remotes' => [],
'remote_groups' => [],
'federated_groups' => [],
'emails' => [],
'circles' => [],
'rooms' => [],
Expand All @@ -91,6 +93,7 @@ class ShareesAPIController extends OCSController {
'groups' => [],
'remotes' => [],
'remote_groups' => [],
'federated_groups' => [],
'emails' => [],
'lookup' => [],
'circles' => [],
Expand Down Expand Up @@ -178,6 +181,10 @@ public function search(string $search = '', string $itemType = null, int $page =

if ($this->isRemoteGroupSharingAllowed($itemType)) {
$shareTypes[] = IShare::TYPE_REMOTE_GROUP;

if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) {
$shareTypes[] = IShare::TYPE_FEDERATED_GROUP;
}
}

if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
Expand Down Expand Up @@ -284,6 +291,7 @@ private function sortShareesByFrequency(array $sharees): array {
IShare::TYPE_GROUP => 'groups',
IShare::TYPE_REMOTE => 'remotes',
IShare::TYPE_REMOTE_GROUP => 'remote_groups',
IShare::TYPE_FEDERATED_GROUP => 'federated_groups',
IShare::TYPE_EMAIL => 'emails',
];

Expand Down Expand Up @@ -356,6 +364,10 @@ public function findRecommended(string $itemType = null, $shareType = null): Dat

if ($this->isRemoteGroupSharingAllowed($itemType)) {
$shareTypes[] = IShare::TYPE_REMOTE_GROUP;

if ($this->shareManager->shareProviderExists(IShare::TYPE_FEDERATED_GROUP)) {
$shareTypes[] = IShare::TYPE_FEDERATED_GROUP;
}
}

if ($this->shareManager->shareProviderExists(IShare::TYPE_EMAIL)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
*
* @author Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\Files_Sharing\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Auto-generated migration step: Please modify to your needs!
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the autocomment and instead add a line explaining what the migration do.

*/
class Version26000Date20230117143027 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

$table = $schema->getTable('share_external');
$changed = false;

$column = $table->getColumn('user');
if ($column->getLength() < 255) {
$column->setLength(255);
$changed = true;
}

if (!$table->hasColumn('remote_share_type')) {
$table->addColumn('remote_share_type', Types::INTEGER, [
'notnull' => false,
'length' => 4,
]);
$changed = true;
}

if ($changed) {
return $schema;
}

return null;
}
}
2 changes: 2 additions & 0 deletions apps/files_sharing/src/components/SharingEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ export default {
title += ` (${t('files_sharing', 'remote group')})`
} else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_GUEST) {
title += ` (${t('files_sharing', 'guest')})`
} else if (this.share.type === this.SHARE_TYPES.SHARE_TYPE_FEDERATED_GROUP) {
title += ` (${t('files_sharing', 'federated group')})`
}
return title
},
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_FEDERATED_GROUP,
]

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_FEDERATED_GROUP:
return {
icon: 'icon-organization',
iconTitle: t('files_sharing', 'Virtual organization'),
}
default:
return {}
}
Expand Down
5 changes: 4 additions & 1 deletion apps/files_sharing/src/mixins/ShareTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import { Type as ShareTypes } from '@nextcloud/sharing'
export default {
data() {
return {
SHARE_TYPES: ShareTypes,
SHARE_TYPES: {
...ShareTypes,
SHARE_TYPE_FEDERATED_GROUP: 14
}
smesterheide marked this conversation as resolved.
Show resolved Hide resolved
}
},
}
16 changes: 16 additions & 0 deletions core/img/actions/organization.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/src/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const icons = {
'menu': path.join(__dirname, '../img', 'actions', 'menu.svg'),
'more': path.join(__dirname, '../img', 'actions', 'more.svg'),
'music': path.join(__dirname, '../img', 'places', 'music.svg'),
'organization': path.join(__dirname, '../img', 'actions', 'organization.svg'),
'password': path.join(__dirname, '../img', 'actions', 'password.svg'),
'pause': path.join(__dirname, '../img', 'actions', 'pause.svg'),
'phone': path.join(__dirname, '../img', 'clients', 'phone.svg'),
Expand Down
Loading