Merge pull request #1207 from Retrospring/fix/if-iframes-are-so-good-why-is-there-no-iframe2

Prevent links from notifications from being opened in the dropdown frame
This commit is contained in:
Karina Kwiatek 2023-05-09 23:38:04 +02:00 committed by GitHub
commit 743d7103fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 37 additions and 21 deletions

View File

@ -12,7 +12,7 @@ module UserHelper
if url
return user_path(user) if link_only
return profile_link(user)
return profile_link(user, target: "_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)

View File

@ -6,12 +6,12 @@
%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
%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 ? "[…]" : "")

View File

@ -7,22 +7,32 @@
- 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
%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 ? "[…]" : "")

View File

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

View File

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

View File

@ -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)),
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)),
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 ? "[…]" : "")

View File

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

View File

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