Exemple #1
0
def send_blinker_signal_roles_changed(user, original):
    """Sends a Blinker signal that the user roles were changed, so others can respond."""

    current_roles = set(user.get('roles', []))
    original_roles = set(original.get('roles', []))

    if current_roles == original_roles:
        return

    from pillar.api.service import signal_user_changed_role

    log.info('User %s changed roles to %s, sending Blinker signal',
             user.get('_id'), current_roles)
    signal_user_changed_role.send(current_app, user=user)
Exemple #2
0
def after_inserting_users(user_docs):
    """Moves the users from the unknown_members to the members list of their organizations."""

    om = current_app.org_manager
    for user_doc in user_docs:
        user_id = user_doc.get('_id')
        user_email = user_doc.get('email')

        if not user_id or not user_email:
            # Missing emails can happen when creating a service account, it's fine.
            log.info(
                'User created with _id=%r and email=%r, unable to check organizations',
                user_id, user_email)
            continue

        om.make_member_known(user_id, user_email)
Exemple #3
0
def grant_org_roles(user_doc):
    """Handle any organization this user may be part of."""

    email = user_doc.get('email')
    if not email:
        log.warning(
            'Unable to check new user for organization membership, no email address! %r',
            user_doc)
        return

    org_roles = current_app.org_manager.unknown_member_roles(email)
    if not org_roles:
        log.debug('No organization roles for user %r', email)
        return

    log.info('Granting organization roles %r to user %r', org_roles, email)
    new_roles = set(user_doc.get('roles') or []) | org_roles
    user_doc['roles'] = list(new_roles)