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

Fs1352 req new link #51

Merged
merged 8 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ FROM python:3.10-bullseye
WORKDIR /app
COPY requirements.txt requirements.txt
# Install git to download utils library
RUN apt update && apt -yq install git
RUN apt update && apt -yq install git
srh-sloan marked this conversation as resolved.
Show resolved Hide resolved
RUN python3 -m pip install --upgrade pip && pip install -r requirements.txt
COPY . .

EXPOSE 8080

CMD ["flask", "run", "--host", "0.0.0.0", "--port", "8080"]
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "8080"]
srh-sloan marked this conversation as resolved.
Show resolved Hide resolved
1 change: 0 additions & 1 deletion api/magic_links/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@


class MagicLinksView(MagicLinkMethods, MethodView):

srh-sloan marked this conversation as resolved.
Show resolved Hide resolved
def use(self, link_id: str):
"""
GET /magic-links/{link_id} endpoint
Expand Down
14 changes: 10 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,19 @@ def before_request_modifier():
def inject_global_constants():
return dict(
stage="beta",
service_title="Apply for funding to save a building in your community",
service_title=(
"Apply for funding to save a building in your community"
),
service_meta_description=(
"Apply for funding to save a building in your community"
),
service_meta_keywords="Apply for funding to save a building in your community",
service_meta_author="Department for Levelling up Housing and Communities",
accessibility_statement_url=Config.APPLICANT_FRONTEND_ACCESSIBILITY_STATEMENT_URL,
service_meta_keywords=(
"Apply for funding to save a building in your community"
),
service_meta_author=(
"Department for Levelling up Housing and Communities"
),
accessibility_statement_url=Config.APPLICANT_FRONTEND_ACCESSIBILITY_STATEMENT_URL, # noqa
cookie_policy_url=Config.APPLICANT_FRONTEND_COOKIE_POLICY_URL,
)

Expand Down
8 changes: 7 additions & 1 deletion config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from os import getenv
from pathlib import Path

from fsd_utils import CommonConfig
from fsd_utils import configclass


Expand All @@ -28,6 +29,7 @@ class DefaultConfig(object):

# Hostname for this service
AUTHENTICATOR_HOST = environ.get("AUTHENTICATOR_HOST", "")
NEW_LINK_ENDPOINT = "/service/magic-links/new"

"""
Azure Configuration
Expand Down Expand Up @@ -92,7 +94,6 @@ class DefaultConfig(object):
# Notification Service
NOTIFICATION_SERVICE_HOST = environ.get("NOTIFICATION_SERVICE_HOST")
SEND_ENDPOINT = "/send"
NOTIFY_TEMPLATE_MAGIC_LINK = "MAGIC_LINK"

# Applicant Frontend
APPLICANT_FRONTEND_HOST = environ.get(
Expand All @@ -105,6 +106,10 @@ class DefaultConfig(object):
APPLICANT_FRONTEND_HOST + "/cookie_policy"
)

# Fund store service
FUND_STORE_API_HOST = CommonConfig.FUND_STORE_API_HOST
FUND_STORE_FUND_ENDPOINT = CommonConfig.FUND_ENDPOINT

"""
Magic Links
"""
Expand All @@ -117,6 +122,7 @@ class DefaultConfig(object):
MAGIC_LINK_RECORD_PREFIX = "link"
MAGIC_LINK_USER_PREFIX = "account"
MAGIC_LINK_LANDING_PAGE = "/service/magic-links/landing/"
FUND_ID_COF = "47aef2f5-3fcb-4d45-acb5-f0152b5f03c4"

"""
Security
Expand Down
4 changes: 3 additions & 1 deletion config/envs/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class DevelopmentConfig(Config):
with open(_test_private_key_path, mode="rb") as private_key_file:
RSA256_PRIVATE_KEY = private_key_file.read()
if not hasattr(Config, "RSA256_PUBLIC_KEY"):
_test_public_key_path = Config.FLASK_ROOT + "/tests/keys/rsa256/public.pem"
_test_public_key_path = (
Config.FLASK_ROOT + "/tests/keys/rsa256/public.pem"
)
with open(_test_public_key_path, mode="rb") as public_key_file:
RSA256_PUBLIC_KEY = public_key_file.read()

Expand Down
1 change: 0 additions & 1 deletion config/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class TestConfig(Config):

SECRET_KEY = environ.get("SECRET_KEY", "test")


COOKIE_DOMAIN = environ.get("COOKIE_DOMAIN", ".test.fundingservice.co.uk")

# GOV.UK PaaS
Expand Down
4 changes: 3 additions & 1 deletion frontend/magic_links/routes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from config import Config
from flask import Blueprint
from flask import redirect
from flask import render_template
Expand Down Expand Up @@ -52,7 +53,8 @@ def new():
Returns a page containing a single question requesting the
users email address.
"""
fund_id = request.args.get("fund_id")
# Default to COF while we only have one fund
fund_id = request.args.get("fund_id", Config.FUND_ID_COF)
round_id = request.args.get("round_id")
fund_round = False

