diff --git a/server/lib/orcasite/accounts/user.ex b/server/lib/orcasite/accounts/user.ex index 4ebfcfd5..2a54c0ee 100644 --- a/server/lib/orcasite/accounts/user.ex +++ b/server/lib/orcasite/accounts/user.ex @@ -19,8 +19,8 @@ defmodule Orcasite.Accounts.User do attribute :hashed_password, :string, allow_nil?: false, sensitive?: true attribute :first_name, :string attribute :last_name, :string - attribute :admin, :boolean - attribute :moderator, :boolean + attribute :admin, :boolean, default: false, allow_nil?: false + attribute :moderator, :boolean, default: false, allow_nil?: false create_timestamp :inserted_at update_timestamp :updated_at diff --git a/server/priv/repo/migrations/20240110222226_update_user_admin_and_mod_default_false.exs b/server/priv/repo/migrations/20240110222226_update_user_admin_and_mod_default_false.exs new file mode 100644 index 00000000..533f3065 --- /dev/null +++ b/server/priv/repo/migrations/20240110222226_update_user_admin_and_mod_default_false.exs @@ -0,0 +1,28 @@ +defmodule Orcasite.Repo.Migrations.UpdateUserAdminAndModDefaultFalse do + @moduledoc """ + Updates resources based on their most recent snapshots. + + This file was autogenerated with `mix ash_postgres.generate_migrations` + """ + + use Ecto.Migration + + def up do + execute "update users set admin = 'f' where admin is null;" + execute "update users set moderator = 'f' where moderator is null;" + + flush() + + alter table(:users) do + modify :moderator, :boolean, null: false, default: false + modify :admin, :boolean, null: false, default: false + end + end + + def down do + alter table(:users) do + modify :admin, :boolean, null: true, default: nil + modify :moderator, :boolean, null: true, default: nil + end + end +end diff --git a/server/priv/resource_snapshots/repo/users/20240110222226.json b/server/priv/resource_snapshots/repo/users/20240110222226.json new file mode 100644 index 00000000..627f1832 --- /dev/null +++ b/server/priv/resource_snapshots/repo/users/20240110222226.json @@ -0,0 +1,118 @@ +{ + "attributes": [ + { + "default": "nil", + "size": null, + "type": "uuid", + "source": "id", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": true + }, + { + "default": "nil", + "size": null, + "type": "citext", + "source": "email", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "hashed_password", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "first_name", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "nil", + "size": null, + "type": "text", + "source": "last_name", + "references": null, + "allow_nil?": true, + "generated?": false, + "primary_key?": false + }, + { + "default": "false", + "size": null, + "type": "boolean", + "source": "admin", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "false", + "size": null, + "type": "boolean", + "source": "moderator", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "fragment(\"now()\")", + "size": null, + "type": "utc_datetime_usec", + "source": "inserted_at", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + }, + { + "default": "fragment(\"now()\")", + "size": null, + "type": "utc_datetime_usec", + "source": "updated_at", + "references": null, + "allow_nil?": false, + "generated?": false, + "primary_key?": false + } + ], + "table": "users", + "hash": "B341A513EC6CF961202B8212C7C4E69600B5AE7A5669D8960EF59C9B41C16164", + "repo": "Elixir.Orcasite.Repo", + "identities": [ + { + "name": "unique_email", + "keys": [ + "email" + ], + "index_name": "users_unique_email_index", + "base_filter": null + } + ], + "schema": null, + "multitenancy": { + "global": null, + "strategy": null, + "attribute": null + }, + "custom_indexes": [], + "base_filter": null, + "check_constraints": [], + "custom_statements": [], + "has_create_action": true +} \ No newline at end of file diff --git a/server/test/orcasite_web/graphql/accounts_test.exs b/server/test/orcasite_web/graphql/accounts_test.exs index 508a0bc6..ec065cfa 100644 --- a/server/test/orcasite_web/graphql/accounts_test.exs +++ b/server/test/orcasite_web/graphql/accounts_test.exs @@ -49,7 +49,7 @@ defmodule OrcasiteWeb.GraphqlTest.AccountsTest do assert %{ "data" => %{ "signInWithPassword" => %{ - "user" => %{"email" => ^user_email, "admin" => nil, "moderator" => nil} + "user" => %{"email" => ^user_email, "admin" => false, "moderator" => false} } } } = @@ -66,7 +66,7 @@ defmodule OrcasiteWeb.GraphqlTest.AccountsTest do assert %{ "data" => %{ "signInWithPassword" => %{ - "user" => %{"email" => ^user_email, "admin" => nil, "moderator" => nil} + "user" => %{"email" => ^user_email, "admin" => false, "moderator" => false} } } } = @@ -76,7 +76,7 @@ defmodule OrcasiteWeb.GraphqlTest.AccountsTest do assert %{ "data" => %{ - "currentUser" => %{"email" => ^user_email, "admin" => nil, "moderator" => nil} + "currentUser" => %{"email" => ^user_email, "admin" => false, "moderator" => false} } } = json_response(conn, 200) diff --git a/ui/src/graphql/generated/index.ts b/ui/src/graphql/generated/index.ts index f2986f2a..f7c13a64 100644 --- a/ui/src/graphql/generated/index.ts +++ b/ui/src/graphql/generated/index.ts @@ -776,19 +776,19 @@ export type SubmitDetectionResult = { export type User = { __typename?: "User"; - admin?: Maybe; + admin: Scalars["Boolean"]["output"]; email: Scalars["String"]["output"]; firstName?: Maybe; id: Scalars["ID"]["output"]; lastName?: Maybe; - moderator?: Maybe; + moderator: Scalars["Boolean"]["output"]; }; export type UserFilterAdmin = { eq?: InputMaybe; greaterThan?: InputMaybe; greaterThanOrEqual?: InputMaybe; - in?: InputMaybe>>; + in?: InputMaybe>; isNil?: InputMaybe; lessThan?: InputMaybe; lessThanOrEqual?: InputMaybe; @@ -855,7 +855,7 @@ export type UserFilterModerator = { eq?: InputMaybe; greaterThan?: InputMaybe; greaterThanOrEqual?: InputMaybe; - in?: InputMaybe>>; + in?: InputMaybe>; isNil?: InputMaybe; lessThan?: InputMaybe; lessThanOrEqual?: InputMaybe; @@ -951,7 +951,7 @@ export type RegisterWithPasswordMutation = { __typename?: "User"; id: string; email: string; - admin?: boolean | null; + admin: boolean; firstName?: string | null; lastName?: string | null; } | null; @@ -999,7 +999,7 @@ export type ResetPasswordMutation = { email: string; firstName?: string | null; lastName?: string | null; - admin?: boolean | null; + admin: boolean; } | null; } | null; }; @@ -1042,7 +1042,7 @@ export type SignInWithPasswordMutation = { __typename?: "User"; id: string; email: string; - admin?: boolean | null; + admin: boolean; firstName?: string | null; lastName?: string | null; } | null; @@ -1125,8 +1125,8 @@ export type GetCurrentUserQuery = { firstName?: string | null; lastName?: string | null; email: string; - admin?: boolean | null; - moderator?: boolean | null; + admin: boolean; + moderator: boolean; } | null; };