Skip to content

Commit

Permalink
Merge pull request #53 from sendahug/Dev
Browse files Browse the repository at this point in the history
This update contains:
-Dependency updates
-Migration from Travis CI to CircleCI
-Workflow to automate PR testing to Dev and master
-User Icons support!
  • Loading branch information
shirblc authored Dec 23, 2020
2 parents 60feb4c + b08fc76 commit d25f47d
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 90 deletions.
73 changes: 73 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
version: 2.1
parameters:
run_workflow_build:
default: false
type: boolean

jobs:
build:
docker:
- image: cimg/python:3.9.0
environment:
FLASK_CONFIG: testing
TEST_DATABASE_URL: postgresql://postgres:password@localhost:5432/test-capstone?sslmode=disable
- image: circleci/postgres:12.5
auth:
username: mydockerhub-user
password: $DOCKERHUB_PASSWORD # context / project UI env-var reference
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test-capstone
POSTGRES_PASSWORD: "password"
steps:
- checkout
- restore_cache:
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
- run: sudo apt-get update
- run: sudo apt-get install -y postgresql-client
- run:
name: Install Python deps
command: |
pip3 install -r requirements.txt
python3 -m pip install --upgrade pip
- run:
name: Install coverage and codecov
command: |
sudo apt-get install -y python3-pip
sudo pip3 install coverage
sudo pip3 install codecov
# Dockerize installation to wait for the database to load
# Taken from: https://support.circleci.com/hc/en-us/articles/360006773953-Race-Conditions-Wait-For-Database
- run:
name: install dockerize
command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
environment:
DOCKERIZE_VERSION: v0.3.0
- run:
name: Wait for db
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Restore database
command: psql -h localhost -p 5432 -U postgres test-capstone < capstone_db.sql
- save_cache:
key: deps1-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
- "/usr/local/lib/python3.9/site-packages"
- run:
command: |
coverage run test_app.py
# Conditionally run testing depending on branch
# Once it's done, run codecov to upload test coverage
workflows:
test:
when:
or:
- << pipeline.parameters.run_workflow_build >>
- equal: [ master, << pipeline.git.branch >> ]
- equal: [ Dev, << pipeline.git.branch >> ]
jobs:
- build:
post-steps:
- run:
command: codecov
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name: New Release
on:
push:
branches: [ master ]
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/triggerbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Trigger CircleCI build
name: Trigger Build

# Controls when the action will run. Triggers the workflow on pull request
# events but only for the master branch
on:
pull_request:
branches: [ master, Dev ]

# Trigger CircleCI build via the API
jobs:
curl:
runs-on: ubuntu-latest
container:
image: python:3.9.1
steps:
- run: >-
curl -X POST "https://circleci.com/api/v2/project/gh/sendahug/send-hug-backend/pipeline"
--header 'Circle-Token: ${{ secrets.CIRCLE_CI_ACCESS_TOKEN }}'
--header 'content-type: application/json'
--header 'x-attribution-actor-id: ${{ github.actor }}'
--header 'x-attribution-login: ${{ github.actor }}'
--data '{"branch": "pull/${{ github.event.pull_request.number }}/head", "parameters":{"run_workflow_build":true}}'
31 changes: 31 additions & 0 deletions .pyup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# configure updates globally
# default: all
# allowed: all, insecure, False
update: insecure

# configure dependency pinning globally
# default: True
# allowed: True, False
pin: True

# set the default branch
# default: empty, the default branch on GitHub
branch: Dev

# update schedule
# default: empty
# allowed: "every day", "every week", ..
schedule: "every day"

# search for requirement files
# default: True
# allowed: True, False
search: True

# configure the branch prefix the bot is using
# default: pyup-
branch_prefix: pyup-

# allow to close stale PRs
# default: True
close_prs: True
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Send A Hug

