diff --git a/lib/shift73k/accounts/user.ex b/lib/shift73k/accounts/user.ex index 9f92c860..23a24406 100644 --- a/lib/shift73k/accounts/user.ex +++ b/lib/shift73k/accounts/user.ex @@ -1,7 +1,6 @@ defmodule Shift73k.Accounts.User do use Ecto.Schema import Ecto.Changeset - import EctoEnum import Shift73k.Util.Dt, only: [weekdays: 0] alias Shift73k.Shifts.Templates.ShiftTemplate @@ -13,8 +12,6 @@ defmodule Shift73k.Accounts.User do admin: "Can delete users and change user roles" ] - defenum(RolesEnum, :role, Keyword.keys(@roles)) - @max_email 254 @min_password 8 @max_password 80 @@ -28,7 +25,7 @@ defmodule Shift73k.Accounts.User do field(:hashed_password, :string) field(:confirmed_at, :naive_datetime) - field(:role, RolesEnum, default: :user) + field(:role, Ecto.Enum, values: Keyword.keys(@roles), default: :user) field(:week_start_at, Ecto.Enum, values: weekdays(), default: :monday) has_many(:shift_templates, ShiftTemplate) @@ -69,13 +66,6 @@ defmodule Shift73k.Accounts.User do |> validate_password(opts) end - # def update_changeset(user, attrs, opts \\ []) - - # def update_changeset(user, %{"password" => ""} = attrs, _), - # do: update_changeset_no_pw(user, attrs) - - # def update_changeset(user, %{password: ""} = attrs, _), do: update_changeset_no_pw(user, attrs) - def update_changeset(user, attrs, opts) do user |> cast(attrs, [:email, :password, :role]) @@ -84,21 +74,10 @@ defmodule Shift73k.Accounts.User do |> validate_password_not_required(opts) end - # def update_changeset_no_pw(user, attrs) do - # user - # |> cast(attrs, [:email, :role]) - # |> validate_role() - # |> validate_email() - # end - - defp role_validator(:role, role) do - (RolesEnum.valid_value?(role) && []) || [role: "invalid user role"] - end - defp validate_role(changeset) do changeset |> validate_required([:role]) - |> validate_change(:role, &role_validator/2) + |> validate_inclusion(:role, Keyword.keys(@roles), message: "invalid user role") end defp validate_email_format(changeset) do diff --git a/lib/shift73k/shifts/shift.ex b/lib/shift73k/shifts/shift.ex index 0e7b7481..69fcb25c 100644 --- a/lib/shift73k/shifts/shift.ex +++ b/lib/shift73k/shifts/shift.ex @@ -2,8 +2,6 @@ defmodule Shift73k.Shifts.Shift do use Ecto.Schema import Ecto.Changeset - alias Shift73k.Shifts.Templates.ShiftTemplate - @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "shifts" do diff --git a/lib/shift73k_web/live/shift_assign_live/index.ex b/lib/shift73k_web/live/shift_assign_live/index.ex index 5e8e08ab..4d12c2e5 100644 --- a/lib/shift73k_web/live/shift_assign_live/index.ex +++ b/lib/shift73k_web/live/shift_assign_live/index.ex @@ -1,10 +1,8 @@ defmodule Shift73kWeb.ShiftAssignLive.Index do use Shift73kWeb, :live_view - alias Ecto.Multi alias Shift73k.Repo alias Shift73k.Shifts - alias Shift73k.Shifts.Shift alias Shift73k.Shifts.Templates alias Shift73k.Shifts.Templates.ShiftTemplate diff --git a/mix.exs b/mix.exs index 17c3a0b2..b30a49b4 100644 --- a/mix.exs +++ b/mix.exs @@ -48,7 +48,6 @@ defmodule Shift73k.MixProject do {:gettext, "~> 0.11"}, {:jason, "~> 1.0"}, {:plug_cowboy, "~> 2.0"}, - {:ecto_enum, "~> 1.4"}, {:bamboo, "~> 2.0"}, {:bamboo_smtp, "~> 4.0"}, {:scrivener_ecto, "~> 2.0"}, diff --git a/priv/repo/migrations/20200913000515_create_users_auth_tables.exs b/priv/repo/migrations/20200913000515_create_users_auth_tables.exs index e57e7d7d..85de1e95 100644 --- a/priv/repo/migrations/20200913000515_create_users_auth_tables.exs +++ b/priv/repo/migrations/20200913000515_create_users_auth_tables.exs @@ -8,8 +8,9 @@ defmodule Shift73k.Repo.Migrations.CreateUsersAuthTables do add(:id, :binary_id, primary_key: true) add(:email, :citext, null: false) add(:hashed_password, :string, null: false) - add(:week_start_at, :string, null: false) + add(:role, :string, null: false) add(:confirmed_at, :naive_datetime) + add(:week_start_at, :string, null: false) timestamps() end diff --git a/priv/repo/migrations/20200913000905_add_role_to_users.exs b/priv/repo/migrations/20200913000905_add_role_to_users.exs deleted file mode 100644 index 6ec24b9a..00000000 --- a/priv/repo/migrations/20200913000905_add_role_to_users.exs +++ /dev/null @@ -1,21 +0,0 @@ -defmodule Shift73k.Repo.Migrations.AddRoleToUsers do - use Ecto.Migration - - alias Shift73k.Accounts.User.RolesEnum - - def up do - RolesEnum.create_type() - - alter table(:users) do - add(:role, RolesEnum.type(), null: false) - end - end - - def down do - alter table(:users) do - remove(:role) - end - - RolesEnum.drop_type() - end -end