Users list and show: Role, Password, OIDC columns; UserHelpers
- Index: load :role; columns Role, Password (has_password?), OIDC; contrast fix. - Show: Role, OIDC (Linked/Not linked); has_password? for Password Authentication. - UserHelpers: has_password?/1, has_oidc?/1. Gettext: new strings and DE translations.
This commit is contained in:
parent
7eba21dc9c
commit
c6082f2831
7 changed files with 180 additions and 4 deletions
58
lib/mv_web/helpers/user_helpers.ex
Normal file
58
lib/mv_web/helpers/user_helpers.ex
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
defmodule MvWeb.Helpers.UserHelpers do
|
||||
@moduledoc """
|
||||
Helper functions for user-related display in the web layer.
|
||||
|
||||
Provides utilities for showing authentication status without exposing
|
||||
sensitive attributes (e.g. hashed_password).
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Returns whether the user has password authentication set.
|
||||
|
||||
Only returns true when `hashed_password` is a non-empty string. This avoids
|
||||
treating `nil`, empty string, or forbidden/redacted values (e.g. when the
|
||||
attribute is not visible to the actor) as "has password".
|
||||
|
||||
## Examples
|
||||
|
||||
iex> user = %{hashed_password: nil}
|
||||
iex> MvWeb.Helpers.UserHelpers.has_password?(user)
|
||||
false
|
||||
|
||||
iex> user = %{hashed_password: "$2b$12$..."}
|
||||
iex> MvWeb.Helpers.UserHelpers.has_password?(user)
|
||||
true
|
||||
|
||||
iex> user = %{hashed_password: ""}
|
||||
iex> MvWeb.Helpers.UserHelpers.has_password?(user)
|
||||
false
|
||||
"""
|
||||
@spec has_password?(map() | struct()) :: boolean()
|
||||
def has_password?(user) when is_map(user) do
|
||||
case Map.get(user, :hashed_password) do
|
||||
hash when is_binary(hash) and byte_size(hash) > 0 -> true
|
||||
_ -> false
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns whether the user is linked via OIDC/SSO (has a non-empty oidc_id).
|
||||
|
||||
## Examples
|
||||
|
||||
iex> user = %{oidc_id: nil}
|
||||
iex> MvWeb.Helpers.UserHelpers.has_oidc?(user)
|
||||
false
|
||||
|
||||
iex> user = %{oidc_id: "sub-from-rauthy"}
|
||||
iex> MvWeb.Helpers.UserHelpers.has_oidc?(user)
|
||||
true
|
||||
"""
|
||||
@spec has_oidc?(map() | struct()) :: boolean()
|
||||
def has_oidc?(user) when is_map(user) do
|
||||
case Map.get(user, :oidc_id) do
|
||||
id when is_binary(id) and byte_size(id) > 0 -> true
|
||||
_ -> false
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue