diff --git a/lib/teiserver/account.ex b/lib/teiserver/account.ex index 9bffb16df..9aabc5bdf 100644 --- a/lib/teiserver/account.ex +++ b/lib/teiserver/account.ex @@ -2152,4 +2152,17 @@ defmodule Teiserver.Account do @spec call_party(T.party_id(), any) :: any | nil defdelegate call_party(party_id, msg), to: PartyLib + + @spec hide_contributor_rank?(T.userid()) :: boolean() + def hide_contributor_rank?(userid) do + stats_data = get_user_stat_data(userid) + Map.get(stats_data, "hide_contributor_rank", false) + end + + @spec set_hide_contributor_rank(T.userid(), boolean()) :: any() + def set_hide_contributor_rank(userid, boolean_value) do + update_user_stat(userid, %{ + "hide_contributor_rank" => boolean_value + }) + end end diff --git a/lib/teiserver/account/libs/role_lib.ex b/lib/teiserver/account/libs/role_lib.ex index 84f2a64ea..72d48b79f 100644 --- a/lib/teiserver/account/libs/role_lib.ex +++ b/lib/teiserver/account/libs/role_lib.ex @@ -81,6 +81,13 @@ defmodule Teiserver.Account.RoleLib do contains: ["Community team"], badge: true }, + %{ + name: "Blog helper", + colour: "#66AA66", + icon: "fa-solid fa-blog", + contains: [], + badge: true + }, # Privileged %{name: "VIP", colour: "#AA8833", icon: "fa-solid fa-sparkles", contains: ["BAR+"]}, @@ -96,11 +103,18 @@ defmodule Teiserver.Account.RoleLib do %{name: "Donor", colour: "#0066AA", icon: "fa-solid fa-euro", contains: ~w(), badge: true}, # Contributor/Staff + %{ + name: "Tester", + colour: "#00AAAA", + icon: "fa-solid fa-vial", + contains: ~w(), + badge: true + }, %{ name: "Contributor", colour: "#66AA66", icon: "fa-solid fa-code-commit", - contains: ["Trusted", "BAR+"], + contains: ["Trusted", "BAR+", "Tester", "Blog helper"], badge: true }, %{name: "Engine", colour: "#007700", icon: "fa-solid fa-engine", contains: ~w(Contributor)}, @@ -124,13 +138,6 @@ defmodule Teiserver.Account.RoleLib do icon: "fa-solid fa-download", contains: ~w(Contributor) }, - %{ - name: "Tester", - colour: "#00AAAA", - icon: "fa-solid fa-vial", - contains: ~w(Contributor), - badge: true - }, %{ name: "Core", colour: "#007700", @@ -246,7 +253,7 @@ defmodule Teiserver.Account.RoleLib do @spec community_roles :: [String.t()] def community_roles() do - ["Mentor", "Academy manager", "Promo team", "Community team"] + ["Mentor", "Academy manager", "Promo team", "Community team", "Blog helper"] end @spec privileged_roles :: [String.t()] diff --git a/lib/teiserver/data/cache_user.ex b/lib/teiserver/data/cache_user.ex index 47f9cef4f..aeb4fa4a4 100644 --- a/lib/teiserver/data/cache_user.ex +++ b/lib/teiserver/data/cache_user.ex @@ -1316,7 +1316,7 @@ defmodule Teiserver.CacheUser do # https://www.beyondallreason.info/guide/rating-and-lobby-balance#rank-icons cond do has_any_role?(userid, ["Tournament winner"]) -> 7 - has_any_role?(userid, ~w(Core Contributor)) -> 6 + has_any_role?(userid, ~w(Core Contributor)) and !Account.hide_contributor_rank?(userid) -> 6 ingame_hours >= 1000 -> 5 ingame_hours >= 250 -> 4 ingame_hours >= 100 -> 3 diff --git a/lib/teiserver_web/live/account/profile/contributor.ex b/lib/teiserver_web/live/account/profile/contributor.ex index f44c8f3b8..186fd7bbb 100644 --- a/lib/teiserver_web/live/account/profile/contributor.ex +++ b/lib/teiserver_web/live/account/profile/contributor.ex @@ -7,6 +7,7 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do def mount(%{"userid" => userid_str}, _session, socket) do userid = String.to_integer(userid_str) user = Account.get_user_by_id(userid) + hide_contributor_rank = Account.hide_contributor_rank?(userid) socket = cond do @@ -27,6 +28,7 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do |> assign(:view_colour, Teiserver.Account.UserLib.colours()) |> assign(:user, user) |> assign(:error_message, nil) + |> assign(:hide_contributor_rank, hide_contributor_rank) |> TeiserverWeb.Account.ProfileLive.Overview.get_relationships_and_permissions() |> user_assigns end @@ -94,6 +96,30 @@ defmodule TeiserverWeb.Account.ProfileLive.Contributor do end end + @doc """ + Handles checkbox to disable contributor rank icon + """ + @impl true + def handle_event("toggle-hide-contributor-rank", event, %{assigns: assigns} = socket) do + [key] = event["_target"] + value = event[key] + + # value will be a string or nil; we will convert to boolean + boolean_value = + if value do + true + else + false + end + + Account.set_hide_contributor_rank(assigns.user.id, boolean_value) + Account.recache_user(assigns.user.id) + + {:noreply, + socket + |> assign(:hide_contributor_rank, boolean_value)} + end + def handle_event(_string, _event, socket) do {:noreply, socket} end diff --git a/lib/teiserver_web/live/account/profile/contributor.html.heex b/lib/teiserver_web/live/account/profile/contributor.html.heex index c2f2cfe05..09c9b8dbc 100644 --- a/lib/teiserver_web/live/account/profile/contributor.html.heex +++ b/lib/teiserver_web/live/account/profile/contributor.html.heex @@ -61,4 +61,25 @@ <% end %> +
+
+
+

