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

Kill some of the old sharing code related to share backends #26608

Merged
merged 21 commits into from
Oct 18, 2018
Merged
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
3 changes: 0 additions & 3 deletions apps/files_sharing/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@

\OCA\Files_Sharing\Helper::registerHooks();

\OCP\Share::registerBackend('file', 'OCA\Files_Sharing\ShareBackend\File');
\OCP\Share::registerBackend('folder', 'OCA\Files_Sharing\ShareBackend\Folder', 'file');

$application = new \OCA\Files_Sharing\AppInfo\Application();
$application->registerMountProviders();
$application->registerNotifier();
Expand Down
15 changes: 12 additions & 3 deletions apps/files_sharing/lib/Controller/ShareesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCP\IUserSession;
use OCP\Share;
use OCA\Files_Sharing\SharingBlacklist;
use OCA\FederatedFileSharing\FederatedShareProvider;

class ShareesController extends OCSController {

Expand Down Expand Up @@ -71,6 +72,9 @@ class ShareesController extends OCSController {
/** @var \OCP\Share\IManager */
protected $shareManager;

/** @var FederatedShareProvider */
protected $federatedShareProvider;

/** @var bool */
protected $shareWithGroupOnly = false;

Expand Down Expand Up @@ -132,7 +136,9 @@ public function __construct($appName,
IURLGenerator $urlGenerator,
ILogger $logger,
\OCP\Share\IManager $shareManager,
SharingBlacklist $sharingBlacklist) {
SharingBlacklist $sharingBlacklist,
FederatedShareProvider $federatedShareProvider
) {
parent::__construct($appName, $request);

$this->groupManager = $groupManager;
Expand All @@ -146,6 +152,7 @@ public function __construct($appName,
$this->shareManager = $shareManager;
$this->sharingBlacklist = $sharingBlacklist;
$this->additionalInfoField = $this->config->getAppValue('core', 'user_additional_info_field', '');
$this->federatedShareProvider = $federatedShareProvider;
}

/**
Expand Down Expand Up @@ -579,8 +586,10 @@ public function search($search = '', $itemType = null, $page = 1, $perPage = 200
*/
protected function isRemoteSharingAllowed($itemType) {
try {
$backend = Share::getBackend($itemType);
return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE);
if ($itemType === 'file' || $itemType === 'folder') {
return $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
}
return false;
} catch (\Exception $e) {
return false;
}
Expand Down
53 changes: 42 additions & 11 deletions apps/files_sharing/lib/ExpireSharesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,46 @@
namespace OCA\Files_Sharing;

use OC\BackgroundJob\TimedJob;
use OCP\Share\IManager;
use OCP\IDBConnection;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\ILogger;

/**
* Delete all shares that are expired
*/
class ExpireSharesJob extends TimedJob {

/**
* sets the correct interval for this timed job
* Database connection
*
* @var IDBConnection
*/
private $connection;

/**
* Share manager
*
* @var IManager
*/
private $shareManager;

/**
* Logger
*
* @var ILogger
*/
public function __construct() {
private $logger;

/**
* Constructor
*
* @param IDBConnection $connection connection
*/
public function __construct(IDBConnection $connection, IManager $shareManager, ILogger $logger) {
$this->connection = $connection;
$this->shareManager = $shareManager;
$this->logger = $logger;
// Run once a day
$this->setInterval(24 * 60 * 60);
}
Expand All @@ -42,17 +72,12 @@ public function __construct() {
* @param array $argument unused argument
*/
public function run($argument) {
$connection = \OC::$server->getDatabaseConnection();
$logger = \OC::$server->getLogger();

//Current time
// Current time
$now = new \DateTime();
$now = $now->format('Y-m-d H:i:s');

/*
* Expire file link shares only (for now)
*/
$qb = $connection->getQueryBuilder();
// Expire file link shares only (for now)
$qb = $this->connection->getQueryBuilder();
$qb->select('id', 'file_source', 'uid_owner', 'item_type')
->from('share')
->where(
Expand All @@ -68,7 +93,13 @@ public function run($argument) {

$shares = $qb->execute();
while ($share = $shares->fetch()) {
\OCP\Share::unshare($share['item_type'], $share['file_source'], \OCP\Share::SHARE_TYPE_LINK, null, $share['uid_owner']);
try {
// the getShareById already deletes those automatically
$this->shareManager->getShareById('ocinternal:' . $share['id']);
} catch (ShareNotFound $e) {
// ignore, already deleted
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather to log something for debugging purposes

$this->logger->debug('ExpireSharesJob: Share with id "' . $share['id'] . '" was already deleted', ['app' => 'files_sharing']);
}
}
$shares->closeCursor();
}
Expand Down
241 changes: 0 additions & 241 deletions apps/files_sharing/lib/ShareBackend/File.php

This file was deleted.

Loading