senior staff

This commit is contained in:
Luna D 2020-08-17 23:58:20 +02:00 committed by byte[]
parent 23bd821838
commit 017890642f
6 changed files with 31 additions and 3 deletions

View file

@ -117,6 +117,7 @@ defmodule Philomena.Users.User do
field :scratchpad, :string
field :secondary_role, :string
field :hide_default_role, :boolean, default: false
field :senior_staff, :boolean, default: false
# For avatar validation/persistence
field :avatar_width, :integer, virtual: true
@ -268,7 +269,7 @@ defmodule Philomena.Users.User do
def update_changeset(user, attrs, roles) do
user
|> cast(attrs, [:name, :email, :role, :secondary_role, :hide_default_role])
|> cast(attrs, [:name, :email, :role, :secondary_role, :hide_default_role, :senior_staff])
|> validate_required([:name, :email, :role])
|> validate_inclusion(:role, ["user", "assistant", "moderator", "admin"])
|> put_assoc(:roles, roles)

View file

@ -21,6 +21,9 @@
label.table-list__label
.table-list__label__text Hide staff banner:
.table-list__label__input = checkbox f, :hide_default_role, class: "checkbox"
label.table-list__label
.table-list__label__text Senior staff:
.table-list__label__input = checkbox f, :senior_staff, class: "checkbox"
.table-list__label
.table-list__label__text Avatar
.table-list__label__input
@ -29,6 +32,10 @@
.block
.block__header
span.block__header__title General user flags
ul
p
strong> Be careful when issuing these permissions to staff members!
| Staff members with relevant roles may have these permissions anyway. Issuing them may break things, such as tag aliasing.
ul = collection_checkboxes f, :roles, filtered_roles(general_permissions(), @roles), mapper: &checkbox_mapper/6
.block

View file

@ -107,12 +107,21 @@ defmodule PhilomenaWeb.UserAttributionView do
defp secondary_role(labels, _user), do: labels
defp staff_role(labels, %{hide_default_role: false, role: "admin", senior_staff: true}),
do: [{"label--danger", "Head Administrator"} | labels]
defp staff_role(labels, %{hide_default_role: false, role: "admin"}),
do: [{"label--danger", "Site Administrator"} | labels]
defp staff_role(labels, %{hide_default_role: false, role: "moderator", senior_staff: true}),
do: [{"label--success", "Senior Moderator"} | labels]
defp staff_role(labels, %{hide_default_role: false, role: "moderator"}),
do: [{"label--success", "Site Moderator"} | labels]
defp staff_role(labels, %{hide_default_role: false, role: "assistant", senior_staff: true}),
do: [{"label--purple", "Senior Assistant"} | labels]
defp staff_role(labels, %{hide_default_role: false, role: "assistant"}),
do: [{"label--purple", "Site Assistant"} | labels]

View file

@ -0,0 +1,9 @@
defmodule Philomena.Repo.Migrations.AddSeniorStaff do
use Ecto.Migration
def change do
alter table(:users) do
add :senior_staff, :boolean, default: false
end
end
end

View file

@ -1974,7 +1974,8 @@ CREATE TABLE public.users (
otp_backup_codes character varying[],
last_renamed_at timestamp without time zone DEFAULT '1970-01-01 00:00:00'::timestamp without time zone NOT NULL,
forced_filter_id bigint,
confirmed_at timestamp(0) without time zone
confirmed_at timestamp(0) without time zone,
senior_staff boolean DEFAULT false
);
@ -4794,3 +4795,4 @@ INSERT INTO public."schema_migrations" (version) VALUES (20200617111116);
INSERT INTO public."schema_migrations" (version) VALUES (20200617113333);
INSERT INTO public."schema_migrations" (version) VALUES (20200706171350);
INSERT INTO public."schema_migrations" (version) VALUES (20200725234412);
INSERT INTO public."schema_migrations" (version) VALUES (20200817213256);