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
committerJoas Schilling <coding@schilljs.com>2022-07-08 13:29:56 +0300
commit213134f5c0187959489afe926d0bd6c3124ed1d6 (patch)
tree58a3fdc59bb0222153abea7f46bb4650c2d887d6
parent79d896a9d318222e9e1b2c464aa6d1d72b6228f3 (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 2173952..e4fc4ff 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 {
private IDBConnection $db;
@@ -59,9 +60,10 @@ class APIController extends Controller {
$cursor = $qb->executeQuery();
- $result = [];
+ $result = $tagIds = [];
while ($data = $cursor->fetch()) {
+ $tagIds[] = (string) $data['tag_id'];
$hasJob = $this->joblist->has(RetentionJob::class, ['tag' => (int)$data['tag_id']]);
$result[] = [
@@ -76,6 +78,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 f91f111..1833c73 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
@@ -163,48 +164,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);