Example #1
0
 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)
Example #2
0
    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
Example #3
0
    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
Example #4
0
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)
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
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)
Example #9
0
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)
Example #10
0
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"
Example #12
0
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)
Example #13
0
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)
Example #14
0
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)
Example #15
0
    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
Example #16
0
 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)
Example #17
0
 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)