Skip to content

Commit e346cf6

Browse files
authored
Merge pull request #49973 from nextcloud/feat/auto-accept-trusted-server
2 parents 33b564d + 669e6ca commit e346cf6

44 files changed

Lines changed: 2471 additions & 387 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/federatedfilesharing/lib/Controller/RequestHandlerController.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
#[OpenAPI(scope: OpenAPI::SCOPE_FEDERATION)]
4040
class RequestHandlerController extends OCSController {
4141

42-
/** @var string */
43-
private $shareTable = 'share';
44-
4542
public function __construct(
4643
string $appName,
4744
IRequest $request,

apps/federatedfilesharing/lib/FederatedShareProvider.php

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -909,99 +909,90 @@ public function userDeletedFromGroup($uid, $gid) {
909909
}
910910

911911
/**
912-
* check if users from other Nextcloud instances are allowed to mount public links share by this instance
913-
*
914-
* @return bool
912+
* Check if users from other Nextcloud instances are allowed to mount public links share by this instance
915913
*/
916-
public function isOutgoingServer2serverShareEnabled() {
914+
public function isOutgoingServer2serverShareEnabled(): bool {
917915
if ($this->gsConfig->onlyInternalFederation()) {
918916
return false;
919917
}
920918
$result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_share_enabled', 'yes');
921-
return ($result === 'yes');
919+
return $result === 'yes';
922920
}
923921

924922
/**
925-
* check if users are allowed to mount public links from other Nextclouds
926-
*
927-
* @return bool
923+
* Check if users are allowed to mount public links from other Nextclouds
928924
*/
929-
public function isIncomingServer2serverShareEnabled() {
925+
public function isIncomingServer2serverShareEnabled(): bool {
930926
if ($this->gsConfig->onlyInternalFederation()) {
931927
return false;
932928
}
933929
$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_share_enabled', 'yes');
934-
return ($result === 'yes');
930+
return $result === 'yes';
935931
}
936932

937933

938934
/**
939-
* check if users from other Nextcloud instances are allowed to send federated group shares
940-
*
941-
* @return bool
935+
* Check if users from other Nextcloud instances are allowed to send federated group shares
942936
*/
943-
public function isOutgoingServer2serverGroupShareEnabled() {
937+
public function isOutgoingServer2serverGroupShareEnabled(): bool {
944938
if ($this->gsConfig->onlyInternalFederation()) {
945939
return false;
946940
}
947941
$result = $this->config->getAppValue('files_sharing', 'outgoing_server2server_group_share_enabled', 'no');
948-
return ($result === 'yes');
942+
return $result === 'yes';
949943
}
950944

951945
/**
952-
* check if users are allowed to receive federated group shares
953-
*
954-
* @return bool
946+
* Check if users are allowed to receive federated group shares
955947
*/
956-
public function isIncomingServer2serverGroupShareEnabled() {
948+
public function isIncomingServer2serverGroupShareEnabled(): bool {
957949
if ($this->gsConfig->onlyInternalFederation()) {
958950
return false;
959951
}
960952
$result = $this->config->getAppValue('files_sharing', 'incoming_server2server_group_share_enabled', 'no');
961-
return ($result === 'yes');
953+
return $result === 'yes';
962954
}
963955

964956
/**
965-
* check if federated group sharing is supported, therefore the OCM API need to be enabled
966-
*
967-
* @return bool
957+
* Check if federated group sharing is supported, therefore the OCM API need to be enabled
968958
*/
969-
public function isFederatedGroupSharingSupported() {
959+
public function isFederatedGroupSharingSupported(): bool {
970960
return $this->cloudFederationProviderManager->isReady();
971961
}
972962

973963
/**
974964
* Check if querying sharees on the lookup server is enabled
975-
*
976-
* @return bool
977965
*/
978-
public function isLookupServerQueriesEnabled() {
966+
public function isLookupServerQueriesEnabled(): bool {
979967
// in a global scale setup we should always query the lookup server
980968
if ($this->gsConfig->isGlobalScaleEnabled()) {
981969
return true;
982970
}
983971
$result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'yes');
984-
return ($result === 'yes');
972+
return $result === 'yes';
985973
}
986974

987975

988976
/**
989977
* Check if it is allowed to publish user specific data to the lookup server
990-
*
991-
* @return bool
992978
*/
993-
public function isLookupServerUploadEnabled() {
979+
public function isLookupServerUploadEnabled(): bool {
994980
// in a global scale setup the admin is responsible to keep the lookup server up-to-date
995981
if ($this->gsConfig->isGlobalScaleEnabled()) {
996982
return false;
997983
}
998984
$result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes');
999-
return ($result === 'yes');
985+
return $result === 'yes';
1000986
}
1001987

1002988
/**
1003-
* @inheritdoc
989+
* Check if auto accepting incoming shares from trusted servers is enabled
1004990
*/
991+
public function isFederatedTrustedShareAutoAccept(): bool {
992+
$result = $this->config->getAppValue('files_sharing', 'federatedTrustedShareAutoAccept', 'yes');
993+
return $result === 'yes';
994+
}
995+
1005996
public function getAccessList($nodes, $currentAccess) {
1006997
$ids = [];
1007998
foreach ($nodes as $node) {

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\Files\Filesystem;
1111
use OCA\FederatedFileSharing\AddressHandler;
1212
use OCA\FederatedFileSharing\FederatedShareProvider;
13+
use OCA\Federation\TrustedServers;
1314
use OCA\Files_Sharing\Activity\Providers\RemoteShares;
1415
use OCA\Files_Sharing\External\Manager;
1516
use OCA\GlobalSiteSelector\Service\SlaveService;
@@ -66,6 +67,7 @@ public function __construct(
6667
private LoggerInterface $logger,
6768
private IFilenameValidator $filenameValidator,
6869
private readonly IProviderFactory $shareProviderFactory,
70+
private TrustedServers $trustedServers,
6971
) {
7072
}
7173

@@ -163,6 +165,11 @@ public function shareReceived(ICloudFederationShare $share) {
163165
->setObject('remote_share', $shareId, $name);
164166
\OC::$server->getActivityManager()->publish($event);
165167
$this->notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
168+
169+
// If auto-accept is enabled, accept the share
170+
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) {
171+
$this->externalShareManager->acceptShare($shareId, $shareWith);
172+
}
166173
} else {
167174
$groupMembers = $this->groupManager->get($shareWith)->getUsers();
168175
foreach ($groupMembers as $user) {
@@ -174,8 +181,14 @@ public function shareReceived(ICloudFederationShare $share) {
174181
->setObject('remote_share', $shareId, $name);
175182
\OC::$server->getActivityManager()->publish($event);
176183
$this->notifyAboutNewShare($user->getUID(), $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $ownerDisplayName);
184+
185+
// If auto-accept is enabled, accept the share
186+
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $this->trustedServers->isTrustedServer($remote)) {
187+
$this->externalShareManager->acceptShare($shareId, $user->getUID());
188+
}
177189
}
178190
}
191+
179192
return $shareId;
180193
} catch (\Exception $e) {
181194
$this->logger->error('Server can not add remote share.', [

apps/federatedfilesharing/lib/Settings/Admin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function getForm() {
4040
$this->initialState->provideInitialState('incomingServer2serverGroupShareEnabled', $this->fedShareProvider->isIncomingServer2serverGroupShareEnabled());
4141
$this->initialState->provideInitialState('lookupServerEnabled', $this->fedShareProvider->isLookupServerQueriesEnabled());
4242
$this->initialState->provideInitialState('lookupServerUploadEnabled', $this->fedShareProvider->isLookupServerUploadEnabled());
43+
$this->initialState->provideInitialState('federatedTrustedShareAutoAccept', $this->fedShareProvider->isFederatedTrustedShareAutoAccept());
4344

4445
return new TemplateResponse('federatedfilesharing', 'settings-admin', [], '');
4546
}
@@ -76,6 +77,7 @@ public function getAuthorizedAppConfig(): array {
7677
'incomingServer2serverGroupShareEnabled',
7778
'lookupServerEnabled',
7879
'lookupServerUploadEnabled',
80+
'federatedTrustedShareAutoAccept',
7981
],
8082
];
8183
}

apps/federatedfilesharing/src/components/AdminSettings.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
@update:checked="update('lookupServerUploadEnabled', lookupServerUploadEnabled)">
4444
{{ t('federatedfilesharing', 'Allow people to publish their data to a global and public address book') }}
4545
</NcCheckboxRadioSwitch>
46+
47+
<!-- Trusted server handling -->
48+
<div class="settings-subsection">
49+
<h3 class="settings-subsection__name">
50+
{{ t('federatedfilesharing', 'Trusted federation') }}
51+
</h3>
52+
<NcCheckboxRadioSwitch type="switch"
53+
:checked.sync="federatedTrustedShareAutoAccept"
54+
@update:checked="update('federatedTrustedShareAutoAccept', federatedTrustedShareAutoAccept)">
55+
{{ t('federatedfilesharing', 'Automatically accept shares from trusted federated accounts and groups by default') }}
56+
</NcCheckboxRadioSwitch>
57+
</div>
4658
</NcSettingsSection>
4759
</template>
4860

@@ -74,6 +86,7 @@ export default {
7486
federatedGroupSharingSupported: loadState('federatedfilesharing', 'federatedGroupSharingSupported'),
7587
lookupServerEnabled: loadState('federatedfilesharing', 'lookupServerEnabled'),
7688
lookupServerUploadEnabled: loadState('federatedfilesharing', 'lookupServerUploadEnabled'),
89+
federatedTrustedShareAutoAccept: loadState('federatedfilesharing', 'federatedTrustedShareAutoAccept'),
7790
internalOnly: loadState('federatedfilesharing', 'internalOnly'),
7891
sharingFederatedDocUrl: loadState('federatedfilesharing', 'sharingFederatedDocUrl'),
7992
}
@@ -111,3 +124,18 @@ export default {
111124
},
112125
}
113126
</script>
127+
<style scoped>
128+
.settings-subsection {
129+
margin-top: 20px;
130+
}
131+
132+
.settings-subsection__name {
133+
display: inline-flex;
134+
align-items: center;
135+
justify-content: center;
136+
font-size: 16px;
137+
font-weight: bold;
138+
max-width: 900px;
139+
margin-top: 0;
140+
}
141+
</style>

apps/federatedfilesharing/tests/Settings/AdminTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ public function testGetForm($state): void {
9191
->expects($this->once())
9292
->method('isIncomingServer2serverGroupShareEnabled')
9393
->willReturn($state);
94+
$this->federatedShareProvider
95+
->expects($this->once())
96+
->method('isFederatedTrustedShareAutoAccept')
97+
->willReturn($state);
9498
$this->gsConfig->expects($this->once())->method('onlyInternalFederation')
9599
->willReturn($state);
96100

97-
$this->initialState->expects($this->exactly(9))
101+
$this->initialState->expects($this->exactly(10))
98102
->method('provideInitialState')
99103
->withConsecutive(
100104
['internalOnly', $state],
@@ -106,6 +110,7 @@ public function testGetForm($state): void {
106110
['incomingServer2serverGroupShareEnabled', $state],
107111
['lookupServerEnabled', $state],
108112
['lookupServerUploadEnabled', $state],
113+
['federatedTrustedShareAutoAccept', $state]
109114
);
110115

111116
$expected = new TemplateResponse('federatedfilesharing', 'settings-admin', [], '');

apps/federation/appinfo/routes.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
88
return [
9-
'routes' => [
10-
[
11-
'name' => 'Settings#addServer',
12-
'url' => '/trusted-servers',
13-
'verb' => 'POST'
14-
],
15-
[
16-
'name' => 'Settings#removeServer',
17-
'url' => '/trusted-servers/{id}',
18-
'verb' => 'DELETE'
19-
],
20-
],
219
'ocs' => [
2210
// old endpoints, only used by Nextcloud and ownCloud
2311
[

apps/federation/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
'OCA\\Federation\\DAV\\FedAuth' => $baseDir . '/../lib/DAV/FedAuth.php',
1717
'OCA\\Federation\\DbHandler' => $baseDir . '/../lib/DbHandler.php',
1818
'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => $baseDir . '/../lib/Listener/SabrePluginAuthInitListener.php',
19-
'OCA\\Federation\\Middleware\\AddServerMiddleware' => $baseDir . '/../lib/Middleware/AddServerMiddleware.php',
2019
'OCA\\Federation\\Migration\\Version1010Date20200630191302' => $baseDir . '/../lib/Migration/Version1010Date20200630191302.php',
2120
'OCA\\Federation\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
2221
'OCA\\Federation\\SyncFederationAddressBooks' => $baseDir . '/../lib/SyncFederationAddressBooks.php',

apps/federation/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class ComposerStaticInitFederation
3131
'OCA\\Federation\\DAV\\FedAuth' => __DIR__ . '/..' . '/../lib/DAV/FedAuth.php',
3232
'OCA\\Federation\\DbHandler' => __DIR__ . '/..' . '/../lib/DbHandler.php',
3333
'OCA\\Federation\\Listener\\SabrePluginAuthInitListener' => __DIR__ . '/..' . '/../lib/Listener/SabrePluginAuthInitListener.php',
34-
'OCA\\Federation\\Middleware\\AddServerMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/AddServerMiddleware.php',
3534
'OCA\\Federation\\Migration\\Version1010Date20200630191302' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630191302.php',
3635
'OCA\\Federation\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
3736
'OCA\\Federation\\SyncFederationAddressBooks' => __DIR__ . '/..' . '/../lib/SyncFederationAddressBooks.php',

apps/federation/css/settings-admin.css

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
#listOfTrustedServers li {
1111
padding-bottom: 10px;
12+
display: flex;
13+
align-items: center;
1214
}
1315

1416
.removeTrustedServer {
1517
display: none;
16-
vertical-align:middle;
18+
vertical-align: middle;
1719
padding-inline-start: 10px;
1820
}
1921

@@ -26,20 +28,20 @@
2628
}
2729

2830
#listOfTrustedServers .icon {
29-
cursor: pointer;
3031
display: inline-block;
32+
cursor: pointer;
3133
vertical-align: middle;
3234
margin-inline-start: 10px;
3335
}
3436

35-
#ocFederationAddServer #serverUrl {
36-
width: 270px;
37-
}
38-
3937
.serverUrl-block {
40-
max-width: 310px;
4138
display: flex;
42-
flex-direction: row;
4339
align-items: center;
44-
justify-content: space-between;
40+
flex-direction: row;
41+
justify-content: flex-start;
42+
gap: 8px;
43+
}
44+
45+
.serverUrl-block input {
46+
width: 270px;
4547
}

0 commit comments

Comments
 (0)