Merge branch 'admin-users' into 'master'
feat: Make users adminable See merge request mythic-insight/legendary!9
This commit is contained in:
commit
2141dd4686
5 changed files with 54 additions and 1 deletions
|
@ -21,6 +21,16 @@ defmodule Auth.User do
|
|||
timestamps()
|
||||
end
|
||||
|
||||
def admin_changeset(user_or_changeset, attrs) do
|
||||
role_list = Phoenix.json_library().decode!(Map.get(attrs, "roles"))
|
||||
attrs = Map.put(attrs, "roles", role_list)
|
||||
|
||||
user_or_changeset
|
||||
|> pow_user_id_field_changeset(attrs)
|
||||
|> Changeset.cast(attrs, [:roles])
|
||||
|> pow_extension_changeset(attrs)
|
||||
end
|
||||
|
||||
def changeset(user_or_changeset, attrs) do
|
||||
user_or_changeset
|
||||
|> pow_user_id_field_changeset(attrs)
|
||||
|
|
|
@ -2,6 +2,14 @@ defmodule Auth.UserAdmin do
|
|||
import Ecto.Query, only: [from: 2]
|
||||
alias Auth.{Repo,User}
|
||||
|
||||
def create_changeset(schema, attrs) do
|
||||
Auth.User.admin_changeset(schema, attrs)
|
||||
end
|
||||
|
||||
def update_changeset(schema, attrs) do
|
||||
Auth.User.admin_changeset(schema, attrs)
|
||||
end
|
||||
|
||||
def widgets(_schema, _conn) do
|
||||
user_count =
|
||||
(from u in User,
|
||||
|
@ -18,4 +26,26 @@ defmodule Auth.UserAdmin do
|
|||
}
|
||||
]
|
||||
end
|
||||
|
||||
def index(_) do
|
||||
[
|
||||
id: nil,
|
||||
email: nil,
|
||||
roles: %{value: fn u -> Enum.join(u.roles, ", ") end},
|
||||
display_name: nil,
|
||||
homepage_url: nil,
|
||||
email_confirmed_at: nil,
|
||||
inserted_at: nil,
|
||||
updated_at: nil,
|
||||
]
|
||||
end
|
||||
|
||||
def form_fields(_) do
|
||||
[
|
||||
email: nil,
|
||||
roles: nil,
|
||||
display_name: nil,
|
||||
homepage_url: nil,
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,6 +17,18 @@ defmodule Content.PostAdmin do
|
|||
Content.Post.changeset(schema, attrs)
|
||||
end
|
||||
|
||||
def index(_) do
|
||||
[
|
||||
id: nil,
|
||||
post_type: nil,
|
||||
post_name: nil,
|
||||
post_title: nil,
|
||||
post_status: nil,
|
||||
post_date_gmt: nil,
|
||||
post_modified_gmt: nil,
|
||||
]
|
||||
end
|
||||
|
||||
def form_fields(_) do
|
||||
authors_query =
|
||||
from u in Auth.User,
|
||||
|
|
|
@ -57,5 +57,6 @@ defmodule CoreWeb.Endpoint do
|
|||
plug Plug.Head
|
||||
plug Plug.Session, @session_options
|
||||
plug Pow.Plug.Session, otp_app: :auth_web
|
||||
plug PowPersistentSession.Plug.Cookie
|
||||
plug CoreWeb.Router
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ config :auth_web,
|
|||
config :auth_web, :pow,
|
||||
user: Auth.User,
|
||||
repo: Auth.Repo,
|
||||
extensions: [PowEmailConfirmation],
|
||||
extensions: [PowEmailConfirmation, PowPersistentSession],
|
||||
controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks,
|
||||
mailer_backend: AuthWeb.Pow.Mailer,
|
||||
web_mailer_module: AuthWeb,
|
||||
|
|
Loading…
Reference in a new issue