diff --git a/assets/static/images/no_avatar.svg b/assets/static/images/no_avatar.svg new file mode 100644 index 00000000..f3caaf30 --- /dev/null +++ b/assets/static/images/no_avatar.svg @@ -0,0 +1,2 @@ + + diff --git a/config/config.exs b/config/config.exs index 7c0fda34..8208ef73 100644 --- a/config/config.exs +++ b/config/config.exs @@ -12,7 +12,8 @@ config :philomena, elasticsearch_url: "http://localhost:9200", password_pepper: "dn2e0EpZrvBLoxUM3gfQveBhjf0bG/6/bYhrOyq3L3hV9hdo/bimJ+irbDWsuXLP", otp_secret_key: "Wn7O/8DD+qxL0X4X7bvT90wOkVGcA90bIHww4twR03Ci//zq7PnMw8ypqyyT/b/C", - image_url_root: "/img" + image_url_root: "/img", + avatar_url_root: "/avatars" config :philomena, :pow, user: Philomena.Users.User, diff --git a/config/prod.secret.exs b/config/prod.secret.exs index fa57d8f4..44dae28b 100644 --- a/config/prod.secret.exs +++ b/config/prod.secret.exs @@ -17,6 +17,7 @@ config :bcrypt_elixir, config :philomena, anonymous_name_salt: System.get_env("ANONYMOUS_NAME_SALT"), password_pepper: System.get_env("PASSWORD_PEPPER"), + avatar_url_root: System.get_env("AVATAR_URL_ROOT"), otp_secret_key: System.get_env("OTP_SECRET_KEY"), image_url_root: System.get_env("IMAGE_URL_ROOT"), camo_host: System.get_env("CAMO_HOST"), diff --git a/lib/philomena_web/templates/comment/_comment.html.slime b/lib/philomena_web/templates/comment/_comment.html.slime index 21bdae75..2c9a0c66 100644 --- a/lib/philomena_web/templates/comment/_comment.html.slime +++ b/lib/philomena_web/templates/comment/_comment.html.slime @@ -1,7 +1,7 @@ article.block.communication id="comment_#{@comment.id}" .block__content.flex.flex--no-wrap .flex__fixed.spacing-right - /=<> user_avatar((comment.user if comment.user_visible?), 'avatar--100px', comment.author) + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @comment .flex__grow.communication__body span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @comment .communication__body__text diff --git a/lib/philomena_web/templates/post/_post.html.slime b/lib/philomena_web/templates/post/_post.html.slime index eb49f5e1..85ab97d7 100644 --- a/lib/philomena_web/templates/post/_post.html.slime +++ b/lib/philomena_web/templates/post/_post.html.slime @@ -1,7 +1,7 @@ article.block.communication id="post_#{@post.id}" .block__content.flex.flex--no-wrap .flex__fixed.spacing-right - /=<> user_avatar((post.user if post.user_visible?), 'avatar--100px', post.author) + = render PhilomenaWeb.UserAttributionView, "_anon_user_avatar.html", object: @post .flex__grow.communication__body span.communication__body__sender-name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @post .communication__body__text 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 new file mode 100644 index 00000000..1d149919 --- /dev/null +++ b/lib/philomena_web/templates/user_attribution/_anon_user_avatar.html.slime @@ -0,0 +1,4 @@ += if !!@object.user and !@object.anonymous do + = anonymous_avatar(@object) +- else + = user_avatar(@object) \ No newline at end of file diff --git a/lib/philomena_web/views/user_attribution_view.ex b/lib/philomena_web/views/user_attribution_view.ex index 45aea15e..c5080160 100644 --- a/lib/philomena_web/views/user_attribution_view.ex +++ b/lib/philomena_web/views/user_attribution_view.ex @@ -12,6 +12,22 @@ defmodule PhilomenaWeb.UserAttributionView do |> Integer.to_string(16) end + def anonymous_avatar(_object, class \\ "avatar--100px") do + img_tag(Routes.static_path(PhilomenaWeb.Endpoint, "/images/no_avatar.svg"), class: class) + end + + def user_avatar(object, class \\ "avatar--100px") do + if object.user.avatar do + img_tag(avatar_url_root() <> object.user.avatar, class: class) + else + anonymous_avatar(object, class) + end + end + + defp avatar_url_root do + Application.get_env(:philomena, :avatar_url_root) + end + defp anonymous_name_salt do Application.get_env(:philomena, :anonymous_name_salt) |> to_string()