philomena/lib/philomena_web/views/admin/user_view.ex

97 lines
2.7 KiB
Elixir
Raw Normal View History

2019-12-16 03:21:14 +01:00
defmodule PhilomenaWeb.Admin.UserView do
use PhilomenaWeb, :view
def page_params(params) do
[]
|> page_param(params, "q", :q)
|> page_param(params, "staff", :staff)
|> page_param(params, "twofactor", :twofactor)
end
defp page_param(list, params, key, key_atom) do
case params[key] do
nil -> list
"" -> list
val -> [{key_atom, val} | list]
end
end
2019-12-16 03:24:23 +01:00
def checkbox_mapper(form, field, input_opts, role, _label_opts, _opts) do
2019-12-16 03:21:14 +01:00
input_id = "user_roles_#{role.id}"
label_opts = [for: input_id]
2020-01-11 05:20:19 +01:00
2019-12-16 03:21:14 +01:00
input_opts =
2020-01-11 05:20:19 +01:00
Keyword.merge(input_opts,
class: "checkbox",
id: input_id,
checked_value: to_string(role.id),
hidden_input: false,
2019-12-16 03:21:14 +01:00
checked: Enum.member?(Enum.map(input_value(form, field), & &1.id), role.id)
2020-01-11 05:20:19 +01:00
)
2019-12-16 03:21:14 +01:00
content_tag(:li, class: "table-list__label") do
content_tag(:div) do
[
checkbox(form, field, input_opts),
" ",
2020-01-11 05:20:19 +01:00
content_tag(:label, description(role.name, role.resource_type), label_opts)
2019-12-16 03:21:14 +01:00
]
end
end
end
def description("moderator", "Image"), do: "Manage images"
def description("moderator", "DuplicateReport"), do: "Manage duplicates"
def description("moderator", "Comment"), do: "Manage comments"
def description("moderator", "UserLink"), do: "Manage artist links"
2019-12-16 03:21:14 +01:00
def description("moderator", "Topic"), do: "Moderate forums"
2019-12-16 03:24:23 +01:00
def description("moderator", "Tag"), do: "Manage tag details"
2019-12-16 03:21:14 +01:00
def description("admin", "Tag"), do: "Alias tags"
def description("batch_update", "Tag"), do: "Update tags in batches"
def description("moderator", "User"), do: "Manage users and wipe votes"
def description("admin", "Role"), do: "Manage permissions"
def description("admin", "SiteNotice"), do: "Manage site notices"
def description("admin", "Badge"), do: "Manage badges"
def description("admin", "Advert"), do: "Manage ads"
2020-03-03 20:29:14 +01:00
def description("admin", "StaticPage"), do: "Manage static pages"
2019-12-16 03:21:14 +01:00
def description(_name, _resource_type), do: "(unknown permission)"
def filtered_roles(permission_set, roles) do
roles
|> Enum.filter(&Enum.member?(permission_set, [&1.name, &1.resource_type]))
|> Enum.map(&{&1, ""})
end
def general_permissions do
[
["batch_update", "Tag"]
]
end
def assistant_permissions do
[
["moderator", "Image"],
["moderator", "DuplicateReport"],
["moderator", "Comment"],
["moderator", "Tag"],
["moderator", "UserLink"],
["moderator", "Topic"]
]
end
def moderator_permissions do
[
["moderator", "User"],
["admin", "Tag"],
["admin", "Role"],
["admin", "SiteNotice"],
["admin", "Badge"],
2020-03-03 20:29:14 +01:00
["admin", "Advert"],
["admin", "StaticPage"]
2019-12-16 03:21:14 +01:00
]
end
end