-
Notifications
You must be signed in to change notification settings - Fork 34
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
Let user choose which version of Notify docs they want to view #5235
base: main
Are you sure you want to change the base?
Changes from 7 commits
812fd25
78a2dfa
3f77feb
720318d
cde01bf
4fecb24
7c0e5a2
bfe101b
585b795
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,7 @@ | |||||
from functools import partial | ||||||
from itertools import chain | ||||||
from numbers import Number | ||||||
from urllib.parse import urlparse | ||||||
|
||||||
import pytz | ||||||
from flask import request | ||||||
|
@@ -2280,6 +2281,50 @@ def validate(self, *args, **kwargs): | |||||
return super().validate(*args, **kwargs) or self.url.data == "" | ||||||
|
||||||
|
||||||
class UrlForm(StripWhitespaceForm): | ||||||
url = GovukTextInputField( | ||||||
"URL", | ||||||
validators=[ | ||||||
DataRequired(message="Cannot be empty"), | ||||||
Regexp(regex="^https.*", message="Must be a valid https URL"), | ||||||
], | ||||||
) | ||||||
|
||||||
def validate(self, *args, **kwargs): | ||||||
self.url.validators.append(self.check_url) | ||||||
return super().validate(*args, **kwargs) | ||||||
|
||||||
def check_url(self, *args, **kwargs): | ||||||
parsed_url = urlparse(self.url.data) | ||||||
|
||||||
if parsed_url.hostname == "docs.notifications.service.gov.uk" and parsed_url.fragment: | ||||||
return parsed_url | ||||||
else: | ||||||
raise ValidationError("Must be a valid https URL, pointing to a section within the GOV.UK Notify API docs.") | ||||||
|
||||||
|
||||||
class ChooseDocsForm(StripWhitespaceForm): | ||||||
|
||||||
def __init__(self, section_tag): | ||||||
super().__init__(section_tag=section_tag) | ||||||
|
||||||
docs_version = GovukRadiosField( | ||||||
"Which version of the docs would you like to view?", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
choices=[ | ||||||
("python", "Python"), | ||||||
("ruby", "Ruby"), | ||||||
("java", "Java"), | ||||||
("node", "Node JS"), | ||||||
("net", ".Net"), | ||||||
("php", "PHP"), | ||||||
("rest-api", "Rest API"), | ||||||
("rest-api", "Any is fine"), | ||||||
joybytes marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
], | ||||||
thing="a language version of GOV.UK Notify's API docs", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apart from the REST API documentation, we refer to these as ‘client libraries’ elsewhere. |
||||||
) | ||||||
section_tag = HiddenField("section tag") | ||||||
|
||||||
|
||||||
class SMSPrefixForm(StripWhitespaceForm): | ||||||
enabled = OnOffField("") # label is assigned on instantiation | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
from app import status_api_client | ||
from app.formatters import message_count | ||
from app.main import main | ||
from app.main.forms import FieldWithNoneOption | ||
from app.main.forms import ChooseDocsForm, FieldWithNoneOption, UrlForm | ||
from app.main.views.sub_navigation_dictionaries import features_nav, using_notify_nav | ||
from app.models.branding import EmailBranding | ||
from app.models.letter_rates import LetterRates | ||
|
@@ -159,6 +159,39 @@ def guidance_api_documentation(): | |
) | ||
|
||
|
||
@main.route("/using-notify/api-documentation/section", methods=["GET", "POST"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this either be platform admin only or have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea to hide it from search engines 🙌🏼 |
||
def guidance_api_documentation_section(): | ||
|
||
form = UrlForm() | ||
|
||
if form.validate_on_submit(): | ||
section_tag = form.url.data.split("#")[-1] | ||
joybytes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return redirect(url_for(".guidance_api_documentation_section_choose_docs", section_tag=section_tag)) | ||
|
||
return render_template( | ||
"views/guidance/using-notify/api-documentation-section.html", | ||
navigation_links=using_notify_nav(), | ||
form=form, | ||
) | ||
|
||
|
||
@main.route("/using-notify/api-documentation/section/choose-docs", methods=["GET", "POST"]) | ||
def guidance_api_documentation_section_choose_docs(): | ||
form = ChooseDocsForm(section_tag=request.args.get("section_tag")) | ||
|
||
if form.validate_on_submit(): | ||
redirect_url = ( | ||
f"https://docs.notifications.service.gov.uk/{form.docs_version.data}.html#{form.section_tag.data}" | ||
) | ||
return redirect(redirect_url) | ||
|
||
return render_template( | ||
"views/guidance/using-notify/api-documentation-section-choose-docs.html", | ||
navigation_links=using_notify_nav(), | ||
form=form, | ||
) | ||
|
||
|
||
@main.route("/using-notify/attach-pages") | ||
def guidance_attach_pages(): | ||
return render_template( | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
{% extends "content_template.html" %} | ||||||
{% from "components/form.html" import form_wrapper %} | ||||||
{% from "components/page-footer.html" import page_footer %} | ||||||
|
||||||
{# Used by the content_template.html layout, prefixes the "navigation" accessible name #} | ||||||
{% set navigation_label_prefix = 'Using Notify' %} | ||||||
{% set page_title = "You have been sent a link to GOV.UK Notify API documentation" %} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
{% block per_page_title %} | ||||||
{{page_title}} | ||||||
{% endblock %} | ||||||
|
||||||
{% block content_column_content %} | ||||||
|
||||||
<h1 class="heading-large">{{page_title}}</h1> | ||||||
|
||||||
{% call form_wrapper() %} | ||||||
{{ form.docs_version }} | ||||||
{{ page_footer("Let's go!") }} | ||||||
{% endcall %} | ||||||
|
||||||
{% endblock %} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
{% extends "content_template.html" %} | ||||||
{% from "components/form.html" import form_wrapper %} | ||||||
{% from "components/page-footer.html" import page_footer %} | ||||||
|
||||||
{# Used by the content_template.html layout, prefixes the "navigation" accessible name #} | ||||||
{% set navigation_label_prefix = 'Using Notify' %} | ||||||
{% set page_title = "Send a link to an API docs section" %} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is for platform admins, do we need to specify ‘Notify’? Can we just say |
||||||
|
||||||
|
||||||
{% block per_page_title %} | ||||||
{{page_title}} | ||||||
{% endblock %} | ||||||
|
||||||
{% block content_column_content %} | ||||||
|
||||||
<h1 class="heading-large">{{page_title}}</h1> | ||||||
<p class="govuk-body">Below, copy paste the full URL for docs section you would like to send to a service user, and click "Submit".</p> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
<p class="govuk-body">You will be taken to | ||||||
a landing page for that section. Send link to that page to your user, and they will be able to choose which language version they want to see.</p> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
{% call form_wrapper() %} | ||||||
{{ form.url }} | ||||||
{{ page_footer('Submit') }} | ||||||
{% endcall %} | ||||||
|
||||||
{% endblock %} |
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,6 +10,16 @@ | |||||||||||||
{% block content_column_content %} | ||||||||||||||
|
||||||||||||||
<h1 class="heading-large">Documentation</h1> | ||||||||||||||
|
||||||||||||||
{% if current_user.platform_admin %} | ||||||||||||||
<a href="{{ url_for(".guidance_api_documentation_section") }}" | ||||||||||||||
class="govuk-link govuk-link--no-visited-state" | ||||||||||||||
target="_blank" rel="noopener"> | ||||||||||||||
Send a link to docs section | ||||||||||||||
</a> | ||||||||||||||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is for platform admins, do we need to specify ‘Notify’? Can we just say |
||||||||||||||
<p></p> | ||||||||||||||
{% endif %} | ||||||||||||||
|
||||||||||||||
<p class="govuk-body">This documentation is for developers who want to integrate the GOV.UK Notify API with a web application or back office system.</p> | ||||||||||||||
<h2 class="heading-medium" id="client-libraries">Client libraries</h2> | ||||||||||||||
<p class="govuk-body">Links to documentation open in a new tab.</p> | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one, I will add this to code (and tests)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably be a little more consistent with our existing validation errors.