zcash-grant-system/backend
Daniel Ternyak 5a15022987
ZF Grants 2.1 (#496)
* fix ccr pagination defaults

* add ccr admin tests

* add ccr user tests

* checkpoint

* fix tslint

* request changes discussion flow mvp

* admin - add discussion status

* backend - add live drafts

* admin - add live drafts

* frontend - add live drafts

* frontend - add edit discussion proposal

* fix tsc

* include DISCUSSION status in propsal listview

* do not make live draft on admin request changes

* hide live drafts from user proposal draft list

* fix backend tests

* add admin tests

* add user tests

* fix: liking, viewing discussion proposals, admin menu

* admin - update hints for live drafts

* fe - add better messaging when updating a proposal

* be - fix like test

* remove TODO comments

* add new email types

* fix storybook

* add revision tab story

* backend - implement proposal revisions

* frontend - implement proposal revisions

* update revision tab story

* fix lint

* remove set detection

* email proposal followers on revision

* restrict banner to team members only

* misc bug fixes

* update, add backend tests

* add milestone title change to revision history story

* fix milestones display in preview

* allow archived proposals to be queried

* implement archived proposal page

* fix tsc

* implement archived proposal get route

* move styling into less

* remove proposal archive parent id

* handle archived proposal status

* cleanup

* remove contributions, switch to USD, implement quarters

* use Qs to preserve formatting

* handle edit only kyc

* prevent ARCHIVED proposals from being sent to admin

* display latest revision first

* admin - proposal & ccr reject permanently

* backend - proposal & ccr reject permanently

* frontend - proposal & ccr reject permanently

* fix tsc

* use $ in milestone payout email

* introduce custom filters to proposal listview

* hide archive link on first revision

* upgrade packages

* add bech32 implementation

* add z address validation with tests

* fix tslint

* use local address validation

* fix tests, remove blockchain mock gets

* add additional bad addresses

* update briefs to include page break message

* remove contributions routes, menu entry

* disable countribution count admin stats

* remove matching and pretty print in finance

* fix tslint

* separate out rejected permanently proposals

* make removing proposals generic

* allow linked tabs to be ignored

* remove rejected permanently, bugfix

* update preview link to point to rejected tab

* implement rejected permanently tab, add tab message

* refactor variable

* fix tslint

* fix tslint

* send ccr reject permanently email on rejection

* fix preview message

* wire up proposal arbiter and rejected emails

* disable tip jar in proposal and profile

* sync ccr/proposal drafts on create form init

* check invites on submit modal open

* update team invite language

* update team text when edit

* fix ccr rejected permanently tag

* text changes, email preview fix

* display changes requested tag when in discussion with changes requested

* enable social share on open for discussion proposals, update language

* place sort below filter

* derive filter from query string

* use better filter names in query params

* fix tslint

* create snapshot of original proposal on first revision

* clear invites between edits, account for additional changes not tracked in revisions

* update tests

* fix test

* remove print

* SameSite Fixes (#150)

* QA Fixes 2 (#151)

* set filters as query strings on change

* remove rejected permanently tags

* add dollar sign in financials legend

* fix tsc

* Copy Touchups (#152)

* Email Fixes (#155)

* fix ZEC in milestone payout emails

* fix links in rejected permanently CCR/proposal emails

* Poll for Team and Invite Changes in Create Flow (#153)

* poll for team and invite changes in create flow

* fix tslint

Co-authored-by: Daniel Ternyak <dternyak@gmail.com>

* pretty print payouts by quarter (#156)

Co-authored-by: Daniel Ternyak <dternyak@gmail.com>

* Remove Blockchain Module (#154)

* remove blockchain route from backend, remove calls to node

* revert blockchain_get removal

* Add Tags to Proposal Cards (#157)

* add tag to proposals and dynamically set v1 card height

* listen on window resize

* make card height props optional

* set tag in bottom right, remove dynamic card resize, add dynamic tag resize

* cleanup

* cleanup

Co-authored-by: Daniel Ternyak <dternyak@gmail.com>

* Improve Frontend Address Validation (#158)

Co-authored-by: Daniel Ternyak <dternyak@gmail.com>

* Remove blockchain module (#162)

* remove blockchain route from backend, remove calls to node

* revert blockchain_get removal

* Remove Blockchain App (#160)

* remove blockchain app

* remove blockchain app from travis

Co-authored-by: Danny Skubak <skubakdj@gmail.com>

* Proposal Edit Fixes (#161)

* fe - display error if edit creation fails

* be - restrict live draft publish

Co-authored-by: Daniel Ternyak <dternyak@gmail.com>

* Restrict Arbiter Assignment (#159)

Co-authored-by: Daniel Ternyak <dternyak@gmail.com>

* Email Copy updates

* Remove Admin Financials Card

* Hookup 'proposal_approved_without_funding' to admin email example

* bump various package versions

* Update yarn.lock files

* Attach 'proposal_approved_without_funding' to backend example email

* bump package versions

Co-authored-by: Danny Skubak <skubakdj@gmail.com>
2020-04-07 21:56:32 -05:00
..
grant ZF Grants 2.1 (#496) 2020-04-07 21:56:32 -05:00
migrations ZF Grants 2.1 (#496) 2020-04-07 21:56:32 -05:00
requirements ZF Grants 2.1 (#496) 2020-04-07 21:56:32 -05:00
tests ZF Grants 2.1 (#496) 2020-04-07 21:56:32 -05:00
.env.example ZF Grants 2.1 (#496) 2020-04-07 21:56:32 -05:00
.gitignore Authenticate endpoints (#193) 2018-11-13 15:17:06 +01:00
.isort.cfg Run reformatter on all files (#98) 2019-01-23 10:00:30 -05:00
.pre-commit-config.yaml Run reformatter on all files (#98) 2019-01-23 10:00:30 -05:00
Procfile initial commit 2018-09-10 11:55:26 -05:00
README.md CCRs (#86) 2019-12-05 19:01:02 -06:00
app.py ZF Grants 2.1 (#496) 2020-04-07 21:56:32 -05:00
requirements.txt initial commit 2018-09-10 11:55:26 -05:00
setup.cfg Run reformatter on all files (#98) 2019-01-23 10:00:30 -05:00

README.md

ZF Grants Backend

This is the backend component of grants.zfnd.org.

Environment Setup

Run the following commands to bootstrap your environment. Note: db setup is configured in .env when running locally. SQLLite is used by default in /tmp/

# Get python in a virtual environment
virtualenv -p python3 venv
source venv/bin/activate

# Install python requirements
pip install -r requirements/dev.txt

# Create environment variables file, edit as needed
cp .env.example .env

If you want emails to work properly, you'll both need a SendGrid secret api key in .env, and if youre running Python 3.6+ on macOS, you'll need to fix your certificates.

Database Setup

Once you have installed your DBMS, run the following to create your app's database tables and perform the initial migration

flask db migrate
flask db upgrade

Generate Admin Authentication

To generate a new admin password, run

flask flask gen-admin-auth

Running the App

Depending on what you need to run, there are several services that need to be started

If you just need the API, you can run

flask run

Deployment

To deploy

export FLASK_ENV=production
export FLASK_DEBUG=0
export DATABASE_URL="<YOUR DATABASE URL>"
flask run       # start the flask server

In your production environment, make sure the FLASK_DEBUG environment variable is unset or is set to 0.

Shell

To open the interactive shell, run

flask shell

By default, you will have access to the flask app.

Running Tests

To run all tests, run

flask test

To run only select test, Flask allows you to match against the test filename with ``-t` like so:

flask test -t proposal

Migrations

Whenever a database migration needs to be made. Run the following commands

flask db migrate

This will generate a new migration script. Then run

flask db upgrade

To apply the migration.

For a full migration command reference, run flask db --help.

Commands

To create a proposal

flask create-proposal "FUNDING_REQUIRED" 1 123 "My Awesome Proposal" "### Hi! I have a great proposal"

To seed many proposal

flask create-proposals <number_of_proposals:int>

To set a user to admin

flask set-admin <email|id>

S3 Storage Setup

  1. create bucket, keep the bucket name and region handy

  2. unblock public access Amazon S3 > BUCKET_NAME > Permissions > Public access settings

  3. set the CORS configuration, replace HOST_NAME with desired domain, or * to allow all
    Amazon S3 > BUCKET_NAME > Permissions > CORS configuration

    <?xml version="1.0" encoding="UTF-8"?>
    <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
         <CORSRule>
             <AllowedOrigin>HOST_NAME</AllowedOrigin>
             <AllowedMethod>GET</AllowedMethod>
             <AllowedMethod>POST</AllowedMethod>
             <AllowedMethod>PUT</AllowedMethod>
             <AllowedHeader>*</AllowedHeader>
         </CORSRule>
    </CORSConfiguration>
    
  4. create IAM Policy, replace BUCKET_NAME with correct name.

     {
         "Version": "2012-10-17",
         "Statement": [
             {
                 "Effect": "Allow",
                 "Action": [
                     "s3:PutObject",
                     "s3:PutObjectAcl",
                     "s3:GetObject",
                     "s3:DeleteObject"
                 ],
                 "Resource": [
                     "arn:aws:s3:::BUCKET_NAME/*"
                 ]
             }
         ]
     }
    
  5. create IAM user with programatic access (Access key) and assign that user the policy created above

  6. copy the user's Access key ID, Secret access key, bucket name & bucket region to private .env, see .env.example

Social Verification (oauth)

These instructions are for development, for production simply replace all hostnames/ips/ports with the proper production hostname.

  1. Create GitHub oauth app https://github.com/settings/developers

    1. select tab OAuth Apps > click New OAuth App button
    2. set Homepage URL to http://localhost:3000
    3. set Authorization callback URL to http://localhost:3000/callback/github
    4. save Client ID and Client Secret to .env GITHUB_CLIENT_ID & GITHUB_CLIENT_SECRET respectively.
  2. Create Twitter oauth app https://developer.twitter.com/en/apply/user

    1. click Create an App
    2. set Website URL to a valid URL, such as http://grants.zfnd.org
    3. check the Enable Sign in with Twitter option
    4. set Callback URLs to http://127.0.0.1:3000/callback/twitter
    5. fill out other required fields
    6. after create, select Keys and tokens tab
    7. save Consumer API key and Consumer API secret key to .env TWITTER_CLIENT_ID & TWITTER_CLIENT_SECRET respectively.