Share only with users from your own groups

I wanted to achive the following (in cloud mode):

  • admins can share to anybody
  • users can only share to users from their own groups

So I enabled the global address book in seahub_settings.py with

ENABLE_GLOBAL_ADDRESSBOOK = True

and used the following Seahub custom function:

import os
import sys

from seaserv import get_group_members, get_personal_groups_by_user

def custom_search_user(request, emails):

    username = request.user.username
    is_staff = request.user.is_staff

    known_users = []
    filtered_users = []

    groups = get_personal_groups_by_user(username)
    for group in groups:
        members = get_group_members(group.id)
        for member in members:
            known_users.append(member.user_name)

    for email in emails:
        if email in known_users:
            filtered_users.append(email)

    if is_staff:
        return emails
    else:
        return filtered_users