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 7 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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Bug fixes:


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

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]
tisto marked this conversation as resolved.
Show resolved Hide resolved
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"] != uid:
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
169 changes: 168 additions & 1 deletion src/plone/restapi/tests/test_services_linkintegrity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from pkg_resources import get_distribution
from plone.app.testing import setRoles
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import SITE_OWNER_PASSWORD
Expand All @@ -18,9 +19,10 @@
import transaction
import unittest

linkintegrity_version = get_distribution("plone.app.linkintegrity").version

class TestLinkIntegrity(unittest.TestCase):

class TestLinkIntegrity(unittest.TestCase):
layer = PLONE_RESTAPI_BLOCKS_FUNCTIONAL_TESTING

def setUp(self):
Expand Down Expand Up @@ -210,3 +212,168 @@ 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)

@unittest.skipUnless(
linkintegrity_version > "4.0.2",
"Remove this skipUnless after release of p.a.linkintegrity.",
)
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,
)
Loading