2020-10-21 12:04:40 +00:00
|
|
|
from canaille.flaskutils import user_needed
|
2021-12-20 22:57:27 +00:00
|
|
|
from canaille.models import Client
|
|
|
|
from canaille.models import Consent
|
|
|
|
from flask import Blueprint
|
|
|
|
from flask import flash
|
|
|
|
from flask import redirect
|
|
|
|
from flask import url_for
|
|
|
|
from flask_babel import gettext
|
|
|
|
from flask_themer import render_template
|
2020-09-17 10:01:21 +00:00
|
|
|
|
|
|
|
|
2021-05-24 15:43:15 +00:00
|
|
|
bp = Blueprint("consents", __name__)
|
2020-09-17 10:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/")
|
|
|
|
@user_needed()
|
|
|
|
def consents(user):
|
|
|
|
consents = Consent.filter(oauthSubject=user.dn)
|
|
|
|
consents = [c for c in consents if not c.oauthRevokationDate]
|
2021-12-20 22:57:27 +00:00
|
|
|
client_dns = list({t.oauthClient for t in consents})
|
2020-09-17 10:01:21 +00:00
|
|
|
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")
|
|
|
|
|
2021-05-24 15:43:15 +00:00
|
|
|
return redirect(url_for("consents.consents"))
|