Skip to content

Commit

Permalink
Show a View link in the toolbar when you are in a sub item of a form.
Browse files Browse the repository at this point in the history
See #219
  • Loading branch information
mauritsvanrees committed Sep 4, 2020
1 parent 7cc512c commit 29c3086
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/219.bugfix
@@ -1,5 +1,6 @@
Make sure action urls are always relative to the easyform object.
And redirect `folder/easyform/folder_contents` to `folder/folder_contents`.
And show a View link in the toolbar when you are in a sub item of a form.
See `issue 219 <https://github.com/collective/collective.easyform/issues/219>`_
and `PR 239 <https://github.com/collective/collective.easyform/pull/239>`_.
[maurits]
7 changes: 7 additions & 0 deletions src/collective/easyform/browser/configure.zcml
Expand Up @@ -37,6 +37,13 @@
class=".view.GetEasyFormURL"
layer="..interfaces.IEasyFormLayer"
/>
<browser:page
name="is-sub-easyform"
for="*"
permission="zope2.View"
class=".view.IsSubEasyForm"
layer="..interfaces.IEasyFormLayer"
/>
<browser:page
name="folder_contents"
for="collective.easyform.interfaces.IEasyForm"
Expand Down
21 changes: 21 additions & 0 deletions src/collective/easyform/browser/view.py
Expand Up @@ -470,6 +470,27 @@ def get_form(self):
return


class IsSubEasyForm(GetEasyFormURL):
"""Is this a sub object of an easyform?
For use in actions.xml.
If this is a sub object of easyform,
then if has portal_type EasyForm,
but only due to acquisition.
"""

def __call__(self):
if self.context.portal_type != "EasyForm":
# The wrong portal_type.
return False
if hasattr(aq_base(self.context), "portal_type"):
# An actual EasyForm
return False
return True



class FolderContentsView(BrowserView):
"""folder_contents view for EasyForm.
Expand Down
23 changes: 23 additions & 0 deletions src/collective/easyform/profiles/default/actions.xml
Expand Up @@ -3,6 +3,29 @@
meta_type="Plone Actions Tool"
name="portal_actions"
>
<object meta_type="CMF Action Category"
name="object"
>
<object meta_type="CMF Action"
name="easyform-view"
insert-after="folderContents"
i18n:domain="collective.easyform"
>
<property name="title"
i18n:translate=""
>View</property>
<property name="description"
i18n:translate=""
/>
<property name="url_expr">python:context.restrictedTraverse('@@get-easyform-url')('')</property>
<property name="icon_expr" />
<property name="available_expr">python:object.portal_type == 'EasyForm' and object.restrictedTraverse('@@is-sub-easyform')()</property>
<property name="permissions">
<element value="Manage portal" />
</property>
<property name="visible">True</property>
</object>
</object>
<object meta_type="CMF Action Category"
name="object_buttons"
>
Expand Down
33 changes: 33 additions & 0 deletions src/collective/easyform/tests/testMisc.py
Expand Up @@ -77,6 +77,39 @@ def test_get_easyform_url_portal(self):
self.check_urls_non_form(view)


class TestIsSubEasyForm(base.EasyFormTestCase):
""" test IsSubEasyForm stuff """

def afterSetUp(self):
self.folder.invokeFactory("EasyForm", "ff1")
self.form = self.folder.ff1
self.form_url = self.form.absolute_url()

def get_view(self, context):
request = self.layer["request"]
return getMultiAdapter((context, request), name="is-sub-easyform")

def test_is_sub_easyform_form(self):
view = self.get_view(self.form)
self.assertFalse(view())

def test_is_sub_easyform_fields(self):
view = self.get_view(self.form.restrictedTraverse("fields"))
self.assertTrue(view())

def test_is_sub_easyform_actions(self):
view = self.get_view(self.form.restrictedTraverse("actions"))
self.assertTrue(view())

def test_is_sub_easyform_folder(self):
view = self.get_view(self.folder)
self.assertFalse(view())

def test_is_sub_easyform_root(self):
view = self.get_view(self.portal)
self.assertFalse(view())


class TestAjaxSaveHandler(base.EasyFormTestCase):
def test_ajax_save_handler_call_unathorized(self):
self.folder.invokeFactory("EasyForm", "ff1")
Expand Down

0 comments on commit 29c3086

Please sign in to comment.