feat: Improve handling of association name config
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
605a897045
commit
2443bc62ac
9 changed files with 179 additions and 4 deletions
|
|
@ -135,8 +135,11 @@ defmodule MvWeb.Layouts do
|
|||
slot :inner_block, required: true
|
||||
|
||||
def app(assigns) do
|
||||
# Single get_settings() for layout; derive club_name and join_form_enabled to avoid duplicate query.
|
||||
%{club_name: club_name, join_form_enabled: join_form_enabled} = get_layout_settings()
|
||||
# Single settings read for layout defaults.
|
||||
# Use an explicitly provided club_name as source of truth to avoid stale
|
||||
# values from cache reads immediately after a settings update in LiveViews.
|
||||
%{club_name: fallback_club_name, join_form_enabled: join_form_enabled} = get_layout_settings()
|
||||
club_name = assigns[:club_name] || fallback_club_name
|
||||
|
||||
# NOTE: Unprocessed count runs on every page load when join form is enabled; consider
|
||||
# loading only on navigation or caching briefly if performance becomes an issue.
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
|> assign(:settings, settings)
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:environment, environment)
|
||||
|> assign(:association_name_env_set, Mv.Config.association_name_env_set?())
|
||||
|> assign(:vereinfacht_env_configured, Mv.Config.vereinfacht_env_configured?())
|
||||
|> assign(:vereinfacht_api_url_env_set, Mv.Config.vereinfacht_api_url_env_set?())
|
||||
|> assign(:vereinfacht_api_key_env_set, Mv.Config.vereinfacht_api_key_env_set?())
|
||||
|
|
@ -125,6 +126,13 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
<div class="mt-6 space-y-6 max-w-4xl px-4">
|
||||
<%!-- Club Settings Section --%>
|
||||
<.form_section title={gettext("Club Settings")}>
|
||||
<%= if @association_name_env_set do %>
|
||||
<p class="text-sm text-base-content/70 mb-4">
|
||||
{gettext(
|
||||
"Association name is set via environment variable ASSOCIATION_NAME. This field is read-only."
|
||||
)}
|
||||
</p>
|
||||
<% end %>
|
||||
<.form for={@form} id="settings-form" phx-change="validate" phx-submit="save">
|
||||
<div class="w-100">
|
||||
<.input
|
||||
|
|
@ -132,10 +140,18 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
type="text"
|
||||
label={gettext("Association Name")}
|
||||
required
|
||||
disabled={@association_name_env_set}
|
||||
placeholder={
|
||||
if(@association_name_env_set, do: gettext("From ASSOCIATION_NAME"), else: nil)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<.button phx-disable-with={gettext("Saving...")} variant="primary">
|
||||
<.button
|
||||
:if={not @association_name_env_set}
|
||||
phx-disable-with={gettext("Saving...")}
|
||||
variant="primary"
|
||||
>
|
||||
{gettext("Save Name")}
|
||||
</.button>
|
||||
</.form>
|
||||
|
|
@ -919,6 +935,7 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
# Never send blank API key / client secret / smtp password so we do not overwrite stored secrets
|
||||
setting_params_clean =
|
||||
setting_params
|
||||
|> drop_env_managed_association_name()
|
||||
|> drop_blank_vereinfacht_api_key()
|
||||
|> drop_blank_oidc_client_secret()
|
||||
|> drop_blank_smtp_password()
|
||||
|
|
@ -927,6 +944,10 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
|
||||
case MvWeb.LiveHelpers.submit_form(socket.assigns.form, setting_params_clean, actor) do
|
||||
{:ok, updated_settings} ->
|
||||
# Keep cross-view reads consistent after settings updates (layouts/sidebar
|
||||
# read via Membership.get_settings/0).
|
||||
Membership.invalidate_settings_cache()
|
||||
|
||||
# Use the returned record for the form so saved values show immediately;
|
||||
# get_settings() can return cached data without the new attribute until reload.
|
||||
test_result =
|
||||
|
|
@ -1195,10 +1216,19 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
end
|
||||
end
|
||||
|
||||
defp drop_env_managed_association_name(params) when is_map(params) do
|
||||
if Mv.Config.association_name_env_set?() do
|
||||
Map.delete(params, "club_name")
|
||||
else
|
||||
params
|
||||
end
|
||||
end
|
||||
|
||||
defp assign_form(%{assigns: %{settings: settings}} = socket) do
|
||||
# Show ENV values in disabled fields (Vereinfacht, OIDC, SMTP); never expose secrets in form
|
||||
# Show ENV values in disabled fields (Association Name, Vereinfacht, OIDC, SMTP); never expose secrets in form
|
||||
settings_display =
|
||||
settings
|
||||
|> merge_association_env_values()
|
||||
|> merge_vereinfacht_env_values()
|
||||
|> merge_oidc_env_values()
|
||||
|> merge_smtp_env_values()
|
||||
|
|
@ -1225,6 +1255,15 @@ defmodule MvWeb.GlobalSettingsLive do
|
|||
defp put_if_env_set(map, _key, false, _value), do: map
|
||||
defp put_if_env_set(map, key, true, value), do: Map.put(map, key, value)
|
||||
|
||||
defp merge_association_env_values(s) do
|
||||
put_if_env_set(
|
||||
s,
|
||||
:club_name,
|
||||
Mv.Config.association_name_env_set?(),
|
||||
Mv.Config.association_name()
|
||||
)
|
||||
end
|
||||
|
||||
defp merge_vereinfacht_env_values(s) do
|
||||
s
|
||||
|> put_if_env_set(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue