2020-10-21 12:04:40 +00:00
|
|
|
from canaille.flaskutils import user_needed
|
2022-01-11 18:49:06 +00:00
|
|
|
from canaille.oidc.models import Client
|
|
|
|
from canaille.oidc.models import Consent
|
2021-12-20 22:57:27 +00:00
|
|
|
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
|
|
|
|
2022-12-28 00:46:05 +00:00
|
|
|
from .utils import SCOPE_DETAILS
|
|
|
|
|
2020-09-17 10:01:21 +00:00
|
|
|
|
2022-01-11 18:49:06 +00:00
|
|
|
bp = Blueprint("consents", __name__, url_prefix="/consent")
|
2020-09-17 10:01:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@bp.route("/")
|
|
|
|
@user_needed()
|
|
|
|
def consents(user):
|
2022-01-11 16:57:58 +00:00
|
|
|
consents = Consent.filter(subject=user.dn)
|
|
|
|
consents = [c for c in consents if not c.revokation_date]
|
|
|
|
client_dns = list({t.client 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(
|
2022-01-11 18:49:06 +00:00
|
|
|
"oidc/user/consent_list.html",
|
|
|
|
consents=consents,
|
|
|
|
clients=clients,
|
|
|
|
menuitem="consents",
|
2022-12-28 00:46:05 +00:00
|
|
|
scope_details=SCOPE_DETAILS,
|
|
|
|
ignored_scopes=["openid"],
|
2020-10-21 10:14:35 +00:00
|
|
|
)
|
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)
|
|
|
|
|
2022-01-11 16:57:58 +00:00
|
|
|
if not consent or consent.subject != user.dn:
|
2020-09-17 10:01:21 +00:00
|
|
|
flash(gettext("Could not delete this access"), "error")
|
|
|
|
|
|
|
|
else:
|
|
|
|
consent.revoke()
|
|
|
|
flash(gettext("The access has been revoked"), "success")
|
|
|
|
|
2022-01-11 18:49:06 +00:00
|
|
|
return redirect(url_for("oidc.consents.consents"))
|