Explicitly use User.formatted_name instead of User.name

This commit is contained in:
Éloi Rivard 2023-04-07 22:45:42 +02:00
parent 087ec1ef58
commit 52f7276527
11 changed files with 38 additions and 33 deletions

View file

@ -134,7 +134,10 @@ def password():
)
del session["attempt_login"]
flash(_("Connection successful. Welcome %(user)s", user=user.name), "success")
flash(
_("Connection successful. Welcome %(user)s", user=user.formatted_name[0]),
"success",
)
return redirect(url_for("account.index"))
return render_template(
@ -147,7 +150,10 @@ def logout():
user = current_user()
if user:
flash(
_("You have been disconnected. See you next time %(user)s", user=user.name),
_(
"You have been disconnected. See you next time %(user)s",
user=user.formatted_name[0],
),
"success",
)
user.logout()
@ -613,7 +619,10 @@ def profile_delete(user, edited_user):
user.logout()
flash(
_("The user %(user)s has been sucessfuly deleted", user=edited_user.name),
_(
"The user %(user)s has been sucessfuly deleted",
user=edited_user.formatted_name[0],
),
"success",
)
edited_user.delete()
@ -665,7 +674,7 @@ def forgotten():
_(
"The user '%(user)s' does not have permissions to update their password. "
"We cannot send a password reset email.",
user=user.name,
user=user.formatted_name[0],
),
"error",
)

View file

@ -129,10 +129,6 @@ class User(LDAPObject):
password.encode("utf-8"),
)
@property
def name(self):
return self.formatted_name[0]
@property
def groups(self):
if self._groups is None:

View file

@ -295,7 +295,7 @@ class IntrospectionEndpoint(_IntrospectionEndpoint):
"active": True,
"client_id": token.client.client_id,
"token_type": token.type,
"username": token.subject.name,
"username": token.subject.formatted_name[0],
"scope": token.get_scope(),
"sub": token.subject.user_name[0],
"aud": audience,

View file

@ -30,7 +30,7 @@
</div>
<div class="ui center aligned container">
{{ gettext('You are logged in as %(name)s', name=user.name) }}
{{ gettext('You are logged in as %(name)s', name=user.formatted_name[0]) }}
</div>
<div class="ui center aligned container">

View file

@ -11,7 +11,7 @@
</h2>
<div class="ui message">
<p>
{{ _("You are currently logged in as %(username)s.", username=user.name) }}
{{ _("You are currently logged in as %(username)s.", username=user.formatted_name[0]) }}
{% if client %}
{{ _("The application %(client_name)s wants to disconnect your account.", client_name=client.client_name) }}
{% endif %}

View file

@ -37,7 +37,7 @@
<td><a href="{{ url_for('account.profile_edition', username=watched_user.user_name[0]) }}">{{ watched_user.user_name[0] }}</a></td>
{% endif %}
{% if user.can_read("family_name") or user.can_read("given_name") %}
<td>{{ watched_user.name }}</td>
<td>{{ watched_user.formatted_name[0] }}</td>
{% endif %}
{% if user.can_read("email") %}
<td><a href="mailto:{{ watched_user.email[0] }}">{{ watched_user.email[0] }}</a></td>

View file

@ -239,12 +239,12 @@ def test_logout_login(testclient, logged_user, client):
res = res.form.submit(name="answer", value="logout", status=302)
res = res.follow(status=200)
res.form["login"] = logged_user.name
res.form["login"] = logged_user.formatted_name[0]
res.form["password"] = "wrong password"
res = res.form.submit(status=200)
assert ("error", "Login failed, please check your information") in res.flashes
res.form["login"] = logged_user.name
res.form["login"] = logged_user.formatted_name[0]
res.form["password"] = "correct horse battery staple"
res = res.form.submit(status=302)
res = res.follow(status=200)

View file

@ -20,7 +20,7 @@ def test_oauth_hybrid(testclient, slapd_connection, user, client):
)
assert "text/html" == res.content_type, res.json
res.form["login"] = user.name
res.form["login"] = user.formatted_name[0]
res.form["password"] = "correct horse battery staple"
res = res.form.submit(status=302)

View file

@ -18,7 +18,7 @@ def test_access_token_introspection(testclient, user, client, token):
"active": True,
"client_id": client.client_id,
"token_type": token.type,
"username": user.name,
"username": user.formatted_name[0],
"scope": token.get_scope(),
"sub": user.user_name[0],
"aud": [client.client_id],
@ -39,7 +39,7 @@ def test_refresh_token_introspection(testclient, user, client, token):
"active": True,
"client_id": client.client_id,
"token_type": token.type,
"username": user.name,
"username": user.formatted_name[0],
"scope": token.get_scope(),
"sub": user.user_name[0],
"aud": [client.client_id],
@ -109,7 +109,7 @@ def test_full_flow(testclient, logged_user, client, user, other_client):
"active": True,
"client_id": client.client_id,
"token_type": token.type,
"username": user.name,
"username": user.formatted_name[0],
"scope": token.get_scope(),
"sub": user.user_name[0],
"iss": "https://auth.mydomain.tld",

View file

@ -170,7 +170,7 @@ def test_moderator_can_create_edit_and_delete_group(
assert Group.get("bar2") is None
members = bar_group.get_members()
for member in members:
res.mustcontain(member.name)
res.mustcontain(member.formatted_name[0])
# Group is deleted
res = form.submit(name="action", value="delete", status=302)
@ -281,14 +281,14 @@ def test_user_list_search(testclient, logged_admin, foo_group, user, moderator):
res = testclient.get("/groups/foo")
res.mustcontain("3 items")
res.mustcontain(user.name)
res.mustcontain(moderator.name)
res.mustcontain(user.formatted_name[0])
res.mustcontain(moderator.formatted_name[0])
form = res.forms["search"]
form["query"] = "ohn"
res = form.submit()
res.mustcontain("1 items")
res.mustcontain(user.name)
res.mustcontain(user.formatted_name[0])
res.mustcontain(no=logged_admin.name)
res.mustcontain(no=moderator.name)
res.mustcontain(no=moderator.formatted_name[0])

View file

@ -44,16 +44,16 @@ def test_user_list_bad_pages(testclient, logged_admin):
def test_user_list_search(testclient, logged_admin, user, moderator):
res = testclient.get("/users")
res.mustcontain("3 items")
res.mustcontain(moderator.name)
res.mustcontain(user.name)
res.mustcontain(moderator.formatted_name[0])
res.mustcontain(user.formatted_name[0])
form = res.forms["search"]
form["query"] = "Jack"
res = form.submit()
res.mustcontain("1 items")
res.mustcontain(moderator.name)
res.mustcontain(no=user.name)
res.mustcontain(moderator.formatted_name[0])
res.mustcontain(no=user.formatted_name[0])
def test_user_list_search_only_allowed_fields(
@ -61,16 +61,16 @@ def test_user_list_search_only_allowed_fields(
):
res = testclient.get("/users")
res.mustcontain("3 items")
res.mustcontain(moderator.name)
res.mustcontain(user.name)
res.mustcontain(moderator.formatted_name[0])
res.mustcontain(user.formatted_name[0])
form = res.forms["search"]
form["query"] = "user"
res = form.submit()
res.mustcontain("1 items")
res.mustcontain(user.name)
res.mustcontain(no=moderator.name)
res.mustcontain(user.formatted_name[0])
res.mustcontain(no=moderator.formatted_name[0])
testclient.app.config["ACL"]["DEFAULT"]["READ"].remove("user_name")
@ -79,8 +79,8 @@ def test_user_list_search_only_allowed_fields(
res = form.submit()
res.mustcontain("0 items")
res.mustcontain(no=user.name)
res.mustcontain(no=moderator.name)
res.mustcontain(no=user.formatted_name[0])
res.mustcontain(no=moderator.formatted_name[0])
def test_edition_permission(