[![Build Status](https://travis-ci.com/sendahug/send-hug-backend.svg?branch=Dev)](https://travis-ci.com/sendahug/send-hug-backend)
[![CircleCI](https://circleci.com/gh/sendahug/send-hug-backend.svg?style=shield)](https://circleci.com/gh/sendahug/send-hug-backend)
[![codecov](https://codecov.io/gh/sendahug/send-hug-backend/graph/badge.svg)](https://codecov.io/gh/sendahug/send-hug-backend)
[![Known Vulnerabilities](https://snyk.io/test/github/sendahug/send-hug-backend/badge.svg)](https://snyk.io/test/github/sendahug/send-hug-backend)
[![Updates](https://pyup.io/repos/github/sendahug/send-hug-backend/shield.svg)](https://pyup.io/repos/github/sendahug/send-hug-backend/)
Expand Down Expand Up @@ -30,21 +30,21 @@ For full project information, check the [`main README file`](https://github.com/
4. Run ```pip install -r requirements.txt``` to install dependencies.
5. Create a database for the app.
6. Update the database URI to match your system.
- The database URI comes from an environment variable named **DATABASE_URL**.
- The database URI comes from an environment variable named **DATABASE_URL**.
7. Set Auth0 configuration variables:
- AUTH0_DOMAIN - environment variable containing your Auth0 domain.
- API_AUDIENCE - environment variable containing your Auth0 API audience.
- CLIENT_ID - environment variable containing your Auth0 application's client ID.
- PRIVATE_KEY - environment variable containing your private VAPID key (required for push notifications).
- MGMT_API_TOKEN - environment variable containing your Auth0 Management API token (required for updating user roles on signup).
- CLIENT_SECRET - environment variable containing your Auth0 application's client secret (required for updating user roles on signup).
- AUTH0_DOMAIN - environment variable containing your Auth0 domain.
- API_AUDIENCE - environment variable containing your Auth0 API audience.
- CLIENT_ID - environment variable containing your Auth0 application's client ID.
- PRIVATE_KEY - environment variable containing your private VAPID key (required for push notifications).
- MGMT_API_TOKEN - environment variable containing your Auth0 Management API token (required for updating user roles on signup).
- CLIENT_SECRET - environment variable containing your Auth0 application's client secret (required for updating user roles on signup).
8. Set up your frontend URI.
- The frontend URI comes from an environment variable named **FRONTEND**.
- The frontend URI comes from an environment variable named **FRONTEND**.
9. Update your database using ```flask migrate upgrade```
10. Run flask with:
- ```export FLASK_APP=app.py```
- ```export FLASK_ENV=development``` (Recommended)
- ```flask run```
- ```export FLASK_APP=app.py```
- ```export FLASK_ENV=development``` (Recommended)
- ```flask run```

### Users

Expand Down
14 changes: 13 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,11 @@ def add_user(token_payload):
display_name=user_data['displayName'],
role='user',last_notifications_read=datetime.now(),
login_count=0,blocked=False,open_report=False,
auto_refresh=True,refresh_rate=20,push_enabled=False)
auto_refresh=True,refresh_rate=20,push_enabled=False,
selected_character='kitty',
icon_colours='{"character":"#BA9F93",\
"lbg":"#e2a275","rbg":"#f8eee4",\
"item":"#f4b56a"}')

# Try to add the post to the database
try:
Expand Down Expand Up @@ -812,6 +816,14 @@ def edit_user(token_payload, user_id):
if('refreshRate' in updated_user):
original_user.refresh_rate = updated_user['refreshRate']

# If the user is changing their selected character
if('selectedIcon' in updated_user):
original_user.selected_character = updated_user['selectedIcon']

# If the user is changing their character colours
if('iconColours' in updated_user):
original_user.icon_colours = json.dumps(updated_user['iconColours'])

# Checks if the user's role is updated based on the
# permissions in the JWT
# Checks whether the user has 'patch:any-post' permission, which
Expand Down
Binary file modified capstone_db
Binary file not shown.
24 changes: 13 additions & 11 deletions capstone_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ CREATE TABLE public.users (
last_notifications_read timestamp without time zone,
auto_refresh boolean,
push_enabled boolean,
refresh_rate integer
refresh_rate integer,
icon_colours character varying,
selected_character character varying(6)
);


Expand Down Expand Up @@ -369,7 +371,7 @@ ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_
--

COPY public.alembic_version (version_num) FROM stdin;
5aa132f978ec
d8921945f241
\.


Expand All @@ -393,13 +395,13 @@ COPY public.messages (id, from_id, for_id, text, date, thread, for_deleted, from
7 1 5 more testing 2020-06-08 14:45:05.713 2 f f
9 4 1 hang in there 2020-06-08 14:43:15 3 f f
16 9 5 hiiiii 2020-06-14 14:25:37.569 6 f f
23 4 5 testing thread delete 2020-11-03 16:38:06.351 4 f f
24 4 5 test 2020-11-03 16:48:33.213 4 f f
10 4 1 hi :) 2020-06-14 14:07:37.49 3 f t
21 4 1 hi 2020-07-06 17:33:55.712 3 f f
25 20 4 hang in there <3 2020-11-03 20:16:58.027 7 f f
22 4 1 test 2020-07-06 17:40:51.288 3 f f
26 20 1 hiiii :) 2020-11-03 20:21:30.972 8 f t
23 4 5 testing thread delete 2020-11-03 16:38:06.351 4 f t
24 4 5 test 2020-11-03 16:48:33.213 4 f t
\.
Expand Down Expand Up @@ -607,22 +609,22 @@ COPY public.threads (id, user_1_id, user_2_id, user_1_deleted, user_2_deleted) F
2 1 5 f f
3 1 4 f f
6 9 5 f f
4 4 5 f f
7 20 4 f f
8 20 1 t f
4 4 5 t f
\.
--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.users (id, auth0_id, received_hugs, given_hugs, display_name, login_count, role, blocked, open_report, release_date, last_notifications_read, auto_refresh, push_enabled, refresh_rate) FROM stdin;
9 auth0|5edf7b060793080013276746 0 1 user93 2 admin f f \N \N \N \N \N
1 auth0|5ed34765f0b8e60c8e87ca62 12 2 shirb 60 admin f f \N \N \N \N \N
20 auth0|5f4b9fd9915cd400670f4633 0 0 user24 4 user t f 2120-08-11 08:33:22.473 2020-11-03 20:21:13.399365 f f 0
4 auth0|5ed8e3d0def75d0befbc7e50 106 117 user14 52 admin f f \N 2020-10-30 18:13:21.282054 f t \N
5 auth0|5ede3e7a0793080013259050 2 0 user52 7 moderator f f \N \N \N \N \N
COPY public.users (id, auth0_id, received_hugs, given_hugs, display_name, login_count, role, blocked, open_report, release_date, last_notifications_read, auto_refresh, push_enabled, refresh_rate, icon_colours, selected_character) FROM stdin;
9 auth0|5edf7b060793080013276746 0 1 user93 2 admin f f \N \N \N \N \N {"character": "#ba9f93", "lbg": "#e2a275", "rbg": "#f8eee4", "item": "#f4b56a"} kitty
1 auth0|5ed34765f0b8e60c8e87ca62 12 2 shirb 60 admin f f \N \N \N \N \N {"character": "#ba9f93", "lbg": "#e2a275", "rbg": "#f8eee4", "item": "#f4b56a"} kitty
20 auth0|5f4b9fd9915cd400670f4633 0 0 user24 4 user t f 2120-08-11 08:33:22.473 2020-11-03 20:21:13.399365 f f 0 {"character": "#ba9f93", "lbg": "#e2a275", "rbg": "#f8eee4", "item": "#f4b56a"} kitty
5 auth0|5ede3e7a0793080013259050 2 0 user52 7 moderator f f \N \N \N \N \N {"character": "#ba9f93", "lbg": "#e2a275", "rbg": "#f8eee4", "item": "#f4b56a"} kitty
4 auth0|5ed8e3d0def75d0befbc7e50 106 117 user14 55 admin f f \N 2020-10-30 18:13:21.282054 f t \N {"character": "#ba9f93", "lbg": "#e2a275", "rbg": "#f8eee4", "item": "#f4b56a"} kitty
\.
Expand Down
32 changes: 32 additions & 0 deletions migrations/versions/d8921945f241_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""empty message
Revision ID: d8921945f241
Revises: 5aa132f978ec
Create Date: 2020-12-20 13:04:33.808749
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd8921945f241'
down_revision = '5aa132f978ec'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('icon_colours', sa.String(),
nullable=True))
op.add_column('users', sa.Column('selected_character',
sa.String(length=6), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'selected_character')
op.drop_column('users', 'icon_colours')
# ### end Alembic commands ###
Loading

0 comments on commit d25f47d

Please sign in to comment.