Exemple #1
0
def discover_community_members_json(context, request):
    """ Return users who share a community with the given user.

    Query string may include:

    - 'userid':  the user whose communities we enumerate (defaults to the
                 current user).
    """
    users = find_users(context)
    userid = request.GET.get('userid', None)
    if userid is None:
        userid = authenticated_userid(request)
        principals = effective_principals(request)
        communities = [x[0] for x in get_community_groups(principals)]
    else:
        info = users.get(userid)
        communities = [x[0] for x in get_community_groups(info['groups'])]
    c_groups = [(x,
                 _quippers_from_users(
                     context, request,
                     users.users_in_group('group.community:%s:members' % x)))
                for x in communities]
    return {
        'userid': userid,
        'members': dict(c_groups),
    }
Exemple #2
0
def to_profile_active(ob, info):
    acl = [
        (Allow, ob.creator, MEMBER_PERMS + ('view_only', )),
    ]
    acl.append(
        (Allow, 'group.KarlUserAdmin', ADMINISTRATOR_PERMS + ('view_only', )))
    acl.append(
        (Allow, 'group.KarlAdmin', ADMINISTRATOR_PERMS + ('view_only', )))
    acl.append((Allow, 'group.KarlStaff', GUEST_PERMS + ('view_only', )))
    users = find_users(ob)
    user = users.get_by_id(ob.creator)
    if user is not None:
        groups = user['groups']
        for group, role in get_community_groups(groups):
            c_group = 'group.community:%s:%s' % (group, role)
            acl.append((Allow, c_group, GUEST_PERMS + ('view_only', )))
    acl.append((Allow, 'system.Authenticated', ('view_only', )))
    acl.append(NO_INHERIT)
    msg = None
    added, removed = acl_diff(ob, acl)
    if added or removed:
        ob.__acl__ = acl
        msg = ts('to-active', resource_path(ob), added, removed)
    _reindex(ob, texts=True)
    _reindex_peopledir(ob)
    return msg
Exemple #3
0
def to_profile_active(ob, info):
    acl  = [
        (Allow, ob.creator, MEMBER_PERMS + ('view_only',)),
    ]
    acl.append((Allow, 'group.KarlUserAdmin',
                ADMINISTRATOR_PERMS + ('view_only',)))
    acl.append((Allow, 'group.KarlAdmin',
                ADMINISTRATOR_PERMS + ('view_only',)))
    acl.append((Allow, 'group.KarlStaff',
                GUEST_PERMS + ('view_only',)))
    users = find_users(ob)
    user = users.get_by_id(ob.creator)
    if user is not None:
        groups = user['groups']
        for group, role in get_community_groups(groups):
            c_group = 'group.community:%s:%s' % (group, role)
            acl.append((Allow, c_group, GUEST_PERMS + ('view_only',)))
    acl.append((Allow, 'system.Authenticated', ('view_only',)))
    acl.append(NO_INHERIT)
    msg = None
    added, removed = acl_diff(ob, acl)
    if added or removed:
        ob.__acl__ = acl
        msg = ts('to-active', resource_path(ob), added, removed)
    _reindex(ob, texts=True)
    _reindex_peopledir(ob)
    return msg
Exemple #4
0
def discover_community_members_json(context, request):
    """ Return users who share a community with the given user.

    Query string may include:

    - 'userid':  the user whose communities we enumerate (defaults to the
                 current user).
    """
    users = find_users(context)
    userid = request.GET.get('userid', None)
    if userid is None:
        userid = authenticated_userid(request)
        principals = effective_principals(request)
        communities = [x[0] for x in get_community_groups(principals)]
    else:
        info = users.get(userid)
        communities = [x[0] for x in get_community_groups(info['groups'])]
    c_groups = [(x, _quippers_from_users(context, request,
         users.users_in_group('group.community:%s:members' % x)))
         for x in communities]
    return {'userid': userid,
            'members': dict(c_groups),
           }
Exemple #5
0
def my_communities_chatter_json(context, request):
    """ Return recent chatter mentioning current user's communities.

    Query string may include:

    - 'start':  the item index at which to begin including items.
    - 'count':  the maximun number of items to return.
    - 'before':  a string timestamp (in timeago format);  include items
                 which are older than the indicated time.
    - 'since':  a string timestamp (in timeago format);  include items
                which are newer than the indicated time.  Note that we
                return the *last* 'count' items newer than the supplied
                value.
    """
    principals = effective_principals(request)
    communities = [x[0] for x in get_community_groups(principals)]
    chatter = find_chatter(context)
    return {'communities': communities,
            'recent': _do_slice(
                      chatter.recentWithCommunities(*communities), request),
           }
Exemple #6
0
def to_profile(ob, info):
    acl  = [
        (Allow, ob.creator, MEMBER_PERMS),
    ]
    acl.append((Allow, 'group.KarlUserAdmin', ADMINISTRATOR_PERMS))
    acl.append((Allow, 'group.KarlAdmin', ADMINISTRATOR_PERMS))
    acl.append((Allow, 'group.KarlStaff', GUEST_PERMS))
    users = find_users(ob)
    user = users.get_by_id(ob.creator)
    if user is not None:
        groups = user['groups']
        for group, role in get_community_groups(groups):
            c_group = 'group.community:%s:%s' % (group, role)
            acl.append((Allow, c_group, GUEST_PERMS))
    acl.append(NO_INHERIT)
    msg = None
    added, removed = acl_diff(ob, acl)
    if added or removed:
        ob.__acl__ = acl
        msg = ts('to-profile', model_path(ob), added, removed)
    _reindex(ob)
    return msg
Exemple #7
0
def my_communities_chatter_json(context, request):
    """ Return recent chatter mentioning current user's communities.

    Query string may include:

    - 'start':  the item index at which to begin including items.
    - 'count':  the maximun number of items to return.
    - 'before':  a string timestamp (in timeago format);  include items
                 which are older than the indicated time.
    - 'since':  a string timestamp (in timeago format);  include items
                which are newer than the indicated time.  Note that we
                return the *last* 'count' items newer than the supplied
                value.
    """
    principals = effective_principals(request)
    communities = [x[0] for x in get_community_groups(principals)]
    chatter = find_chatter(context)
    return {
        'communities': communities,
        'recent': _do_slice(chatter.recentWithCommunities(*communities),
                            request),
    }
 def _callFUT(self, principals):
     from karl.views.communities import get_community_groups
     return get_community_groups(principals)
Exemple #9
0
 def _callFUT(self, principals):
     from karl.views.communities import get_community_groups
     return get_community_groups(principals)