Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_retention.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-07-08 13:29:56 +0300
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>2022-07-08 13:59:40 +0300
commit32a4f96b4b66f70a7651424c73bae15868ba8749 (patch)
tree3bf1a139acdf6b0cabca682e03267d093c05c939
parenta09bd6b234a31e63ded405b563081f6f58eb5e05 (diff)
Fix the UI when a tag was deleted
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/Controller/APIController.php15
-rw-r--r--tests/lib/Contoller/APIControllerTest.php48
2 files changed, 44 insertions, 19 deletions
diff --git a/lib/Controller/APIController.php b/lib/Controller/APIController.php
index 242251a..630aa7c 100644
--- a/lib/Controller/APIController.php
+++ b/lib/Controller/APIController.php
@@ -32,6 +32,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\SystemTag\ISystemTagManager;
+use OCP\SystemTag\TagNotFoundException;
class APIController extends Controller {
@@ -77,9 +78,10 @@ class APIController extends Controller {
$cursor = $qb->execute();
- $result = [];
+ $result = $tagIds = [];
while ($data = $cursor->fetch()) {
+ $tagIds[] = (string) $data['tag_id'];
$hasJob = $this->joblist->has(RetentionJob::class, ['tag' => (int)$data['tag_id']]);
$result[] = [
@@ -94,6 +96,17 @@ class APIController extends Controller {
$cursor->closeCursor();
+
+ try {
+ $this->tagManager->getTagsByIds($tagIds);
+ } catch (TagNotFoundException $e) {
+ $missingTags = array_map('intval', $e->getMissingTags());
+
+ $result = array_values(array_filter($result, static function (array $rule) use ($missingTags) {
+ return !in_array($rule['tagid'], $missingTags, true);
+ }));
+ }
+
return new JSONResponse($result);
}
diff --git a/tests/lib/Contoller/APIControllerTest.php b/tests/lib/Contoller/APIControllerTest.php
index 8d76aba..f869cdc 100644
--- a/tests/lib/Contoller/APIControllerTest.php
+++ b/tests/lib/Contoller/APIControllerTest.php
@@ -30,6 +30,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\SystemTag\ISystemTagManager;
+use OCP\SystemTag\TagNotFoundException;
/**
* Class APIControllerTest
@@ -165,48 +166,59 @@ class APIControllerTest extends \Test\TestCase {
],
[
[
- [1, Constants::DAY, 1, 0, null],
+ ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => null],
]
],
[
[
- [1, Constants::DAY, 1, 0, null],
- [2, Constants::WEEK, 2, 0, null],
- [3, Constants::MONTH, 3, 1, null],
- [4, Constants::YEAR, 4, 1, null],
+ ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => null],
+ ['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => null],
+ ['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => null],
+ ['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => null],
]
],
+ [
+ [
+ ['tagid' => 1, 'timeunit' => Constants::DAY, 'timeamount' => 1, 'timeafter' => 0, 'hasJob' => null],
+ ['tagid' => 2, 'timeunit' => Constants::WEEK, 'timeamount' => 2, 'timeafter' => 0, 'hasJob' => null, 'expected' => false],
+ ['tagid' => 3, 'timeunit' => Constants::MONTH, 'timeamount' => 3, 'timeafter' => 1, 'hasJob' => null, 'expected' => false],
+ ['tagid' => 4, 'timeunit' => Constants::YEAR, 'timeamount' => 4, 'timeafter' => 1, 'hasJob' => null],
+ ],
+ ['2', '3'],
+ ],
];
}
/**
* @dataProvider dataGetRetentions
* @param array $data
+ * @param array $missingTags
*/
- public function testGetRetentions($data) {
+ public function testGetRetentions(array $data, array $missingTags = []): void {
$expected = [];
foreach ($data as $d) {
$qb = $this->db->getQueryBuilder();
$qb->insert('retention')
- ->setValue('tag_id', $qb->createNamedParameter($d[0]))
- ->setValue('time_unit', $qb->createNamedParameter($d[1]))
- ->setValue('time_amount', $qb->createNamedParameter($d[2]))
- ->setValue('time_after', $qb->createNamedParameter($d[3]));
+ ->setValue('tag_id', $qb->createNamedParameter($d['tagid']))
+ ->setValue('time_unit', $qb->createNamedParameter($d['timeunit']))
+ ->setValue('time_amount', $qb->createNamedParameter($d['timeamount']))
+ ->setValue('time_after', $qb->createNamedParameter($d['timeafter']));
$qb->execute();
$id = $qb->getLastInsertId();
- $expected[] = [
- 'id' => $id,
- 'tagid' => $d[0],
- 'timeunit' => $d[1],
- 'timeamount' => $d[2],
- 'timeafter' => $d[3],
- 'hasJob' => null,
- ];
+ if ($d['expected'] ?? true) {
+ unset($d['expected']);
+ $expected[] = array_merge([
+ 'id' => $id,
+ ], $d);
+ }
}
+ $this->tagManager->method('getTagsByIds')
+ ->willThrowException(new TagNotFoundException('', 0, null, $missingTags));
+
$response = $this->api->getRetentions();
$this->assertInstanceOf(Http\JSONResponse::class, $response);