Exemplo n.º 1
0
def remove_user_from_service(service_id, user_id):
    user = user_api_client.get_user(user_id)
    # Need to make the email address read only, or a disabled field?
    # Do it through the template or the form class?
    form = PermissionsForm(
        **{
            role: user.has_permission_for_service(service_id, role)
            for role in roles.keys()
        })

    if request.method == 'POST':
        try:
            service_api_client.remove_user_from_service(service_id, user_id)
        except HTTPError as e:
            msg = "You cannot remove the only user for a service"
            if e.status_code == 400 and msg in e.message:
                flash(msg, 'info')
                return redirect(url_for('.manage_users',
                                        service_id=service_id))
            else:
                abort(500, e)

        return redirect(url_for('.manage_users', service_id=service_id))

    flash('Are you sure you want to remove {}?'.format(user.name), 'remove')
    return render_template('views/edit-user-permissions.html',
                           user=user,
                           form=form)
Exemplo n.º 2
0
def remove_user_from_service(service_id, user_id):
    user = user_api_client.get_user(user_id)
    # Need to make the email address read only, or a disabled field?
    # Do it through the template or the form class?
    form = PermissionsForm(**{
        role: user.has_permissions(permissions=permissions) for role, permissions in roles.items()
        })

    if request.method == 'POST':
        try:
            service_api_client.remove_user_from_service(service_id, user_id)
        except HTTPError as e:
            msg = "You cannot remove the only user for a service"
            if e.status_code == 400 and msg in e.message:
                flash(msg, 'info')
                return redirect(url_for(
                    '.manage_users',
                    service_id=service_id))
            else:
                abort(500, e)

        return redirect(url_for(
            '.manage_users',
            service_id=service_id
        ))

    flash('Are you sure you want to remove {}?'.format(user.name), 'remove')
    return render_template(
        'views/edit-user-permissions.html',
        user=user,
        form=form
    )
Exemplo n.º 3
0
def remove_user_from_service(service_id, user_id):
    try:
        service_api_client.remove_user_from_service(service_id, user_id)
    except HTTPError as e:
        msg = "You cannot remove the only user for a service"
        if e.status_code == 400 and msg in e.message:
            flash(msg, 'info')
            return redirect(url_for('.manage_users', service_id=service_id))
        else:
            abort(500, e)

    return redirect(url_for('.manage_users', service_id=service_id))
def remove_user_from_service(service_id, user_id):
    user = user_api_client.get_user(user_id)
    form = PermissionsForm.from_user(user, service_id)

    if request.method == 'POST':
        try:
            service_api_client.remove_user_from_service(service_id, user_id)
        except HTTPError as e:
            msg = "You cannot remove the only user for a service"
            if e.status_code == 400 and msg in e.message:
                flash(msg, 'info')
                return redirect(url_for('.manage_users',
                                        service_id=service_id))
            else:
                abort(500, e)

        return redirect(url_for('.manage_users', service_id=service_id))

    flash('Are you sure you want to remove {}?'.format(user.name), 'remove')
    return render_template('views/edit-user-permissions.html',
                           user=user,
                           form=form)