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

Update allowed urls for public engagement and debate summaries #894

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions app/models/archived/debate_outcome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,36 @@ module Archived
class DebateOutcome < ActiveRecord::Base
VALID_OTHER_URLS = /\Ahttps?:\/\/(?:[a-z][\-\.a-z0-9]{0,63}\.parliament\.uk|www\.youtube\.com).*\z/
VALID_VIDEO_URLS = /\Ahttps?:\/\/(?:(?:www\.)?parliamentlive\.tv|www\.youtube\.com).*\z/
VALID_PUBLIC_ENGAGEMENT_URLS = /\Ahttps?:\/\/(?:committees\.parliament\.uk|ukparliament\.shorthandstories\.com).*\z/
VALID_DEBATE_SUMMARY_URLS = /\Ahttps?:\/\/ukparliament\.shorthandstories\.com.*\z/

belongs_to :petition, touch: true

validates :petition, presence: true
validates :debated_on, presence: true, if: :debated?
validates :transcript_url, :video_url, :debate_pack_url, :public_engagement_url, :debate_summary_url, length: { maximum: 500 }

validates :debate_pack_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
validates :transcript_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
validates :video_url, format: { with: VALID_VIDEO_URLS }, allow_blank: true
validates :public_engagement_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
validates :debate_summary_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
with_options length: { maximum: 500 } do
validates :transcript_url, :video_url, :debate_pack_url
validates :public_engagement_url, :debate_summary_url
end

with_options allow_blank: true do
with_options format: { with: VALID_OTHER_URLS } do
validates :debate_pack_url, :transcript_url
end

with_options format: { with: VALID_VIDEO_URLS } do
validates :video_url
end

with_options format: { with: VALID_PUBLIC_ENGAGEMENT_URLS } do
validates :public_engagement_url
end

with_options format: { with: VALID_DEBATE_SUMMARY_URLS } do
validates :debate_summary_url
end
end

has_one_attached :image

Expand Down
30 changes: 24 additions & 6 deletions app/models/debate_outcome.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
class DebateOutcome < ActiveRecord::Base
VALID_OTHER_URLS = /\Ahttps?:\/\/(?:[a-z][\-\.a-z0-9]{0,63}\.parliament\.uk|www\.youtube\.com).*\z/
VALID_VIDEO_URLS = /\Ahttps?:\/\/(?:(?:www\.)?parliamentlive\.tv|www\.youtube\.com).*\z/
VALID_PUBLIC_ENGAGEMENT_URLS = /\Ahttps?:\/\/(?:committees\.parliament\.uk|ukparliament\.shorthandstories\.com).*\z/
VALID_DEBATE_SUMMARY_URLS = /\Ahttps?:\/\/ukparliament\.shorthandstories\.com.*\z/

belongs_to :petition, touch: true

validates :petition, presence: true
validates :debated_on, presence: true, if: :debated?
validates :transcript_url, :video_url, :debate_pack_url, :public_engagement_url, :debate_summary_url, length: { maximum: 500 }

validates :debate_pack_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
validates :transcript_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
validates :video_url, format: { with: VALID_VIDEO_URLS }, allow_blank: true
validates :public_engagement_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
validates :debate_summary_url, format: { with: VALID_OTHER_URLS }, allow_blank: true
with_options length: { maximum: 500 } do
validates :transcript_url, :video_url, :debate_pack_url
validates :public_engagement_url, :debate_summary_url
end

with_options allow_blank: true do
with_options format: { with: VALID_OTHER_URLS } do
validates :debate_pack_url, :transcript_url
end

with_options format: { with: VALID_VIDEO_URLS } do
validates :video_url
end

with_options format: { with: VALID_PUBLIC_ENGAGEMENT_URLS } do
validates :public_engagement_url
end

with_options format: { with: VALID_DEBATE_SUMMARY_URLS } do
validates :debate_summary_url
end
end

has_one_attached :image

