def test_find_peopledirectory_catalog(self): from karl.utils import find_peopledirectory_catalog context = testing.DummyModel() self.assertEqual(find_peopledirectory_catalog(context), None) people = context['people'] = testing.DummyModel() people.catalog = testing.DummyModel() self.failUnless( find_peopledirectory_catalog(context) is people.catalog)
def get_active_letters(self): report = self.context catalog = find_peopledirectory_catalog(report) # Use the lastnamestartswith index directly for speed. index = catalog["lastnamestartswith"] filters = [(name, obj) for name, obj in report.items() if IPeopleReportFilter.providedBy(obj)] if not filters: # Any letter in the index will suffice. This is a fast # common case. # XXX using undocumented _fwd_index attribute return set(index._fwd_index.keys()) # Perform a catalog search, but don't resolve any paths. kw = {} for catid, filter in filters: if IPeopleReportCategoryFilter.providedBy(filter): kw["category_%s" % str(catid)] = {"query": filter.values, "operator": "or"} elif IPeopleReportGroupFilter.providedBy(filter): kw["groups"] = {"query": filter.values, "operator": "or"} total, docids = catalog.search(**kw) # Intersect the search result docids with the docid set # for each letter. docid_set = index.family.IF.Set(docids) active = set() intersection = index.family.IF.intersection for letter in string.uppercase: # XXX using undocumented _fwd_index attribute letter_set = index._fwd_index.get(letter) if not letter_set: continue if intersection(letter_set, docid_set): active.add(letter) return active
def get_active_letters(self): report = self.context catalog = find_peopledirectory_catalog(report) # Use the lastnamestartswith index directly for speed. index = catalog['lastnamestartswith'] if not report.filters and not report.query: # Any letter in the index will suffice. This is a fast # common case. # XXX using undocumented _fwd_index attribute return set(index._fwd_index.keys()) # Perform a catalog search, but don't resolve any paths. kw = {} if report.query: kw.update(report.query) for catid, values in report.filters.items(): kw['category_%s' % catid] = {'query': values, 'operator': 'or'} total, docids = catalog.search(**kw) # Intersect the search result docids with the docid set # for each letter. docid_set = index.family.IF.Set(docids) active = set() intersection = index.family.IF.intersection for letter in string.uppercase: # XXX using undocumented _fwd_index attribute letter_set = index._fwd_index.get(letter) if not letter_set: continue if intersection(letter_set, docid_set): active.add(letter) return active
def _reindex_peopledir(profile): catalog = find_peopledirectory_catalog(profile) # The docid stored as an attribute on the profile is the docid for the main # site catalog. The peopledir catalog has a different set of docids, so it # is necessary to consult the document map. path = resource_path(profile) docid = catalog.document_map.docid_for_address(path) catalog.reindex_doc(docid, profile)
def reindex_profile(obj, event): """ Reindex a single piece of profile (non-recursive); an IObjectModifed event subscriber """ catalog = find_peopledirectory_catalog(obj) if catalog is not None: path = resource_path(obj) docid = catalog.document_map.docid_for_address(path) catalog.unindex_doc(docid) catalog.index_doc(docid, obj)
def reindex_profile_after_group_change(event): """ Subscriber for group change events to reindex the profile in peopledir catalog """ profiles = find_profiles(event.site) profile = profiles.get(event.id) if profile is not None: catalog = find_peopledirectory_catalog(profile) if catalog is not None: path = resource_path(profile) docid = catalog.document_map.docid_for_address(path) catalog.unindex_doc(docid) catalog.index_doc(docid, profile)
def index_profile(obj, event): """ Index profile (an IObjectAddedEvent subscriber) """ catalog = find_peopledirectory_catalog(obj) if catalog is not None: for node in postorder(obj): if IProfile.providedBy(node): path = resource_path(node) docid = getattr(node, 'docid', None) if docid is None: docid = node.docid = catalog.document_map.add(path) else: catalog.document_map.add(path, docid) catalog.index_doc(docid, node)
def dump_senders(args, instance): root, closer = args.get_root(instance) set_current_instance(instance) set_subsystem('dump_senders') pc = find_peopledirectory_catalog(root) for email in pc['email']._fwd_index.keys(): if ',' in email: for e in email.split(','): if not e.isspace() and len(e) != 0: print e.strip() + " permit_auth_destination" else: if not email.isspace() and len(email) != 0: print email.strip() + " permit_auth_destination"
def unindex_profile(obj, event): """ Unindex profile (an IObjectWillBeRemovedEvent subscriber) """ catalog = find_peopledirectory_catalog(obj) if catalog is not None: path = resource_path(obj) path_docid = catalog.document_map.docid_for_address(path) num, docids = catalog.search(path=path) for docid in docids: # unindex any children of the path first catalog.unindex_doc(docid) catalog.document_map.remove_docid(docid) if path_docid is not None: # and then finally the parent catalog.unindex_doc(path_docid) catalog.document_map.remove_docid(path_docid)
def evolve(context): """ Remove any people directory categories set for non-Staff users. """ profiles = find_profiles(context) users = find_users(context) catalog = find_peopledirectory_catalog(context) docid_for_address = catalog.document_map.docid_for_address for profile in profiles.values(): user = users.get_by_id(profile.__name__) if user is None: continue if 'group.KarlStaff' not in user['groups']: if getattr(profile, 'categories', None): print "Removing categories for", profile.__name__ profile.categories = {} docid = docid_for_address(model_path(profile)) catalog.reindex_doc(docid, profile)
def get_active_letters(self): report = self.context catalog = find_peopledirectory_catalog(report) # Use the lastnamestartswith index directly for speed. index = catalog['lastnamestartswith'] filters = [(name, obj) for name, obj in report.items() if IPeopleReportFilter.providedBy(obj)] if not filters: # Any letter in the index will suffice. This is a fast # common case. # XXX using undocumented _fwd_index attribute return set(index._fwd_index.keys()) # Perform a catalog search, but don't resolve any paths. kw = {} for catid, filter in filters: if IPeopleReportCategoryFilter.providedBy(filter): kw['category_%s' % str(catid)] = { 'query': filter.values, 'operator': 'or', } elif IPeopleReportGroupFilter.providedBy(filter): kw['groups'] = { 'query': filter.values, 'operator': 'or', } total, docids = catalog.search(**kw) # Intersect the search result docids with the docid set # for each letter. docid_set = index.family.IF.Set(docids) active = set() intersection = index.family.IF.intersection for letter in string.uppercase: # XXX using undocumented _fwd_index attribute letter_set = index._fwd_index.get(letter) if not letter_set: continue if intersection(letter_set, docid_set): active.add(letter) return active
def __init__(self, context, request=None): # XXX request argument is not used, is left in for backwards # compatability. Should be phased out. self.context = context self.catalog = find_peopledirectory_catalog(context)