Skip to content

Commit

Permalink
- Factorize show_history functionnality. The method is now defined …
Browse files Browse the repository at this point in the history
…on the `IHContentHistoryView` and is used by `IHDocumentBylineViewlet.show_history` and the `@@historyview`. This way, we make sure that if the link is not shown on the viewlet, the history is not shown in the `@@historyview` if user enter the view name manually in the browser.
  • Loading branch information
gbastien committed Mar 16, 2018
1 parent d1f76ed commit 21573c3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
9 changes: 7 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ Changelog
1.17 (unreleased)
-----------------

- Nothing changed yet.

- Factorize `show_history` functionnality. The method is now defined on the
`IHContentHistoryView` and is used by
`IHDocumentBylineViewlet.show_history` and the `@@historyview`.
This way, we make sure that if the link is not shown on the viewlet, the
history is not shown in the `@@historyview` if user enter the view name
manually in the browser.
[gbastien]

1.16 (2018-02-22)
-----------------
Expand Down
7 changes: 4 additions & 3 deletions src/imio/history/browser/templates/content_history.pt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<div id="content" define-macro="history" i18n:domain="plone"
tal:define="events view/getHistory;
showColors view/showColors;
showRevisionInfos view/showRevisionInfos;">
tal:condition="view/show_history"
tal:define="events view/getHistory;
showColors view/showColors;
showRevisionInfos view/showRevisionInfos;">
<tal:block replace="structure view/renderCustomJS"></tal:block>
<tal:comment replace="nothing">Table containing the history</tal:comment>
<tal:history condition="events">
Expand Down
44 changes: 28 additions & 16 deletions src/imio/history/browser/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
from zope.component import getAdapter, getAdapters
from zope.component import getAdapter
from zope.component import getAdapters
from zope.component import getMultiAdapter
from zope.i18n import translate

from Products.CMFCore.utils import getToolByName
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFPlone.utils import safe_unicode
from plone import api
from plone.app.layout.viewlets.content import ContentHistoryView
from plone.app.layout.viewlets.content import DocumentBylineViewlet
from plone.memoize.view import memoize
Expand All @@ -20,16 +23,16 @@ class IHDocumentBylineViewlet(DocumentBylineViewlet):
index = ViewPageTemplateFile("templates/document_byline.pt")

def show_history(self):
"""
Originally, the history is shown to people having the
'CMFEditions: Access previous versions' permission, here
we want everybody than can acces the object to see the history...
"""
# do not show a link to the history if we are displaying something in a popup
# because history is deiaplayed also in a popup...
if 'ajax_load' in self.request:
return False
return True
"""Rely on contenthistory.show_history."""
contenthistory = getMultiAdapter(
(self.context, self.request), name='contenthistory')
res = contenthistory.show_history()
if res:
# do not show a link to the history if we are displaying something in
# an overlay because history is displayed in an overlay and it does not work...
if 'ajax_load' in self.request:
res = False
return res

def highlight_history_link(self):
"""
Expand All @@ -48,10 +51,6 @@ class IHContentHistoryView(ContentHistoryView):
histories_to_handle = (u'revision', u'workflow')
index = ViewPageTemplateFile("templates/content_history.pt")

def __init__(self, context, request):
super(IHContentHistoryView, self).__init__(context, request)
self.transformsTool = getToolByName(self.context, 'portal_transforms')

def getHistory(self, checkMayViewEvent=True, checkMayViewComment=True):
"""Get the history for current object.
Merge workflow history with content history and sort by time."""
Expand Down Expand Up @@ -101,7 +100,8 @@ def renderComments(self, event):
mapping=mapping,
domain='imio.history',
context=self.request)
data = self.transformsTool.convertTo('text/x-html-safe', translated)
transformsTool = api.portal.get_tool('portal_transforms')
data = transformsTool.convertTo('text/x-html-safe', translated)
return data.getData()

@memoize
Expand All @@ -119,6 +119,18 @@ def showColors(self):
"""
return True

def show_history(self):
"""
Show the history? This is a common method used by :
- the view (@@historyview);
- the viewlet (imio.history.documentbyline);
- imio.actionspanel history action icon.
Originally, the history is shown to people having the
'CMFEditions: Access previous versions' permission, here
we want everybody than can acces the object to see the history...
"""
return True

def showRevisionInfos(self):
"""Return True if the type of the context is versioned. """
pr = getToolByName(self.context, 'portal_repository')
Expand Down

0 comments on commit 21573c3

Please sign in to comment.