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

Allows working copy of Plone Site #130

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions news/130.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allows working copy of Plone Site. @wesleybl
7 changes: 6 additions & 1 deletion plone/app/iterate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ def checkout(self, container):

# use the object copier to checkout the content to the container
copier = queryAdapter(self.context, IObjectCopier)
working_copy, relation = copier.copyTo(container)
# The container for the Portal's working copy is the Portal itself.
if self.context.portal_type == "Plone Site":
working_copy_container = self.context
else:
working_copy_container = container
working_copy, relation = copier.copyTo(working_copy_container)

# publish the event for any subscribers
notify(CheckoutEvent(self.context, working_copy, relation))
Expand Down
10 changes: 5 additions & 5 deletions plone/app/iterate/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def __init__(self, context):

@property
def available(self):
return bool(
getSecurityManager().checkPermission(
AddPortalContent, aq_parent(aq_inner(self.context))
)
)
obj = aq_inner(self.context)
# In Plone Site checkout, the working copy container is the portal itself.
if obj.portal_type != "Plone Site":
obj = aq_parent(obj)
return bool(getSecurityManager().checkPermission(AddPortalContent, obj))

def __call__(self):
if not self.available:
Expand Down
4 changes: 4 additions & 0 deletions plone/app/iterate/dexterity/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@
<implements interface="plone.app.iterate.dexterity.interfaces.IDexterityIterateAware" />
</class>

<class class="Products.CMFPlone.Portal.PloneSite">
<implements interface="plone.app.iterate.dexterity.interfaces.IDexterityIterateAware" />
</class>

</configure>
15 changes: 14 additions & 1 deletion plone/app/iterate/dexterity/copier.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def _replaceBaseline(self, baseline):
return baseline

def _reassembleWorkingCopy(self, new_baseline, baseline):
# Does not change Plone Site permissions.
if new_baseline.portal_type == "Plone Site":
return new_baseline

# reattach the source's workflow history, try avoid a dangling ref
try:
new_baseline.workflow_history = PersistentMapping(
Expand Down Expand Up @@ -171,11 +175,20 @@ def checkin(self, checkin_message):

class FolderishContentCopier(ContentCopier):
def _copyBaseline(self, container):
if self.context.portal_type == "Plone Site":
portal_type = "Document"
else:
portal_type = self.context.portal_type
obj = createContentInContainer(
container,
self.context.portal_type,
portal_type,
id=f"working_copy_of_{self.context.id}",
)
# Since the working copy of the Portal is originally a Document,
# we force its portal_type to "Plone Site", so that the "Plone Site"
# schema is used.
if self.context.portal_type == "Plone Site":
obj.portal_type = "Plone Site"

# copy all field values from the baseline to the working copy
for schema in iterSchemata(self.context):
Expand Down
4 changes: 2 additions & 2 deletions plone/app/iterate/tests/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ def test_container_control_checkin_allowed_with_no_policy(self):
self.assertFalse(control.checkin_allowed())

def test_container_control_checkout_allowed_with_no_policy(self):
control = Control(self.portal, self.layer["request"])
control = Control(self.portal.docs, self.layer["request"])
self.assertFalse(control.checkout_allowed())

def test_container_control_cancel_allowed_with_no_policy(self):
control = Control(self.portal, self.layer["request"])
control = Control(self.portal.docs, self.layer["request"])
self.assertFalse(control.cancel_allowed())

def test_container_control_cancel_on_original_does_not_delete_original(self):
Expand Down
4 changes: 2 additions & 2 deletions plone/app/iterate/tests/test_iterate.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ def test_control_checkin_allowed_with_no_policy(self):
self.assertFalse(control.checkin_allowed())

def test_control_checkout_allowed_with_no_policy(self):
control = Control(self.portal, self.layer["request"])
control = Control(self.portal.docs, self.layer["request"])
self.assertFalse(control.checkout_allowed())

def test_control_cancel_allowed_with_no_policy(self):
control = Control(self.portal, self.layer["request"])
control = Control(self.portal.docs, self.layer["request"])
self.assertFalse(control.cancel_allowed())

def test_control_cancel_on_original_does_not_delete_original(self):
Expand Down
Loading