Skip to content

Commit 6850683

Browse files
committed
refactor(external-share): Cleanup OCA\FIles_Sharing\External\Manager
- Port away from Files::buildNotExistingFileName - Use IUser and IGroup instead of plain string Signed-off-by: Carl Schwan <[email protected]>
1 parent 9fc6442 commit 6850683

File tree

4 files changed

+241
-212
lines changed

4 files changed

+241
-212
lines changed

apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use NCU\Federation\ISignedCloudFederationProvider;
1010
use OC\AppFramework\Http;
1111
use OC\Files\Filesystem;
12+
use OC\Files\SetupManager;
1213
use OCA\FederatedFileSharing\AddressHandler;
1314
use OCA\FederatedFileSharing\FederatedShareProvider;
1415
use OCA\Federation\TrustedServers;
@@ -34,6 +35,7 @@
3435
use OCP\IDBConnection;
3536
use OCP\IGroupManager;
3637
use OCP\IURLGenerator;
38+
use OCP\IUser;
3739
use OCP\IUserManager;
3840
use OCP\Notification\IManager as INotificationManager;
3941
use OCP\Server;
@@ -68,6 +70,7 @@ public function __construct(
6870
private LoggerInterface $logger,
6971
private IFilenameValidator $filenameValidator,
7072
private readonly IProviderFactory $shareProviderFactory,
73+
private readonly SetupManager $setupManager,
7174
) {
7275
}
7376

@@ -128,6 +131,8 @@ public function shareReceived(ICloudFederationShare $share) {
128131
throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST);
129132
}
130133

134+
$userOrGroup = null;
135+
131136
// FIXME this should be a method in the user management instead
132137
if ($shareType === IShare::TYPE_USER) {
133138
$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
@@ -138,19 +143,23 @@ public function shareReceived(ICloudFederationShare $share) {
138143
);
139144
$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
140145

141-
if (!$this->userManager->userExists($shareWith)) {
146+
$userOrGroup = $this->userManager->get($shareWith);
147+
if ($userOrGroup === null) {
142148
throw new ProviderCouldNotAddShareException('User does not exists', '', Http::STATUS_BAD_REQUEST);
143149
}
144150

145-
\OC_Util::setupFS($shareWith);
151+
$this->setupManager->setupForUser($userOrGroup);
146152
}
147153

148-
if ($shareType === IShare::TYPE_GROUP && !$this->groupManager->groupExists($shareWith)) {
149-
throw new ProviderCouldNotAddShareException('Group does not exists', '', Http::STATUS_BAD_REQUEST);
154+
if ($shareType === IShare::TYPE_GROUP) {
155+
$userOrGroup = $this->groupManager->get($shareWith);
156+
if ($userOrGroup === null) {
157+
throw new ProviderCouldNotAddShareException('Group does not exists', '', Http::STATUS_BAD_REQUEST);
158+
}
150159
}
151160

152161
try {
153-
$this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $shareWith, $remoteId);
162+
$this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $userOrGroup, $remoteId);
154163
$shareId = Server::get(IDBConnection::class)->lastInsertId('*PREFIX*share_external');
155164

156165
// get DisplayName about the owner of the share
@@ -179,7 +188,8 @@ public function shareReceived(ICloudFederationShare $share) {
179188

180189
// If auto-accept is enabled, accept the share
181190
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
182-
$this->externalShareManager->acceptShare($shareId, $shareWith);
191+
/** @var IUser $userOrGroup */
192+
$this->externalShareManager->acceptShare($shareId, $userOrGroup);
183193
}
184194
} else {
185195
$groupMembers = $this->groupManager->get($shareWith)->getUsers();
@@ -195,7 +205,7 @@ public function shareReceived(ICloudFederationShare $share) {
195205

196206
// If auto-accept is enabled, accept the share
197207
if ($this->federatedShareProvider->isFederatedTrustedShareAutoAccept() && $trustedServers?->isTrustedServer($remote) === true) {
198-
$this->externalShareManager->acceptShare($shareId, $user->getUID());
208+
$this->externalShareManager->acceptShare($shareId, $user);
199209
}
200210
}
201211
}

0 commit comments

Comments
 (0)