mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-14 21:45:37 -05:00
Some Sonar code smell suggestions
This commit is contained in:
@@ -34,17 +34,17 @@ describe('flattenTags', () => {
|
||||
expect(flat.map((t) => t.orderIndex)).toEqual([0, 1, 2, 3, 4, 5, 6])
|
||||
|
||||
// Children are rebuilt
|
||||
const aRoot = flat.find((t) => t.name === 'A-root')!
|
||||
const aRoot = flat.find((t) => t.name === 'A-root')
|
||||
expect(new Set(aRoot.children?.map((c) => c.name))).toEqual(
|
||||
new Set(['child 2', 'Child 10'])
|
||||
)
|
||||
|
||||
const bRoot = flat.find((t) => t.name === 'B-root')!
|
||||
const bRoot = flat.find((t) => t.name === 'B-root')
|
||||
expect(new Set(bRoot.children?.map((c) => c.name))).toEqual(
|
||||
new Set(['Alpha', 'beta'])
|
||||
)
|
||||
|
||||
const child2 = flat.find((t) => t.name === 'child 2')!
|
||||
const child2 = flat.find((t) => t.name === 'child 2')
|
||||
expect(new Set(child2.children?.map((c) => c.name))).toEqual(
|
||||
new Set(['Sub 1'])
|
||||
)
|
||||
|
@@ -8,7 +8,7 @@ export function flattenTags(all: Tag[]): Tag[] {
|
||||
for (const t of map.values()) {
|
||||
if (t.parent) {
|
||||
const p = map.get(t.parent)
|
||||
p && p.children.push(t)
|
||||
p?.children.push(t)
|
||||
}
|
||||
}
|
||||
const roots = Array.from(map.values()).filter((t) => !t.parent)
|
||||
@@ -29,6 +29,7 @@ export function flattenTags(all: Tag[]): Tag[] {
|
||||
}
|
||||
}
|
||||
}
|
||||
roots.sort(sortByName).forEach((r) => walk(r, 0))
|
||||
roots.sort(sortByName)
|
||||
roots.forEach((r) => walk(r, 0))
|
||||
return ordered
|
||||
}
|
||||
|
@@ -522,7 +522,7 @@ def update_document_parent_tags(tag: Tag, new_parent: Tag) -> None:
|
||||
When a tag's parent changes, ensure all documents containing the tag also have
|
||||
the parent tag (and its ancestors) applied.
|
||||
"""
|
||||
DocumentTagRelationship = Document.tags.through
|
||||
doc_tag_relationship = Document.tags.through
|
||||
|
||||
doc_ids: list[int] = list(
|
||||
Document.objects.filter(tags=tag).values_list("pk", flat=True),
|
||||
@@ -540,13 +540,13 @@ def update_document_parent_tags(tag: Tag, new_parent: Tag) -> None:
|
||||
missing_qs = Document.objects.filter(id__in=doc_ids).exclude(tags=parent)
|
||||
missing_ids = list(missing_qs.values_list("pk", flat=True))
|
||||
to_create.extend(
|
||||
DocumentTagRelationship(document_id=doc_id, tag_id=parent.id)
|
||||
doc_tag_relationship(document_id=doc_id, tag_id=parent.id)
|
||||
for doc_id in missing_ids
|
||||
)
|
||||
affected.update(missing_ids)
|
||||
|
||||
if to_create:
|
||||
DocumentTagRelationship.objects.bulk_create(
|
||||
doc_tag_relationship.objects.bulk_create(
|
||||
to_create,
|
||||
ignore_conflicts=True,
|
||||
)
|
||||
|
@@ -31,16 +31,6 @@ class TestTagHierarchy(APITestCase):
|
||||
mime_type="application/pdf",
|
||||
)
|
||||
|
||||
def test_api_add_child_adds_parent(self):
|
||||
self.client.patch(
|
||||
f"/api/documents/{self.document.pk}/",
|
||||
{"tags": [self.child.pk]},
|
||||
format="json",
|
||||
)
|
||||
self.document.refresh_from_db()
|
||||
tags = set(self.document.tags.values_list("pk", flat=True))
|
||||
assert tags == {self.parent.pk, self.child.pk}
|
||||
|
||||
def test_document_api_add_child_adds_parent(self):
|
||||
self.client.patch(
|
||||
f"/api/documents/{self.document.pk}/",
|
||||
|
Reference in New Issue
Block a user