Skip to content

Commit be27a8b

Browse files
committed
Add share provider for federated groups
Signed-off-by: Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
1 parent 57f7b17 commit be27a8b

27 files changed

+4439
-2
lines changed

appinfo/info.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ VO Federation enhances existing federation features by allowing Community AAIs t
2424
<personal>OCA\VO_Federation\Settings\Personal</personal>
2525
<personal-section>OCA\VO_Federation\Settings\PersonalSection</personal-section>
2626
</settings>
27+
<collaboration>
28+
<plugins>
29+
<plugin type="collaborator-search" share-type="SHARE_TYPE_FEDERATED_GROUP">OCA\VO_Federation\Collaboration\FederatedGroupPlugin</plugin>
30+
</plugins>
31+
</collaboration>
32+
<background-jobs>
33+
<job>OCA\VO_Federation\BackgroundJob\OCMNotificationJob</job>
34+
</background-jobs>
2735
</info>

js/vo_federation-adminSettings.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/vo_federation-adminSettings.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/vo_federation-filesSharing.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*!
2+
* Determine if an object is a Buffer
3+
*
4+
* @author Feross Aboukhadijeh <https://feross.org>
5+
* @license MIT
6+
*/
7+
8+
/*!
9+
* The buffer module from node.js, for the browser.
10+
*
11+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
12+
* @license MIT
13+
*/
14+
15+
/*!
16+
* The buffer module from node.js, for the browser.
17+
*
18+
* @author Feross Aboukhadijeh <https://feross.org>
19+
* @license MIT
20+
*/
21+
22+
/*!
23+
* Toastify js 1.12.0
24+
* https://github.com/apvarun/toastify-js
25+
* @license MIT licensed
26+
*
27+
* Copyright (C) 2018 Varun A P
28+
*/
29+
30+
/*!
31+
* Vue.js v2.7.14
32+
* (c) 2014-2022 Evan You
33+
* Released under the MIT License.
34+
*/
35+
36+
/*!
37+
* escape-html
38+
* Copyright(c) 2012-2013 TJ Holowaychuk
39+
* Copyright(c) 2015 Andreas Lubbe
40+
* Copyright(c) 2015 Tiancheng "Timothy" Gu
41+
* MIT Licensed
42+
*/
43+
44+
/*!
45+
* focus-trap 7.3.1
46+
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
47+
*/
48+
49+
/*!
50+
* tabbable 6.1.1
51+
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
52+
*/
53+
54+
/*! @license DOMPurify 2.4.4 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.4/LICENSE */
55+
56+
/*! For license information please see NcHighlight.js.LICENSE.txt */
57+
58+
/*! For license information please see index.module.js.LICENSE.txt */
59+
60+
/*! Hammer.JS - v2.0.7 - 2016-04-22
61+
* http://hammerjs.github.io/
62+
*
63+
* Copyright (c) 2016 Jorik Tangelder;
64+
* Licensed under the MIT license */
65+
66+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
67+
68+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
69+
70+
/**
71+
* @copyright Copyright (c) 2019 Georg Ehrke
72+
*
73+
* @author Georg Ehrke <georg-nextcloud@ehrke.email>
74+
*
75+
* @author Richard Steinmetz <richard@steinmetz.cloud>
76+
*
77+
* @license AGPL-3.0-or-later
78+
*
79+
* This program is free software: you can redistribute it and/or modify
80+
* it under the terms of the GNU Affero General Public License as
81+
* published by the Free Software Foundation, either version 3 of the
82+
* License, or (at your option) any later version.
83+
*
84+
* This program is distributed in the hope that it will be useful,
85+
* but WITHOUT ANY WARRANTY without even the implied warranty of
86+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87+
* GNU Affero General Public License for more details.
88+
*
89+
* You should have received a copy of the GNU Affero General Public License
90+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
91+
*
92+
*/
93+
94+
/**
95+
* @copyright Copyright (c) 2019 Georg Ehrke
96+
*
97+
* @author Georg Ehrke <georg-nextcloud@ehrke.email>
98+
*
99+
* @license AGPL-3.0-or-later
100+
*
101+
* This program is free software: you can redistribute it and/or modify
102+
* it under the terms of the GNU Affero General Public License as
103+
* published by the Free Software Foundation, either version 3 of the
104+
* License, or (at your option) any later version.
105+
*
106+
* This program is distributed in the hope that it will be useful,
107+
* but WITHOUT ANY WARRANTY without even the implied warranty of
108+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
109+
* GNU Affero General Public License for more details.
110+
*
111+
* You should have received a copy of the GNU Affero General Public License
112+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
113+
*
114+
*/
115+
116+
/**
117+
* @copyright Copyright (c) 2021 Christoph Wurst
118+
*
119+
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
120+
*
121+
* @license AGPL-3.0-or-later
122+
*
123+
* This program is free software: you can redistribute it and/or modify
124+
* it under the terms of the GNU Affero General Public License as
125+
* published by the Free Software Foundation, either version 3 of the
126+
* License, or (at your option) any later version.
127+
*
128+
* This program is distributed in the hope that it will be useful,
129+
* but WITHOUT ANY WARRANTY without even the implied warranty of
130+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131+
* GNU Affero General Public License for more details.
132+
*
133+
* You should have received a copy of the GNU Affero General Public License
134+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
135+
*
136+
*/
137+
138+
/**
139+
* @copyright Copyright (c) 2023, Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
140+
*
141+
* @author Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
142+
*
143+
* @license AGPL-3.0-or-later
144+
*
145+
* This program is free software: you can redistribute it and/or modify
146+
* it under the terms of the GNU Affero General Public License as
147+
* published by the Free Software Foundation, either version 3 of the
148+
* License, or (at your option) any later version.
149+
*
150+
* This program is distributed in the hope that it will be useful,
151+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
152+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153+
* GNU Affero General Public License for more details.
154+
*
155+
* You should have received a copy of the GNU Affero General Public License
156+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
157+
*
158+
*/

