canaille-globuzma/canaille/consents.py

35 lines
1 KiB
Python
Raw Normal View History

2020-09-17 10:01:21 +00:00
from flask import Blueprint, render_template, flash, redirect, url_for
from flask_babel import gettext
2020-10-21 12:04:40 +00:00
from canaille.models import Consent, Client
from canaille.flaskutils import user_needed
2020-09-17 10:01:21 +00:00
bp = Blueprint(__name__, "consents")
@bp.route("/")
@user_needed()
def consents(user):
consents = Consent.filter(oauthSubject=user.dn)
consents = [c for c in consents if not c.oauthRevokationDate]
client_dns = list(set(t.oauthClient for t in consents))
clients = {dn: Client.get(dn) for dn in client_dns}
2020-10-21 10:14:35 +00:00
return render_template(
"consent_list.html", consents=consents, clients=clients, menuitem="consents"
)
2020-09-17 10:01:21 +00:00
@bp.route("/delete/<consent_id>")
@user_needed()
def delete(user, consent_id):
consent = Consent.get(consent_id)
if not consent or consent.oauthSubject != user.dn:
flash(gettext("Could not delete this access"), "error")
else:
consent.revoke()
flash(gettext("The access has been revoked"), "success")
2020-10-21 12:04:40 +00:00
return redirect(url_for("canaille.consents.consents"))