def _emit(self, event): # Get community in which event occurred and alert members community = find_community(event['content']) if not community: log.warning('No community found for event: %s' % str(event)) return profiles = find_profiles(event['content']) all_names = community.member_names | community.moderator_names for profile in [profiles[name] for name in all_names]: self.emit_to_user(profile, community, event)
def __call__(self, docid): site = self.context.site catalog = find_catalog(site) if catalog is None: raise ValueError('No catalog') path = catalog.document_map.address_for_docid(docid) if path is None: raise KeyError(docid) doc = find_model(site, path) community = find_community(doc) return community and community.__name__ or None
def emit_to_user(self, profile, event): alerts_on = get_setting(profile, 'alert_notifications_on', 'true') if not asbool(alerts_on): log.debug('alert notifications are disabled, alert not sent.') return alert = event # flag alerts are treated differently. Just send straight to admin # not the flagged user. if isinstance(alert, FlagAlert): log.info('flag alert received. sending directly to admin only.') self._send_immediately(alert) return def action_pref(pref, alert): if pref == IProfile.ALERT_DIGEST: self._queue_digest(alert, profile) elif pref == IProfile.ALERT_IMMEDIATELY: self._send_immediately(alert) alerts_inbox_on = get_setting(profile, 'alert_notifications_inbox_on', 'false') if not asbool(alerts_inbox_on): log.debug('alert inbox notifications are disabled, alert not sent ' 'to inbox.') else: # preferences not used for inbox, alert always sent self._send_to_inbox(alert, profile) # profile alerts are for content that does not belong to a community # such as profile comments if alert.is_profile_alert: log.debug('profile alert') action_pref(profile.get_alerts_preference('profile'), alert) return community = find_community(event['content']) if community: community_pref = profile.get_alerts_preference(community.__name__) log.debug('alert received for user: %s, alert: %s, in community: ' '%s with pref:%s' % (profile.__name__, str(alert), community.__name__, community_pref)) action_pref(community_pref, alert) return # site preference e.g. for hcd stories action_pref(profile.get_alerts_preference('site'), alert)
def _find_dst_container(src_obj, dst_community): """ Given a source object and a destination community, figures out the container insider the destination community where source object can be moved to. For example, if source object is a blog entry in community `foo` (/communities/foo/blog/entry1) and we want to move it to the `bar` community, this will take the relative path of the source object from its community and attempt to find analogous containers inside of the destination community. In this example, the relative container path is 'blog', so we the destination container is /communities/bar/blog.' """ src_container_path = model_path(src_obj.__parent__) src_community_path = model_path(find_community(src_obj)) rel_container_path = src_container_path[len(src_community_path):] dst_container = dst_community for node_name in filter(None, rel_container_path.split('/')): dst_container = dst_container.get(node_name, None) if dst_container is None: raise _DstNotFound( 'Path does not exist in destination community: %s' % model_path(dst_community) + rel_container_path ) return dst_container
def community(self): if not self._community: self._community = find_community(self.context) return self._community
def move_content(root, src, dst, wf_state): try: context = find_model(root, src) except KeyError: print >>sys.stderr, "Source content not found: %s" % src sys.exit(-1) try: dest_folder = find_model(root, dst) except KeyError: print >>sys.stderr, "Destination folder not found: %s" % dst sys.exit(-1) src_community = find_community(context) catalog = find_catalog(root) assert catalog is not None users = find_users(root) assert users is not None if src_community is not None: move_header = ('<p><em>This was originally authored ' 'in the "%s" community.</em></p>' % src_community.title) else: move_header = '' src_folder = context.__parent__ name = context.__name__ log.info("Moving %s", model_path(context)) for obj in postorder(context): if hasattr(obj, 'docid'): docid = obj.docid catalog.document_map.remove_docid(docid) catalog.unindex_doc(docid) del src_folder[name] if (context.creator != 'admin' and users.get_by_id(context.creator) is None): # give the entry to the system admin log.warning( "User %s not found; reassigning to admin", context.creator) context.creator = 'admin' if name in dest_folder: name = make_unique_name(dest_folder, context.title) dest_folder[name] = context for obj in postorder(context): if hasattr(obj, 'docid'): docid = obj.docid catalog.document_map.add(model_path(obj), docid) catalog.index_doc(docid, obj) if wf_state is not None: wf = get_workflow(get_content_type(context), 'security', context) wf.transition_to_state(context, None, wf_state) if hasattr(context, 'text'): context.text = "%s\n%s" % (move_header, context.text)