Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
add new PF auth class
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbi-hbrown committed Feb 20, 2024
1 parent 320f9a1 commit ee1491f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
26 changes: 21 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
from jinja2 import ChoiceLoader, PackageLoader, PrefixLoader

import static_assets
from app.const import TOWNS_FUND_AUTH
from app.const import FUND_AUTH
from app.main.authorisation import AuthMapping, AuthService
from app.main.fund import TOWNS_FUND_APP_CONFIG, FundConfig, FundService
from app.main.fund import (
PATH_FINDERS_APP_CONFIG,
TOWNS_FUND_APP_CONFIG,
FundConfig,
FundService,
)
from config import Config

assets = Environment()
Expand Down Expand Up @@ -73,7 +78,7 @@ def setup_funds_and_auth(app: Flask) -> None:
TODO: Going forwards the logic and state for "auth" and "fund" config should be extracted from this repo and
encapsulated in separate microservices with their own databases.
This current mono-repo implementation with state stored in code (see _TF_FUND_CONFIG and _TOWNS_FUND_AUTH) works
This current mono-repo implementation with state stored in code (see _TF_FUND_CONFIG and _FUND_AUTH) works
for now but should not be seen as a long term solution.
:param app: the Flask app
Expand All @@ -86,11 +91,22 @@ def setup_funds_and_auth(app: Flask) -> None:
towns_fund: FundConfig = TOWNS_FUND_APP_CONFIG
app.config["FUND_CONFIGS"] = FundService(role_to_fund_configs={towns_fund.user_role: towns_fund})

pathfinders: FundConfig = PATH_FINDERS_APP_CONFIG
app.config["FUND_CONFIGS"] = FundService(role_to_fund_configs={pathfinders.user_role: pathfinders})

# auth
tf_auth = TOWNS_FUND_AUTH
tf_auth = FUND_AUTH
tf_auth.update(Config.ADDITIONAL_EMAIL_LOOKUPS)

pf_auth = {}
for key, value in FUND_AUTH.items():
pf_auth[key] = (value[0], "Pathfinders")

app.config["AUTH_MAPPINGS"] = AuthService(
fund_to_auth_mappings={towns_fund.fund_name: AuthMapping(towns_fund.auth_class, tf_auth)}
fund_to_auth_mappings={
towns_fund.fund_name: AuthMapping(towns_fund.auth_class, tf_auth),
pathfinders.fund_name: AuthMapping(pathfinders.auth_class, pf_auth),
}
)


Expand Down
2 changes: 1 addition & 1 deletion app/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MIMETYPE(StrEnum):
}

# domain/email: (LAs, Places, Funds)
TOWNS_FUND_AUTH = {
FUND_AUTH = {
"ambervalley.gov.uk": (("Amber Valley Borough Council",), ("Heanor",), ("Town_Deal", "Future_High_Street_Fund")),
"ashfield.gov.uk": (
("Ashfield District Council",),
Expand Down
30 changes: 30 additions & 0 deletions app/main/authorisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,33 @@ def get_auth_dict(self) -> dict[str, tuple[str, ...]]:
:return: a dictionary of place names and fund types.
"""
return {"Place Names": self._place_names, "Fund Types": self._fund_types}


class PFAuth(AuthBase):
"""A Pathfinders auth class"""

_local_authorities: tuple[str, ...]
_programme: str

def __init__(self, local_authorities: tuple[str, ...], programme: str):
"""
:param local_authorities: a tuple of local authorities
:param programme: a fund agnostic term defining which programme a user is authorised to submit for
"""
self._local_authorities = local_authorities
self._programme = programme

def get_organisations(self) -> tuple[str, ...]:
"""Returns the local authorities for this PFAuth class.
:return: a tuple local authorities.
"""
return self._local_authorities

def get_auth_dict(self) -> dict[str, tuple[str, ...]]:
"""Returns the auth dictionary for this PFAuth class.
:return: a dictionary containing the programme name.
"""
return {"Programme": self._programme}
13 changes: 12 additions & 1 deletion app/main/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import datetime
import re

from app.main.authorisation import AuthBase, TFAuth
from app.main.authorisation import AuthBase, PFAuth, TFAuth
from config import Config


Expand Down Expand Up @@ -101,3 +101,14 @@ def get_active_funds(self, roles: list[str]):
active=True,
auth_class=TFAuth,
)

PATH_FINDERS_APP_CONFIG = FundConfig(
fund_name="Pathfinders",
user_role="PF_MONITORING_RETURN_SUBMITTER", # TODO replace with PF role
current_reporting_period="October to December 2024",
current_reporting_round=1,
current_deadline=datetime.date(day=1, month=12, year=2024), # TODO replace with accurate value
email=Config.PF_CONFIRMATION_EMAIL_ADDRESS,
active=True,
auth_class=PFAuth,
)
2 changes: 2 additions & 0 deletions config/envs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class DefaultConfig(object):
"LA_CONFIRMATION_EMAIL_TEMPLATE_ID", "e9397bff-7767-4557-bd39-fbcb2ef6217b"
)
TF_CONFIRMATION_EMAIL_ADDRESS = os.environ.get("TF_CONFIRMATION_EMAIL_ADDRESS", "fake.email@townsfund.gov.uk")
PF_CONFIRMATION_EMAIL_ADDRESS = os.environ.get("PF_CONFIRMATION_EMAIL_ADDRESS", "fake.email@pathfinders.gov.uk")
# TODO create new email template for Pathfinders
FUND_CONFIRMATION_EMAIL_TEMPLATE_ID = os.environ.get(
"TF_CONFIRMATION_EMAIL_TEMPLATE_ID", "d238cc3e-f46a-4170-87d4-1c5768b80ed5"
)
Expand Down
2 changes: 1 addition & 1 deletion config/envs/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ class DevelopmentConfig(DefaultConfig):
DEBUG_USER = {
"full_name": "Development User",
"email": "dev@communities.gov.uk",
"roles": ["TF_MONITORING_RETURN_SUBMITTER"],
"roles": ["TF_MONITORING_RETURN_SUBMITTER", "PF_MONITORING_RETURN_SUBMITTER"],
"highest_role_map": {},
}

0 comments on commit ee1491f

Please sign in to comment.