Beispiel #1
0
def notify_org_data_changed(org, user, changes, team=None):
    """
    Like :func:`notify_user_data_changed`, except we'll also look at
    all other owners of this org to find apps that need to be notified.
    """
    client_users = {}
    if team is not None:
        team_access = set(org.clients_with_team_access()) | (set(
            user.clients_with_team_access()) if user else set())
    else:
        team_access = []
    for token in AuthToken.all(users=org.owners.users):
        if ('organizations' in token.effective_scope
                or 'organizations/*' in token.effective_scope
            ) and token.client.notification_uri and token.is_valid():
            if team is not None:
                if token.client not in team_access:
                    continue
            client_users.setdefault(token.client, []).append(token.user)
    # Now we have a list of clients to notify and a list of users to notify them with
    for client, users in client_users.items():
        if user is not None and user in users:
            notify_user = user
        else:
            notify_user = users[0]  # First user available
        send_notice.delay(
            client.notification_uri,
            data={
                'userid': notify_user.buid,  # XXX: Deprecated parameter
                'buid': notify_user.buid,
                'type': 'org' if team is None else 'team',
                'orgid': org.buid,
                'teamid': team.buid if team is not None else None,
                'changes': changes,
            })
Beispiel #2
0
def notify_org_data_changed(org, user, changes, team=None):
    """
    Like :func:`notify_user_data_changed`, except we'll also look at
    all other owners of this org to find apps that need to be notified.
    """
    client_users = {}
    if team is not None:
        team_access = set(org.clients_with_team_access()) | (set(user.clients_with_team_access()) if user else set())
    else:
        team_access = []
    for token in AuthToken.all(users=org.owners.users):
        if ('organizations' in token.effective_scope or 'organizations/*' in token.effective_scope) and token.client.notification_uri and token.is_valid():
            if team is not None:
                if token.client not in team_access:
                    continue
            client_users.setdefault(token.client, []).append(token.user)
    # Now we have a list of clients to notify and a list of users to notify them with
    for client, users in client_users.items():
        if user is not None and user in users:
            notify_user = user
        else:
            notify_user = users[0]  # First user available
        send_notice.delay(client.notification_uri, data={
            'userid': notify_user.buid,  # XXX: Deprecated parameter
            'buid': notify_user.buid,
            'type': 'org' if team is None else 'team',
            'orgid': org.buid,
            'teamid': team.buid if team is not None else None,
            'changes': changes,
            })