Expand Down
8 changes: 4 additions & 4 deletions config/locales/activerecord.en-GB.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ en-GB:
video_url:
invalid: "Please use a url on the parliamentlive.tv website or www.youtube.com"
public_engagement_url:
invalid: "Please use a url on the parliament.uk website or a subdomain"
invalid: "Please use a url on the committees.parliament.uk or ukparliament.shorthandstories.com websites"
debate_summary_url:
invalid: "Please use a url on the parliament.uk website or a subdomain"
invalid: "Please use a url on the ukparliament.shorthandstories.com website"
archived/petition:
attributes:
parliament:
Expand Down Expand Up @@ -159,9 +159,9 @@ en-GB:
video_url:
invalid: "Please use a url on the parliamentlive.tv website or www.youtube.com"
public_engagement_url:
invalid: "Please use a url on the parliament.uk website or a subdomain"
invalid: "Please use a url on the committees.parliament.uk or ukparliament.shorthandstories.com websites"
debate_summary_url:
invalid: "Please use a url on the parliament.uk website or a subdomain"
invalid: "Please use a url on the ukparliament.shorthandstories.com website"

rate_limit:
attributes:
Expand Down
10 changes: 5 additions & 5 deletions features/step_definitions/actioned_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
transcript_url = "https://hansard.parliament.uk/path/to/transcript"
elsif links_command == " with a debate pack url"
debate_pack_url = "https://researchbriefings.parliament.uk/path/to/briefing"
elsif links_command == " with a public engagement url"
public_engagement_url = "https://committees.parliament.uk/public-engagement"
elsif links_command == " with a debate summary url"
public_engagement_url = "https://www.parliament.uk/public-engagement"
elsif links_command == " with a debate summary url"
debate_summary_url = "https://www.parliament.uk/summary-debates"
debate_summary_url = "https://ukparliament.shorthandstories.com/about-a-petition"
elsif links_command == " with all debate outcome urls"
video_url = "https://www.youtube.com/watch?v=1234abcd"
transcript_url = "https://hansard.parliament.uk/path/to/transcript"
debate_pack_url = "https://researchbriefings.parliament.uk/path/to/briefing"
public_engagement_url = "https://www.parliament.uk/public-engagement"
debate_summary_url = "https://www.parliament.uk/summary-debates"
public_engagement_url = "https://committees.parliament.uk/public-engagement"
debate_summary_url = "https://ukparliament.shorthandstories.com/about-a-petition"
end

debated_count.times do |count|
Expand Down
20 changes: 10 additions & 10 deletions features/step_definitions/debate_outcome_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
transcript_url: 'https://hansard.parliament.uk/path/to/transcript',
video_url: 'https://www.youtube.com?v=1234abcd',
debate_pack_url: 'https://researchbriefings.parliament.uk/path/to/briefing',
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates"
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition"
)
@petition.update(debate_outcome_at: debated_days_ago.days.ago)
end
Expand All @@ -21,8 +21,8 @@
transcript_url: 'https://hansard.parliament.uk/path/to/transcript',
video_url: 'https://www.youtube.com?v=1234abcd',
debate_pack_url: 'https://researchbriefings.parliament.uk/path/to/briefing',
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates"
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition"
)
end

Expand Down Expand Up @@ -53,8 +53,8 @@
expect(page).to have_link('Watch the debate', href: 'https://www.youtube.com?v=1234abcd')
expect(page).to have_link('Read the transcript', href: 'https://hansard.parliament.uk/path/to/transcript')
expect(page).to have_link('Read the research', href: 'https://researchbriefings.parliament.uk/path/to/briefing')
expect(page).to have_link('Read what the public said', href: 'https://www.parliament.uk/public-engagement')
expect(page).to have_link('Read a summary of the debate', href: 'https://www.parliament.uk/summary-debates')
expect(page).to have_link('Read what the public said', href: 'https://committees.parliament.uk/public-engagement')
expect(page).to have_link('Read a summary of the debate', href: 'https://ukparliament.shorthandstories.com/about-a-petition')
end
end

Expand All @@ -75,8 +75,8 @@
fill_in 'Transcript URL', with: 'https://hansard.parliament.uk/path/to/transcript'
fill_in 'Video URL', with: 'https://www.youtube.com/watch?v=1234abcd'
fill_in 'Debate Pack URL', with: 'https://researchbriefings.parliament.uk/path/to/briefing'
fill_in 'Public Engagement URL', with: 'https://www.parliament.uk/public-engagement'
fill_in 'Debate Summary URL', with: 'https://www.parliament.uk/summary-debates'
fill_in 'Public Engagement URL', with: 'https://committees.parliament.uk/public-engagement'
fill_in 'Debate Summary URL', with: 'https://ukparliament.shorthandstories.com/about-a-petition'
end

Then(/^the petition should have the debate details I provided$/) do
Expand All @@ -88,8 +88,8 @@
expect(@petition.debate_outcome.transcript_url).to eq 'https://hansard.parliament.uk/path/to/transcript'
expect(@petition.debate_outcome.video_url).to eq 'https://www.youtube.com/watch?v=1234abcd'
expect(@petition.debate_outcome.debate_pack_url).to eq 'https://researchbriefings.parliament.uk/path/to/briefing'
expect(@petition.debate_outcome.public_engagement_url).to eq "https://www.parliament.uk/public-engagement"
expect(@petition.debate_outcome.debate_summary_url).to eq "https://www.parliament.uk/summary-debates"
expect(@petition.debate_outcome.public_engagement_url).to eq "https://committees.parliament.uk/public-engagement"
expect(@petition.debate_outcome.debate_summary_url).to eq "https://ukparliament.shorthandstories.com/about-a-petition"
end

Then(/^the petition creator should have been emailed about the debate$/) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
transcript_url: 'http://www.publications.parliament.uk/pa/cm201415/cmhansrd/cm141218/debtext/141218-0003.htm#14121849000001',
video_url: 'http://parliamentlive.tv/event/index/f9eb68af-6a5c-4a94-95d3-6108aa87e9d7?in=13:57:00',
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2014-1234",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates",
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition",
}
end

Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/admin/debate_outcomes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
transcript_url: 'http://www.publications.parliament.uk/pa/cm201415/cmhansrd/cm141218/debtext/141218-0003.htm#14121849000001',
video_url: 'http://parliamentlive.tv/event/index/f9eb68af-6a5c-4a94-95d3-6108aa87e9d7?in=13:57:00',
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2014-1234",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates",
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition",
}
end

Expand Down
8 changes: 4 additions & 4 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-#{debated_on.strftime('%Y')}-#{ '%04d' % n }"
}
public_engagement_url {
"https://www.parliament.uk/public-engagement"
"https://committees.parliament.uk/public-engagement"
}
debate_summary_url {
"https://www.parliament.uk/summary-debates"
"https://ukparliament.shorthandstories.com/about-a-petition"
}
end
end
Expand Down Expand Up @@ -771,10 +771,10 @@
"http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-#{debated_on.strftime('%Y')}-#{ '%04d' % n }"
}
public_engagement_url {
"https://www.parliament.uk/public-engagement"
"https://committees.parliament.uk/public-engagement"
}
debate_summary_url {
"https://www.parliament.uk/summary-debates"
"https://ukparliament.shorthandstories.com/about-a-petition"
}
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/jobs/archive_petition_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@
transcript_url: "https://hansard.parliament.uk/commons/2017-04-24/debates/123456/KidsTV",
video_url: "http://www.parliamentlive.tv/Event/Index/123456",
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2015-0001",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates",
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition",
)
end

Expand Down
4 changes: 2 additions & 2 deletions spec/mailers/archived/petition_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@
transcript_url: "http://www.publications.parliament.uk/pa/cm201509/cmhansrd/cm20150924/debtext/20150924-0003.htm#2015092449#000001",
video_url: "http://parliamentlive.tv/event/index/20150924000001",
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2015-0001",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates",
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition",
)
end

Expand Down
8 changes: 4 additions & 4 deletions spec/mailers/petition_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@
transcript_url: "http://www.publications.parliament.uk/pa/cm201509/cmhansrd/cm20150924/debtext/20150924-0003.htm#2015092449#000001",
video_url: "http://parliamentlive.tv/event/index/20150924000001",
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2015-0001",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates",
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition",
petition: petition,
)
end
Expand Down Expand Up @@ -690,8 +690,8 @@
transcript_url: "http://www.publications.parliament.uk/pa/cm201509/cmhansrd/cm20150924/debtext/20150924-0003.htm#2015092449#000001",
video_url: "http://parliamentlive.tv/event/index/20150924000001",
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2015-0001",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates",
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition",
petition: petition,
)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/archived/debate_outcome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@
it { is_expected.to allow_value("https://hansard.parliament.uk/").for(:transcript_url) }
it { is_expected.to allow_value("https://parliamentlive.tv/").for(:video_url) }
it { is_expected.to allow_value("https://www.youtube.com/").for(:video_url) }
it { is_expected.to allow_value("https://committees.parliament.uk/").for(:public_engagement_url) }
it { is_expected.to allow_value("https://ukparliament.shorthandstories.com/").for(:public_engagement_url) }
it { is_expected.to allow_value("https://ukparliament.shorthandstories.com/").for(:debate_summary_url) }

it { is_expected.not_to allow_value("https://www.example.com/").for(:debate_pack_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:transcript_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:video_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:public_engagement_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:debate_summary_url) }

context "when then petition was debated" do
subject { described_class.new(debated: true) }
Expand Down
5 changes: 5 additions & 0 deletions spec/models/debate_outcome_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@
it { is_expected.to allow_value("https://hansard.parliament.uk/").for(:transcript_url) }
it { is_expected.to allow_value("https://parliamentlive.tv/").for(:video_url) }
it { is_expected.to allow_value("https://www.youtube.com/").for(:video_url) }
it { is_expected.to allow_value("https://committees.parliament.uk/").for(:public_engagement_url) }
it { is_expected.to allow_value("https://ukparliament.shorthandstories.com/").for(:public_engagement_url) }
it { is_expected.to allow_value("https://ukparliament.shorthandstories.com/").for(:debate_summary_url) }

it { is_expected.not_to allow_value("https://www.example.com/").for(:debate_pack_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:transcript_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:video_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:public_engagement_url) }
it { is_expected.not_to allow_value("https://www.example.com/").for(:debate_summary_url) }

context "when then petition was debated" do
subject { described_class.new(debated: true) }
Expand Down
8 changes: 4 additions & 4 deletions spec/requests/archived_petition_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
transcript_url: "http://www.publications.parliament.uk/pa/cm201212/cmhansrd/cm120313/debtext/120313-0001.htm#12031360000001",
video_url: "http://parliamentlive.tv/event/index/da084e18-0e48-4d0a-9aa5-be27f57d5a71?in=16:31:00",
debate_pack_url: "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2014-1234",
public_engagement_url: "https://www.parliament.uk/public-engagement",
debate_summary_url: "https://www.parliament.uk/summary-debates"
public_engagement_url: "https://committees.parliament.uk/public-engagement",
debate_summary_url: "https://ukparliament.shorthandstories.com/about-a-petition"

get "/archived/petitions/#{petition.id}.json"
expect(response).to be_successful
Expand All @@ -186,8 +186,8 @@
"transcript_url" => "http://www.publications.parliament.uk/pa/cm201212/cmhansrd/cm120313/debtext/120313-0001.htm#12031360000001",
"video_url" => "http://parliamentlive.tv/event/index/da084e18-0e48-4d0a-9aa5-be27f57d5a71?in=16:31:00",
"debate_pack_url" => "http://researchbriefings.parliament.uk/ResearchBriefing/Summary/CDP-2014-1234",
"public_engagement_url" => "https://www.parliament.uk/public-engagement",
"debate_summary_url" => "https://www.parliament.uk/summary-debates",
"public_engagement_url" => "https://committees.parliament.uk/public-engagement",
"debate_summary_url" => "https://ukparliament.shorthandstories.com/about-a-petition",
)
)
)
Expand Down
Loading
Loading