Skip to content

IMS Indicator on new version should update links to figures 282960 #50

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

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Changes from 24 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6df26b6
Update version.py
dobri1408 Feb 25, 2025
669f7db
Update version.py
dobri1408 Feb 25, 2025
1463702
Update version.py
dobri1408 Feb 25, 2025
d8f7eab
Update version.py
dobri1408 Feb 25, 2025
019ec1d
Update version.py
dobri1408 Feb 25, 2025
a6c72b6
Update version.py
dobri1408 Feb 25, 2025
9b54a98
Update version.py
dobri1408 Feb 25, 2025
432e22e
Update version.py
dobri1408 Feb 25, 2025
95ce986
Update version.py
dobri1408 Feb 25, 2025
42490ec
Update version.py
dobri1408 Feb 25, 2025
7e1fbb5
Update version.py
dobri1408 Feb 25, 2025
1bf5558
Update version.py
dobri1408 Feb 25, 2025
ad4fb61
Update version.py
dobri1408 Feb 25, 2025
f825391
Update version.py
dobri1408 Feb 25, 2025
7c7a00e
Update version.py
dobri1408 Feb 25, 2025
4692bf0
Update version.py
dobri1408 Feb 25, 2025
0e74225
Update version.py
dobri1408 Feb 26, 2025
0722087
Update version.py
dobri1408 Feb 26, 2025
36a72ed
Update version.py
dobri1408 Feb 26, 2025
3462bb3
Update version.py
dobri1408 Feb 26, 2025
5b2cda2
Update version.py
dobri1408 Feb 26, 2025
a51f7fb
Merge branch 'develop' into update_datafigure
dobri1408 May 14, 2025
b4ceb32
Update version.py
dobri1408 May 14, 2025
2965e73
Update version.py
dobri1408 May 14, 2025
7592d59
Update version.py
dobri1408 May 14, 2025
9c15011
chore: fix pep8
avoinea May 19, 2025
0e77fa2
simplify
dobri1408 May 19, 2025
b5194c1
simplify
dobri1408 May 19, 2025
6ada665
clean spaces
dobri1408 May 19, 2025
5c36461
clean spaces
dobri1408 May 19, 2025
d574b88
fix pep8
dobri1408 May 19, 2025
5520424
please fix pep8
dobri1408 May 19, 2025
6d9c59a
please fix pep8
dobri1408 May 19, 2025
982e3e3
Add initial page to relatedItems
Narcis2005 May 20, 2025
93ddf36
Fix shortname changes breaking drafts
Narcis2005 May 21, 2025
b88b408
linting
Narcis2005 May 21, 2025
288f8b2
linting
Narcis2005 May 21, 2025
de97316
lLinting
Narcis2005 May 21, 2025
fc3fd1b
Linter
Narcis2005 May 21, 2025
6d0bb37
Merge pull request #54 from eea/fix_renaming
dobri1408 May 21, 2025
160b093
Stop using relatedItems and create new field, fix creating multiple d…
Narcis2005 May 27, 2025
06d69ed
Linter
Narcis2005 May 27, 2025
285f359
linting
Narcis2005 May 27, 2025
53cbd1f
Make field a simple uid
Narcis2005 May 28, 2025
cd645be
Linting
Narcis2005 May 28, 2025
06302fc
Linter
Narcis2005 May 28, 2025
561009c
Linter
Narcis2005 May 28, 2025
a46626e
Check if attribute exists
Narcis2005 May 28, 2025
5f687a5
Merge pull request #55 from eea/parent_draft
dobri1408 May 28, 2025
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
47 changes: 44 additions & 3 deletions eea/dexterity/indicators/contentrules/version.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
"""Copy action for content rules."""

import copy
from urllib.parse import urlparse
import transaction
from Acquisition import aq_base
from OFS.event import ObjectClonedEvent
from OFS.SimpleItem import SimpleItem
import OFS.subscribers
from plone.restapi.blocks import visit_blocks
from plone.app.contentrules import PloneMessageFactory as _
from plone.app.contentrules.actions import ActionAddForm
from plone.app.contentrules.actions import ActionEditForm
from plone.app.contentrules.browser.formhelper import ContentRuleFormWrapper
from plone.app.vocabularies.catalog import CatalogSource
from plone.contentrules.rule.interfaces import IExecutable
from plone.contentrules.rule.interfaces import IRuleElementData
from plone.restapi.serializer.utils import uid_to_url
from plone.restapi.deserializer.utils import path2uid

try:
from plone.base.utils import pretty_title_or_id
except ImportError:
Expand All @@ -23,7 +31,19 @@
from zope.event import notify
from zope.interface import implementer
from zope.interface import Interface
from zope.lifecycleevent import ObjectCopiedEvent
from zope.lifecycleevent import ObjectCopiedEvent, modified


def getLink(path):
"""
Get link
"""

URL = urlparse(path)

if URL.netloc.startswith("localhost") and URL.scheme:
return path.replace(URL.scheme + "://" + URL.netloc, "")
return path


class ICopyAction(Interface):
Expand Down Expand Up @@ -75,11 +95,13 @@ def __init__(self, context, element, event):
self.event = event

def __call__(self):

portal_url = getToolByName(self.context, "portal_url", None)
if portal_url is None:
return False

obj = self.event.object
previous_obj_path = obj.absolute_url_path()

path = self.element.target_folder
change_note = self.element.change_note
Expand All @@ -100,7 +122,7 @@ def __call__(self):

old_id = obj.getId()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify here if there is in related items an uid even if this is return .1, maybe that .1 is renamed

new_id = self.generate_id(target, old_id)
if not new_id.endswith('.1'):
if not new_id.endswith(".1"):
# Version already exists, redirect to it - refs #279130
return True

Expand Down Expand Up @@ -128,9 +150,26 @@ def __call__(self):

notify(ObjectClonedEvent(obj))

pr = getToolByName(obj, 'portal_repository')
pr = getToolByName(obj, "portal_repository")
pr.save(obj=obj, comment=change_note)

# CHANGE URL OF FIGURES TO THE NEW DRAFT VERSION
for block_data in visit_blocks(obj, obj.blocks):
if (block_data.get("@type") == "embed_content" and
"url" in block_data):
new_block = copy.deepcopy(block_data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary. In place modifying new_block["url"] = url should be enough. You can test this by restarting Plone instance n order to make sure there is no cache keeping the new value.

url = uid_to_url(block_data["url"])
if previous_obj_path in url:
url = url.replace(
previous_obj_path,
previous_obj_path + ".1"
)
url = path2uid(context=self.context, link=getLink(url))
new_block["url"] = url
block_data.clear()
block_data.update(new_block)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need

modified(obj)
transaction.commit()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the transaction.commit() is redundant here 🤔

return True

def error(self, obj, error):
Expand Down Expand Up @@ -169,6 +208,7 @@ class CopyAddForm(ActionAddForm):

class CopyAddFormView(ContentRuleFormWrapper):
"""A wrapper for the add form."""

form = CopyAddForm


Expand All @@ -186,4 +226,5 @@ class CopyEditForm(ActionEditForm):

class CopyEditFormView(ContentRuleFormWrapper):
"""A wrapper for the edit form."""

form = CopyEditForm