reveal anon

This commit is contained in:
Luna D 2019-12-10 11:57:01 -05:00
parent 64d789c357
commit 2d9d32af81
No known key found for this signature in database
GPG key ID: D0F46C94720BAA4B
4 changed files with 13 additions and 4 deletions

View file

@ -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...
#

View file

@ -5,4 +5,7 @@
= render PhilomenaWeb.ProfileView, "_awards.html", awards: @object.user.awards
- else
strong<>
= anonymous_name(@object)
= if can?(@conn, :reveal_anon, @object) do
= link(anonymous_name(@object, true), to: Routes.profile_path(@conn, :show, @object.user))
- else
= anonymous_name(@object)

View file

@ -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")
= anonymous_avatar(@object, assigns[:class] || "avatar--100px")

View file

@ -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