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

1791 enforce full domain in site settings #2201

Merged
merged 7 commits into from
Jan 23, 2024

Conversation

aaaaargZombies
Copy link
Contributor

fixes #1791

A small fix that required a lot of test wrangling

@aaaaargZombies aaaaargZombies requested a review from a team January 22, 2024 09:18
@r-ferrier r-ferrier self-assigned this Jan 22, 2024
@ivan-kocienski-gfsc
Copy link
Contributor

Looking at the PR and the issue I think the issue is incorrect: the field is called "domain" and is intended to be just a URL domain, which doesn't include the http bit or anything after the query string.

Copy link
Contributor

@r-ferrier r-ferrier left a comment

Choose a reason for hiding this comment

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

I think this looks good, I prefer this route of validating on submit because it makes it clear what needs changing with the least visual clutter and only needs to fire if someone gets it wrong.

Annoying about the tests!

Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc left a comment

Choose a reason for hiding this comment

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

wait i think i found a bug with this.

i will write it up. just stopping this being merged quickly

@aaaaargZombies
Copy link
Contributor Author

change domain to url so clear what it's being used for. do migration.

Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc left a comment

Choose a reason for hiding this comment

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

As per our discussions

@@ -36,6 +36,7 @@ class Site < ApplicationRecord
validates :name, :slug, :domain, presence: true
validates :place_name unless :default_site?
validates :hero_text, length: { maximum: 120 }
validates :domain, format: { with: %r{\Ahttps://[^\s,]+\z}, message: 'A domain must start with "https://"' }
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this domain field is a really important part for how sites work!

here we use domain to find the site from the request.


Okay (after discussing this) it looks like we don't want to use the domain this way any more, so maybe refactor Site.find_by_request method to not reference the domain and update any tests covering that logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe also rename the field to URL (or site_url if that is too generic a name)

Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc left a comment

Choose a reason for hiding this comment

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

Unfortunately got some small things, one of them a showstopper.

You missed a domain->url switch in the PartnershipCardComponent

Screenshot_2024-01-23_09-09-34

(Might be worth writing a test for this page?)

@@ -16,7 +16,7 @@ class SiteType < Types::BaseObject
null: false,
description: 'Short unique URL friendly version of name'

field :domain, String,
field :url, String,
Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc Jan 23, 2024

Choose a reason for hiding this comment

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

This is probably okay but its worth bearing in mind that outside people may rely on our public API and so we should not change the name in a breaking way for them. Let's just alias domain to url for now


class ChangeDomainToUrl < ActiveRecord::Migration[6.1]
def self.up
rename_column :sites, :domain, :url
Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc Jan 23, 2024

Choose a reason for hiding this comment

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

you can actually just use the one method here self.change and rails will figure out the inverse of the rename depending if you are migrating up or down on its own (not a suggestion, just a comment for future)

@aaaaargZombies
Copy link
Contributor Author

@ivan-kocienski-gfsc hopefully this resolves those last issues

@aaaaargZombies
Copy link
Contributor Author

I should also say I rebuilt transdimension elm app locally with no issues, I looked at the data folder and I think we just pull in partners based on the (partnership)tag not any site rule, probably because it covers the whole uk so geographic info is redundant.

Copy link
Contributor

@ivan-kocienski-gfsc ivan-kocienski-gfsc left a comment

Choose a reason for hiding this comment

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

Looks great! good work here

@aaaaargZombies aaaaargZombies merged commit 888ef00 into main Jan 23, 2024
2 checks passed
@aaaaargZombies aaaaargZombies deleted the 1791-enforce-full-domain-in-site-settings branch January 23, 2024 12:20
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.

[Bug]: Enforce full domain in site settings
3 participants