Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #30143 - passing root_url without section to documentation_url #7754

Merged
merged 1 commit into from
Jul 14, 2020

Conversation

Ron-Lavi
Copy link
Member

documentation_url expect section to be provided
also when only using root_url

@theforeman-bot
Copy link
Member

Issues: #30143

Comment on lines 34 to 38
if section.empty?
"https://theforeman.org/documentation.html##{SETTINGS[:version].short}"
options[:root_url] || "https://theforeman.org/documentation.html##{SETTINGS[:version].short}"
else
root_url + section
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://theforeman.org/documentation.html is an old url that doesn't exist anymore, it redirects to the quickstart guide.
I believe this whole condition should just be: root_url + section without checking if the section is empty (since that would just return the root_url).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to create a default url, so the user will not be redirected to 404 page, if some pages did move. Especially for stale plugins.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but right now if the section is empty it points to a stale url, while the base works just fine. And this function doesn't work for plugins anyways?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @tbrisker !
I would be ok with removing the section,
or replacing it with another url, e.g: https://theforeman.org/manuals/`version`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking to @tbrisker, it looks like leftovers of our old documentation site structure. Now we can redirect to https://theforeman.org/manuals/#{SETTINGS[:version].short}/index.html. Meaning we can simplify the method to always return root_url + section (in case the section is empty - it will fall back to root_url, which is fine.

Comment on lines 34 to 38
if section.empty?
"https://theforeman.org/documentation.html##{SETTINGS[:version].short}"
options[:root_url] || "https://theforeman.org/documentation.html##{SETTINGS[:version].short}"
else
root_url + section
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After talking to @tbrisker, it looks like leftovers of our old documentation site structure. Now we can redirect to https://theforeman.org/manuals/#{SETTINGS[:version].short}/index.html. Meaning we can simplify the method to always return root_url + section (in case the section is empty - it will fall back to root_url, which is fine.

@Ron-Lavi
Copy link
Member Author

Thanks @ShimShtein @tbrisker !
rebased and updated with your suggestion.

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failure related

@Ron-Lavi
Copy link
Member Author

Failed on:

TypeError: no implicit conversion of nil into String
    app/controllers/links_controller.rb:34:in `+'
    app/controllers/links_controller.rb:34:in `documentation_url'

Trying to use a ternary instead, e.g:
section ? root_url + section : root_url

@tbrisker
Copy link
Member

Failed on:

TypeError: no implicit conversion of nil into String
    app/controllers/links_controller.rb:34:in `+'
    app/controllers/links_controller.rb:34:in `documentation_url'

Trying to use a ternary instead, e.g:
section ? root_url + section : root_url

The issue is in the external_url method - it calls the function with options['section'], options, so the first argument is nil if the key doesn't exist, thus the default is never triggered.
The same issue is al true for the other methods - in ruby, the default value is only used if no parameter is passed to the function, if nil is passed than it overrides the default. I have to say I find it quite odd that each of the functions in the controller expects the parameters in a different way, rather than having a common interface (e.g. taking options and extracting needed parameters from it).

@Ron-Lavi
Copy link
Member Author

@tbrisker @ShimShtein should we refactor to pass only options as argument to each case in external_url?

Copy link
Member

@ShimShtein ShimShtein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not to change method signatures - they are used by the theme

else
root_url + section
end
section ? root_url + section : root_url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
section ? root_url + section : root_url
root_url + (section || '')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, updated!

@Ron-Lavi
Copy link
Member Author

Ron-Lavi commented Jul 9, 2020

rebased, ready for another round :)

@Ron-Lavi Ron-Lavi force-pushed the fix/documentation_url_section branch from b42d8b9 to b565547 Compare July 12, 2020 11:18
@Ron-Lavi Ron-Lavi force-pushed the fix/documentation_url_section branch from b565547 to a50c0b9 Compare July 14, 2020 12:37
@Ron-Lavi
Copy link
Member Author

sorry, my fix got reverted on the rebase,
now it should work - tests passed locally.

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APJ, thanks @LaViro !

@tbrisker tbrisker merged commit 86c0f63 into theforeman:develop Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants