Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

AO3-4516 Make remaining absolute urls, relative paths #2395

Merged
merged 10 commits into from Aug 11, 2016

Conversation

Projects
None yet
5 participants
app/helpers/application_helper.rb
@@ -126,7 +126,7 @@ def non_anonymous_byline(creation)
end
def pseud_link(pseud)
@sarken

sarken Mar 14, 2016

Owner

This is used in byline, which is used in a lot of places, some of which need the full URL -- have you checked RSS feeds, downloads, emails, and share code to make sure that they still have the full URL? I just did a spot check and while the share code looks okay, an HTML download of a work has a broken link for the byline, giving me only <a href="/users/testy2/pseuds/testy2" rel="author">testy2</a> when it needs to be the full URL.

app/helpers/tags_helper.rb
@@ -76,7 +76,7 @@ def link_to_tag_works(tag, options = {})
end
def link_to_tag_with_text(tag, link_text, options = {})
- link_to_with_tag_class(@collection ? collection_tag_url(@collection, tag) : tag_url(tag), link_text, options)
+ link_to_with_tag_class(@collection ? collection_tag_path(@collection, tag) : tag_path(tag), link_text, options)
@sarken

sarken Mar 14, 2016

Owner

I'm pretty sure these are okay, but while you're checking on the byline change, it would be a good idea to also do a quick check of tag links in emails, RSS feeds, downloads, and the share code just to be sure.

Contributor

zz9pzza commented Mar 14, 2016

Thanks sarken I will look at that and fix it, I can't see an obvious way of testing the content of the downloads. We might be able to do it for html. If we had multiple urls we supported, would the correct way be to have a set url at the front ( eg a download generated via a "insecure or secure" url should have the canonical url for the site be from the archive config "APP_URL"

For what it's worth, the branch that's currently on test.a.o seems to have solved a mixed-content issue that happens with the user icons off of the s3 bucket when you expand comments on a work.

Contributor

zz9pzza commented Mar 19, 2016

I have done the downloads. I have checked the rss and that those need to be absolute.The share code is absolute.

app/helpers/tags_helper.rb
@@ -76,7 +76,11 @@ def link_to_tag_works(tag, options = {})
end
def link_to_tag_with_text(tag, link_text, options = {})
- link_to_with_tag_class(@collection ? collection_tag_path(@collection, tag) : tag_path(tag), link_text, options)
+ if options[:full_path]
@sarken

sarken Mar 20, 2016

Owner

Would it be possible to do something like this to make it DRYer?

def link_to_tag_with_text(tag, link_text, options = {})
  collection_url_for_tag = options[:full_path] ? collection_tag_url(@collection, tag) : collection_tag_path(@collection, tag)
  link_to_with_tag_class(@collection ? collection_url_for_tag : tag_path(tag), link_text, options)
end

My other question is do we definitely always want tag_path, or should it be tag_url when options[:full_path]?

@sarken

sarken Mar 25, 2016

Owner

Actually, ignore my question about DRYness -- it's so much easier to read the way it is, I think we can probably leave it. >.>

However, the question about path vs. url remains.

@zz9pzza

zz9pzza Mar 25, 2016

Contributor

If we want the full url then we should se the option to be full_path otherwise not :)

@sarken

sarken Mar 25, 2016

Owner

What I mean is you're using tag_path even when full_path is true.

@zz9pzza

zz9pzza Mar 25, 2016

Contributor

your right I will look at that

app/helpers/works_helper.rb
@@ -134,7 +134,7 @@ def download_url_for_work(work, format)
# Generates a list of a work's tags and details for use in feeds
def feed_summary(work)
tags = work.tags.group_by(&:type)
- text = "<p>by #{byline(work, visibility: 'public')}</p>"
+ text = "<p>by #{byline(work, { visibility: 'public', full_path: true})}</p>"
@sarken

sarken Mar 20, 2016

Owner

Can you add a space between true and the }?

app/helpers/works_helper.rb
@@ -152,7 +152,7 @@ def feed_summary(work)
else
type.pluralize
end
- text << "<li>#{label}: #{tags[type].map{ |t| link_to_tag_works(t) }.join(', ')}</li>"
+ text << "<li>#{label}: #{tags[type].map{ |t| link_to_tag_works(t,{full_path: true}) }.join(', ')}</li>"
@sarken

sarken Mar 20, 2016

Owner

I think there needs to be a space after the , and before the }

