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

Treat sub-items like items in @linkintegrity #1714

Merged
merged 19 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 17 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: 3 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ Bug fixes:


- Added url field to Actions (#817)
- Update statictime tests following changes to p.a.disucssion (see
https://github.com/plone/plone.app.discussion/pull/204) - [instification] (#1520)
- Update @portrait endpoint to use sanitized user id [instification] (#1524)
- Updated ``statictime`` tests following changes to ``p.a.discussion`` (see
https://github.com/plone/plone.app.discussion/pull/204) - @instification (#1520)
tisto marked this conversation as resolved.
Show resolved Hide resolved
- Updated ``@portrait`` endpoint to use sanitized user id. @instification (#1524)


8.31.0 (2022-10-20)
Expand Down
1 change: 1 addition & 0 deletions news/1714.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Treat sub-items like items in ``@linkintegrity`` endpoint. @jaroel
3 changes: 2 additions & 1 deletion plone-5.2.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ extends =
black = 22.3.0

# we need the newest plone.rest release
plone.rest = 3.0.1
plone.rest = 3.0.1
plone.app.linkintegrity = 3.6.2
1 change: 1 addition & 0 deletions plone-6.0.x.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ zodb-temporary-storage = off
[versions]
black = 22.3.0
pygments = 2.14.0
plone.app.linkintegrity = 4.0.3
3 changes: 3 additions & 0 deletions src/plone/restapi/services/linkintegrity/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def reply(self):
data = getMultiAdapter((item, self.request), ISerializeToJsonSummary)()
data["breaches"] = []
for breach in breaches:
if breach["target"]["uid"] not in uids:
uids.append(breach["target"]["uid"])
jaroel marked this conversation as resolved.
Show resolved Hide resolved
continue
for source in breach.get("sources", []):
# remove unwanted data
source["@id"] = source["url"]
Expand Down
162 changes: 161 additions & 1 deletion src/plone/restapi/tests/test_services_linkintegrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


class TestLinkIntegrity(unittest.TestCase):

layer = PLONE_RESTAPI_BLOCKS_FUNCTIONAL_TESTING

def setUp(self):
Expand Down Expand Up @@ -210,3 +209,164 @@ def test_return_items_total_in_subfolders(self):
self.assertEqual(result[0]["@id"], level1.absolute_url())
self.assertEqual(result[0]["breaches"], [])
self.assertEqual(result[0]["items_total"], 1)

def test_tree_breaches_no_duplicates(self):
# /target_parent/target_child
target_parent = createContentInContainer(
self.portal, "Folder", id="target-parent"
)
target_child = createContentInContainer(
target_parent, "Document", id="target-child"
)
target_parent_uid = IUUID(target_parent)
target_child_uid = IUUID(target_child)

source_a = createContentInContainer(
self.portal,
"Document",
id="source-a",
title="Source A",
blocks={
"block-uuid1": {
"@type": "text",
"text": {
"blocks": [{"text": "some link"}],
"entityMap": {
"0": {
"data": {
"href": f"../resolveuid/{target_parent_uid}",
"rel": "nofollow",
"url": f"../resolveuid/{target_parent_uid}",
},
"mutability": "MUTABLE",
"type": "LINK",
}
},
},
},
"block-uuid2": {
"@type": "text",
"text": {
"blocks": [{"text": "some other link"}],
"entityMap": {
"0": {
"data": {
"href": f"../resolveuid/{target_child_uid}",
"rel": "nofollow",
"url": f"../resolveuid/{target_child_uid}",
},
"mutability": "MUTABLE",
"type": "LINK",
}
},
},
},
},
)

source_b = createContentInContainer(
self.portal,
"Document",
id="source-b",
title="Source B",
blocks={
"block-uuid3": {
"@type": "text",
"text": {
"blocks": [{"text": "some link"}],
"entityMap": {
"0": {
"data": {
"href": f"../resolveuid/{target_parent_uid}",
"rel": "nofollow",
"url": f"../resolveuid/{target_parent_uid}",
},
"mutability": "MUTABLE",
"type": "LINK",
}
},
},
}
},
)

source_c = createContentInContainer(
self.portal,
"Document",
id="source-c",
title="Source C",
blocks={
"block-uuid4": {
"@type": "text",
"text": {
"blocks": [{"text": "some other link"}],
"entityMap": {
"0": {
"data": {
"href": f"../resolveuid/{target_child_uid}",
"rel": "nofollow",
"url": f"../resolveuid/{target_child_uid}",
},
"mutability": "MUTABLE",
"type": "LINK",
}
},
},
},
},
)

transaction.commit()

response = self.api_session.get(
"/@linkintegrity", params={"uids": [target_parent_uid]}
)

results = response.json()
self.assertEqual(
[
{
"@id": target_parent.absolute_url(),
"@type": "Folder",
"breaches": [
{
"@id": source_a.absolute_url(),
"title": "Source A",
"uid": IUUID(source_a),
},
{
"@id": source_b.absolute_url(),
"title": "Source B",
"uid": IUUID(source_b),
},
],
"description": "",
"items_total": 1,
"review_state": "private",
"title": "",
"type_title": "Folder",
},
{
"@id": target_child.absolute_url(),
"@type": "Document",
"breaches": [
{
"@id": source_a.absolute_url(),
"title": "Source A",
"uid": IUUID(source_a),
},
{
"@id": source_c.absolute_url(),
"title": "Source C",
"uid": IUUID(source_c),
},
],
"description": "",
"items_total": 0,
"review_state": "private",
"title": "",
"type_title": "Page",
},
],
results,
)