Expand Down
1 change: 0 additions & 1 deletion frontend/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@
]
}
}) }}

2 changes: 1 addition & 1 deletion frontend/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
{{ govukPhaseBanner({'tag': {'text': 'beta'}, 'html':
'This is a new service - your <a href="https://forms.office.com/Pages/ResponsePage.aspx?id=EGg0v32c3kOociSi7zmVqN48ORk8WN5LlJITE3Swt-lURUNCR0dHMjgxWFZOMTMxQzlOTVIxVkQ0Sy4u" class="govuk-link">feedback</a> will help us to improve it.'
})}}
</div>
</div>
28 changes: 23 additions & 5 deletions models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

from config import Config
from flask import current_app
from fsd_utils.config.notify_constants import NotifyConstants
from models.application import Application
from models.application import ApplicationMethods
from models.data import get_data
from models.data import post_data
from models.fund import FundMethods
from models.magic_link import MagicLinkMethods
from models.notification import Notification

Expand Down Expand Up @@ -107,27 +109,43 @@ def get_magic_link(
if not account:
account = new_account = cls.create_account(email)
if account:
notification_content = {}

fund = FundMethods.get_fund(fund_id)

notification_content = {
NotifyConstants.FIELD_REQUEST_NEW_LINK_URL: Config.AUTHENTICATOR_HOST # noqa
+ Config.NEW_LINK_ENDPOINT,
NotifyConstants.FIELD_CONTACT_HELP_EMAIL: fund.contact_help, # noqa
NotifyConstants.FIELD_FUND_NAME: fund.name,
}
if fund_id and round_id and new_account:
# Create an application if none exists
new_application = ApplicationMethods.create_application(
account.id, fund_id, round_id
)
if new_application:
notification_content.update(
{"fund_name": new_application.fund_name}
{
NotifyConstants.FIELD_FUND_NAME: new_application.fund_name # noqa
}
)

# Create a fresh link
new_link_json = MagicLinkMethods().create_magic_link(account)
notification_content.update(
{"magic_link_url": new_link_json.get("link")}
{
NotifyConstants.FIELD_MAGIC_LINK_URL: new_link_json.get( # noqa
"link"
)
}
)

current_app.logger.debug(f"Magic Link URL: {new_link_json.get('link')}")
current_app.logger.debug(
f"Magic Link URL: {new_link_json.get('link')}"
)
# Send notification
Notification.send(
Config.NOTIFY_TEMPLATE_MAGIC_LINK,
NotifyConstants.TEMPLATE_TYPE_MAGIC_LINK,
account.email,
notification_content,
)
Expand Down
21 changes: 18 additions & 3 deletions models/fund.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from dataclasses import dataclass
from typing import List

from config import Config
from models.data import get_data
from models.round import Round


Expand All @@ -9,17 +11,30 @@ class Fund:
name: str
identifier: str
description: str
contact_help: str
rounds: List[Round] = None

@staticmethod
def from_json(data: dict):
return Fund(
name=data.get("fund_name"),
identifier=data.get("fund_id"),
description=data.get("fund_description"),
name=data.get("name"),
identifier=data.get("id"),
description=data.get("description"),
contact_help=data.get("contact_email"),
)

def add_round(self, fund_round: Round):
if not self.rounds:
self.rounds = []
self.rounds.append(fund_round)


class FundMethods:
@staticmethod
def get_fund(fund_id: str) -> Fund:
url = (
Config.FUND_STORE_API_HOST + Config.FUND_STORE_FUND_ENDPOINT
).format(fund_id=fund_id)
response = get_data(endpoint=url)
if response and "id" in response:
return Fund.from_json(response)
7 changes: 6 additions & 1 deletion models/notification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from config import Config
from fsd_utils.config.notify_constants import NotifyConstants
from models.data import post_data


Expand All @@ -21,7 +22,11 @@ def send(template_type: str, to_email: str, content: dict):
fill out the notification template
"""
url = Config.NOTIFICATION_SERVICE_HOST + Config.SEND_ENDPOINT
params = {"type": template_type, "to": to_email, "content": content}
params = {
NotifyConstants.FIELD_TYPE: template_type,
NotifyConstants.FIELD_TO: to_email,
NotifyConstants.FIELD_CONTENT: content,
}
response = post_data(url, params)
if response:
return True
Expand Down
18 changes: 13 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ attrs==21.4.0
# trio
axe-selenium-python==2.1.6
# via -r requirements-dev.in
babel==2.10.3
# via
# -r requirements.txt
# flask-babel
bandit==1.7.4
# via -r requirements-dev.in
black==22.3.0
Expand Down Expand Up @@ -108,6 +112,7 @@ flask==2.1.1
# -r requirements.txt
# connexion
# flask-assets
# flask-babel
# flask-compress
# flask-migrate
# flask-redis
Expand All @@ -118,6 +123,10 @@ flask==2.1.1
# pytest-flask
flask-assets==2.0
# via -r requirements.txt
flask-babel==2.0.0
# via
# -r requirements.txt
# funding-service-design-utils
flask-compress==1.10.1
# via -r requirements.txt
flask-migrate==3.1.0
Expand All @@ -134,18 +143,14 @@ flask-talisman==0.8.1
# via -r requirements.txt
flask-wtf==1.0.0
# via -r requirements.txt
funding-service-design-utils @ https://github.com/communitiesuk/funding-service-design-utils/archive/refs/tags/0.0.14.tar.gz
funding-service-design-utils @ git+https://github.com/communitiesuk/funding-service-design-utils@bau-notify-fields
# via -r requirements.txt
gitdb==4.0.9
# via gitpython
gitpython==3.1.27
# via bandit
govuk-frontend-jinja==2.0.0
# via -r requirements.txt
greenlet==1.1.3
# via
# -r requirements.txt
# sqlalchemy
gunicorn==20.1.0
# via
# -r requirements.txt
Expand Down Expand Up @@ -177,6 +182,7 @@ jinja2==3.1.2
# via
# -r requirements.txt
# flask
# flask-babel
# govuk-frontend-jinja
# swagger-ui-bundle
jsmin==3.0.1
Expand Down Expand Up @@ -310,6 +316,8 @@ python-json-logger==2.0.2
pytz==2022.1
# via
# -r requirements.txt
# babel
# flask-babel
# funding-service-design-utils
pyyaml==6.0
# via
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# FSD Utils
#-----------------------------------

https://github.com/communitiesuk/funding-service-design-utils/archive/refs/tags/0.0.14.tar.gz
git+https://github.com/communitiesuk/funding-service-design-utils@bau-notify-fields

requests

Expand Down
15 changes: 11 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ async-timeout==4.0.2
# via redis
attrs==21.4.0
# via jsonschema
babel==2.10.3
# via flask-babel
brotli==1.0.9
# via flask-compress
cachelib==0.9.0
Expand Down Expand Up @@ -49,6 +51,7 @@ flask==2.1.1
# -r requirements.in
# connexion
# flask-assets
# flask-babel
# flask-compress
# flask-migrate
# flask-redis
Expand All @@ -58,6 +61,8 @@ flask==2.1.1
# funding-service-design-utils
flask-assets==2.0
# via -r requirements.in
flask-babel==2.0.0
# via funding-service-design-utils
flask-compress==1.10.1
# via -r requirements.in
flask-migrate==3.1.0
Expand All @@ -74,12 +79,10 @@ flask-talisman==0.8.1
# via -r requirements.in
flask-wtf==1.0.0
# via -r requirements.in
funding-service-design-utils @ https://github.com/communitiesuk/funding-service-design-utils/archive/refs/tags/0.0.14.tar.gz
funding-service-design-utils @ git+https://github.com/communitiesuk/funding-service-design-utils@bau-notify-fields
srh-sloan marked this conversation as resolved.
Show resolved Hide resolved
# via -r requirements.in
govuk-frontend-jinja==2.0.0
# via -r requirements.in
greenlet==1.1.3
# via sqlalchemy
gunicorn==20.1.0
# via funding-service-design-utils
idna==3.3
Expand All @@ -96,6 +99,7 @@ itsdangerous==2.1.2
jinja2==3.1.2
# via
# flask
# flask-babel
# govuk-frontend-jinja
# swagger-ui-bundle
jsmin==3.0.1
Expand Down Expand Up @@ -146,7 +150,10 @@ python-dotenv==0.20.0
python-json-logger==2.0.2
# via funding-service-design-utils
pytz==2022.1
# via funding-service-design-utils
# via
# babel
# flask-babel
# funding-service-design-utils
pyyaml==6.0
# via
# clickclick
Expand Down
Loading