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 atom feeds to travel advice #257

Merged
merged 5 commits into from Mar 3, 2017
Merged

Add atom feeds to travel advice #257

merged 5 commits into from Mar 3, 2017

Conversation

@fofr
Copy link
Contributor

@fofr fofr commented Feb 24, 2017

https://trello.com/c/mNRwOtHL/139-2-render-travel-advice-atom-feeds-in-government-frontend-m

Render atom feeds for travel advice countries. Output of atom feed is identical to multipage-frontend’s (and live). Template and tests ported from multipage-frontend.

When reviewing please double-check the routing logic and tests

Add support for rendering atom routes:

  • Update routing to allow atom format
  • Use a regex to constrain matches on locale and format
  • Test that all supported locales work with regex
  • Append the locale when matched to the content_item_path
  • Return 406 when unacceptable format requested

Paired with @andrewgarner

Example feed:
Matches: https://www.gov.uk/foreign-travel-advice/thailand.atom

<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>https://www.gov.uk/foreign-travel-advice/thailand</id>
  <link rel="alternate" type="text/html" href="https://www.gov.uk/foreign-travel-advice/thailand"/>
  <link rel="self" type="application/atom+xml" href="http://government-frontend.dev.gov.uk/foreign-travel-advice/thailand.atom"/>
  <title>Travel Advice Summary</title>
  <updated>2017-02-08T10:23:34+00:00</updated>
  <author>
    <name>GOV.UK</name>
  </author>
  <entry>
    <id>https://www.gov.uk/foreign-travel-advice/thailand#2017-02-08T10:23:34+00:00</id>
    <updated>2017-02-08T10:23:34+00:00</updated>
    <link rel="alternate" type="text/html" href="https://www.gov.uk/foreign-travel-advice/thailand"/>
    <title>Thailand travel advice</title>
    <link rel="self" type="application/atom+xml" href="https://www.gov.uk/foreign-travel-advice/thailand.atom"/>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
<p>Latest update: Summary – updated guidance for visitors following the passing of His Majesty King Bhumibol Adulyadej
</p>      </div>
    </summary>
  </entry>
</feed>
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 Feb 24, 2017 Inactive
@fofr fofr force-pushed the travel-advice-atom branch from 21430ce to ba4a046 Feb 24, 2017
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 Feb 24, 2017 Inactive
get '*path(.:locale)(.:format)' => 'content_items#show',
constraints: {
format: /atom/,
locale: /\w{2}(-[\d\w]{2,3})?/,

This comment has been minimized.

@nickcolley

nickcolley Feb 27, 2017
Contributor

This regex is gnarly for my simple monkey brain, should we have a few tests around this?

This comment has been minimized.

@fofr

fofr Feb 27, 2017
Author Contributor

There is a test: https://github.com/alphagov/government-frontend/pull/257/files#diff-7dd9638113bd162736166ccac21fae7cR25

It tests every supported locale against the regex. If we add a new locale that's not supported, the test will fail.

@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 Feb 27, 2017 Inactive
# FIXME: Update when https://trello.com/c/w8HN3M4A/ is ready
get 'foreign-travel-advice/:country/:part' => 'travel_advice#show'

get '*path(.:locale)(.:format)' => 'content_items#show',

This comment has been minimized.

@nickcolley

nickcolley Feb 27, 2017
Contributor

It looks like the only thing that constrains this route is that it's got an /atom/ and a valid locale.

What happens when you try to render something that is not a travel advice format? Does this work?

This comment has been minimized.

@fofr

fofr Feb 27, 2017
Author Contributor

It returns a 406: ba4a046 (ie not an accepted format)
If the templates were added, they would work.

@fofr fofr requested a review from gpeng Feb 27, 2017
@mcgoooo
mcgoooo approved these changes Mar 1, 2017
Copy link
Contributor

@mcgoooo mcgoooo left a comment

looks good

@@ -1,3 +1,5 @@
require 'htmlentities'

This comment has been minimized.

@gpeng

gpeng Mar 1, 2017
Contributor

Is this necessary? I think bundler will require it.

This comment has been minimized.

@fofr

fofr Mar 2, 2017
Author Contributor

Fixed and rebased.

@fofr fofr force-pushed the travel-advice-atom branch from d34e48f to a867eff Mar 2, 2017
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 Mar 2, 2017 Inactive
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 Mar 2, 2017 Inactive
@gpeng
gpeng approved these changes Mar 2, 2017
@fofr fofr force-pushed the travel-advice-atom branch from eefb0b9 to 3e8e5dd Mar 2, 2017
@boffbowsh boffbowsh temporarily deployed to government-frontend-pr-257 Mar 2, 2017 Inactive
fofr added 5 commits Feb 24, 2017
* Update routing to allow atom format
* Use a regex to constrain matches on locale and format
* Test that all supported locales work with regex
* Append the locale when matched to the content_item_path

Paired with @andrewgarner
* Output of atom feed identical to multipage frontend (and live)
* Port template and tests from multipage frontend
* Use html entities gem to encode HTML entities for XML feed

Context: alphagov/multipage-frontend#6
Previously, calling a format without an atom feed via:
/government/consultations/postgraduate-doctoral-loans.atom

Would have 404’d. Now there is atom support this retrieves a content
item, but throws a “MissingTemplate” error when it comes to rendering.

Catch this error and return a “not acceptable” 406 response. eg The
target resource does not have a current representation that would be
acceptable to the user agent
* Matches multipage-frontend
* Allows supporting browsers to highlight when feeds are available for
content
* Makes country name method public for use with feed link
@fofr fofr force-pushed the travel-advice-atom branch from 3e8e5dd to 89990f8 Mar 3, 2017
@fofr fofr merged commit 039651b into master Mar 3, 2017
2 checks passed
2 checks passed
continuous-integration/jenkins/branch This commit looks good
Details
security/snyk No new vulnerabilities
Details
@fofr fofr deleted the travel-advice-atom branch Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.