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

gs.federation.auto_accept_shares #41743

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 12 additions & 2 deletions apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use OCA\FederatedFileSharing\AddressHandler;
use OCA\FederatedFileSharing\FederatedShareProvider;
use OCA\Files_Sharing\Activity\Providers\RemoteShares;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\Manager as ExternalManager;
use OCP\Activity\IManager as IActivityManager;
use OCP\App\IAppManager;
use OCP\Constants;
Expand Down Expand Up @@ -62,6 +62,8 @@
use Psr\Log\LoggerInterface;

class CloudFederationProviderFiles implements ICloudFederationProvider {
const AUTO_ACCEPT_SHARES = 'gs.federation.auto_accept_shares';

/**
* CloudFederationProvider constructor.
*/
Expand All @@ -80,7 +82,7 @@ public function __construct(
private IDBConnection $connection,
private IGroupManager $groupManager,
private IConfig $config,
private Manager $externalShareManager,
private ExternalManager $externalShareManager,
private LoggerInterface $logger,
) {
}
Expand Down Expand Up @@ -166,6 +168,10 @@ public function shareReceived(ICloudFederationShare $share) {
try {
$this->externalShareManager->addShare($remote, $token, '', $name, $owner, $shareType, false, $shareWith, $remoteId);
$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
if ($this->config->getSystemValueBool(self::AUTO_ACCEPT_SHARES)) {
$this->externalShareManager->initUserId($shareWith);
$this->externalShareManager->acceptShare($shareId);
}

// get DisplayName about the owner of the share
$ownerDisplayName = $this->getUserDisplayName($ownerFederatedId);
Expand Down Expand Up @@ -255,6 +261,10 @@ private function mapShareTypeToNextcloud($shareType) {
}

private function notifyAboutNewShare($shareWith, $shareId, $ownerFederatedId, $sharedByFederatedId, $name, $displayName): void {
if ($this->config->getSystemValueBool(self::AUTO_ACCEPT_SHARES)) {
return;
}

$notification = $this->notificationManager->createNotification();
$notification->setApp('files_sharing')
->setUser($shareWith)
Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/lib/External/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ private function updateAccepted(int $shareId, bool $accepted) : void {
$updateResult->closeCursor();
}

public function initUserId(string $userId): void {
$this->uid = $userId;
}

/**
* accept server-to-server share
*
Expand Down
Loading