app/helpers/application_helper.rb
@@ -90,15 +90,16 @@ def byline(creation, options={})
if creation.respond_to?(:anonymous?) && creation.anonymous?
anon_byline = ts("Anonymous")
if (logged_in_as_admin? || is_author_of?(creation)) && options[:visibility] != 'public'
- anon_byline += " [".html_safe + non_anonymous_byline(creation) + "]".html_safe
+ anon_byline += " [".html_safe + non_anonymous_byline(creation,options[:only_path]) + "]".html_safe
@sarken

sarken Mar 20, 2016

Owner

Missing space between the , and options[:only_path]

app/helpers/application_helper.rb
- expand_all = content_tag(:a, ts("Expand All"), :href=>"#", :class => "expand_all", "target_class" => target, :role => "button")
- contract_all = content_tag(:a, ts("Contract All"), :href=>"#", :class => "contract_all", "target_class" => target, :role => "button")
- content_tag(:span, expand_all + "\n".html_safe + contract_all, :class => "actions hidden showme", :role => "menu")
+ expand_all = content_tag(:a, ts("Expand All"), href:"#", class: "expand_all", "target_class" => target, role: "button")
@sarken

sarken Mar 20, 2016

Owner

Missing space between href: and "#"

app/helpers/application_helper.rb
- contract_all = content_tag(:a, ts("Contract All"), :href=>"#", :class => "contract_all", "target_class" => target, :role => "button")
- content_tag(:span, expand_all + "\n".html_safe + contract_all, :class => "actions hidden showme", :role => "menu")
+ expand_all = content_tag(:a, ts("Expand All"), href:"#", class: "expand_all", "target_class" => target, role: "button")
+ contract_all = content_tag(:a, ts("Contract All"), href:"#", class: "contract_all", "target_class" => target, role: "button")
@sarken

sarken Mar 20, 2016

Owner

Missing space between href: and "#"

Owner

shalott commented Apr 10, 2016

The code looks okay to me reading it over but I am definitely leery of whether the existing tests adequately cover this change. Would there be any way to crawl the live production AO3 site to find all the instances of "http://(www.)?archiveofourown" that currently exist so we can check them?

@@ -152,7 +152,7 @@ def feed_summary(work)
else
type.pluralize
end
- text << "<li>#{label}: #{tags[type].map{ |t| link_to_tag_works(t) }.join(', ')}</li>"
+ text << "<li>#{label}: #{tags[type].map{ |t| link_to_tag_works(t, {full_path: true }) }.join(', ')}</li>"
@houndci-bot

houndci-bot May 8, 2016

Redundant curly braces around a hash parameter.
Space missing to the left of {.
Space inside { missing.

@@ -134,7 +134,7 @@ def download_url_for_work(work, format)
# Generates a list of a work's tags and details for use in feeds
def feed_summary(work)
tags = work.tags.group_by(&:type)
- text = "<p>by #{byline(work, visibility: 'public')}</p>"
+ text = "<p>by #{byline(work, { visibility: 'public', full_path: true })}</p>"
@houndci-bot

houndci-bot May 8, 2016

Redundant curly braces around a hash parameter.

@@ -79,7 +79,7 @@ def allowed_css_instructions
# see http://stackoverflow.com/questions/2425690/multiple-remote-form-for-on-the-same-page-causes-duplicate-ids
def field_with_unique_id( form, field_type, object, field_name )
field_id = "#{object.class.name.downcase}_#{object.id.to_s}_#{field_name.to_s}"
- form.send( field_type, field_name, :id => field_id )
+ form.send( field_type, field_name, id: field_id )
@houndci-bot

houndci-bot May 8, 2016

Space inside parentheses detected.

}.merge(options)
field_name = options[:field_name] || field_name(form, attribute)
field_name += '[]'
base_id = options[:field_id] || field_id(form, attribute)
checkboxes_id = "#{base_id}_checkboxes"
- opts = options[:disabled] ? {:disabled => "true"} : {}
+ opts = options[:disabled] ? {disabled: "true"} : {}
@houndci-bot

houndci-bot May 8, 2016

Space inside { missing.
Space inside } missing.

- form.fields_for(nested_model_name, new_nested_model, :child_index => child_index) {|child_form|
- render(:partial => partial_to_render, :locals => {:form => child_form, :index => child_index}.merge(locals))
+ form.fields_for(nested_model_name, new_nested_model, child_index: child_index) {|child_form|
+ render(partial: partial_to_render, locals: {form: child_form, index: child_index}.merge(locals))
@houndci-bot

houndci-bot May 8, 2016

Space inside { missing.
Space inside } missing.

toggle = "".html_safe
if options[:include_toggle] && !options[:concise] && size > (ArchiveConfig.OPTIONS_TO_SHOW * 6)
toggle = checkbox_section_toggle(checkboxes_id, size)
end
# We wrap the whole thing in a div
- return content_tag(:div, checkboxes_ul + toggle + (options[:include_blank] ? hidden_field_tag(field_name, " ") : ''.html_safe), :id => checkboxes_id)
+ return content_tag(:div, checkboxes_ul + toggle + (options[:include_blank] ? hidden_field_tag(field_name, " ") : ''.html_safe), id: checkboxes_id)
@houndci-bot

houndci-bot May 8, 2016

Redundant return detected.

else
- link_to_unless params[:sort_column].nil?, title, url_for(params.merge :sort_column => nil, :sort_direction => nil)
+ link_to_unless params[:sort_column].nil?, title, url_for(params.merge sort_column: nil, sort_direction: nil)
@houndci-bot

houndci-bot May 8, 2016

Add parentheses to nested method call params.merge sort_column: nil, sort_direction: nil.

end
# see above
def link_to_remove_section(linktext, form, class_of_section_to_remove="removeme")
form.hidden_field(:_destroy) + "\n" +
- link_to_function(linktext, "remove_section(this, \"#{class_of_section_to_remove}\")", :class => "hidden showme")
+ link_to_function(linktext, "remove_section(this, \"#{class_of_section_to_remove}\")", class: "hidden showme")
@houndci-bot

houndci-bot May 8, 2016

Use 2 (not 0) spaces for indenting an expression spanning multiple lines.

@@ -512,8 +513,8 @@ def checkbox_section(form, attribute, choices, options = {})
end
value = choice.send(options[:value_method])
checkbox_id = "#{base_id}_#{name_to_id(value)}"
- checkbox = check_box_tag(field_name, value, is_checked, opts.merge({:id => checkbox_id}))
- checkbox_and_label = label_tag checkbox_id, :class => "action" do
+ checkbox = check_box_tag(field_name, value, is_checked, opts.merge({id: checkbox_id}))
@houndci-bot

houndci-bot May 8, 2016

Redundant curly braces around a hash parameter.
Space inside { missing.
Space inside } missing.

@@ -323,16 +324,16 @@ def link_to_add_section(linktext, form, nested_model_name, partial_to_render, lo
new_nested_model = form.object.class.reflect_on_association(nested_model_name).klass.new
child_index = "new_#{nested_model_name}"
rendered_partial_to_add =
- form.fields_for(nested_model_name, new_nested_model, :child_index => child_index) {|child_form|
- render(:partial => partial_to_render, :locals => {:form => child_form, :index => child_index}.merge(locals))
+ form.fields_for(nested_model_name, new_nested_model, child_index: child_index) {|child_form|
@houndci-bot

houndci-bot May 8, 2016

Avoid using {...} for multi-line blocks.

@@ -253,9 +254,9 @@ def sort_link(title, column=nil, options = {})
direction = options[:desc_default] ? 'DESC' : 'ASC'
end
link_to_unless condition, ((direction == 'ASC' ? '&#8593;&#160;' : '&#8595;&#160;') + title).html_safe,
- request.parameters.merge( {:sort_column => column, :sort_direction => direction} ), {:class => css_class, :title => (direction == 'ASC' ? ts('sort up') : ts('sort down'))}
+ request.parameters.merge( {sort_column: column, sort_direction: direction} ), {class: css_class, title: (direction == 'ASC' ? ts('sort up') : ts('sort down'))}
@houndci-bot

houndci-bot May 8, 2016

Align the parameters of a method call if they span more than one line.
Redundant curly braces around a hash parameter.
Space inside { missing.
Space inside } missing.
Space inside parentheses detected.

- Rails.cache.fetch("#{creation.cache_key}/byline-nonanon") do
+ def non_anonymous_byline(creation, url_path = nil)
+ only_path = url_path.nil? ? true : url_path
+ Rails.cache.fetch("#{creation.cache_key}/byline-nonanon/#{only_path.to_s}") do
@houndci-bot

houndci-bot May 8, 2016

Redundant use of Object#to_s in interpolation.

Contributor

zz9pzza commented May 8, 2016

"The code looks okay to me reading it over but I am definitely leery of whether the existing tests adequately cover this change. Would there be any way to crawl the live production AO3 site to find all the instances of "http://(www.)?archiveofourown" that currently exist so we can check them?"

Not easily and I would point out that we don't need to rely on this code immediately we can start out with a secure.archiveofourown.org which we can examine and look at before the migration to https by default.

So in short I can't reliably crawl ao3.org.

@sarken sarken merged commit 6d33efb into otwcode:master Aug 11, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
hound 22 violations found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment