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

fix(FileListener): Listen to file movements across share boundaries #1126

Merged
merged 7 commits into from
Apr 18, 2024
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
6 changes: 4 additions & 2 deletions .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Set up php
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
uses: shivammathur/setup-php@v2 # v2
with:
php-version: 8.1
coverage: none
Expand All @@ -43,7 +43,9 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: composer i
run: |
composer i
composer i
marcelklehr marked this conversation as resolved.
Show resolved Hide resolved

- name: Lint
run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )
2 changes: 1 addition & 1 deletion .github/workflows/lint-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
uses: shivammathur/setup-php@v2 # v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
uses: shivammathur/setup-php@v2 # v2
with:
php-version: ${{ matrix.php-versions }}
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
uses: shivammathur/setup-php@v2 # v2
with:
php-version: ${{ matrix.php-versions }}
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
path: apps/${{ env.APP_NAME }}

- name: Set up php ${{ matrix.php-versions }}
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
uses: shivammathur/setup-php@v2 # v2
with:
php-version: ${{ matrix.php-versions }}
# https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html#prerequisites-for-manual-installation
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Set up php
uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2
uses: shivammathur/setup-php@v2 # v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
Expand Down
297 changes: 176 additions & 121 deletions lib/Hooks/FileListener.php

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions tests/ClassifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
class ClassifierTest extends TestCase {
public const TEST_USER1 = 'test-user1';
public const TEST_USER2 = 'test-user2';

public const TEST_FILES = ['alpine.jpg' ,'eiffeltower.jpg', 'Rock_Rejam.mp3', 'jumpingjack.gif', 'test'];
public const ALL_MODELS = [
Expand All @@ -58,11 +59,13 @@ class ClassifierTest extends TestCase {
private FaceDetectionMapper $faceDetectionMapper;
private IJobList $jobList;
private IAppConfig $config;
private \OCP\Share\IManager $shareManager;

public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
$backend = new \Test\Util\User\Dummy();
$backend->createUser(self::TEST_USER1, self::TEST_USER1);
$backend->createUser(self::TEST_USER2, self::TEST_USER2);
\OC::$server->get(\OCP\IUserManager::class)->registerBackend($backend);
}

Expand All @@ -79,6 +82,7 @@ public function setUp(): void {
$this->jobList = \OC::$server->get(IJobList::class);
$this->config = \OC::$server->getRegisteredAppContainer('recognize')->get(IAppConfig::class);
$this->queue = \OC::$server->get(QueueService::class);
$this->shareManager = \OC::$server->get(\OCP\Share\IManager::class);
foreach (self::TEST_FILES as $filename) {
try {
$this->userFolder->get($filename)->delete();
Expand Down Expand Up @@ -483,6 +487,26 @@ public function testFacesPipeline() : void {
}
}
}

// Test FileListener for moving files across share boundaries

self::assertCount(0, $this->faceDetectionMapper->findByUserId(self::TEST_USER2), 'user 2 should have no face detections');

$sharedFolder = $this->userFolder->newFolder('/shared/');
$share = $this->shareManager->newShare();
$share->setSharedBy(self::TEST_USER1);
$share->setSharedWith(self::TEST_USER2);
$share->setShareType(\OCP\Share\IShare::TYPE_USER);
$share->setNode($sharedFolder);
$share->setPermissions(\OCP\Constants::PERMISSION_ALL);
$this->shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_USER2);

$testFiles[0]->move($sharedFolder->getPath().'/'.$testFiles[0]->getName());

self::assertCount(1, $this->faceDetectionMapper->findByUserId(self::TEST_USER2), 'user 2 should have 1 face detection now');
$this->shareManager->deleteShare($share);
self::assertCount(0, $this->faceDetectionMapper->findByUserId(self::TEST_USER2), 'user 2 should have 0 face detections after deleting the share');
}

/**
Expand Down
Loading