Beispiel #1
0
def other_permissions_form(id_role, id_filter_type, id_permission=None):
    """
    Form to define permisisons for a user expect SCOPE permissions
    .. :quickref: View_Permission;
    """
    if id_permission:
        perm = DB.session.query(CorRoleActionFilterModuleObject).get(
            id_permission)
        form = OtherPermissionsForm(
            id_filter_type,
            action=perm.id_action,
            filter=perm.id_filter,
            module=perm.id_module,
        )
    else:
        form = OtherPermissionsForm(id_filter_type)
    user = DB.session.query(User).get(id_role).as_dict()
    filter_type = DB.session.query(BibFiltersType).get(id_filter_type)

    if request.method == "POST" and form.validate_on_submit():

        permInstance = CorRoleActionFilterModuleObject(
            id_permission=id_permission,
            id_role=id_role,
            id_action=int(form.data["action"]),
            id_filter=int(form.data["filter"]),
            id_module=int(form.data["module"]),
        )
        if id_permission:
            DB.session.merge(permInstance)
        else:
            DB.session.add(permInstance)
        DB.session.commit()

        return redirect(
            url_for("gn_permissions_backoffice.user_other_permissions",
                    id_role=id_role))

    return render_template("other_permissions_form.html",
                           user=user,
                           form=form,
                           filter_type=filter_type)
Beispiel #2
0
def other_permissions_form(id_role, id_filter_type, id_permission=None):
    """
    Form to define permisisons for a user expect SCOPE permissions
    """
    if id_permission:
        perm = DB.session.query(CorRoleActionFilterModuleObject).get(id_permission)
        form = OtherPermissionsForm(
            id_filter_type,
            action=perm.id_action,
            filter=perm.id_filter,
            module=perm.id_module
        )
    else:
        form = OtherPermissionsForm(id_filter_type)
    user = DB.session.query(User).get(id_role).as_dict()
    filter_type = DB.session.query(BibFiltersType).get(id_filter_type)
    
    if request.method == 'POST' and form.validate_on_submit():
        
        permInstance = CorRoleActionFilterModuleObject(
            id_permission=id_permission,
            id_role=id_role,
            id_action=int(form.data['action']),
            id_filter=int(form.data['filter']),
            id_module=int(form.data['module']),
        )
        if id_permission:
            DB.session.merge(permInstance)
        else:
            DB.session.add(permInstance)
        DB.session.commit()
        
        return redirect(url_for('gn_permissions_backoffice.user_other_permissions', id_role=id_role))

    return render_template(
        'other_permissions_form.html',
        user=user,
        form=form,
        filter_type=filter_type,
    )