def last_modifier(self): # Let's see if we have any last_modifier annotation raw_last_modifier = self._raw_last_modifier() if raw_last_modifier: return raw_last_modifier # If we are here: try with with history support if is available. history = queryMultiAdapter((self.context, self.request), interface=Interface, name=u"contenthistory") # Security is in the view definition. Here we act as an omnipotent user old_sm = getSecurityManager() tmp_user = UnrestrictedUser(old_sm.getUser().getId() or '', '', ['Manager'], '') newSecurityManager(None, tmp_user) try: if not history and sys.version_info < (2, 6): # We didn't found any history... is this a Plone 3? Let's try with the old history viewlet # To be sure of that let's do it only if we are using Python 2.4 # Please remove this abomination when Plone 3.3 compatibity will be dropped history = ContentHistoryViewlet(self.context, self.request, None, manager=None) history.update() if history: full_history = history.fullHistory() if full_history: return full_history[0].get('actorid') or full_history[0].get('actor').get('username') finally: setSecurityManager(old_sm)
def reply(self): # Traverse to historical version if self.version: serializer = queryMultiAdapter((self.context, self.request), ISerializeToJson) data = serializer(version=self.version) return data # Listing historical data content_history_viewlet = ContentHistoryViewlet( self.context, self.request, None, None) site_url = getSite().absolute_url() content_history_viewlet.navigation_root_url = site_url content_history_viewlet.site_url = site_url history = content_history_viewlet.fullHistory() unwanted_keys = [ 'diff_current_url', 'diff_previous_url', 'preview_url', 'actor_home', 'actorid', 'revert_url', 'version_id', ] for item in history: item['actor'] = { '@id': '{}/@users/{}'.format(site_url, item['actorid']), 'id': item['actorid'], 'fullname': item['actor'].get('fullname'), 'username': item['actor'].get('username'), } if item['type'] == 'versioning': item['version'] = item['version_id'] item['@id'] = '{}/@history/{}'.format( self.context.absolute_url(), item['version']) # If a revert_url is present, then CMFEditions has checked our # permissions. item['may_revert'] = bool(item.get('revert_url')) # Versioning entries use a timestamp, # workflow ISO formatted string if not isinstance(item['time'], basestring): item['time'] = dt.fromtimestamp(item['time']).isoformat() # The create event has an empty 'action', but we like it to say # 'Create', alike the transition_title if item['action'] is None: item['action'] = 'Create' # clean up for key in unwanted_keys: if key in item: del item[key] return json_compatible(history)
def getFullHistory(item): """ http://docs.plone.org/develop/plone/content/history.html """ history = None # TODO: user must exist in plonsite ! Zopeadmin can watch anyway. #admin = portal().acl_users.getUser('siteadmin') #newSecurityManager(request, admin) request = TestRequest() chv = ContentHistoryViewlet(item, request, None, None) # These attributes are needed, the fullHistory() call fails otherwise chv.navigation_root_url = chv.site_url = 'http://www.example.org' history = chv.fullHistory() return history
def test_statictime_full_history(self): frozen_time = datetime(1950, 7, 31, 17, 30) statictime = StaticTime(modified=frozen_time) statictime.start() doc1 = self.create_document("doc1") doc1.setTitle("Current version") api.content.transition(doc1, "publish") viewlet = ContentHistoryViewlet(doc1, doc1.REQUEST, None) viewlet.update() history = viewlet.fullHistory() real_datetimes = list(map(itemgetter("time"), history)) self.assertEqual( real_datetimes, [ DateTime("1950/07/31 17:30:00 UTC"), -612855000.0, DateTime("1950/07/31 19:30:00 UTC"), ], ) statictime.stop() doc2 = self.create_document("doc2") doc2.setTitle("Current version") api.content.transition(doc2, "publish") viewlet = ContentHistoryViewlet(doc2, doc2.REQUEST, None) viewlet.update() history = viewlet.fullHistory() fake_datetimes = list(map(itemgetter("time"), history)) for ts in fake_datetimes: self.assert_roughly_now(ts) self.assert_of_same_type(fake_datetimes, real_datetimes)
def reply(self): # Traverse to historical version if self.version: serializer = queryMultiAdapter((self.context, self.request), ISerializeToJson) data = serializer(version=self.version) return data # Listing historical data content_history_viewlet = ContentHistoryViewlet( self.context, self.request, None, None) site_url = getSite().absolute_url() content_history_viewlet.navigation_root_url = site_url content_history_viewlet.site_url = site_url history = content_history_viewlet.fullHistory() if history is None: history = [] unwanted_keys = [ "diff_current_url", "diff_previous_url", "preview_url", "actor_home", "actorid", "revert_url", "version_id", ] for item in history: item["actor"] = { "@id": "{}/@users/{}".format(site_url, item["actorid"]), "id": item["actorid"], "fullname": item["actor"].get("fullname"), "username": item["actor"].get("username"), } if item["type"] == "versioning": item["version"] = item["version_id"] item["@id"] = "{}/@history/{}".format( self.context.absolute_url(), item["version"]) # If a revert_url is present, then CMFEditions has checked our # permissions. item["may_revert"] = bool(item.get("revert_url")) # Versioning entries use a timestamp, # workflow ISO formatted string if not isinstance(item["time"], str): item["time"] = dt.fromtimestamp(int(item["time"])).isoformat() # The create event has an empty 'action', but we like it to say # 'Create', alike the transition_title if item["action"] is None: item["action"] = "Create" # We want action, state and transition names translated if "state_title" in item: item["state_title"] = self.context.translate( safe_unicode(item["state_title"]), context=self.request) if "transition_title" in item: item["transition_title"] = self.context.translate( safe_unicode(item["transition_title"]), context=self.request) if "action" in item: item["action"] = self.context.translate(safe_unicode( item["action"]), context=self.request) # clean up for key in unwanted_keys: if key in item: del item[key] return json_compatible(history)