Skip to content

Commit

Permalink
Merge pull request #37391 from owncloud/feature/fed-shares-cronjob
Browse files Browse the repository at this point in the history
Add fed shares scanner batched cronjob
  • Loading branch information
DeepDiver1975 authored May 19, 2020
2 parents 9607406 + b7858c1 commit bb488fd
Show file tree
Hide file tree
Showing 13 changed files with 819 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected function configure() {
* @return int|null|void
*/
public function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("WARNING: incoming-shares:poll has been deprecated and replaced by periodic external shares cronjob. Please check Federated Cloud Sharing settings and documentation.");
if ($this->externalMountProvider === null) {
$output->writeln("Polling is not possible when files_sharing app is disabled. Please enable it with 'occ app:enable files_sharing'");
return 1;
Expand Down
10 changes: 10 additions & 0 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,16 @@ public function userDeletedFromGroup($uid, $gid) {
return;
}

/**
* check if scan of federated shares from other ownCloud instances should be performed
*
* @return bool
*/
public function isCronjobScanExternalEnabled() {
$result = $this->config->getAppValue('files_sharing', 'cronjob_scan_external_enabled', 'no');
return ($result === 'yes') ? true : false;
}

/**
* check if users from other ownCloud instances are allowed to mount public links share by this instance
*
Expand Down
1 change: 1 addition & 0 deletions apps/federatedfilesharing/lib/Panels/AdminPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function getSectionID() {

public function getPanel() {
$tmpl = new Template('federatedfilesharing', 'settings-admin');
$tmpl->assign('cronjobScanExternalEnabled', $this->shareProvider->isCronjobScanExternalEnabled());
$tmpl->assign('outgoingServer2serverShareEnabled', $this->shareProvider->isOutgoingServer2serverShareEnabled());
$tmpl->assign('incomingServer2serverShareEnabled', $this->shareProvider->isIncomingServer2serverShareEnabled());
$tmpl->assign(
Expand Down
10 changes: 10 additions & 0 deletions apps/federatedfilesharing/templates/settings-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
title="<?php p($l->t('Open documentation'));?>"
href="<?php p(link_to_docs('admin-sharing-federated')); ?>"></a>

<p>
<input type="checkbox" name="cronjob_scan_external_enabled" id="cronjobScanExternalEnabled" class="checkbox"
value="1" <?php if ($_['cronjobScanExternalEnabled']) {
print_unescaped('checked="checked"');
} ?> />
<label for="cronjobScanExternalEnabled">
<?php p($l->t('Periodically synchronize outdated federated shares for active users'));?>
</label>
</p>

<p>
<input type="checkbox" name="outgoing_server2server_share_enabled" id="outgoingServer2serverShareEnabled" class="checkbox"
value="1" <?php if ($_['outgoingServer2serverShareEnabled']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testNoSharesPoll() {
$this->dbConnection->method('getQueryBuilder')->willReturn($qbMock);
$this->commandTester->execute([]);
$output = $this->commandTester->getDisplay();
$this->assertEmpty($output);
$this->assertEquals($output, "WARNING: incoming-shares:poll has been deprecated and replaced by periodic external shares cronjob. Please check Federated Cloud Sharing settings and documentation.\n");
}

public function testWithFilesSharingDisabled() {
Expand Down
16 changes: 16 additions & 0 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,22 @@ public function testDeleteUser($owner, $initiator, $recipient, $deletedUser, $ro
$this->assertCount($rowDeleted ? 0 : 1, $data);
}

/**
* @dataProvider dataTestFederatedSharingSettings
*
* @param string $isEnabled
* @param bool $expected
*/
public function testIsCronjobScanExternalEnabled($isEnabled, $expected) {
$this->config->expects($this->once())->method('getAppValue')
->with('files_sharing', 'cronjob_scan_external_enabled', 'no')
->willReturn($isEnabled);

$this->assertSame($expected,
$this->provider->isCronjobScanExternalEnabled()
);
}

/**
* @dataProvider dataTestFederatedSharingSettings
*
Expand Down
1 change: 1 addition & 0 deletions apps/federatedfilesharing/tests/Panels/AdminPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function testGetPriority() {
}

public function testGetPanel() {
$this->shareProvider->expects($this->once())->method('isCronjobScanExternalEnabled')->willReturn(false);
$this->shareProvider->expects($this->once())->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
$this->shareProvider->expects($this->once())->method('isIncomingServer2serverShareEnabled')->willReturn(true);
$templateHtml = $this->panel->getPanel()->fetchPage();
Expand Down
31 changes: 31 additions & 0 deletions apps/files_sharing/appinfo/Migrations/Version20200504211654.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace OCA\Files_Sharing\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use OCP\Migration\ISchemaMigration;

/**
* Adds lastscan column
*/
class Version20200504211654 implements ISchemaMigration {
public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];

if ($schema->hasTable("${prefix}share_external")) {
$table = $schema->getTable("${prefix}share_external");

if (!$table->hasColumn('lastscan')) {
$table->addColumn(
'lastscan',
Types::BIGINT,
[
'length' => 11,
'unsigned' => true,
'notnull' => false,
]
);
}
}
}
}
3 changes: 2 additions & 1 deletion apps/files_sharing/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Turning the feature off removes shared files and folders on the server for all s
<licence>AGPL</licence>
<author>Michael Gapczynski, Bjoern Schiessle</author>
<default_enable/>
<version>0.12.0</version>
<version>0.13.0</version>
<types>
<filesystem/>
</types>
Expand All @@ -35,6 +35,7 @@ Turning the feature off removes shared files and folders on the server for all s
<background-jobs>
<job>OCA\Files_Sharing\DeleteOrphanedSharesJob</job>
<job>OCA\Files_Sharing\ExpireSharesJob</job>
<job>OCA\Files_Sharing\External\ScanExternalSharesJob</job>
</background-jobs>

<commands>
Expand Down
Loading

0 comments on commit bb488fd

Please sign in to comment.