2024-03-06 14:15:37 -05:00

2023-11-22 14:10:03 -05:00
# Notify.gov Admin UI
2015-11-18 16:32:15 +00:00
2023-11-22 10:28:18 -05:00
This is the Notify front-end for government users and admins. To see it in
action, check out [the demo site ](https://notify-demo.app.cloud.gov )
(contact team for credentials).
2022-08-01 11:14:37 -07:00
2022-11-08 09:44:09 -05:00
Through the interface, users can:
2015-11-23 14:37:29 +00:00
2023-04-24 15:52:38 -04:00
- Register and manage users
- Create and manage services
- Send batch SMS by uploading a CSV
- View their history of notifications
Use a Node-based tools for handling assets
…or how to move a bunch of things from a bunch of different places into
`app/static`.
There are three main reasons not to use Flask Assets:
- It had some strange behaviour like only
- It was based on Ruby SASS, which is slower to get new features than libsass,
and meant depending on Ruby, and having the SASS Gem globally installed—so
you’re already out of being a ‘pure’ Python app
- Martyn and I have experience of doing it this way on Marketplace, and we’ve
ironed out the initial rough patches
The specific technologies this introduces, all of which are Node-based:
- Gulp – like a Makefile written in Javascript
- NPM – package management, used for managing Gulp and its related dependencies
- Bower – also package management, and the only way I can think to have
GOV.UK template as a proper dependency
…speaking of which, GOV.UK template is now a dependency. This means it can’t be
modified at all (eg to add a global `#content` wrapper), so every page now
inherits from a template that has this wrapper. But it also means that we have a
clean upgrade path when the template is modified.
Everything else (toolkit, elements) I’ve kept as submodules but moved them to a
more logical place (`app/assets` not `app/assets/stylesheets`, because they
contain more than just SASS/CSS).
2015-12-15 08:20:25 +00:00
2023-11-22 10:28:18 -05:00
The [Notify.gov API ](https://github.com/GSA/notifications-api ) provides the
UI's backend and is required for most things to function. Set that up first!
2022-04-05 12:00:26 +01:00
2023-11-22 10:28:18 -05:00
Our other repositories are:
2016-03-23 14:09:07 +00:00
2023-11-22 10:28:18 -05:00
- [notifications-admin ](https://github.com/GSA/notifications-admin )
- [us-notify-compliance ](https://github.com/GSA/us-notify-compliance/ )
- [notify-python-demo ](https://github.com/GSA/notify-python-demo )
2023-03-14 16:00:40 -04:00
2023-11-22 10:28:18 -05:00
## Before You Start
2023-03-14 16:00:40 -04:00
2025-10-20 10:38:42 -04:00
### Pre-requisites
2023-03-14 16:00:40 -04:00
2025-10-20 10:38:42 -04:00
Before setting up the Admin UI, you must complete the following:
2023-03-14 16:00:40 -04:00
2025-10-20 10:38:42 -04:00
1. **Set up the Notify.gov API first ** - [Follow the complete API setup instructions here ](https://github.com/GSA/notifications-api#before-you-start ). The API is required for the Admin UI to run and handles most of the system dependencies (Homebrew, Python, Poetry, Terraform, etc.).
2016-08-17 15:59:16 +01:00
2025-10-20 10:38:42 -04:00
2. **Cloud.gov account ** - An active cloud.gov account with access to the `notify-local-dev` and `notify-staging` spaces. Contact your onboarding buddy for help with [setting up an account ](https://cloud.gov/sign-up/ ) (requires a `.mil` , `.gov` , or `.fed.us` email address).
2022-08-05 15:29:51 +00:00
2025-10-20 10:38:42 -04:00
3. **Admin privileges ** - Admin privileges and SSH access on your machine. Work with your organization's IT support staff if you need help with this.
2022-08-05 15:29:51 +00:00
2023-11-22 10:28:18 -05:00
## Local Environment Setup
2023-05-17 17:09:23 -04:00
2023-11-22 10:28:18 -05:00
This project is set up to work with
[nvm (Node Version Manager) ](https://github.com/nvm-sh/nvm#installing-and-updating )
2024-06-19 08:40:11 -07:00
for managing and using Node.js (version 22.3.0) and the `npm` package manager.
2022-08-05 15:29:51 +00:00
2023-11-22 10:28:18 -05:00
### Docker installation
If you are using VS Code, there are also instructions for
[running inside Docker ](./docs/docker-remote-containers.md ).
2023-07-28 09:31:45 -04:00
2025-10-20 10:38:42 -04:00
### Node.js and npm Installation
2023-11-22 10:28:18 -05:00
The project will manage most of the Node.js pieces for you, but you will need to
2025-10-20 10:38:42 -04:00
install [nvm (Node Version Manager) ](https://github.com/nvm-sh/nvm#installing-and-updating ).
2023-11-22 10:28:18 -05:00
2025-10-20 10:38:42 -04:00
Follow the [nvm installation instructions ](https://github.com/nvm-sh/nvm#installing-and-updating )
to install it with the provided script. The installation will automatically set up
your shell configuration.
2023-11-22 10:28:18 -05:00
### First-Time Project Setup
Once all of pre-requisites for the project are installed and you have a
cloud.gov account, you can now set up the admin project and get things running
locally!
2024-03-21 13:01:14 -07:00
First, clone the repository in the directory of your choosing on your machine:
2023-11-22 10:28:18 -05:00
```sh
git clone git@github .com:GSA/notifications-admin.git
```
Now go into the project directory (`notifications-admin` by default), create a
virtual environment, and set the local Python version to point to the virtual
2025-08-28 08:26:46 -07:00
environment (assumes version Python `3.13.2` is what is installed on your
2023-11-22 10:28:18 -05:00
machine):
```sh
cd notifications-admin
2025-08-28 08:26:46 -07:00
pyenv virtualenv 3.13.2 notify-admin
2023-11-22 10:28:18 -05:00
pyenv local notify-admin
```
2025-10-20 10:38:42 -04:00
_NOTE: If you're not sure which version of Python was installed with `pyenv` , you can check by running `pyenv versions` and it'll list everything available currently._
2023-11-22 10:28:18 -05:00
Now [log into cloud.gov ](https://cloud.gov/docs/getting-started/setup/#set-up-the-command-line )
in the command line by using this command:
```sh
cf login -a api.fr.cloud.gov --sso
```
_REMINDER: Ensure you have access to the `notify-local-dev` and `notify-staging` spaces in cloud.gov_
Now run the development Terraform setup by navigating to the development
folder and running the script in it:
```sh
cd terraform/development
./run.sh
```
In addition to some infrastructure setup, this will also create a local `.env`
file for you in the project's root directory, which will include a handful of
project-specific environment variables.
2023-03-14 16:00:40 -04:00
2024-03-21 13:01:14 -07:00
#### Upgrading Python in existing projects
2024-03-19 09:19:26 -07:00
2024-03-21 13:01:14 -07:00
If you're upgrading an existing project to a newer version of Python, you can
follow these steps to get yourself up-to-date.
2024-03-19 09:19:26 -07:00
2024-03-21 13:01:14 -07:00
First, use `pyenv` to install the newer version of Python you'd like to use;
2025-08-28 08:26:46 -07:00
we'll use `3.13` in our example here since we recently upgraded to this version:
2024-03-19 09:19:26 -07:00
```sh
2025-08-28 08:26:46 -07:00
pyenv install 3.13
2024-03-19 09:19:26 -07:00
```
2024-06-26 11:08:20 -06:00
Next, delete the virtual environment you previously had set up. If you followed
2024-03-21 13:01:14 -07:00
the instructions above with the first-time set up, you can do this with `pyenv` :
```sh
pyenv virtualenv-delete notify-admin
```
Now, make sure you are in your project directory and recreate the same virtual
environment with the newer version of Python you just installed:
2024-03-19 09:19:26 -07:00
```sh
2024-03-20 14:11:16 -07:00
cd notifications-admin
2025-08-28 08:26:46 -07:00
pyenv virtualenv 3.13.2 notify-admin
2024-03-21 13:01:14 -07:00
pyenv local notify-admin
2024-03-19 09:19:26 -07:00
```
2024-03-21 13:01:14 -07:00
At this point, proceed with the rest of the instructions here in the README and
you'll be set with an upgraded version of Python.
2024-03-19 09:19:26 -07:00
2025-10-20 10:38:42 -04:00
_NOTE: If you're not sure about the details of your current virtual environment, you can run `poetry env info` to get more information. If you've been using `pyenv` for everything, you can also see all available virtual environments with `pyenv virtualenvs` ._
2024-03-19 09:19:26 -07:00
2025-05-29 08:49:38 -07:00
#### Poetry upgrades ####
If you are doing a new project setup, then after you install poetry you need to install the export plugin
```sh
poetry self add poetry-plugin-export
```
If you are upgrading from poetry 1.8.5, you need to do this:
```sh
curl -sSL https://install.python-poetry.org | python3 - --version 2.1.3
poetry self add poetry-export-plugin
```
2024-06-26 11:08:20 -06:00
#### Updating the .env file for Login.gov
To configure the application for Login.gov, you will need to update the following environment variables in the .env file:
```
COMMIT_HASH=”--------”
```
Reach out to someone on the team to get the most recent Login.gov key.
```
LOGIN_PEM="INSERT_LOGIN_GOV_KEY_HERE"
```
2023-11-22 10:28:18 -05:00
#### Updating the .env file for E2E tests
With the newly created `.env` file in place, you'll need to make one more
adjustment in it for things to run properly for the E2E tests.
Open the `.env` file and look for the `NODE_EXTRA_CA_CERTS` environment variable
toward the top. You will need to modify its value to be the path to Homebrew's
CA certificate file.
Run `brew --prefix` to see Homebrew's root directory, and use that value to
update the `NODE_EXTRA_CA_CERTS` environment variable with the path. For
example, if `brew --prefix` gave `/opt/homebrew` as output, then the line would
look like this:
```
NODE_EXTRA_CA_CERTS=/opt/homebrew/etc/ca-certificates/cert.pem
```
Save this change to the `.env` file and you'll be squared away.
## Running the Project and Routine Maintenance
The first time you run the project you'll need to run the project setup from the
root project directory:
```sh
make bootstrap
```
This command is handled by the `Makefile` file in the root project directory, as
are a few others.
2025-10-20 10:38:42 -04:00
_NOTE: Run `make bootstrap` again whenever you pull new changes that include dependency updates or when you encounter issues with your development environment. This ensures your project stays up-to-date._
2023-11-22 10:28:18 -05:00
Now you can run the web server and background workers for asynchronous jobs:
```sh
make run-flask
```
This will run the local development web server and make the admin site
available at http://localhost:6012; remember to make sure that the Notify.gov
API is running as well!
2024-05-08 08:36:39 -07:00
## Creating a 'First User' in the database
2025-10-20 10:38:42 -04:00
To login as a user in the database, first create that user with the `create-test-user`
command. There will then be a user to link to your login.gov account.
2024-05-08 08:36:39 -07:00
2024-11-15 08:44:32 -05:00
Open a terminal pointing to the api project and then run this command.
2024-05-08 08:36:39 -07:00
2024-11-15 08:44:32 -05:00
```poetry run flask command create-test-user --admin=True` ``
2024-05-08 09:10:41 -07:00
Supply your name, email address, mobile number, and password when prompted. Make sure the email address
is the same one you are using in login.gov and make sure your phone number is in the format 5555555555.
2024-05-08 08:36:39 -07:00
If for any reason in the course of development it is necessary for your to delete your db
via the `dropdb` command, you will need to repeat these steps when you recreate your db.
2023-11-22 10:42:57 -05:00
## Git Hooks
We're using [`pre-commit` ](https://pre-commit.com/ ) to manage hooks in order to
automate common tasks or easily-missed cleanup. It's installed as part of
`make bootstrap` and is limited to this project's virtualenv.
To run the hooks in advance of a `git` operation, use
`poetry run pre-commit run` . For running across the whole codebase (useful after
adding a new hook), use `poetry run pre-commit run --all-files` .
The configuration is stored in `.pre-commit-config.yaml` . In that config, there
are links to the repos from which the hooks are pulled, so hop through there if
2025-10-20 10:38:42 -04:00
you want a detailed description of what each one is doing.
2023-11-22 10:42:57 -05:00
We do not maintain any hooks in this repository.
2023-11-22 10:28:18 -05:00
## Python Dependency Management
We're using [`Poetry` ](https://python-poetry.org/ ) for managing our Python
2025-10-20 10:38:42 -04:00
dependencies and local virtual environments.
This project has two key dependency files that must be managed together:
- `pyproject.toml` - Contains the dependency specifications
- `poetry.lock` - Contains the exact versions of all dependencies (including transitive ones)
2023-11-22 10:28:18 -05:00
2025-10-20 10:38:42 -04:00
### Managing Dependencies
There are two approaches for updating dependencies:
#### 1. Manual manipulation of `pyproject.toml`
If you manually edit the `pyproject.toml` file, you should use the `make py-lock` command to sync the `poetry.lock` file. This will
2023-11-22 10:28:18 -05:00
ensure that you don't inadvertently bring in other transitive dependency updates
that have not been fully tested with the project yet.
2025-10-20 10:38:42 -04:00
#### 2. Using Poetry to update dependencies (recommended)
If you're updating a dependency to a newer (or the latest) version,
let Poetry handle it by running:
2023-11-22 10:28:18 -05:00
```sh
poetry update <dependency> [<dependency>...]
```
You can specify more than one dependency together. With this command, Poetry
will do the following for you:
- Find the latest compatible version(s) of the specified dependency/dependencies
- Install the new versions
- Update and sync the `poetry.lock` file
In either situation, once you are finished and have verified the dependency
changes are working, please be sure to commit both the `pyproject.toml` and
`poetry.lock` files.
## Known Installation Issues
### Python Installation Errors
On M1 Macs, if you get a `fatal error: 'Python.h' file not found` message, try a
different method of installing Python. The recommended approach is to use
[`pyenv` ](https://github.com/pyenv/pyenv ), as noted above in the installation
instructions.
If you're using PyCharm for Python development, we've noticed some quirkiness
with the IDE and the interaction between Poetry and virtual environment
management that could cause a variety of problems to come up during project
setup and dependency management. Other tools, such as Visual Studio Code, have
proven to be a smoother experience for folks.
2021-02-22 17:12:03 +00:00
## To test the application
2023-04-24 15:52:38 -04:00
2022-08-01 11:14:37 -07:00
From a terminal within the running devcontainer:
2021-02-22 17:12:03 +00:00
```
2021-05-11 18:20:40 +01:00
# run all the tests
2021-02-22 17:12:03 +00:00
make test
2021-05-11 18:20:40 +01:00
# continuously run js tests
npm run test-watch
2021-02-22 17:12:03 +00:00
```
2018-07-10 15:16:14 +01:00
2023-11-22 10:28:18 -05:00
To run a specific JavaScript test, you'll need to copy the full command from
`package.json` .
2021-05-11 18:20:40 +01:00
2022-08-30 10:31:48 -04:00
## Running a11y-scans locally
2023-11-22 10:28:18 -05:00
Unlike most of the tests and scans, pa11y-ci cannot currently be run from within
the VSCode dev container.
2022-08-30 10:31:48 -04:00
2023-04-24 15:52:38 -04:00
1. `make run-flask` from within the devcontainer
2022-08-30 10:31:48 -04:00
2. Run `make a11y-scan` from your host computer.
2022-11-08 09:44:09 -05:00
## Further docs from UK
2018-12-14 16:25:31 +00:00
2021-02-22 17:15:09 +00:00
- [Working with static assets ](docs/static-assets.md )
2022-04-05 12:00:26 +01:00
- [JavaScript documentation ](https://github.com/alphagov/notifications-manuals/wiki/JavaScript-Documentation )
2021-12-29 15:01:21 +00:00
- [Updating dependencies ](https://github.com/alphagov/notifications-manuals/wiki/Dependencies )
2022-11-07 11:29:20 -05:00
2025-10-20 10:38:42 -04:00
## License & public domain
2022-11-07 11:29:20 -05:00
2023-11-22 10:28:18 -05:00
Work through
[commit `543be77` ](https://github.com/GSA/notifications-admin/commit/543be77776b64fddb6ba70fbb015ecd81a372478 )
is licensed by the UK government under the MIT license. Work after that commit
is in the worldwide public domain. See [LICENSE.md ](./LICENSE.md ) for more
information.
2022-11-07 11:29:20 -05:00
## Contributing
2023-11-22 10:28:18 -05:00
As stated in [CONTRIBUTING.md ](CONTRIBUTING.md ), all contributions to this
project will be released under the CC0 dedication. By submitting a pull request,
you are agreeing to comply with this waiver of copyright interest.
2022-11-08 16:10:50 -05:00
## About the TTS Public Benefits Studio
2023-11-22 10:28:18 -05:00
The Public Benefits Studio is a team inside of
[GSA’ s Technology Transformation Services ](https://www.gsa.gov/about-us/organization/federal-acquisition-service/technology-transformation-services )
(TTS), home to innovative programs like [18F ](https://18f.gsa.gov/ ) and
[Login.gov ](https://login.gov ). We collaborate with benefits programs to develop
shared technology tools and best practices that reduce the burden of navigating
government programs for low income individuals and families.
2022-11-08 16:10:50 -05:00
2023-11-22 10:28:18 -05:00
We’ re a cross-functional team of technologists with specialized experience
working across public benefits programs like Medicaid, SNAP, and unemployment
insurance.
2022-11-08 16:10:50 -05:00
2023-11-22 10:28:18 -05:00
For more information on what we're working on, the Notify tool, and how to get
involved with our team,
[see our flyer. ](https://github.com/GSA/notifications-admin/blob/main/docs/notify-pilot-flyer.md )
2024-10-07 10:45:02 -07:00
## Updating secrets for the E2E tests
At some point, E2E tests will fail because the secrets held in VCAP_SERVICES have expired. To refresh
them, you will need to do the following:
1. Log in the normal way to access cloudfoundry command line options
2024-10-09 09:43:48 -07:00
2. In your terminal, run `chmod +x print_vcap.sh`
3. In your terminal, run `./print_vcap.sh`
4. Copy the value in your terminal and paste it into the VCAP_SERVICES secret in Github on the staging tier.