-
Notifications
You must be signed in to change notification settings - Fork 79
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
Add Gmail client and update email functions #944
Merged
Merged
Changes from 120 commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
7bdad86
Update requirements.txt
michplunkett 3e79072
Update requirements.txt
michplunkett 665d2b0
Update requirements.txt
michplunkett 47e0f09
Update requirements.txt
michplunkett ea734a9
Create mail_client.py
michplunkett 6f98f5f
Update requirements.txt
michplunkett 77e69e0
Update .gitignore
michplunkett 5c7029b
Update mail_client.py
michplunkett f8521dd
Switch file name
michplunkett d842413
Update __init__.py
michplunkett b627ccd
Merge branch 'develop' into email_issue
michplunkett c008090
Merge branch 'develop' into email_issue
michplunkett 886672d
Update __init__.py
michplunkett 0885ecb
Update __init__.py
michplunkett 7a72ef6
Update gmail_client.py
michplunkett 152fa8c
Update gmail_client.py
michplunkett b4eede3
Update gmail_client.py
michplunkett cbd8be7
Update views.py
michplunkett 78d67d4
Update views.py
michplunkett f4688e9
Update gmail_client.py
michplunkett 2d8c12c
Update gmail_client.py
michplunkett 311dbbe
Update docker-compose.yml
michplunkett 4d1c87f
Update __init__.py
michplunkett 10af5d7
Update __init__.py
michplunkett 79669cd
Update views.py
michplunkett 59723d7
Update gmail_client.py
michplunkett 3b5f6b3
Delete email.py
michplunkett d7c283f
alpha-sort docker environment variables
michplunkett a996b6d
Update docker-compose.yml
michplunkett 09a1f88
Remove flask-mail requirement
michplunkett f72bc53
Update config.py
michplunkett 380f1c7
Update gmail_client.py
michplunkett 09412a6
Remove flask_mail code
michplunkett da308e8
Update __init__.py
michplunkett aceff6c
Variable editing
michplunkett 6662d34
Update gmail_client.py
michplunkett d77a540
Update config.py
michplunkett 7515790
Sorting lines
michplunkett 34c9634
Update __init__.py
michplunkett f5befa9
Update __init__.py
michplunkett ae58496
Update config.py
michplunkett c2f91ff
Add file size constants
michplunkett 961aa62
Use html email templates
michplunkett 25d0871
Remove txt email templates
michplunkett 62355a6
Use config values, not key searching
michplunkett 1640a18
Update views.py
michplunkett e3a3c31
Update docker-compose.prod-img.yml
michplunkett 5ce1043
Update docker-compose.prod-img.yml
michplunkett 1883628
Update gmail_client.py
michplunkett eea6308
Update requirements.txt
michplunkett 3a3c9c0
Update requirements.txt
michplunkett d6fcf4c
Update test_user_api.py
michplunkett d272952
Update test_user_api.py
michplunkett 352e751
Update test_user_api.py
michplunkett a3a5a5c
Update test_user_api.py
michplunkett f4140df
Update requirements.txt
michplunkett d545435
Update test_user_api.py
michplunkett 75b1588
Update test_user_api.py
michplunkett daa9d06
Update test_user_api.py
michplunkett eac3483
Update general.py
michplunkett fc5a2a9
Update test_user_api.py
michplunkett 27dfdc5
Update gmail_client.py
michplunkett d329f9f
Update gmail_client.py
michplunkett 3fa934e
Trying again
michplunkett 6077f71
Update __init__.py
michplunkett 10b1073
Fix test and dev docker starts.
abandoned-prototype 215ea41
Merge branch 'develop' into email_issue
abandoned-prototype 4d57a52
Update docker-compose.yml
michplunkett ca34a9e
Update docker-compose.prod-img.yml
michplunkett 82629b6
Update gmail_client.py
michplunkett 6ff3af9
Update Makefile
michplunkett c3af59a
Update Makefile
michplunkett 632e14e
Spacing and standardize naming format
michplunkett 0f300ef
Remove OO_SERVICE_EMAIL from docker files
michplunkett 10ba6fc
TRAVIS_PYTHON_VERSION -> MAKE_PYTHON_VERSION
michplunkett f3e84ec
Update Makefile
michplunkett 8775555
Update Makefile
michplunkett b4df3bf
Spaces
michplunkett 5936a30
Update test_user_api.py
michplunkett 3477bcf
Update general.py
michplunkett c3351c4
Update gmail_client.py
michplunkett ea9d82c
Update gmail_client.py
michplunkett 6189cc7
Update CONTRIB.md
michplunkett 57eadd4
Update CONTRIB.md
michplunkett bf1885f
Update CONTRIB.md
michplunkett 25bec63
Update CONTRIB.md
michplunkett 6785f62
Update CONTRIB.md
michplunkett 774ef60
Update docker-compose.yml
michplunkett d7c7205
Update Makefile
michplunkett 1aa8772
Update Makefile
michplunkett 4491206
Update CONTRIB.md
michplunkett 57d4ae4
Add models package and email file
michplunkett ba12f69
Add email objects
michplunkett e6ea11b
Remove email objects from mail client
michplunkett 23532db
gmail_client -> email_client
michplunkett d334b24
GmailClient -> EmailClient
michplunkett 067cd37
Update email_client.py
michplunkett bc739f1
Delete models package
michplunkett 2b26e94
BaseConfig change
michplunkett a3e352d
Move Email class
michplunkett 43957f4
Update views.py
michplunkett 013b085
Update email_client.py
michplunkett 15c7836
Update test_functional.py
michplunkett 97129bc
Update views.py
michplunkett fd44c96
Update utils.py
michplunkett 22a0921
Update models.py
michplunkett 6252755
Update test_functional.py
michplunkett 7ae657c
Update test_functional.py
michplunkett dfb4db5
Move emails back
michplunkett 6145fb5
Update email_client.py
michplunkett fcf0d9d
Update email_client.py
michplunkett 9e46d85
Update email_client.py
michplunkett d4a77fc
Add dev logic to the init file
michplunkett 38347e6
Update CONTRIB.md
michplunkett ebb0e58
Update docker-compose.yml
michplunkett e5e1aa2
Update CONTRIB.md
michplunkett 1614924
Update email_client.py
michplunkett 2360fb3
Update .gitignore
michplunkett 6dd2f50
Merge branch 'develop' into email_issue
abandoned-prototype aea80a2
Merge branch 'develop' into email_issue
abandoned-prototype 57c3726
Update requirements.txt
michplunkett 0843f3d
Update requirements.txt
michplunkett 910ddc1
Update requirements.txt
michplunkett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
# Contributing Guide | ||
|
||
First, thanks for being interested in helping us out! If you find an issue you're interested in, feel free to make a comment about how you're thinking of approaching implementing it in the issue and we can give you feedback. Please also read our [code of conduct](/CODE_OF_CONDUCT.md) before getting started. | ||
|
||
## Submitting a Pull Request (PR) | ||
|
||
When you come to implement your new feature, clone the repository and then create a branch off `develop` locally and add commits to implement your feature. | ||
|
||
If your git history is not so clean, please do rewrite before you submit your PR - if you're not sure if you need to do this, go ahead and submit and we can let you know when you submit. | ||
|
@@ -21,13 +19,11 @@ git config user.name "<your-github-username>" | |
This will make sure that all commits you make locally are associated with your github account and do not contain any additional identifying information. More detailed information on this topic can be found [here](https://docs.github.com/en/free-pro-team@latest/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address). | ||
|
||
### Linting / Style Checks | ||
We use [pre-commit](https://pre-commit.com/) for automated linting and style checks. Be sure to [install pre-commit](https://pre-commit.com/#installation) and run `pre-commit install` in your local version of the repository to install our pre-commit checks. This will make sure your commits are always formatted correctly. | ||
|
||
We use [pre-commit](https://pre-commit.com/) for automated linting and style checks. Be sure to [install pre-commit](https://pre-commit.com/#installation) and run `pre-commit install` in your local version of the repository to install our pre-commit checks. This will make sure your commits are always formatted correctly. | ||
|
||
You can run `pre-commit run --all-files` or `make lint` to run pre-commit over your local codebase, or `pre-commit run` to run it only over the currently stages files. | ||
You can run `pre-commit run --all-files` or `make lint` to run pre-commit over your local codebase, or `pre-commit run` to run it only over the currently stages files. | ||
|
||
## Development Environment | ||
|
||
You can use our Docker-compose environment to stand up a development OpenOversight. | ||
|
||
You will need to have Docker installed in order to use the Docker development environment. | ||
|
@@ -53,8 +49,24 @@ $ docker exec -it openoversight_web_1 /bin/bash | |
|
||
Once you're done, `make stop` and `make clean` to stop and remove the containers respectively. | ||
|
||
## Testing S3 Functionality | ||
## Gmail Requirements | ||
**NOTE:** If you are running on dev and do not currently have a `service_account_key.json` file, create one and leave it empty. The email client will then default to an empty object and simulate emails in the logs. | ||
|
||
For the application to work properly, you will need a [Google Cloud Platform service account](https://cloud.google.com/iam/docs/service-account-overview) that is attached to a GSuite email address. Here are some general tips for working with service accounts: [Link](https://support.google.com/a/answer/7378726?hl=en). | ||
We would suggest that you do not use a personal email address, but instead one that is used strictly for sending out OpenOversight emails. | ||
|
||
You will need to do these two things for the service account to work as a Gmail bot: | ||
1. Enable domain-wide delegation for the service account: [Link](https://support.google.com/a/answer/162106?hl=en) | ||
2. Enable the `https://www.googleapis.com/auth/gmail.send` scope in the Gmail API for your service account: [Link](https://developers.google.com/gmail/api/auth/scopes#scopes) | ||
3. Save the service account key file in OpenOversight's base folder as `service_account_key.json`. The file is in the `.gitignore` file GitHub will not allow you to save it, provided you've named it correctly. | ||
4. For production, save the email address associated with your service account to a variable named `OO_SERVICE_EMAIL` in a `.env` file in the base directory of this repository. For development and testing, update the `OO_SERVICE_EMAIL` variable in the `docker-compose.yml` file. | ||
|
||
Example `.env` variable: | ||
```bash | ||
OO_SERVICE_EMAIL="[email protected]" | ||
``` | ||
Comment on lines
+53
to
+67
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. This should be all of the info needed, @abandoned-prototype. |
||
|
||
## Testing S3 Functionality | ||
We use an S3 bucket for image uploads. If you are working on functionality involving image uploads, | ||
then you should follow the "S3 Image Hosting" section in [DEPLOY.md](/DEPLOY.md) to make a test S3 bucket | ||
on Amazon Web Services. | ||
|
@@ -72,7 +84,6 @@ Now when you run `make dev` as usual in the same session, you will be able to su | |
your test bucket. | ||
|
||
## Database commands | ||
|
||
Running `make dev` will create the database and persist it into your local filesystem. | ||
|
||
You can access your PostgreSQL development database via psql using: | ||
|
@@ -89,7 +100,6 @@ or | |
`$ python test_data.py --cleanup` to delete the data | ||
|
||
### Migrating the Database | ||
|
||
If you e.g. add a new column or table, you'll need to migrate the database using the Flask CLI. First we need to 'stamp' the current version of the database: | ||
|
||
```sh | ||
|
@@ -152,7 +162,6 @@ pip install -r dev-requirements.txt | |
``` | ||
|
||
## OpenOversight Management Interface | ||
|
||
In addition to generating database migrations, the Flask CLI can be used to run additional commands: | ||
|
||
```sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,19 @@ export UID=$(shell id -u) | |
default: build start create_db populate test stop clean | ||
|
||
.PHONY: build | ||
build: ## Build containers | ||
build: ## Build containers | ||
docker-compose build | ||
|
||
.PHONY: build_with_version | ||
build_with_version: | ||
docker-compose build --build-arg TRAVIS_PYTHON_VERSION=$(PYTHON_VERSION) | ||
build_with_version: create_empty_secret create_empty_env | ||
docker-compose build --build-arg MAKE_PYTHON_VERSION=$(PYTHON_VERSION) | ||
|
||
.PHONY: test_with_version | ||
test_with_version: build_with_version assets | ||
FLASK_ENV=testing docker-compose run --rm web pytest --cov=OpenOversight --cov-report xml:OpenOversight/tests/coverage.xml --doctest-modules -n 4 --dist=loadfile -v OpenOversight/tests/ | ||
|
||
.PHONY: start | ||
start: build ## Run containers | ||
start: build ## Run containers | ||
docker-compose up -d | ||
|
||
.PHONY: create_db | ||
|
@@ -36,7 +36,7 @@ assets: | |
dev: build start create_db populate | ||
|
||
.PHONY: populate | ||
populate: create_db ## Build and run containers | ||
populate: create_db ## Build and run containers | ||
@until docker-compose exec postgres psql -h localhost -U openoversight -c '\l' postgres &>/dev/null; do \ | ||
echo "Postgres is unavailable - sleeping..."; \ | ||
sleep 1; \ | ||
|
@@ -46,27 +46,27 @@ populate: create_db ## Build and run containers | |
docker-compose run --rm web python ./test_data.py -p | ||
|
||
.PHONY: test | ||
test: start ## Run tests | ||
test: start ## Run tests | ||
if [ -z "$(name)" ]; then \ | ||
FLASK_ENV=testing docker-compose run --rm web pytest --cov --doctest-modules -n auto --dist=loadfile -v OpenOversight/tests/; \ | ||
else \ | ||
FLASK_ENV=testing docker-compose run --rm web pytest --cov --doctest-modules -v OpenOversight/tests/ -k $(name); \ | ||
FLASK_ENV=testing docker-compose run --rm web pytest --cov --doctest-modules -v OpenOversight/tests/ -k $(name); \ | ||
fi | ||
|
||
.PHONY: lint | ||
lint: | ||
pre-commit run --all-files | ||
|
||
.PHONY: cleanassets | ||
cleanassets: | ||
.PHONY: clean_assets | ||
clean_assets: | ||
rm -rf ./OpenOversight/app/static/dist/ | ||
|
||
.PHONY: stop | ||
stop: ## Stop containers | ||
stop: ## Stop containers | ||
docker-compose stop | ||
|
||
.PHONY: clean | ||
clean: cleanassets stop ## Remove containers | ||
clean: clean_assets stop ## Remove containers | ||
docker-compose rm -f | ||
|
||
.PHONY: clean_all | ||
|
@@ -88,3 +88,18 @@ help: ## Print this message and exit | |
.PHONY: attach | ||
attach: | ||
docker-compose exec postgres psql -h localhost -U openoversight openoversight-dev | ||
|
||
# TODO: These two commands are the same with the exception of the file name, this should be addressed at some point | ||
.PHONY: create_empty_secret | ||
create_empty_secret: # This is needed to make sure docker doesn't create an empty directory, or delete that directory first | ||
touch service_account_key.json || \ | ||
(echo "Need to delete that empty directory first"; \ | ||
sudo rm -d service_account_key.json/; \ | ||
touch service_account_key.json) | ||
|
||
.PHONY: create_empty_env | ||
create_empty_env: # This is needed to make sure docker doesn't create an empty directory, or delete that directory first | ||
touch .env || \ | ||
(echo "Need to delete that empty directory first"; \ | ||
sudo rm -d .env/; \ | ||
touch .env) | ||
Comment on lines
+100
to
+105
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. Created so that the base level docker-compose command doesn't error out. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
These spaces don't visually change anything in the document, as the header elements have a built-in bottom margin.