Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog Helper + Permission improvements + Toggle contributor icon #361

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/teiserver/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 16 additions & 9 deletions lib/teiserver/account/libs/role_lib.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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+"]},
Expand All @@ -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)},
Expand All @@ -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",
Expand Down Expand Up @@ -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()]
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver/data/cache_user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions lib/teiserver_web/live/account/profile/contributor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions lib/teiserver_web/live/account/profile/contributor.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,25 @@
<% end %>
</div>
</div>
<div class="row mt-3 mb-3">
<div class="col">
<form>
<h4>Contributor Rank Icon</h4>
<div class="form-check">
<input
name="hide-rank-icon"
id="hide-rank-icon"
class="form-check-input"
type="checkbox"
value="true"
checked={@hide_contributor_rank}
phx-change="toggle-hide-contributor-rank"
/>
<label class="form-check-label" for="hide-rank-icon">
Hide contributor rank icon
</label>
</div>
</form>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions lib/teiserver_web/live/battles/match/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/teiserver_web/live/battles/match/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</.tab_nav>
<% 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}>
<Fontawesome.icon icon="fa-solid fa-scale-balanced" style="solid" /> Balance
</.tab_nav>
Expand Down Expand Up @@ -282,7 +282,7 @@
</div>
<% end %>

<%= if allow_any?(@current_user, ["Overwatch", "Contributor"]) do %>
<%= if allow_any?(@current_user, ["Overwatch", "Tester"]) do %>
<div :if={@tab == :balance} class="p-4">
<form method="post" class="">
<.input
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/microblog/admin/post/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)}

Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/microblog/admin/post/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/microblog/blog/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</a>

<a
:if={allow?(@current_user, "Contributor")}
:if={allow?(@current_user, "Blog helper")}
href={~p"/microblog/admin/posts"}
class="btn btn-primary btn-sm mx-1"
>
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/live/microblog/microblog_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule TeiserverWeb.MicroblogComponents do
</.sub_menu_button>

<.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"}
Expand Down
2 changes: 1 addition & 1 deletion lib/teiserver_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading