Accept timezone parameter in user registration changeset

This commit is contained in:
Graham McIntire 2026-02-01 11:21:50 -06:00
parent 77e62df9da
commit 0037f18848
No known key found for this signature in database
2 changed files with 31 additions and 2 deletions

View file

@ -24,7 +24,7 @@ defmodule Towerops.Accounts.User do
field :authenticated_at, :utc_datetime, virtual: true
field :is_superuser, :boolean, default: false
field :name, :string
field :timezone, :string
field :timezone, :string, default: "UTC"
field :totp_secret, :binary, redact: true
field :totp_verified_at, :utc_datetime, virtual: true
field :privacy_policy_consent, :boolean, virtual: true
@ -122,7 +122,7 @@ defmodule Towerops.Accounts.User do
"""
def registration_changeset(user, attrs, opts \\ []) do
user
|> cast(attrs, [:email, :password, :privacy_policy_consent, :terms_of_service_consent])
|> cast(attrs, [:email, :password, :timezone, :privacy_policy_consent, :terms_of_service_consent])
|> validate_email_for_registration(opts)
|> validate_password(opts)
|> validate_consent()

View file

@ -772,4 +772,33 @@ defmodule Towerops.AccountsTest do
assert 11 = Accounts.count_unused_recovery_codes(user.id)
end
end
describe "register_user_with_organization/1" do
test "accepts timezone in registration params" do
valid_attrs = %{
"email" => "user@example.com",
"password" => "a valid password",
"privacy_policy_consent" => true,
"terms_of_service_consent" => true,
"organization_name" => "Test Org",
"timezone" => "America/Chicago"
}
assert {:ok, user} = Accounts.register_user_with_organization(valid_attrs)
assert user.timezone == "America/Chicago"
end
test "defaults to UTC when timezone not provided" do
valid_attrs = %{
"email" => "user@example.com",
"password" => "a valid password",
"privacy_policy_consent" => true,
"terms_of_service_consent" => true,
"organization_name" => "Test Org"
}
assert {:ok, user} = Accounts.register_user_with_organization(valid_attrs)
assert user.timezone == "UTC"
end
end
end