Don't autoload PeopleHelper during initialization
this is for future rails versions with zeitwerk autoloader where this isn't allowed anymore
This commit is contained in:
parent
a7a02e87cf
commit
41633fcea9
5 changed files with 26 additions and 33 deletions
|
|
@ -27,10 +27,10 @@ module PeopleHelper
|
||||||
|
|
||||||
def person_link(person, opts={})
|
def person_link(person, opts={})
|
||||||
css_class = person_link_class(person, opts[:class])
|
css_class = person_link_class(person, opts[:class])
|
||||||
remote_or_hovercard_link = Rails.application.routes.url_helpers.person_path(person).html_safe
|
remote_or_hovercard_link = person_path(person)
|
||||||
"<a data-hovercard='#{remote_or_hovercard_link}' href='#{remote_or_hovercard_link}' class='#{css_class}'>"\
|
tag.a('data-hovercard': remote_or_hovercard_link, href: remote_or_hovercard_link, class: css_class) do
|
||||||
"#{html_escape_once(opts[:display_name] || person.name)}</a>"\
|
opts[:display_name] || person.name
|
||||||
.html_safe
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def person_image_tag(person, size = :thumb_small)
|
def person_image_tag(person, size = :thumb_small)
|
||||||
|
|
@ -44,15 +44,12 @@ module PeopleHelper
|
||||||
if opts[:to] == :photos
|
if opts[:to] == :photos
|
||||||
link_to person_image_tag(person, opts[:size]), person_photos_path(person)
|
link_to person_image_tag(person, opts[:size]), person_photos_path(person)
|
||||||
else
|
else
|
||||||
css_class = person_link_class(person, opts[:class])
|
tag.a(href: person_path(person), class: person_link_class(person, opts[:class])) do
|
||||||
remote_or_hovercard_link = Rails.application.routes.url_helpers.person_path(person).html_safe
|
person_image_tag(person, opts[:size])
|
||||||
"<a href='#{remote_or_hovercard_link}' class='#{css_class}' #{('target=' + opts[:target]) if opts[:target]}>
|
end
|
||||||
#{person_image_tag(person, opts[:size])}
|
|
||||||
</a>".html_safe
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Rails.application.routes.url_helpers is needed since this is indirectly called from a model
|
|
||||||
def local_or_remote_person_path(person, opts={})
|
def local_or_remote_person_path(person, opts={})
|
||||||
opts.merge!(:protocol => AppConfig.pod_uri.scheme, :host => AppConfig.pod_uri.authority)
|
opts.merge!(:protocol => AppConfig.pod_uri.scheme, :host => AppConfig.pod_uri.authority)
|
||||||
absolute = opts.delete(:absolute)
|
absolute = opts.delete(:absolute)
|
||||||
|
|
@ -61,19 +58,11 @@ module PeopleHelper
|
||||||
username = person.username
|
username = person.username
|
||||||
unless username.include?('.')
|
unless username.include?('.')
|
||||||
opts.merge!(:username => username)
|
opts.merge!(:username => username)
|
||||||
if absolute
|
return absolute ? user_profile_url(opts) : user_profile_path(opts)
|
||||||
return Rails.application.routes.url_helpers.user_profile_url(opts)
|
|
||||||
else
|
|
||||||
return Rails.application.routes.url_helpers.user_profile_path(opts)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if absolute
|
absolute ? person_url(person, opts) : person_path(person, opts)
|
||||||
return Rails.application.routes.url_helpers.person_url(person, opts)
|
|
||||||
else
|
|
||||||
return Rails.application.routes.url_helpers.person_path(person, opts)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Diaspora::Mentionable
|
module Diaspora::Mentionable
|
||||||
|
|
@ -93,7 +92,7 @@ module Diaspora::Mentionable
|
||||||
|
|
||||||
# inline module for namespacing
|
# inline module for namespacing
|
||||||
module MentionsInternal
|
module MentionsInternal
|
||||||
extend ::PeopleHelper
|
extend ERB::Util
|
||||||
|
|
||||||
# output a formatted mention link as defined by the given arguments.
|
# output a formatted mention link as defined by the given arguments.
|
||||||
# if the display name is blank, falls back to the person's name.
|
# if the display name is blank, falls back to the person's name.
|
||||||
|
|
@ -105,10 +104,15 @@ module Diaspora::Mentionable
|
||||||
def self.mention_link(person, display_name, diaspora_id, opts)
|
def self.mention_link(person, display_name, diaspora_id, opts)
|
||||||
return display_name || diaspora_id unless person.present?
|
return display_name || diaspora_id unless person.present?
|
||||||
|
|
||||||
|
display_name ||= person.name
|
||||||
if opts[:plain_text]
|
if opts[:plain_text]
|
||||||
display_name || person.name
|
display_name
|
||||||
else
|
else
|
||||||
person_link(person, class: PERSON_HREF_CLASS, display_name: display_name)
|
# rubocop:disable Rails/OutputSafety
|
||||||
|
remote_or_hovercard_link = Rails.application.routes.url_helpers.person_path(person).html_safe
|
||||||
|
"<a data-hovercard=\"#{remote_or_hovercard_link}\" href=\"#{remote_or_hovercard_link}\" " \
|
||||||
|
"class=\"#{PERSON_HREF_CLASS}\">#{html_escape_once(display_name)}</a>".html_safe
|
||||||
|
# rubocop:enable Rails/OutputSafety
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -121,7 +125,7 @@ module Diaspora::Mentionable
|
||||||
def self.profile_link(person, display_name, diaspora_id)
|
def self.profile_link(person, display_name, diaspora_id)
|
||||||
return display_name || diaspora_id unless person.present?
|
return display_name || diaspora_id unless person.present?
|
||||||
|
|
||||||
"[#{display_name || person.name}](#{local_or_remote_person_path(person)})"
|
"[#{display_name || person.name}](#{Rails.application.routes.url_helpers.person_path(person)})"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ describe PeopleHelper, :type => :helper do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'links by id for a local user' do
|
it 'links by id for a local user' do
|
||||||
expect(person_link(@user.person)).to include "href='#{person_path(@user.person)}'"
|
expect(person_link(@user.person)).to include "href=\"#{person_path(@user.person)}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
it "recognizes the 'display_name' option" do
|
it "recognizes the 'display_name' option" do
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe Diaspora::Mentionable do
|
describe Diaspora::Mentionable do
|
||||||
include PeopleHelper
|
|
||||||
|
|
||||||
let(:people) { [alice, bob, eve].map(&:person) }
|
let(:people) { [alice, bob, eve].map(&:person) }
|
||||||
let(:names) { %w(Alice\ A Bob\ B "Eve>\ E) }
|
let(:names) { %w(Alice\ A Bob\ B "Eve>\ E) }
|
||||||
|
|
||||||
|
|
@ -41,7 +39,9 @@ STR
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".format" do
|
describe ".format" do
|
||||||
context "html output" do
|
context "html output", type: :helper do
|
||||||
|
include PeopleHelper
|
||||||
|
|
||||||
it "adds the links to the formatted message" do
|
it "adds the links to the formatted message" do
|
||||||
fmt_msg = Diaspora::Mentionable.format(test_text_with_names, people)
|
fmt_msg = Diaspora::Mentionable.format(test_text_with_names, people)
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ STR
|
||||||
fmt_msg = Diaspora::Mentionable.format(test_txt, people)
|
fmt_msg = Diaspora::Mentionable.format(test_txt, people)
|
||||||
|
|
||||||
expect(fmt_msg).not_to include(name)
|
expect(fmt_msg).not_to include(name)
|
||||||
expect(fmt_msg).to include(">", "<", "'") # ">", "<", "'"
|
expect(fmt_msg).to include("</a><script>alert('h')</script>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ STR
|
||||||
user_a.aspects.where(name: "generic").first.contacts.map(&:person_id)
|
user_a.aspects.where(name: "generic").first.contacts.map(&:person_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(txt).to include("@[user C](#{local_or_remote_person_path(user_c.person)}")
|
expect(txt).to include("@[user C](#{Rails.application.routes.url_helpers.person_path(user_c.person)}")
|
||||||
expect(txt).not_to include("href")
|
expect(txt).not_to include("href")
|
||||||
expect(txt).not_to include(mention)
|
expect(txt).not_to include(mention)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ describe Diaspora::MessageRenderer do
|
||||||
it 'makes plain links for people not in the post aspects' do
|
it 'makes plain links for people not in the post aspects' do
|
||||||
message = message("@{Bob; #{bob.person.diaspora_handle}}", link_all_mentions: true).html
|
message = message("@{Bob; #{bob.person.diaspora_handle}}", link_all_mentions: true).html
|
||||||
expect(message).to_not include 'hovercard'
|
expect(message).to_not include 'hovercard'
|
||||||
expect(message).to include '/u/bob'
|
expect(message).to include "/people/#{bob.person.guid}"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "makes no hovercards if they're disabled" do
|
it "makes no hovercards if they're disabled" do
|
||||||
|
|
@ -91,7 +91,7 @@ describe Diaspora::MessageRenderer do
|
||||||
disable_hovercards: true
|
disable_hovercards: true
|
||||||
).html
|
).html
|
||||||
expect(message).to_not include 'hovercard'
|
expect(message).to_not include 'hovercard'
|
||||||
expect(message).to include '/u/bob'
|
expect(message).to include "/people/#{bob.person.guid}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue