From e096ddc999dc4e262420df90d8fce79e03d3b414 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 9 May 2023 22:51:40 +0200 Subject: [PATCH 1/6] Prevent links from notifications from being opened in the dropdown frame --- app/helpers/user_helper.rb | 6 +++--- app/views/notifications/type/_answer.html.haml | 2 +- app/views/notifications/type/_comment.html.haml | 6 +++--- app/views/notifications/type/_dataexport.html.haml | 2 +- app/views/notifications/type/_follow.html.haml | 2 +- app/views/notifications/type/_reaction.html.haml | 4 ++-- app/views/notifications/type/_webpushsubscription.html.haml | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index a494a4d1..5d487409 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -12,7 +12,7 @@ module UserHelper if url return user_path(user) if link_only - return profile_link(user) + return profile_link(user, "_top") end user.profile.safe_name.strip end @@ -23,8 +23,8 @@ module UserHelper private - def profile_link(user) - link_to(user.profile.safe_name, user_path(user), class: ("user--banned" if user.banned?).to_s) + def profile_link(user, target = nil) + link_to(user.profile.safe_name, user_path(user), class: ("user--banned" if user.banned?).to_s, target:) end def should_unmask?(author_identifier) diff --git a/app/views/notifications/type/_answer.html.haml b/app/views/notifications/type/_answer.html.haml index bef0030a..ff2cc2a9 100644 --- a/app/views/notifications/type/_answer.html.haml +++ b/app/views/notifications/type/_answer.html.haml @@ -6,7 +6,7 @@ %img.avatar-xs{ src: notification.target.user.profile_picture.url(:small), loading: :lazy } = t(".heading_html", user: user_screen_name(notification.target.user), - question: link_to(t(".link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.id)), + question: link_to(t(".link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.id), target: "_top"), time: time_tooltip(notification.target)) .list-group .list-group-item diff --git a/app/views/notifications/type/_comment.html.haml b/app/views/notifications/type/_comment.html.haml index 26cb55cd..325ceb61 100644 --- a/app/views/notifications/type/_comment.html.haml +++ b/app/views/notifications/type/_comment.html.haml @@ -7,17 +7,17 @@ - if notification.target.answer.user == current_user = t(".heading_html", user: user_screen_name(notification.target.user), - answer: link_to(t(".active.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)), + answer: link_to(t(".active.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id), target: "_top"), time: time_tooltip(notification.target)) - elsif notification.target.user == notification.target.answer.user = t(".heading_html", user: user_screen_name(notification.target.user), - answer: link_to(t(".passive.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)), + answer: link_to(t(".passive.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id), target: "_top"), time: time_tooltip(notification.target)) - else = t(".heading_html", user: user_screen_name(notification.target.user), - answer: link_to(t(".other.link_text_html", user: user_screen_name(notification.target.answer.user, url: false)), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id)), + answer: link_to(t(".other.link_text_html", user: user_screen_name(notification.target.answer.user, url: false)), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id), target: "_top"), time: time_tooltip(notification.target)) .list-group .list-group-item diff --git a/app/views/notifications/type/_dataexport.html.haml b/app/views/notifications/type/_dataexport.html.haml index 3da53c4c..eeffef10 100644 --- a/app/views/notifications/type/_dataexport.html.haml +++ b/app/views/notifications/type/_dataexport.html.haml @@ -5,4 +5,4 @@ %h6.notification__user = t(".heading") .notification__text - = t(".text_html", settings_export: link_to(t(".settings_export"), settings_export_path)) + = t(".text_html", settings_export: link_to(t(".settings_export"), settings_export_path, target: "_top")) diff --git a/app/views/notifications/type/_follow.html.haml b/app/views/notifications/type/_follow.html.haml index ec44fc56..0994b6de 100644 --- a/app/views/notifications/type/_follow.html.haml +++ b/app/views/notifications/type/_follow.html.haml @@ -5,4 +5,4 @@ %h6.notification__user = user_screen_name notification.target.source .notification__text - = t(".heading_html", time: time_ago_in_words(notification.target.created_at)) + = t(".heading_html", time: time_ago_in_words(notification.target.created_at), target: "_top") diff --git a/app/views/notifications/type/_reaction.html.haml b/app/views/notifications/type/_reaction.html.haml index 8462dd88..08716738 100644 --- a/app/views/notifications/type/_reaction.html.haml +++ b/app/views/notifications/type/_reaction.html.haml @@ -7,12 +7,12 @@ - if notification.target.parent_type == 'Answer' = t(".heading_html", user: user_screen_name(notification.target.user), - type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.parent.id)), + type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.parent.id), target: "_top"), time: time_tooltip(notification.target)) - elsif notification.target.parent_type == 'Comment' = t(".heading_html", user: user_screen_name(notification.target.user), - type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.parent.answer.id)), + type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.parent.answer.id), target: "_top"), time: time_tooltip(notification.target)) .list-group .list-group-item diff --git a/app/views/notifications/type/_webpushsubscription.html.haml b/app/views/notifications/type/_webpushsubscription.html.haml index b077f489..599130ce 100644 --- a/app/views/notifications/type/_webpushsubscription.html.haml +++ b/app/views/notifications/type/_webpushsubscription.html.haml @@ -7,4 +7,4 @@ %h6.notification__user = t(".heading") .notification__text - = t(".text_html", settings_push: link_to(t(".settings_push"), settings_push_notifications_path)) + = t(".text_html", settings_push: link_to(t(".settings_push"), settings_push_notifications_path, target: "_top")) From 0d55ff16c3d2f0ff82da26e8630f882232288f91 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 9 May 2023 22:57:18 +0200 Subject: [PATCH 2/6] Appease the dog overlords --- app/views/notifications/type/_comment.html.haml | 11 +++++++++-- app/views/notifications/type/_reaction.html.haml | 16 +++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/views/notifications/type/_comment.html.haml b/app/views/notifications/type/_comment.html.haml index 325ceb61..4e079878 100644 --- a/app/views/notifications/type/_comment.html.haml +++ b/app/views/notifications/type/_comment.html.haml @@ -7,7 +7,10 @@ - if notification.target.answer.user == current_user = t(".heading_html", user: user_screen_name(notification.target.user), - answer: link_to(t(".active.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id), target: "_top"), + answer: link_to(t(".active.link_text"), + answer_path(username: notification.target.user.screen_name, + id: notification.target.answer.id), + target: "_top"), time: time_tooltip(notification.target)) - elsif notification.target.user == notification.target.answer.user = t(".heading_html", @@ -17,7 +20,11 @@ - else = t(".heading_html", user: user_screen_name(notification.target.user), - answer: link_to(t(".other.link_text_html", user: user_screen_name(notification.target.answer.user, url: false)), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id), target: "_top"), + answer: link_to(t(".other.link_text_html", + user: user_screen_name(notification.target.answer.user, url: false)), + answer_path(username: notification.target.user.screen_name, + id: notification.target.answer.id), + target: "_top"), time: time_tooltip(notification.target)) .list-group .list-group-item diff --git a/app/views/notifications/type/_reaction.html.haml b/app/views/notifications/type/_reaction.html.haml index 08716738..e9958905 100644 --- a/app/views/notifications/type/_reaction.html.haml +++ b/app/views/notifications/type/_reaction.html.haml @@ -4,17 +4,23 @@ .flex-grow-1 .notification__heading %img.avatar-xs{ src: notification.target.user.profile_picture.url(:small), loading: :lazy } - - if notification.target.parent_type == 'Answer' + - if notification.target.parent_type == "Answer" = t(".heading_html", user: user_screen_name(notification.target.user), - type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.parent.id), target: "_top"), + type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), + answer_path(username: notification.target.user.screen_name, + id: notification.target.parent.id), + target: "_top"), time: time_tooltip(notification.target)) - - elsif notification.target.parent_type == 'Comment' + - elsif notification.target.parent_type == "Comment" = t(".heading_html", user: user_screen_name(notification.target.user), - type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.parent.answer.id), target: "_top"), + type: link_to(t(".#{notification.target.parent_type.downcase}.link_text"), + answer_path(username: notification.target.user.screen_name, + id: notification.target.parent.answer.id), + target: "_top"), time: time_tooltip(notification.target)) .list-group .list-group-item %h6.notification__list-heading= t("activerecord.models.#{notification.target.parent_type.downcase}.one") - = markdown notification.target.parent.content[0..60] + (notification.target.parent.content.length > 60 ? '[...]' : '') + = markdown notification.target.parent.content[0..60] + (notification.target.parent.content.length > 60 ? "[...]" : "") From 2c7225259160b324e177683aab2d9a5be9722f79 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 9 May 2023 22:57:51 +0200 Subject: [PATCH 3/6] Use Unicode ellipsis --- app/views/notifications/type/_answer.html.haml | 4 ++-- app/views/notifications/type/_comment.html.haml | 4 ++-- app/views/notifications/type/_reaction.html.haml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/notifications/type/_answer.html.haml b/app/views/notifications/type/_answer.html.haml index ff2cc2a9..8850c957 100644 --- a/app/views/notifications/type/_answer.html.haml +++ b/app/views/notifications/type/_answer.html.haml @@ -11,7 +11,7 @@ .list-group .list-group-item %h6.notification__list-heading= t("activerecord.models.question.one") - = markdown notification.target.question.content[0..60] + (notification.target.question.content.length > 60 ? '[...]' : '') + = markdown notification.target.question.content[0..60] + (notification.target.question.content.length > 60 ? '[…]' : '') .list-group-item %h6.notification__list-heading= t("activerecord.models.answer.one") - = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? '[...]' : '') + = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? '[…]' : '') diff --git a/app/views/notifications/type/_comment.html.haml b/app/views/notifications/type/_comment.html.haml index 4e079878..397d03ca 100644 --- a/app/views/notifications/type/_comment.html.haml +++ b/app/views/notifications/type/_comment.html.haml @@ -29,7 +29,7 @@ .list-group .list-group-item %h6.notification__list-heading= t("activerecord.models.answer.one") - = markdown notification.target.answer.content[0..60] + (notification.target.answer.content.length > 60 ? '[...]' : '') + = markdown notification.target.answer.content[0..60] + (notification.target.answer.content.length > 60 ? '[…]' : '') .list-group-item %h6.notification__list-heading= t("activerecord.models.comment.one") - = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? '[...]' : '') + = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? '[…]' : '') diff --git a/app/views/notifications/type/_reaction.html.haml b/app/views/notifications/type/_reaction.html.haml index e9958905..ae9259c1 100644 --- a/app/views/notifications/type/_reaction.html.haml +++ b/app/views/notifications/type/_reaction.html.haml @@ -23,4 +23,4 @@ .list-group .list-group-item %h6.notification__list-heading= t("activerecord.models.#{notification.target.parent_type.downcase}.one") - = markdown notification.target.parent.content[0..60] + (notification.target.parent.content.length > 60 ? "[...]" : "") + = markdown notification.target.parent.content[0..60] + (notification.target.parent.content.length > 60 ? "[…]" : "") From 4bf977e96cd42f1ed19c93d72452f042edf338e4 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 9 May 2023 23:03:26 +0200 Subject: [PATCH 4/6] Fix lint errors for the remaining notification types --- app/views/notifications/type/_answer.html.haml | 4 ++-- app/views/notifications/type/_comment.html.haml | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/notifications/type/_answer.html.haml b/app/views/notifications/type/_answer.html.haml index 8850c957..890fb394 100644 --- a/app/views/notifications/type/_answer.html.haml +++ b/app/views/notifications/type/_answer.html.haml @@ -11,7 +11,7 @@ .list-group .list-group-item %h6.notification__list-heading= t("activerecord.models.question.one") - = markdown notification.target.question.content[0..60] + (notification.target.question.content.length > 60 ? '[…]' : '') + = markdown notification.target.question.content[0..60] + (notification.target.question.content.length > 60 ? "[…]" : "") .list-group-item %h6.notification__list-heading= t("activerecord.models.answer.one") - = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? '[…]' : '') + = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? "[…]" : "") diff --git a/app/views/notifications/type/_comment.html.haml b/app/views/notifications/type/_comment.html.haml index 397d03ca..56c3797c 100644 --- a/app/views/notifications/type/_comment.html.haml +++ b/app/views/notifications/type/_comment.html.haml @@ -15,7 +15,10 @@ - elsif notification.target.user == notification.target.answer.user = t(".heading_html", user: user_screen_name(notification.target.user), - answer: link_to(t(".passive.link_text"), answer_path(username: notification.target.user.screen_name, id: notification.target.answer.id), target: "_top"), + answer: link_to(t(".passive.link_text"), + answer_path(username: notification.target.user.screen_name, + id: notification.target.answer.id), + target: "_top"), time: time_tooltip(notification.target)) - else = t(".heading_html", @@ -29,7 +32,7 @@ .list-group .list-group-item %h6.notification__list-heading= t("activerecord.models.answer.one") - = markdown notification.target.answer.content[0..60] + (notification.target.answer.content.length > 60 ? '[…]' : '') + = markdown notification.target.answer.content[0..60] + (notification.target.answer.content.length > 60 ? "[…]" : "") .list-group-item %h6.notification__list-heading= t("activerecord.models.comment.one") - = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? '[…]' : '') + = markdown notification.target.content[0..60] + (notification.target.content.length > 60 ? "[…]" : "") From 46c2412ad8d6aab01ac9973dea3828fcdbc59129 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 9 May 2023 23:08:35 +0200 Subject: [PATCH 5/6] Update tests for `user_screen_name` to include `target` attribute --- spec/helpers/user_helper_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/helpers/user_helper_spec.rb b/spec/helpers/user_helper_spec.rb index 1187070a..254c6b6e 100644 --- a/spec/helpers/user_helper_spec.rb +++ b/spec/helpers/user_helper_spec.rb @@ -123,7 +123,7 @@ describe UserHelper, type: :helper do context "user is not banned" do it "returns a link tag to the user's profile" do - expect(subject).to eq(link_to(user.profile.safe_name, user_path(user), class: "")) + expect(subject).to eq(link_to(user.profile.safe_name, user_path(user), class: "", target: "_top")) end end @@ -133,7 +133,7 @@ describe UserHelper, type: :helper do end it "returns a link tag to the user's profile" do - expect(subject).to eq(link_to(user.profile.safe_name, user_path(user), class: "user--banned")) + expect(subject).to eq(link_to(user.profile.safe_name, user_path(user), class: "user--banned", target: "_top")) end end end From 6643a4763f963664ab33b4c1f46fa7a1ac0bc758 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 9 May 2023 23:20:36 +0200 Subject: [PATCH 6/6] Make `target` a keyword argument for `user_screen_name` helper Co-authored-by: nilsding --- app/helpers/user_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index 5d487409..0f027e52 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -12,7 +12,7 @@ module UserHelper if url return user_path(user) if link_only - return profile_link(user, "_top") + return profile_link(user, target: "_top") end user.profile.safe_name.strip end @@ -23,7 +23,7 @@ module UserHelper private - def profile_link(user, target = nil) + def profile_link(user, target: nil) link_to(user.profile.safe_name, user_path(user), class: ("user--banned" if user.banned?).to_s, target:) end