From f69bc8fc1eca27335953bdd04d1ca20b74024ad4 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 29 Sep 2024 13:35:49 +0100 Subject: [PATCH] Fix ungraceful error on non-unique OAuthClient title --- app/blueprints/oauth/__init__.py | 5 +++++ app/templates/oauth/create_edit.html | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/blueprints/oauth/__init__.py b/app/blueprints/oauth/__init__.py index 02368095..6a46b839 100644 --- a/app/blueprints/oauth/__init__.py +++ b/app/blueprints/oauth/__init__.py @@ -194,6 +194,10 @@ def create_edit_client(username, id_=None): if form.validate_on_submit(): if is_new: + if OAuthClient.query.filter(OAuthClient.title.ilike(form.title.data.strip())).count() > 0: + flash(gettext("An OAuth client with that title already exists. Please choose a new title."), "danger") + return render_template("oauth/create_edit.html", user=user, form=form, client=client) + client = OAuthClient() db.session.add(client) client.owner = user @@ -201,6 +205,7 @@ def create_edit_client(username, id_=None): client.secret = random_string(32) client.approved = current_user.rank.at_least(UserRank.EDITOR) + form.populate_obj(client) verb = "Created" if is_new else "Edited" diff --git a/app/templates/oauth/create_edit.html b/app/templates/oauth/create_edit.html index 862a4711..4cdf67c9 100644 --- a/app/templates/oauth/create_edit.html +++ b/app/templates/oauth/create_edit.html @@ -64,8 +64,8 @@
{{ form.hidden_tag() }} - {{ render_field(form.title) }} - {{ render_field(form.description, hint=_("Shown to users when you request access to their account")) }} + {{ render_field(form.title, hint=_("Titles must be globally unique. For example, what's the name of your application?")) }} + {{ render_field(form.description, hint=_("Shown to users when you request access to their account. For example, what does your application do?")) }} {{ render_field(form.redirect_url) }} {{ render_field(form.app_type, hint=_("Where will you store your client_secret?")) }}