Skip to content

Commit

Permalink
Treat sub-items like items in @linkintegrity (#1714)
Browse files Browse the repository at this point in the history
* Expose the sources + their target instead of just some sources in "breaches" attribute in @linkintegrity endpoint response

Signed-off-by: Roel Bruggink <roel@jaroel.nl>

* Be explicit about which data we copy

Signed-off-by: Roel Bruggink <roel@jaroel.nl>

* Fixup tests

Signed-off-by: Roel Bruggink <roel@jaroel.nl>

* lint

Signed-off-by: Roel Bruggink <roel@jaroel.nl>

* test_tree_breaches_no_duplicates is conditional

* Treat sub-items like items in @linkintegrity endpoint

* Add uid only if we haven't seen it

* Unpin plone.app.linktegrity

* Pin plone.app.linkintegrity explicitly for both Plone 6 and Plone 5.2

* Update CHANGES.rst

Co-authored-by: Steve Piercy <web@stevepiercy.com>

* Update CHANGES.rst

Co-authored-by: Steve Piercy <web@stevepiercy.com>

* Update news/1714.bugfix

Co-authored-by: Steve Piercy <web@stevepiercy.com>

* Update CHANGES.rst

Co-authored-by: Steve Piercy <web@stevepiercy.com>

* Update CHANGES.rst

Co-authored-by: Steve Piercy <web@stevepiercy.com>

---------

Signed-off-by: Roel Bruggink <roel@jaroel.nl>
Co-authored-by: Timo Stollenwerk <tisto@users.noreply.github.com>
Co-authored-by: Steve Piercy <web@stevepiercy.com>
  • Loading branch information
3 people committed Oct 18, 2023
1 parent 817b859 commit 1d899d8
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 5 deletions.
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)
- 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,6 +15,7 @@ zodb-temporary-storage = off
[versions]
black = 22.3.0
pygments = 2.14.0
plone.app.linkintegrity = 4.0.3
robotframework-browser = 17.5.2
robotframework-assertion-engine = 2.0.0
robotframework-debuglibrary = 2.3.0
Expand Down
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"])
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,
)

0 comments on commit 1d899d8

Please sign in to comment.