canaille-globuzma/canaille/oidc/authorizations.py

37 lines
1.1 KiB
Python
Raw Normal View History

2021-12-20 22:57:27 +00:00
from canaille.flaskutils import permissions_needed
from canaille.flaskutils import render_htmx_template
from canaille.forms import TableForm
2022-01-11 18:49:06 +00:00
from canaille.oidc.models import AuthorizationCode
from flask import abort
from flask import Blueprint
from flask import request
from flask_themer import render_template
2020-08-26 14:27:08 +00:00
2022-01-11 18:49:06 +00:00
bp = Blueprint("authorizations", __name__, url_prefix="/admin/authorization")
2020-08-26 14:27:08 +00:00
@bp.route("/", methods=["GET", "POST"])
2021-12-02 17:23:14 +00:00
@permissions_needed("manage_oidc")
2020-10-29 10:09:31 +00:00
def index(user):
table_form = TableForm(AuthorizationCode, formdata=request.form)
if request.form and request.form.get("page") and not table_form.validate():
abort(404)
return render_htmx_template(
"oidc/admin/authorization_list.html",
menuitem="admin",
table_form=table_form,
2020-08-27 08:50:50 +00:00
)
2020-08-26 14:27:08 +00:00
@bp.route("/<authorization_id>", methods=["GET", "POST"])
2021-12-02 17:23:14 +00:00
@permissions_needed("manage_oidc")
2020-10-29 10:09:31 +00:00
def view(user, authorization_id):
2020-08-26 14:27:08 +00:00
authorization = AuthorizationCode.get(authorization_id)
2020-10-21 10:14:35 +00:00
return render_template(
2022-01-11 18:49:06 +00:00
"oidc/admin/authorization_view.html",
authorization=authorization,
menuitem="admin",
2020-10-21 10:14:35 +00:00
)