diff --git a/lib/philomena/users/ability.ex b/lib/philomena/users/ability.ex index 1cf88368..3a2b9994 100644 --- a/lib/philomena/users/ability.ex +++ b/lib/philomena/users/ability.ex @@ -56,6 +56,9 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do def can?(%User{role: "moderator"}, :edit, %UserLink{}), do: true def can?(%User{role: "moderator"}, :index, UserLink), do: true + # Reveal anon users + def can?(%User{role: "moderator"}, :reveal_anon, %User{}), do: true + # # Assistants can... # diff --git a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime index 92ec0b37..d02c1a6b 100644 --- a/lib/philomena_web/templates/user_attribution/_anon_user.html.slime +++ b/lib/philomena_web/templates/user_attribution/_anon_user.html.slime @@ -5,4 +5,7 @@ = render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards - else strong<> - = anonymous_name(@object) \ No newline at end of file + = if can?(@conn, :reveal_anon, @object) do + = link(anonymous_name(@object, true), to: Routes.profile_path(@conn, :show, @object.user)) + - else + = anonymous_name(@object) diff --git a/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime b/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime index d411abaa..dccab704 100644 --- a/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime +++ b/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime @@ -1,4 +1,4 @@ = if !!@object.user and !anonymous?(@object) do = user_avatar(@object, assigns[:class] || "avatar--100px") - else - = anonymous_avatar(@object, assigns[:class] || "avatar--100px") \ No newline at end of file + = anonymous_avatar(@object, assigns[:class] || "avatar--100px") diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index 49d12748..b05ebef1 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -7,7 +7,7 @@ defmodule PhilomenaWeb.UserAttributionView do Attribution.anonymous?(object) end - def anonymous_name(object) do + def anonymous_name(object, reveal_anon? \\ false) do salt = anonymous_name_salt() id = Attribution.object_identifier(object) user_id = Attribution.best_user_identifier(object) @@ -17,7 +17,10 @@ defmodule PhilomenaWeb.UserAttributionView do |> Integer.to_string(16) |> String.pad_leading(4, "0") - "Background Pony ##{hash}" + case reveal_anon? do + true -> "#{object.user.name} (##{hash}, hidden)" + false -> "Background Pony ##{hash}" + end end def anonymous_avatar(_object, class \\ "avatar--100px") do