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

Add validation to competition tab content to not allow relative URLs #9792

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

danieljames-dj
Copy link
Member

There are cases where the competition tab content will have relative URLs instead of full URLs. In many cases, the relative URLs may not be intentional. To avoid those cases, added an error if the URL doesn't exist.

@FinnIckler
Copy link
Member

I think this is a good idea, but wouldn't this really slow down saving the competition form? It takes seconds to timeout a request, so even with a couple of wrong links this would turn into a really slow request

@dunkOnIT
Copy link
Contributor

Another option here might be to disable relative links entirely - perhaps a simpler approach to this, as organizers are probably trying to link to absolute URLs in most cases anyway?

@simonkellly
Copy link
Member

Is a potential use case of relative urls to link to something like the registration tab, or a waiting list tab etc. from the same competition without having to change the tab content from a template being cloned?

@dunkOnIT
Copy link
Contributor

Hmm that does make sense. I wonder if it would be possible to create some kind of variable like {competition-id} that people could use in their URL's? This would also fix issues with people hardcoding links to the competition that end up dead later on.

@danieljames-dj
Copy link
Member Author

@FinnIckler This is applicable only for competition tab and not for competition form's markdown fields. Yes, it will slow down the competition tab but it will check only those URLs which doesn't have "http" prefix, and hence all the cases will be within WCA websites. So I guess this should be fine, please let me know if this doesn't makes sense to you, thank you.

I like idea of @dunkOnIT - disable relative links entirely. But as @simonkellly said, they might use it for linking registration tab or waiting list, or something like that.

But I am wondering if anybody will actually be using relative links in the competition tab. This can be investigated with help of WRT by querying the database. The reason why I wonder if it's actually used is because the relative URLs will get "https://worldcubeassociation.org/competitions" prefixed. So in case they want to add relative link to another tab, they have to add the relative link as "CompetitionId2024#1234-tabid" and I don't think somebody will do this instead will directly paste the full URL.

@danieljames-dj
Copy link
Member Author

I had a quick discussion with @gregorbg over slack and he also agrees with @dunkOnIT's suggestion of not allowing relative URLs. I've implemented that now.

@danieljames-dj danieljames-dj changed the title Add validation to competition tab content to verify if the URL actually exists Add validation to competition tab content to not allow relative URLs Aug 25, 2024
@@ -2080,6 +2080,7 @@ en:
tabs_introduction_text: "Here you can add and edit tabs which are shown on the competition info page."
edit:
edit_tab_title: "Edit %{tab_name} tab"
not_full_url_error_message: "You have a relative URL (%{url}) in the content. Please enter full URLs with prefix http:// or https://."
Copy link
Member

Choose a reason for hiding this comment

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

There's already a block competition.errors in the YML file, you should move this key there and drop the _error_message suffix.

@@ -34,6 +34,16 @@ def slug
competition.tabs.where("display_order > ?", display_order).update_all("display_order = display_order - 1")
end

validate :verify_if_urls_are_full_urls, on: :update
private def verify_if_urls_are_full_urls
Copy link
Member

Choose a reason for hiding this comment

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

verify_full_urls should do, maybe I can be convinced to call it verify_if_full_urls. But you don't have to turn the method name into a whole English sentence 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants