def get_object_metadata(obj, **kw): """Get object metadata :param obj: Content object :returns: Dictionary of extracted object metadata """ # inject metadata of volatile data metadata = { "actor": get_user_id(), "roles": get_roles(), "action": "", "review_state": api.get_review_status(obj), "active": api.is_active(obj), "snapshot_created": DateTime().ISO(), "modified": api.get_modification_date(obj).ISO(), "remote_address": "", "user_agent": "", "referer": "", "comments": "", } # Update request data metadata.update(get_request_data()) # allow metadata overrides metadata.update(kw) return metadata
def init_auditlog(portal): """Initialize the contents for the audit log """ # reindex the auditlog folder to display the icon right in the setup portal.bika_setup.auditlog.reindexObject() # Initialize contents for audit logging start = time.time() uid_catalog = api.get_tool("uid_catalog") brains = uid_catalog() total = len(brains) logger.info("Initializing {} objects for the audit trail...".format(total)) for num, brain in enumerate(brains): # Progress notification if num and num % 1000 == 0: transaction.commit() logger.info("{}/{} ojects initialized for audit logging".format( num, total)) # End progress notification if num + 1 == total: end = time.time() duration = float(end - start) logger.info( "{} ojects initialized for audit logging in {:.2f}s".format( total, duration)) if api.get_portal_type(brain) in SKIP_TYPES_FOR_AUDIT_LOG: continue obj = api.get_object(brain) if not supports_snapshots(obj): continue if has_snapshots(obj): continue # Take one snapshot per review history item rh = api.get_review_history(obj, rev=False) for item in rh: actor = item.get("actor") user = get_user(actor) if user: # remember the roles of the actor item["roles"] = get_roles(user) # The review history contains the variable "time" which we will set # as the "modification" time timestamp = item.pop("time", DateTime()) item["time"] = timestamp.ISO() item["modified"] = timestamp.ISO() item["remote_address"] = None take_snapshot(obj, **item)
def linkable_users(self): """Search Plone users which are not linked to a contact or lab contact """ # Only users with at nost these roles are displayed linkable_roles = {"Authenticated", "Member", "Client"} out = [] for user in self.get_users(): userid = user.get("id", None) if userid is None: continue # Skip users which are already linked to a Contact contact = Contact.getContactByUsername(userid) labcontact = LabContact.getContactByUsername(userid) if contact or labcontact: continue if self.is_contact(): # Checking Plone user belongs to Client group only. Otherwise, # weird things could happen (a client contact assigned to a # user with labman privileges, different contacts from # different clients assigned to the same user, etc.) user_roles = security.get_roles(user=userid) if not linkable_roles.issuperset(set(user_roles)): continue userdata = { "userid": userid, "email": user.get("email"), "fullname": user.get("title"), } # filter out users which do not match the searchstring if self.searchstring: s = self.searchstring.lower() if not any( map(lambda v: re.search(s, str(v).lower()), userdata.values())): continue # update data (maybe for later use) userdata.update(user) # Append the userdata for the results out.append(userdata) out.sort(lambda x, y: cmp(x["fullname"], y["fullname"])) return out