js/vo_federation-filesSharing.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/AddressHandler.php

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016, ownCloud, Inc.
4+
*
5+
* @author Bjoern Schiessle <bjoern@schiessle.org>
6+
* @author Björn Schießle <bjoern@schiessle.org>
7+
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
8+
* @author Morris Jobke <hey@morrisjobke.de>
9+
* @author Robin Appelman <robin@icewind.nl>
10+
* @author Sandro Mesterheide <sandro.mesterheide@extern.publicplan.de>
11+
*
12+
* @license AGPL-3.0
13+
*
14+
* This code is free software: you can redistribute it and/or modify
15+
* it under the terms of the GNU Affero General Public License, version 3,
16+
* as published by the Free Software Foundation.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU Affero General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Affero General Public License, version 3,
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>
25+
*
26+
*/
27+
28+
namespace OCA\VO_Federation;
29+
30+
use OCA\VO_Federation\Backend\GroupBackend;
31+
use OCA\VO_Federation\Service\ProviderService;
32+
use OCP\Federation\ICloudIdManager;
33+
use OCP\HintException;
34+
use OCP\IGroupManager;
35+
use OCP\IL10N;
36+
use OCP\IURLGenerator;
37+
38+
/**
39+
* Class AddressHandler - parse, modify and construct federated sharing addresses
40+
*
41+
* @package OCA\FederatedFileSharing
42+
*/
43+
class AddressHandler {
44+
/** @var IL10N */
45+
private $l;
46+
47+
/** @var IURLGenerator */
48+
private $urlGenerator;
49+
50+
/** @var ICloudIdManager */
51+
private $cloudIdManager;
52+
53+
/** @var GroupBackend */
54+
private $voGroupBackend;
55+
56+
/** @var ProviderService */
57+
private $providerService;
58+
59+
/** @var IGroupManager */
60+
private $groupManager;
61+
62+
/**
63+
* AddressHandler constructor.
64+
*
65+
* @param IURLGenerator $urlGenerator
66+
* @param IL10N $il10n
67+
* @param ICloudIdManager $cloudIdManager
68+
*/
69+
public function __construct(
70+
IURLGenerator $urlGenerator,
71+
IL10N $il10n,
72+
ICloudIdManager $cloudIdManager,
73+
GroupBackend $voGroupBackend,
74+
ProviderService $providerService,
75+
IGroupManager $groupManager
76+
) {
77+
$this->l = $il10n;
78+
$this->urlGenerator = $urlGenerator;
79+
$this->cloudIdManager = $cloudIdManager;
80+
$this->voGroupBackend = $voGroupBackend;
81+
$this->providerService = $providerService;
82+
$this->groupManager = $groupManager;
83+
}
84+
85+
/**
86+
* split user and remote from federated cloud id
87+
*
88+
* @param string $address federated share address
89+
* @return array [user, remoteURL]
90+
* @throws HintException
91+
*/
92+
public function splitUserRemote($address) {
93+
try {
94+
$cloudId = $this->cloudIdManager->resolveCloudId($address);
95+
return [$cloudId->getUser(), $cloudId->getRemote()];
96+
} catch (\InvalidArgumentException $e) {
97+
$hint = $this->l->t('Invalid Federated Cloud ID');
98+
throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e);
99+
}
100+
}
101+
102+
/**
103+
* generate remote URL part of federated ID
104+
*
105+
* @return string url of the current server
106+
*/
107+
public function generateRemoteURL() {
108+
return $this->urlGenerator->getAbsoluteURL('/');
109+
}
110+
111+
/**
112+
* check if two federated cloud IDs refer to the same user
113+
*
114+
* @param string $user1
115+
* @param string $server1
116+
* @param string $user2
117+
* @param string $server2
118+
* @return bool true if both users and servers are the same
119+
*/
120+
public function compareAddresses($user1, $server1, $user2, $server2) {
121+
$normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1));
122+
$normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2));
123+
124+
if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) {
125+
// FIXME this should be a method in the user management instead
126+
\OCP\Util::emitHook(
127+
'\OCA\Files_Sharing\API\Server2Server',
128+
'preLoginNameUsedAsUserName',
129+
['uid' => &$user1]
130+
);
131+
\OCP\Util::emitHook(
132+
'\OCA\Files_Sharing\API\Server2Server',
133+
'preLoginNameUsedAsUserName',
134+
['uid' => &$user2]
135+
);
136+
137+
if ($user1 === $user2) {
138+
return true;
139+
}
140+
}
141+
142+
return false;
143+
}
144+
145+
/**
146+
* remove protocol from URL
147+
*
148+
* @param string $url
149+
* @return string
150+
*/
151+
public function removeProtocolFromUrl($url) {
152+
if (strpos($url, 'https://') === 0) {
153+
return substr($url, strlen('https://'));
154+
} elseif (strpos($url, 'http://') === 0) {
155+
return substr($url, strlen('http://'));
156+
}
157+
158+
return $url;
159+
}
160+
161+
/**
162+
* check if the url contain the protocol (http or https)
163+
*
164+
* @param string $url
165+
* @return bool
166+
*/
167+
public function urlContainProtocol($url) {
168+
if (strpos($url, 'https://') === 0 ||
169+
strpos($url, 'http://') === 0) {
170+
return true;
171+
}
172+
173+
return false;
174+
}
175+
176+
public function getShareWithDescription($gid) : string {
177+
$providerId = $this->voGroupBackend->getProviderId($gid);
178+
$provider = $this->providerService->getProvider($providerId);
179+
return $provider->getIdentifier();
180+
}
181+
182+
public function getGroupDisplayName($gid) {
183+
$group = $this->groupManager->get($gid);
184+
if ($group) {
185+
return $group->getDisplayName();
186+
}
187+
return $gid;
188+
}
189+
}

0 commit comments

Comments
 (0)