def __init__(self, object, event): self.object = object # TODO: do we really need this different from object? self.content = content = event.object if not is_flowplayer_installed(content): return if not self.interface.providedBy(content): return if self.value is None: remove_marker(content) return ext = self.check_extension() if ext is None: remove_marker(content) return # set the view to flowplayer view # TODO: give up automatic view changing - it causes problems when # product is deinstalled. instead provide a file_view for # the interfaces IAudio and IVideo in combination with # IFileContent and IATLink. if IObjectInitializedEvent.providedBy(event): content.setLayout('flowplayer') if ext in AUDIO_EXTENSIONS: self.handleAudio() elif ext in VIDEO_EXTENSIONS: self.handleVideo()
def modified(event): """When an object is modified, execute rules assigned to its parent """ # Let the special handler take care of IObjectInitializedEvent if not IObjectInitializedEvent.providedBy(event): execute_rules(event)
def store_activity(document, event): if IObjectInitializedEvent.providedBy(event): return elif IContainerModifiedEvent.providedBy(event): return elif not ILayer.providedBy(getattr(document, 'REQUEST', None)): return elif not IUUIDAware.providedBy(document): return folder = document.aq_parent get_tool().store_activity(folder, 'modify', uid=IUUID(document))
def generate_image(obj, evt): """ EVENT called on objectmodified. Tries to generate the cover image. """ # Make sure we execute this only on the canonical #If the event is an ObjectInitializedEvent, we skip if IObjectInitializedEvent.providedBy(evt): return if hasattr(obj.aq_explicit, 'getCanonical') and obj != obj.getCanonical(): return interfaces.IPublication(obj).generateImage()
def modified(event): """When an object is modified, execute rules assigned to its parent """ if handlers.is_portal_factory(event.object): return if hasattr(event.object,'getId'): if event.object.getId().split('.')[0]=='file': return # Let the special handler take care of IObjectInitializedEvent if not IObjectInitializedEvent.providedBy(event): handlers.execute(aq_parent(aq_inner(event.object)), event)
def sparql_added_or_modified(obj, evt): """Update last working results when sparql is added or modified""" async = getUtility(IAsyncService) obj.scheduled_at = DateTime.DateTime() bookmarks_folder_added = False if ISparqlBookmarksFolder.providedBy(obj) and \ IObjectInitializedEvent.providedBy(evt): bookmarks_folder_added = True async.queueJob(async_updateLastWorkingResults, obj, scheduled_at=obj.scheduled_at, bookmarks_folder_added=bookmarks_folder_added)
def __init__(self, object, event): self.object = object # TODO: do we really need this different from object? self.content = content = event.object if not self.interface.providedBy(content): return if self.value is None: remove_marker(content) return ext = self.check_extension() if ext is None: remove_marker(content) return # set the view to mediaelementjs view if IObjectInitializedEvent.providedBy(event): content.setLayout('mediaelementjs') if ext in VIDEO_EXTENSIONS: self.handleVideo()
def sparql_added_or_modified(obj, evt): """Update last working results when sparql is added or modified""" async_service = queryUtility(IAsyncService) if async_service is None: logger.warn( "Can't schedule sparql update. plone.app.async NOT installed!") return obj.scheduled_at = DateTime.DateTime() bookmarks_folder_added = False if ISparqlBookmarksFolder.providedBy(obj) and \ IObjectInitializedEvent.providedBy(evt): bookmarks_folder_added = True async_queue = async_service.getQueues()[''] async_service.queueJobInQueue( async_queue, ('sparql',), async_updateLastWorkingResults, obj, scheduled_at=obj.scheduled_at, bookmarks_folder_added=bookmarks_folder_added)
def sparql_added_or_modified(obj, evt): """Update last working results when sparql is added or modified""" async_service = queryUtility(IAsyncService) if async_service is None: logger.warn( "Can't schedule sparql update. plone.app.async NOT installed!") return obj.scheduled_at = DateTime.DateTime() bookmarks_folder_added = False if ISparqlBookmarksFolder.providedBy(obj) and \ IObjectInitializedEvent.providedBy(evt): bookmarks_folder_added = True async_queue = async_service.getQueues()[''] async_service.queueJobInQueue( async_queue, ('sparql', ), async_updateLastWorkingResults, obj, scheduled_at=obj.scheduled_at, bookmarks_folder_added=bookmarks_folder_added)
def __init__(self, object, event): self.context = event.object if IObjectInitializedEvent.providedBy(event): # create group logging.info('Creating user group for community %s', self.context.title) group_name = self.get_group_name(self.context) if self.portal_groups is not None: group_exists = self.portal_groups.getGroupById(group_name) if group_exists is None: self.portal_groups.addGroup(group_name) self.context.manage_setLocalRoles(group_name, CONTRIBUTOR_ROLES) self.context.reindexObjectSecurity() logging.info('Updated sharing settings for community %s', self.context.title) else: logging.error('Unable to access portal groups tool') else: #initialization event did not fire pass
def getLogEntry(self): ''' Get's a log entry for your action ''' event = self.event obj = event.object data = {'info': ''} # order of those checks is important since some interfaces # base off the others if IPloneFormGenField.providedBy(obj): # if ploneformgen field, use parent object for modified data data['field'] = obj.getId() obj = aq_parent(obj) # the order of those interface checks matters since some interfaces # inherit from others if IObjectRemovedEvent.providedBy(event): # need to keep track of removed events so it doesn't get called # more than once for each object action = 'removed' elif ( IObjectInitializedEvent.providedBy(event) or IObjectCreatedEvent.providedBy(event) or IObjectAddedEvent.providedBy(event) ): action = 'added' elif IObjectMovedEvent.providedBy(event): # moves can also be renames. Check the parent object if event.oldParent == event.newParent: if 'Rename' not in self.rule.rule.title: # cut out here, double action for this event return {} data['info'] = 'previous id: %s' % event.oldName action = 'rename' else: if 'Moved' not in self.rule.rule.title: # step out immediately since this could be a double action return {} data['info'] = 'previous location: %s/%s' % ( '/'.join(event.oldParent.getPhysicalPath()), event.oldName, ) action = 'moved' elif IObjectModifiedEvent.providedBy(event): action = 'modified' elif IActionSucceededEvent.providedBy(event): data['info'] = 'workflow transition: %s; comments: %s' % ( event.action, self.get_history_comment(), ) action = 'workflow' elif IObjectClonedEvent.providedBy(event): action = 'copied' elif ICheckinEvent.providedBy(event): data['info'] = event.message action = 'checked in' self.request.environ['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) obj = event.baseline elif IBeforeCheckoutEvent.providedBy(event): action = 'checked out' self.request.environ['disable.auditlog'] = True elif ICancelCheckoutEvent.providedBy(event): action = 'cancel check out' self.request.environ['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) obj = event.baseline else: logger.warn('no action matched') return {} if IWorkingCopy.providedBy(obj): # if working copy, iterate, check if Track Working Copies is # enabled if not self.trackWorkingCopies: # if not enabled, we only care about checked messages if 'check' not in action: return {} # if enabled in control panel, use original object and move # working copy path to working_copy data['working_copy'] = '/'.join(obj.getPhysicalPath()) relationships = obj.getReferences( WorkingCopyRelation.relationship) # check relationships, if none, something is wrong, not logging # action if len(relationships) <= 0: return {} obj = relationships[0] data.update(self._getObjectInfo(obj)) data['action'] = action return data
def handler(obj, evt): if not IObjectInitializedEvent.providedBy(evt): return fileHandler(obj)
def __call__(self): req = getRequest() if req.environ.get('disable.auditlog', False): return True event = self.event obj = event.object # order of those checks is important since some interfaces # base off the others rule = inspect.stack()[1][0].f_locals.get('self', None) registry = getUtility(IRegistry) trackWorkingCopies = registry['collective.auditlog.interfaces.IAuditLogSettings.trackworkingcopies'] # noqa if not self.canExecute(rule, req): return True # cut out early, we can't do this event data = { 'info': '' } if IPloneFormGenField.providedBy(obj): # if ploneformgen field, use parent object for modified data data['field'] = obj.getId() obj = aq_parent(obj) # the order of those interface checks matters since some interfaces # inherit from others if IObjectRemovedEvent.providedBy(event): # need to keep track of removed events so it doesn't get called # more than once for each object action = 'removed' elif (IObjectInitializedEvent.providedBy(event) or IObjectCreatedEvent.providedBy(event) or IObjectAddedEvent.providedBy(event)): action = 'added' elif IObjectMovedEvent.providedBy(event): # moves can also be renames. Check the parent object if event.oldParent == event.newParent: if rule is None or 'Rename' in rule.rule.title: info = {'previous_id': event.oldName} data['info'] = json.dumps(info) action = 'rename' else: # cut out here, double action for this event return True else: if rule is None or 'Moved' in rule.rule.title: parent_path = '/'.join(event.oldParent.getPhysicalPath()) previous_location = parent_path + '/' + event.oldName info = {'previous_location': previous_location} data['info'] = json.dumps(info) action = 'moved' else: # step out immediately since this could be a double action return True elif IObjectModifiedEvent.providedBy(event): action = 'modified' elif IActionSucceededEvent.providedBy(event): info = {'transition': event.action, 'comments': self.get_history_comment()} data['info'] = json.dumps(info) action = 'workflow' elif IObjectClonedEvent.providedBy(event): action = 'copied' elif ICheckinEvent.providedBy(event): info = {'message': event.message} data['info'] = json.dumps(info) action = 'checked in' req.environ['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) obj = event.baseline elif IBeforeCheckoutEvent.providedBy(event): action = 'checked out' req.environ['disable.auditlog'] = True elif ICancelCheckoutEvent.providedBy(event): action = 'cancel check out' req.environ['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) obj = event.baseline elif IUserLoggedInEvent.providedBy(event): action = 'logged in' info = {'user': event.object.getUserName()} data['info'] = json.dumps(info) elif IUserLoggedOutEvent.providedBy(event): action = 'logged out' else: logger.warn('no action matched') return True if IWorkingCopy.providedBy(obj): # if working copy, iterate, check if Track Working Copies is # enabled if trackWorkingCopies: # if enabled in control panel, use original object and move # working copy path to working_copy data['working_copy'] = '/'.join(obj.getPhysicalPath()) relationships = obj.getReferences( WorkingCopyRelation.relationship) # check relationships, if none, something is wrong, not logging # action if len(relationships) > 0: obj = relationships[0] else: return True else: # if not enabled, we only care about checked messages if 'check' not in action: return True data.update(getObjectInfo(obj)) data['action'] = action addLogEntry(obj, data) return True
def getLogEntry(self): ''' Get's a log entry for your action ''' event = self.event obj = event.object data = {'info': ''} # order of those checks is important since some interfaces # base off the others if IPloneFormGenField.providedBy(obj): # if ploneformgen field, use parent object for modified data data['field'] = obj.getId() obj = aq_parent(obj) # the order of those interface checks matters since some interfaces # inherit from others if IObjectRemovedEvent.providedBy(event): # need to keep track of removed events so it doesn't get called # more than once for each object action = 'removed' elif (IObjectInitializedEvent.providedBy(event) or IObjectCreatedEvent.providedBy(event) or IObjectAddedEvent.providedBy(event)): action = 'added' elif IObjectMovedEvent.providedBy(event): # moves can also be renames. Check the parent object if event.oldParent == event.newParent: if 'Rename' not in self.rule.rule.title: # cut out here, double action for this event return {} data['info'] = 'previous id: %s' % event.oldName action = 'rename' else: if 'Moved' not in self.rule.rule.title: # step out immediately since this could be a double action return {} data['info'] = 'previous location: %s/%s' % ( '/'.join(event.oldParent.getPhysicalPath()), event.oldName, ) action = 'moved' elif IObjectModifiedEvent.providedBy(event): action = 'modified' elif IActionSucceededEvent.providedBy(event): data['info'] = 'workflow transition: %s; comments: %s' % ( event.action, self.get_history_comment(), ) action = 'workflow' elif IObjectClonedEvent.providedBy(event): action = 'copied' elif ICheckinEvent.providedBy(event): data['info'] = event.message action = 'checked in' self.request.environ['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) obj = event.baseline elif IBeforeCheckoutEvent.providedBy(event): action = 'checked out' self.request.environ['disable.auditlog'] = True elif ICancelCheckoutEvent.providedBy(event): action = 'cancel check out' self.request.environ['disable.auditlog'] = True data['working_copy'] = '/'.join(obj.getPhysicalPath()) obj = event.baseline else: logger.warn('no action matched') return {} if IWorkingCopy.providedBy(obj): # if working copy, iterate, check if Track Working Copies is # enabled if not self.trackWorkingCopies: # if not enabled, we only care about checked messages if 'check' not in action: return {} # if enabled in control panel, use original object and move # working copy path to working_copy data['working_copy'] = '/'.join(obj.getPhysicalPath()) relationships = obj.getReferences(WorkingCopyRelation.relationship) # check relationships, if none, something is wrong, not logging # action if len(relationships) <= 0: return {} obj = relationships[0] data.update(self._getObjectInfo(obj)) data['action'] = action return data