def group_add_user_action(model, request):
    """Add user to group.
    """
    user_id = request.params.get('id')
    if not user_id:
        user_ids = request.params.getall('id[]')
    else:
        user_ids = [user_id]
    try:
        group = model.model
        validate_add_users_to_groups(model, user_ids, [group.id])
        for user_id in user_ids:
            group.add(user_id)
        group()
        model.parent.invalidate(group.name)
        localizer = get_localizer(request)
        message = localizer.translate(_(
            'added_user_to_group',
            default="Added user '${uid}' to group '${gid}'.",
            mapping={
                'uid': ', '.join(user_ids),
                'gid': group.id
            }
        ))
        return {
            'success': True,
            'message': message
        }
    except ManageMembershipError as e:
        if e.reason is not LM_TARGET_UID_NOT_ALLOWED:
            raise Exception(u"Unknown ManageMembershipError reason.")
        localizer = get_localizer(request)
        message = localizer.translate(_(
            'lm_add_target_uid_not_allowed',
            default=(
                "Failed adding user '${uid}' to group '${gid}'. "
                "Manage membership denied for user."
            ),
            mapping={
                'uid': e.data,
                'gid': group.id
            }
        ))
        return {
            'success': False,
            'message': message
        }
    except Exception as e:
        return {
            'success': False,
            'message': str(e)
        }
def group_add_user_action ( model , request ) : user_id = request . params . get ( 'id' ) if not user_id : user_ids = request . params . getall ( 'id[]' ) else : user_ids = [ user_id ] try : group = model . model validate_add_users_to_groups ( model , user_ids , [ group . id ] ) for user_id in user_ids : group . add ( user_id ) group ( ) model . parent . invalidate ( group . name ) localizer = get_localizer ( request ) message = localizer . translate ( _ ( 'added_user_to_group' , default = "Added user '${uid}' to group '${gid}'." , mapping = { 'uid' : ', ' . join ( user_ids ) , 'gid' : group . id } ) ) return { 'success' : True , 'message' : message } except ManageMembershipError as e : if e . reason is not LM_TARGET_UID_NOT_ALLOWED : raise Exception ( u"Unknown ManageMembershipError reason." ) localizer = get_localizer ( request ) message = localizer . translate ( _ ( 'lm_add_target_uid_not_allowed' , default = ( "Failed adding user '${uid}' to group '${gid}'. " "Manage membership denied for user." ) , mapping = { 'uid' : e . data , 'gid' : group . id } ) ) return { 'success' : False , 'message' : message } except Exception as e : return { 'success' : False , 'message' : str ( e ) }
Add user to group.