From e5b8ea017cb42b76c03b1eaaaa773595d086da55 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Sat, 25 Jun 2022 10:17:53 +0200 Subject: [PATCH] Show anon identifier in tooltip when unmasking --- app/helpers/application_helper.rb | 4 ---- .../application_helper/title_methods.rb | 6 +++--- app/helpers/user_helper.rb | 21 ++++++++++++++----- app/views/answerbox/_header.haml | 2 +- app/views/answerbox/_smiles.haml | 2 +- app/views/inbox/_entry.haml | 2 +- app/views/question/_question.haml | 2 +- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 289e7b61..12434f81 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -42,10 +42,6 @@ module ApplicationHelper false end - def moderation_view? - current_user.mod? && session[:moderation_view] == true - end - def rails_admin_path_for_resource(resource) [rails_admin_path, resource.model_name.param_key, resource.id].join("/") end diff --git a/app/helpers/application_helper/title_methods.rb b/app/helpers/application_helper/title_methods.rb index 163d583c..7de1ca72 100644 --- a/app/helpers/application_helper/title_methods.rb +++ b/app/helpers/application_helper/title_methods.rb @@ -27,17 +27,17 @@ module ApplicationHelper::TitleMethods def question_title(question) context_user = question.answers&.first&.user if question.direct - name = user_screen_name question.user, context_user: context_user, anonymous: question.author_is_anonymous, url: false + name = user_screen_name question.user, context_user: context_user, author_identifier: question.author_identifier, url: false generate_title name, "asked", question.content end def answer_title(answer) - name = user_screen_name answer.user, anonymous: false, url: false + name = user_screen_name answer.user, url: false generate_title name, "answered", answer.question.content end def user_title(user, junction = nil) - name = user_screen_name user, anonymous: false, url: false + name = user_screen_name user, url: false generate_title name, junction, nil, !junction.nil? end diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index eae142b1..734c48c7 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -3,10 +3,11 @@ module UserHelper # Decides what user name to show. # @param context_user [User] the user whose the profile preferences should be applied + # @param author_identifier [nil, String] the author identifier of the question (questions only) # @return [String] The user name - def user_screen_name(user, context_user: nil, anonymous: false, url: true, link_only: false) - return profile_link(user) if should_unmask?(user, anonymous) - return anonymous_name(context_user) if anonymous?(user, anonymous) + def user_screen_name(user, context_user: nil, author_identifier: nil, url: true, link_only: false) + return unmask(user, context_user, author_identifier) if should_unmask?(author_identifier) + return anonymous_name(context_user) if anonymous?(user, author_identifier.present?) if url return show_user_profile_path(user.screen_name) if link_only @@ -16,14 +17,24 @@ module UserHelper user.profile.safe_name.strip end + def moderation_view? + current_user.mod? && session[:moderation_view] == true + end + private def profile_link(user) link_to(user.profile.safe_name, show_user_profile_path(user.screen_name), class: ("user--banned" if user.banned?).to_s) end - def should_unmask?(user, anonymous) - user.present? && moderation_view? && anonymous + def should_unmask?(anonymous_identifier) + moderation_view? && anonymous_identifier.present? + end + + def unmask(user, context_user, anonymous_identifier) + return profile_link(user) if user.present? + + "#{anonymous_name(context_user)}" end def anonymous_name(context_user) diff --git a/app/views/answerbox/_header.haml b/app/views/answerbox/_header.haml index 7fcffff1..3e96efdc 100644 --- a/app/views/answerbox/_header.haml +++ b/app/views/answerbox/_header.haml @@ -25,7 +25,7 @@ %h6.text-muted.media-heading.answerbox__question-user - if a.question.author_is_anonymous %i.fa.fa-user-secret{ title: t('.anon_hint') } - = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, context_user: a.user, anonymous: a.question.author_is_anonymous), time: time_tooltip(a.question)) + = raw t('views.answerbox.asked', user: user_screen_name(a.question.user, context_user: a.user, author_identifier: a.question.author_identifier), time: time_tooltip(a.question)) - if !a.question.author_is_anonymous && !a.question.direct · %a{ href: show_user_question_path(a.question.user.screen_name, a.question.id) } diff --git a/app/views/answerbox/_smiles.haml b/app/views/answerbox/_smiles.haml index 84cad86a..ea6ac6ce 100644 --- a/app/views/answerbox/_smiles.haml +++ b/app/views/answerbox/_smiles.haml @@ -7,6 +7,6 @@ - else - a.smiles.all.each do |smile| %a{ href: show_user_profile_path(smile.user.screen_name), - title: user_screen_name(smile.user, anonymous: false, url: false), + title: user_screen_name(smile.user, url: false), data: { toggle: :tooltip, placement: :top, smile_id: smile.id } } %img.avatar-xs{ src: smile.user.profile_picture.url(:medium) } diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index 819b9bda..439c1b25 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -8,7 +8,7 @@ %h6.text-muted.media-heading.answerbox__question-user - if i.question.author_is_anonymous %i.fa.fa-user-secret{ title: t('.anon_hint') } - = t(".asked_html", user: user_screen_name(i.question.user, context_user: i.user, anonymous: i.question.author_is_anonymous), time: time_tooltip(i.question)) + = t(".asked_html", user: user_screen_name(i.question.user, context_user: i.user, author_identifier: i.question.author_identifier), time: time_tooltip(i.question)) - if !i.question.author_is_anonymous && i.question.answer_count.positive? · %a{ href: show_user_question_path(i.question.user.screen_name, i.question.id) } diff --git a/app/views/question/_question.haml b/app/views/question/_question.haml index 4304f786..b68cf563 100644 --- a/app/views/question/_question.haml +++ b/app/views/question/_question.haml @@ -29,5 +29,5 @@ - if hidden = user_screen_name question.user, anonymous: question.author_is_anonymous, url: false - else - = raw t('views.answerbox.asked', user: user_screen_name(question.user, anonymous: question.author_is_anonymous), time: time_tooltip(question)) + = raw t('views.answerbox.asked', user: user_screen_name(question.user, author_identifier: question.author_identifier), time: time_tooltip(question)) .answerbox__question-text= question_markdown question.content