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 <213943+nickvergessen@users.noreply.github.com>2022-07-13 12:53:20 +0300
committerGitHub <noreply@github.com>2022-07-13 12:53:20 +0300
commit4faab4c6eda04412f3f793e9018b6ef3b0006d27 (patch)
tree3a53bbd0b6b55041dc9efb7d854ac3d4fa48f48e
parent5b9e8e35b9c09931519e6a29bd4ae384506c847c (diff)
parent3a935cd874645e74ee080ba41e6a9fc9968d9afc (diff)
Merge pull request #185 from nextcloud/backport/184/stable24
[stable24] Fix the UI when a tag was deleted
-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..252ca23 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): bool {
+ 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);