fx-private-relay/README.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

366 строки
15 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

2023-07-20 14:39:10 +03:00
<p align="center">
<img src="https://raw.githubusercontent.com/mozilla/fx-private-relay/11ad17e197e23a0453bfb74fa3670c87cfc35e36/frontend/src/components/landing/images/logo-firefox-relay.svg" width="250" />
</p>
# Private Relay
2023-07-20 14:39:10 +03:00
<!-- Badges include: license, size of repository, overall coverage for project via coveralls.io on main branch, status of what is deployed via whatsdeployed.io and our circleci status for main branch. -->
2023-07-20 14:39:10 +03:00
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://raw.githubusercontent.com/mozilla/fx-private-relay/main/LICENSE)
![Repo Size](https://img.shields.io/github/repo-size/Mozilla/fx-private-relay)
[![Coverage Status](https://coveralls.io/repos/github/mozilla/fx-private-relay/badge.svg?branch=main)](https://coveralls.io/github/mozilla/fx-private-relay?branch=main)
[![What's Deployed](https://img.shields.io/badge/whatsdeployed-dev,stage,prod-green.svg)](https://whatsdeployed.io/s/60j/mozilla/fx-private-relay)
2023-07-20 14:39:10 +03:00
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/mozilla/fx-private-relay/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/mozilla/fx-private-relay/tree/main)
[![Relay e2e Tests](https://github.com/mozilla/fx-private-relay/actions/workflows/playwright.yml/badge.svg?branch=main)](https://github.com/mozilla/fx-private-relay/actions/workflows/playwright.yml)
2023-09-29 22:22:41 +03:00
2019-06-07 05:36:09 +03:00
Private Relay provides generated email addresses to use in place of personal
email addresses.
Recipients will still receive emails, but Private Relay keeps their personal
email address from being [harvested](https://blog.hubspot.com/marketing/what-is-a-landing-page-ht),
and then [bought, sold, traded, or combined](https://www.bookyourdata.com/)
with other data to personally identify, track, and/or [target
2019-06-07 05:36:09 +03:00
them](https://www.facebook.com/business/help/606443329504150?helpref=faq_content).
2023-07-20 14:39:10 +03:00
- [Private Relay](#private-relay)
- [Development](#development)
- [Requirements](#requirements)
- [Install and Run the Site Locally](#install-and-run-the-site-locally)
- [Working with translations](#working-with-translations)
- [Getting the latest translations](#getting-the-latest-translations)
- [Add/update messages for translation](#addupdate-messages-for-translation)
- [Commit translations for release](#commit-translations-for-release)
- [Recommended: Enable Mozilla Accounts authentication](#recommended-enable-mozilla-accounts-authentication)
2023-07-20 14:39:10 +03:00
- [Optional: Install and run the add-on locally](#optional-install-and-run-the-add-on-locally)
- [Optional: Run a development server to compile the frontend](#optional-run-a-development-server-to-compile-the-frontend)
- [Optional: Enable Premium Features](#optional-enable-premium-features)
- [Optional: Debugging JavaScript bundle sizes](#optional-debugging-javascript-bundle-sizes)
- [Test Premium](#test-premium)
- [Production Environments](#production-environments)
- [Requirements](#requirements-1)
- [Environment Variables](#environment-variables)
2019-06-07 05:36:09 +03:00
## Development
Please refer to our [coding standards](docs/coding-standards.md) for code styles, naming conventions and other methodologies.
2019-06-07 05:36:09 +03:00
### Requirements
2022-11-19 02:04:16 +03:00
- python 3.10 (we recommend [virtualenv](https://docs.python-guide.org/dev/virtualenvs/))
- PostgreSQL - even if you are using sqlite for development, requirements.txt installs
psycopg2 which [requires libpq](https://www.psycopg.org/docs/install.html#build-prerequisites) and Python header files.
The following should work:
- [On Windows](https://www.postgresql.org/download/windows/)
- On Ubuntu: `sudo apt install postgresql libpq-dev python3-dev`
- On OSX: `brew install postgresql libpq`
- On Fedora: `sudo dnf install libpq-devel python3-devel`
- [SES](https://aws.amazon.com/ses/) if you want to send real emails
- [Volta](https://volta.sh/) – Sets up the right versions of Node and npm, needed to compile the front-end
2019-06-07 05:36:09 +03:00
2020-04-02 23:35:40 +03:00
### Install and Run the Site Locally
2019-06-07 05:36:09 +03:00
1. Clone and change to the directory:
```sh
git clone --recurse-submodules https://github.com/mozilla/fx-private-relay.git
cd fx-private-relay
```
2019-06-07 05:36:09 +03:00
2. Create and activate a virtual environment:
Unix based systems:
```sh
virtualenv env
source env/bin/activate
```
Windows:
```sh
python -m venv env
2023-07-07 00:28:00 +03:00
source env/Scripts/activate
```
2023-07-07 00:28:00 +03:00
If you are not using Git Bash on Windows, instead of typing `source env/Scripts/activate`, type `.\env\Scripts\activate`.
Note: If you're running on Windows and get an error message stating that executing scripts are disabled on your computer, go into the Windows powershell and type `Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted`, then try again.
3. Install Python and Node requirements:
2019-06-07 05:36:09 +03:00
```sh
pip install -r requirements.txt
```
2021-06-11 00:16:21 +03:00
```sh
cd frontend
npm install
cd ../
```
2021-06-11 00:16:21 +03:00
Note: If you're running on Windows, you may run into an issue with usage of environment variables in npm scripts. You can force npm to use git-bash: `npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"`. This the default location, your install may be different.
2019-06-07 05:36:09 +03:00
4. Copy `.env` file for
2020-10-27 12:57:12 +03:00
[`decouple`](https://pypi.org/project/python-decouple/) config:
2019-06-07 05:36:09 +03:00
```sh
cp .env-dist .env
```
2019-06-07 05:36:09 +03:00
2019-06-13 18:09:24 +03:00
5. Add a `SECRET_KEY` value to `.env`:
```ini
SECRET_KEY=secret-key-should-be-different-for-every-install
```
2019-06-13 18:09:24 +03:00
6. Migrate DB:
2019-06-07 05:36:09 +03:00
```sh
python manage.py migrate
```
2019-06-07 05:36:09 +03:00
2019-06-13 18:09:24 +03:00
7. Create superuser:
2019-06-07 05:36:09 +03:00
```sh
python manage.py createsuperuser
```
2019-06-07 05:36:09 +03:00
8. Run the backend:
2019-06-07 05:36:09 +03:00
```sh
python manage.py runserver
```
2019-06-07 05:36:09 +03:00
and in a different terminal, build the frontend:
```sh
cd frontend
npm run watch
```
2021-08-13 20:06:59 +03:00
### Working with translations
2022-05-26 00:05:57 +03:00
The following docs will get you started with development, include creating new
strings to translate. See [Translation and Localization](docs/translations.md)
2022-05-26 00:05:57 +03:00
for general information on Relay localization.
2021-08-13 20:06:59 +03:00
#### Getting the latest translations
2021-08-13 20:06:59 +03:00
We use a [git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules)
for translated message files. The `--recurse-submodules` step of installation
should bring the message files into your working directory already, but you may
2022-05-26 00:05:57 +03:00
want also want to update the translations after install. The easiest way to do
2021-08-13 20:06:59 +03:00
that is:
- `git submodule update --remote`
2021-08-13 20:06:59 +03:00
2022-06-01 00:29:27 +03:00
To update the submodule automatically when running `git pull` or other commands:
- `git config --global submodule.recurse true`
2022-06-01 00:29:27 +03:00
2021-08-13 20:06:59 +03:00
#### Add/update messages for translation
2021-08-13 20:06:59 +03:00
The `privaterelay/locales` directory is a git repository like any other, so to
make changes to the messages:
1. Make whatever changes you need in `privaterelay/locales/en` as you work.
2. `cd privaterelay/locales/en`
3. `git branch message-updates-yyyymmdd`
4. `git push -u origin message-updates-yyyymmdd`
You can then open a pull request from the `message-updates-yyyymmdd` branch to
[the l10n repo](https://github.com/mozilla-l10n/fx-private-relay-l10n) `main` branch.
If you're not yet ready to submit some strings for translation, you can
2022-05-26 00:05:57 +03:00
tentatively add them to `frontend/pendingTranslations.ftl`. Strings in that file
will show up until strings with the same ID are added to the l10n repository.
2021-08-13 20:06:59 +03:00
#### Commit translations for release
2021-08-13 20:06:59 +03:00
To commit updates to the app's translations (e.g., before a release), we need
to commit this submodule update. So, if the updated translations are ready to
be committed into the app, you can `git add` the submodule just like any other
file:
- `git add privaterelay/locales`
2021-08-13 20:06:59 +03:00
You can then commit and push to set the app repository to the updated version
of the translations submodule:
- `git push`
2021-08-13 20:06:59 +03:00
2022-05-26 00:05:57 +03:00
An automated process updates the submodule daily, bringing in any new changes
and translations from the Localization Team.
### Recommended: Enable Mozilla Accounts authentication
To enable Mozilla Accounts authentication on your local server, you can use the
"Firefox Private Relay local dev" OAuth app on accounts.stage.mozaws.net.
2019-06-07 05:36:09 +03:00
To do so:
1. Set `ADMIN_ENABLED=True` in your `.env` file
2. Shutdown the server if running, and add the admin tables with:
```sh
python manage.py migrate
```
3. Run the server, now with `/admin` endpoints:
```sh
python manage.py runserver
```
4. Go to [the django admin page to change the default
site](http://127.0.0.1:8000/admin/sites/site/1/change/).
5. Change `example.com` to `127.0.0.1:8000` and click Save.
6. [Go to the django-allauth social app admin
page](http://127.0.0.1:8000/admin/socialaccount/socialapp/), sign in with the
2023-09-29 22:20:38 +03:00
superuser account you created above, and add a social app for Firefox Accounts:
2019-06-07 05:36:09 +03:00
| Field | Value |
| ---------- | ------------------------------------------------------- |
| Provider | Mozilla Accounts |
| Name | `accounts.stage.mozaws.net` |
| Client id | `9ebfe2c2f9ea3c58` |
| Secret key | Request this from `#fx-private-relay-eng` Slack channel |
| Sites | `127.0.0.1:8000` -> Chosen sites |
2019-06-07 05:36:09 +03:00
Now you can sign into [http://127.0.0.1:8000/](http://127.0.0.1:8000/) with an
FxA.
:warning: Remember that you'll need to use an account on https://accounts.stage.mozaws.net/, not
the production site, accounts.firefox.com.
<!-- #### Optional: Enable SES
TODO -->
2020-04-02 23:35:40 +03:00
### Optional: Install and run the add-on locally
2020-04-02 23:35:40 +03:00
_Note: The add-on is located in a [separate repo](https://github.com/mozilla/fx-private-relay-add-on/). See it for additional information on getting started._
2020-04-02 23:35:40 +03:00
The add-on adds Firefox UI to generate and auto-fill email addresses across the web. Running the add-on locally allows it to communicate with your local server (`127.0.0.1:8000`) instead of the production server (`relay.firefox.com`).
2020-04-02 23:35:40 +03:00
### Optional: Run a development server to compile the frontend
`npm run watch` watches the `frontend/src` directory and builds the frontend
when it detects changes. However, creating a production build is just time-consuming
enough to interrupt your development flow. It is therefore also possible to run the
front-end on a separate server that only recompiles changed modules, and does not
apply production optimizations. To do so, instead of `npm run watch`, run
`npm run dev`.
The frontend is now available at http://localhost:3000. Keep in mind that this
does make your local development environment less similar to production; in
particular, authentication is normally bound to the backend server, and thus
needs to be simulated when running the frontend on a separate server. If
you make any changes related to authentication, make sure to test them using
`npm run watch` as well.
### Optional: Enable Premium Features
**Note:** Premium features are automatically enabled for any user with an email address ending in
`mozilla.com`, `getpocket.com`, or `mozillafoundation.org` (see `PREMIUM_DOMAINS` in
`emails/models.py`). To mimic the customer's experience, it is recommended to follow the below
procedure.
To enable the premium Relay features, we integrate with the [FXA Subscription
2023-02-08 18:01:34 +03:00
Platform](https://mozilla.github.io/ecosystem-platform/relying-parties/reference/sub-plat-overview).
At a high level, to set up Relay premium subscription, we:
1. [Enable Mozilla Accounts Authentication](#recommended-enable-firefox-accounts-authentication) as described above.
2. Create a product & price in our [Stripe dashboard](https://dashboard.stripe.com/).
(Ask in #subscription-platform Slack channel to get access to our Stripe dashboard.)
3. Link free users of Relay to the appropriate SubPlat purchase flow.
4. Check users' FXA profile json for a `subscriptions` field to see if they can
access a premium, subscription-only feature.
In detail:
1. [Enable Mozilla Accounts Authentication](#recommended-enable-firefox-accounts-authentication) as described above.
2. Go to our [Stripe dashboard](https://dashboard.stripe.com/).
(Ask in #subscription-platform Slack channel to get access to our Stripe dashboard.)
3. Create a new product in Stripe.
4. Add all [required `product:` metadata](https://github.com/mozilla/fxa/blob/a0c7ac2b4bad0412a0f3a25fc82b5670922f8957/packages/fxa-auth-server/lib/routes/validators.js#L396-L437).
- Note: each piece of this metadata must have a `product:` prefix. So, for
example, `webIconURL` must be entered as `product:webIconURL`.
5. Add `capabilities:` metadata.
- Note: Each piece of this metadata must have a format like
`capabilities:<fxa oauth client ID>`, and the value is a free-form string
to describe the "capability" that purchasing the subscription gives to the
user. E.g., `capabilities:9ebfe2c2f9ea3c58` with value of `premium-relay`.
6. Set some env vars with values from the above steps:
| Var | Value |
| ------------------------------ | --------------------------------------------------------------------- |
| `FXA_SUBSCRIPTIONS_URL` | `https://accounts.stage.mozaws.net/subscriptions` |
| `PERIODICAL_PREMIUM_PROD_ID` | `prod_KEq0LXqs7vysQT` (from Stripe) |
| `PREMIUM_PLAN_ID_US_MONTHLY` | `price_1LiMjeKb9q6OnNsLzwixHuRz` (from Stripe) |
| `PREMIUM_PLAN_ID_US_YEARLY` | `price_1LiMlBKb9q6OnNsL7tvrtI7y` (from Stripe) |
| `PHONE_PROD_ID` | `prod_LviM2I0paxH1DZ` (from Stripe) |
| `PHONE_PLAN_ID_US_MONTHLY` | `price_1LDqw3Kb9q6OnNsL6XIDst28` (from Stripe) |
| `PHONE_PLAN_ID_US_YEARLY` | `price_1Lhd35Kb9q6OnNsL9bAxjUGq` (from Stripe) |
| `BUNDLE_PROD_ID` | `prod_MQ9Zf1cyI81XS2` (from Stripe) |
| `BUNDLE_PLAN_ID_US` | `price_1Lwp7uKb9q6OnNsLQYzpzUs5` (from Stripe) |
| `SUBSCRIPTIONS_WITH_UNLIMITED` | `"premium-relay"` (match the `capabilities` value you used in Stripe) |
| `SUBSCRIPTIONS_WITH_PHONE` | `"relay-phones"` (match the `capabilities` value you used in Stripe) |
### Optional: Debugging JavaScript bundle sizes
In `frontend/`, set `ANALYZE=true` when running `npm run build` to generate a
report detailing which modules are taking up most of the bundle size. A report
will be generated for both the client and server part of the frontend, but since
we only use the client, we're really only interested in that. The reports will
automatically open in your browser, and can also be found in
`/frontend/.next/analyze/`.
```sh
ANALYZE=true npm run build
```
#### Test Premium
There is a [comprehensive doc of test
cases](https://docs.google.com/spreadsheets/d/1fMl4LHr1kIuGHfS9jyhLrv5vAyJMBUCr2AP0sODFmJw/edit#gid=0) for purchasing premium Relay.
2021-09-17 13:04:39 +03:00
You can use [Stripe's test credit card details](https://stripe.com/docs/testing#cards) for payment.
The phone features are further protected by a waffle flag `phones`. In stage,
you'll need an SRE to add the flag to your test user. On the development
server, a developer can add the flag.
## Production Environments
### Requirements
In addition to the requirements for dev, production environments should use:
- [PostgreSQL](https://www.postgresql.org/)-compatible DB
### Environment Variables
Production environments should also set some additional environment variables:
```
DATABASE_URL=postgresql://<username>:<password>@<host>:<port>/<database>
DJANGO_SECURE_HSTS_SECONDS=15768000
DJANGO_SECURE_SSL_REDIRECT=True
```