Contributor Rank Icon

+
+ + +
+
+
+
diff --git a/lib/teiserver_web/live/battles/match/show.ex b/lib/teiserver_web/live/battles/match/show.ex index 09ff0660c..6518d7b40 100644 --- a/lib/teiserver_web/live/battles/match/show.ex +++ b/lib/teiserver_web/live/battles/match/show.ex @@ -55,9 +55,9 @@ defmodule TeiserverWeb.Battle.MatchLive.Show do defp apply_action(%{assigns: %{match_name: match_name}} = socket, :balance, _params) do # Restrict the balance tab to certain roles. - # Note that Staff roles like "Tester" also contain Contributor role. + # Note that Staff roles like Contributor will inherit Tester permissions socket - |> mount_require_any(["Reviewer", "Contributor"]) + |> mount_require_any(["Reviewer", "Tester"]) |> assign(:page_title, "#{match_name} - Balance") end diff --git a/lib/teiserver_web/live/battles/match/show.html.heex b/lib/teiserver_web/live/battles/match/show.html.heex index 6cf6094b0..62deade99 100644 --- a/lib/teiserver_web/live/battles/match/show.html.heex +++ b/lib/teiserver_web/live/battles/match/show.html.heex @@ -41,7 +41,7 @@ <% end %> - <%= if @rating_logs != %{} and allow_any?(@current_user, ["Overwatch", "Contributor"]) do %> + <%= if @rating_logs != %{} and allow_any?(@current_user, ["Overwatch", "Tester"]) do %> <.tab_nav url={~p"/battle/#{@match.id}/balance"} selected={@tab == :balance}> Balance @@ -282,7 +282,7 @@ <% end %> - <%= if allow_any?(@current_user, ["Overwatch", "Contributor"]) do %> + <%= if allow_any?(@current_user, ["Overwatch", "Tester"]) do %>
<.input diff --git a/lib/teiserver_web/live/microblog/admin/post/index.ex b/lib/teiserver_web/live/microblog/admin/post/index.ex index 6222d9a7e..8d1a94a12 100644 --- a/lib/teiserver_web/live/microblog/admin/post/index.ex +++ b/lib/teiserver_web/live/microblog/admin/post/index.ex @@ -11,7 +11,7 @@ defmodule TeiserverWeb.Microblog.Admin.PostLive.Index do @impl true def handle_params(params, _url, socket) do - case allow?(socket.assigns[:current_user], "Contributor") do + case allow?(socket.assigns[:current_user], "Blog helper") do true -> {:noreply, apply_action(socket, socket.assigns.live_action, params)} diff --git a/lib/teiserver_web/live/microblog/admin/post/show.ex b/lib/teiserver_web/live/microblog/admin/post/show.ex index c98e3a7ed..49139b9dc 100644 --- a/lib/teiserver_web/live/microblog/admin/post/show.ex +++ b/lib/teiserver_web/live/microblog/admin/post/show.ex @@ -10,7 +10,7 @@ defmodule TeiserverWeb.Microblog.Admin.PostLive.Show do @impl true def handle_params(%{"id" => id}, _url, socket) do - if allow?(socket.assigns[:current_user], "Contributor") do + if allow?(socket.assigns[:current_user], "Blog helper") do post = Microblog.get_post!(id, preload: [:tags]) if post.poster_id == socket.assigns.current_user.id or diff --git a/lib/teiserver_web/live/microblog/blog/index.html.heex b/lib/teiserver_web/live/microblog/blog/index.html.heex index 4a67ad323..6bb1589fc 100644 --- a/lib/teiserver_web/live/microblog/blog/index.html.heex +++ b/lib/teiserver_web/live/microblog/blog/index.html.heex @@ -30,7 +30,7 @@ diff --git a/lib/teiserver_web/live/microblog/microblog_components.ex b/lib/teiserver_web/live/microblog/microblog_components.ex index 4c310738e..f2e7a0573 100644 --- a/lib/teiserver_web/live/microblog/microblog_components.ex +++ b/lib/teiserver_web/live/microblog/microblog_components.ex @@ -35,7 +35,7 @@ defmodule TeiserverWeb.MicroblogComponents do <.sub_menu_button - :if={allow?(@current_user, "Contributor")} + :if={allow?(@current_user, "Blog helper")} bsname={@view_colour} icon={Teiserver.Microblog.PostLib.icon()} active={@active == "posts"} diff --git a/lib/teiserver_web/router.ex b/lib/teiserver_web/router.ex index 7851b490a..e73d3e614 100644 --- a/lib/teiserver_web/router.ex +++ b/lib/teiserver_web/router.ex @@ -106,7 +106,7 @@ defmodule TeiserverWeb.Router do live_session :microblog_admin, on_mount: [ {Teiserver.Account.AuthPlug, :ensure_authenticated}, - {Teiserver.Account.AuthPlug, {:authorise, "Contributor"}} + {Teiserver.Account.AuthPlug, {:authorise, "Blog helper"}} ] do live "/admin/posts", Admin.PostLive.Index, :index live "/admin/posts/:id", Admin.PostLive.Show, :show