Skip to content

changes from techx -> treehacks #30

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

Draft
wants to merge 80 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
23f2092
Initial commit, use docker-compose + make, use hackerapi, rename to j…
kpsuperplane May 31, 2019
9aabcc4
forgot the source whoops
kpsuperplane May 31, 2019
039057d
Update mds
kpsuperplane May 31, 2019
b5fee05
Fix rendering and counting bug, add returned status
kpsuperplane Jun 1, 2019
9cfa631
prep for deploy
kpsuperplane Jun 1, 2019
02bca4d
capital env vars
kpsuperplane Jun 1, 2019
e349b87
Use templater
kpsuperplane Jun 1, 2019
0416a02
nope back to envsubst
kpsuperplane Jun 1, 2019
7bcc944
Rename to template yaml
kpsuperplane Jun 1, 2019
b4254f1
Import os
kpsuperplane Jun 1, 2019
57a1764
Make resource requests a suggestion
kpsuperplane Jun 1, 2019
117ae14
Correct redirect uri, error state for login
kpsuperplane Jun 2, 2019
68a16c3
fix redirect uri
kpsuperplane Jun 2, 2019
2173b61
Use correct token name
kpsuperplane Jun 2, 2019
c0ba034
Remember to delete the cookie
kpsuperplane Jun 2, 2019
3149a6b
Add CSRF protection
kpsuperplane Jun 2, 2019
c0b7b0a
Fix csrf token
kpsuperplane Jun 2, 2019
d9a3851
fix csrf token typo
kpsuperplane Jun 2, 2019
10f22e9
Make csrf token lowercase
kpsuperplane Jun 2, 2019
34b5f58
Finally fix csrf token
kpsuperplane Jun 2, 2019
e9a5c5b
Basic theming
kpsuperplane Jun 7, 2019
91604b1
Allow people to fix their emails/phones if not set
kpsuperplane Jun 7, 2019
813d7d5
mobile-friendly everything
kpsuperplane Jul 8, 2019
50d3ebd
Improve desktop positioning of requests
kpsuperplane Jul 8, 2019
41370aa
Improve inventory styling
kpsuperplane Jul 8, 2019
5247ddf
top 40px
kpsuperplane Jul 8, 2019
eaecc90
revert temporary fake auth
kpsuperplane Jul 9, 2019
9ac4c07
forgot to comment out token
kpsuperplane Jul 9, 2019
9bea67b
Add support for MLH items
kpsuperplane Sep 1, 2019
f64ef85
Update deployment details
kpsuperplane Sep 1, 2019
cdd4c79
Add email notice
kpsuperplane Sep 1, 2019
28ef680
fix indentation
kpsuperplane Sep 1, 2019
4fe9318
fix secrets config
kpsuperplane Sep 1, 2019
779bc71
fix secrets again
kpsuperplane Sep 1, 2019
76b9dfb
Fix db secret
kpsuperplane Sep 1, 2019
13d703c
Change login path
kpsuperplane Sep 1, 2019
05ae8a9
Check user claims
kpsuperplane Sep 4, 2019
efc91c9
properly dispose cookie
kpsuperplane Sep 4, 2019
5d67813
get information from claim
kpsuperplane Sep 4, 2019
0d03d46
bugfix
kpsuperplane Sep 4, 2019
d65bddb
Never disable phone number
kpsuperplane Sep 4, 2019
7289be6
Update css
kpsuperplane Sep 5, 2019
96d9883
update notice
kpsuperplane Sep 10, 2019
1981ddd
Ensure hacker is checked in or confirmed
kpsuperplane Sep 10, 2019
31f45ce
Update copy
kpsuperplane Sep 13, 2019
2ee415b
Update deployment template
kpsuperplane Sep 14, 2019
33c164b
pool size 2
kpsuperplane Sep 14, 2019
1eb0e7d
pool size 2
kpsuperplane Sep 14, 2019
8cfb45d
Reduce resource allocation
kpsuperplane Sep 14, 2019
129644d
Remove socket support
kpsuperplane Sep 14, 2019
ecfdf42
Remove socket entirely
kpsuperplane Sep 14, 2019
4ab5cff
change dockerfile to run on port 8000
epicfaace Feb 4, 2020
4c9d7b1
run dev mode with right env vars
epicfaace Feb 4, 2020
fa0e526
redirect to login.treehacks.com on login
epicfaace Feb 4, 2020
9ca83ea
finish login integration
epicfaace Feb 4, 2020
ec8b5b0
fix cookie auth
epicfaace Feb 4, 2020
5c0069c
rename variables and things so it can be deployed on heroku
epicfaace Feb 4, 2020
1ef5dec
remove python 2.7 runtime
epicfaace Feb 4, 2020
743e909
remove cryptography and pycrypto requirements
epicfaace Feb 4, 2020
3b8dcb9
don't make SECRET env var required
epicfaace Feb 4, 2020
e304a65
don't make ENV variable required
epicfaace Feb 4, 2020
ec83369
use PORT instead of FLASK_RUN_PORT so it works on Heroku
epicfaace Feb 4, 2020
fe14242
upgrade psycopg2 to fix https://github.com/taigaio/taiga-back/issues/…
epicfaace Feb 4, 2020
f52de81
make SECRET required again (needed for sessions / csrf tokens)
epicfaace Feb 4, 2020
a5b7683
fix typo
epicfaace Feb 5, 2020
1ff2d61
wording changes
epicfaace Feb 5, 2020
f0e07f4
add slack and email methods
epicfaace Feb 9, 2020
f27fd0c
disable updating user, remove user phone and location
epicfaace Feb 9, 2020
93d1a94
auto-reply to received slack messages
epicfaace Feb 9, 2020
b38d0c4
add proper error handling for slack bot
epicfaace Feb 9, 2020
f81a301
remove slack rtm integration (not working)
epicfaace Feb 9, 2020
7a6e988
save user first_name and last_name in db
epicfaace Feb 9, 2020
9fedc40
fix: properly reload page when buttons are clicked
epicfaace Feb 9, 2020
6ef35c1
send email / slack upon approval
epicfaace Feb 9, 2020
cae9b9c
add "slack ..." button
epicfaace Feb 9, 2020
c5cfe78
add info about heroku deployment
epicfaace Feb 9, 2020
5ef8d29
add warning
epicfaace Feb 9, 2020
0cf1fa9
update sample env to include DEBUG and FORCE_SSL
epicfaace Feb 12, 2020
45cb8a9
update favicon and default image
epicfaace Feb 12, 2020
e74e027
add hardware_admin
epicfaace Feb 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ node_modules/
.DS_Store
__pycache__
.cache/
Cog
.vscode/
.env
62 changes: 1 addition & 61 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
Contributing
============

All kinds of contributions to Cog are greatly appreciated. For someone
unfamiliar with the code base, the most efficient way to contribute is usually
to submit a [feature request](#feature-requests) or [bug report](#bug-reports).

If you want to dive into the source code, you can submit a [patch](#patches) as
well. Working on [existing issues][issues] is super helpful!

Feature Requests
----------------

Do you have an idea for an awesome new feature for Cog? Please [submit a
feature request][issue]. It's great to hear about new ideas.

If you are inclined to do so, you're welcome to [fork][fork] Cog, work on
implementing the feature yourself, and submit a patch. In this case, it's
*highly recommended* that you first [open an issue][issue] describing your
enhancement to get early feedback on the new feature that you are implementing.
This will help avoid wasted efforts and ensure that your work is incorporated
into the code base.

Bug Reports
-----------

Did something go wrong with Cog? Sorry about that! Bug reports are greatly
appreciated!

When you [submit a bug report][issue], please include relevant information such
as Cog version, operating system, configuration, error messages, and steps to
reproduce the bug. The more details you can include, the easier it is to find
and fix the bug.

Patches
-------

Want to hack on Cog? Awesome!

If there are [open issues][issues], you're more than welcome to work on those -
this is probably the best way to contribute to Cog. If you have your own
ideas, that's great too! In that case, before working on substantial changes to
the code base, it is *highly recommended* that you first [open an issue][issue]
describing what you intend to work on.

Patches should be submitted as Github pull requests.

Any changes to the code base should follow the style and coding conventions
used in the rest of the project. The version history should be clean, and
commit messages should be descriptive. Please run the included tests to ensure
that nothing has broken, and, if applicable, we recommend writing tests for
any new features you add!

---

If you have any questions about anything, feel free to [ask][email]!

_Thanks to Anish Athalye for letting us borrow this contribution guide from [Gavel](https://github.com/anishathalye/gavel)._

[issue]: https://github.com/techx/cog/issues/new
[issues]: https://github.com/techx/cog/issues
[fork]: https://github.com/techx/cog/fork
[email]: mailto:[email protected]
[gavel]: https://github.com/anishathalye/gavel
Contributions are not welcome at this time. If you would like to contribute, please visit the [original cog repo](https://github.com/techx/cog).
33 changes: 12 additions & 21 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
# Development

## Setup
- Set up a Python2
[virtualenv](http://python-guide-pt-br.readthedocs.io/en/latest/dev/virtualenvs/)
to manage Python dependencies
- Source your virtualenv
- Run `pip install -r requirements.txt` to install all dependencies
- Install [PostgreSQL](https://www.postgresql.org/download/) to run a database locally
- If you're using Mac, install *Postgres.app* from
[here](https://www.postgresql.org/download/)
- Set three environment variables:
- `DATABASE_URL` points to the URL of a development database,
which has to be set up using Postgres on your system. A sample `DATABASE_URL`
could look like `postgres://username:password@localhost/cog`.
- `QUILL` is the URL to your Quill instance for auth.
- `SECRET` needs to be the same JWT secret used in your Quill instance.
- Run `python initialize.py`
- This initializes the database - run it if you make any changes to the models and
are fine with overwriting data.
- Install Docker
- Install Docker Compose
- Copy `sample.env` to `.env` and enter in the proper values
- `make migrate` to initialize and set up the db

## Build
- If you need to rebuild (in case you change the Dockerfile), run `make build`

## Running
- Run `make run`
- The site will be visible at `localhost:8000`
- Run `make start`
- The site will be visible at `localhost:80`
- `make logs` for a live stream of logs.

## Tests
- Run `make test` to run all tests
## Destroying
- Run `make stop` to destroy
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:2
FROM python:3.6.3

ARG APP_PATH=/hardware-checkout
ARG APP_PATH=/cog

WORKDIR $APP_PATH

Expand All @@ -9,6 +9,6 @@ RUN pip install -r requirements.txt

ADD . $APP_PATH

EXPOSE 8000
CMD ["gunicorn", "--bind", ":8000", "-k", "geventwebsocket.gunicorn.workers.GeventWebSocketWorker", "hardwarecheckout:app"]

EXPOSE $FLASK_RUN_PORT
CMD ["python", "runserver.py"]
# CMD ["flask", "run"]
2 changes: 2 additions & 0 deletions HEROKU.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Deploying on Heroku
After deploying on Heroku, you should go into the console and then run `python initialize.py` to properly set up the database. (WARNING: doing this will clear all existing data in the database)
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
test:
python -m pytest tests/
build:
docker-compose build

PORT = 8000
run:
gunicorn --bind 0.0.0.0:$(PORT) -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker hardwarecheckout:app
sass:
cd cog/static && sass --watch sass/app.scss:css/app.css
start:
docker-compose up -d
@echo "cog listening on port 8000, postgres on 5432"
@echo "run 'make logs' to watch logs"

stop:
docker-compose down

# watch the logs from cog
logs:
docker-compose logs -f -t cog

# run all the migrations
migrate:
docker-compose run cog python initialize.py
# db/containers still running
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: python runserver.py $PORT
web: python runserver.py
46 changes: 18 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Cog
**THIS IS A FORKED, IN-DEVELOPMENT VERSION OF COG**

If you're looking for a working copy of the original cog, please visit https://github.com/techx/cog.

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/techx/cog)
---

# Cog

Cog is a hardware checkout system for hackathons, originally written for use
at HackMIT and MakeMIT.
at HackMIT and MakeMIT, now forked by Hack the North.

![Cog](/media/cog.png?raw=true)

Expand All @@ -29,39 +33,20 @@ View, approve, and fulfill item requests in real-time as they come in. As
soon as an organizer approves a request, hackers can see that their item is
ready to be picked up.

### Quill-Integrated Login
Users login using credentials from an associated
[Quill](https://github.com/techx/quill) instance, forgoing the need to create
an additional account.

## Deployment & Configuration
The easiest way to deploy Cog is to smash this Deploy to Heroku button right
here:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/techx/cog)

If you're interested in deploying on other infrastructure, that should be
doable as well. Cog is written in Python 2, and all dependencies can easily
be installed using Pip via `requirements.txt`. Cog uses PostgreSQL as a
database. Deployments of Cog generally use Gunicorn as a web server
(alongside gevent or eventlet for handling websockets). The exception to this
is Cog's default Heroku configuration which uses the built in
[Flask-SocketIO](https://flask-socketio.readthedocs.io/en/latest/) web server
due to performance issues using Gunicorn on Heroku.
Cog is written in Python 3 (at least our fork partially is) and uses PostgreSQL as a
database. Hack the North's fork of Cog is configured with `docker-compose` for local development and deploys to Kubernetes through Skaffold.

A myriad of configuration options are available to be tweaked in
[`config.py`](hardwarecheckout/config.py). Alternatively, all values set in
[`config.py`](cog/config.py). Alternatively, all values set in
this file can be set as environment variables of the same name - environment
variable values will take precedence over the value specified in `config.py`.
Sensible defaults are in place for all of the event logistical settings, but
we recommend playing around with them a bit. At the bare minimum you
should change the `HACKATHON_NAME` and set your `QUILL` and `SECRET` env
variables to match the associated Quill instance.
should change the `HACKATHON_NAME` and set your `SECRET` env
variables.

We strongly recommend deploying Cog and experimenting with/testing your
desired configuration options **in advance** of your event to ensure it
behaves in a manner consistent with the logistical organization of your
event.

### Adding Hardware via Google Sheets
While you can add individual items one-by-one, we recommend creating a
Expand All @@ -80,14 +65,16 @@ Branding can easily be customized using Semantic UI
[themes](https://semantic-ui.com/usage/theming.html).

While Cog mostly uses default Semantic UI styling, a minimal amount of custom
CSS lives in `hardwarecheckout/static/sass/app.scss`. In order to rebuild the
CSS lives in `cog/static/sass/app.scss`. In order to rebuild the
CSS when the Sass is changed, install [Sass](https://sass-lang.com/) and run
`sass --watch sass:css` in the `/static` directory.

*If you end up using Cog for your event, please take a moment to add yourself to our
[users list](https://github.com/techx/cog/wiki/Cog-Users)!*

## Development
**Here be dragons**

Interested in hacking on Cog? Check out the [development guide](DEVELOPMENT.md)
for some steps to get you started.

Expand All @@ -97,6 +84,9 @@ contributions - have a look at our [contributing guide](CONTRIBUTING.md) for
information on how you can get involved.

## Acknowledgements

**Pre-fork acknowledgements**

Thanks to the following folks for their contributions to Cog pre-open
sourcing:
- [Ethan Weber](https://github.com/ethanweber) and [Albert
Expand Down
16 changes: 9 additions & 7 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
"description": "A hackathon hardware check-out system by HackMIT",
"repository": "https://github.com/techx/cog",
"env": {
"QUILL": {
"description": "URL of Quill instance (for auth integration)"
},
"SECRET": {
"description": "Random Secret for JWTs - must match Quill secret"
"description": "Random Secret for JWTs"
},
"DEBUG": {
"description": "Toggle Flask debug mode. Should always be False in production",
Expand Down Expand Up @@ -59,17 +56,22 @@
},
"LOTTERY_TEXT": {
"description": "The info text underneath the 'Lottery Required' section",
"value": "We have a limited quantity of these items. Please fill out a brief proposal describing your project idea, and we'll randomly accept as many requests as we can 30 minutes after hacking starts.",
"value": "We have a limited quantity of these items. Please fill out a brief proposal describing your project idea by 12:30. If you are randomly selected to hack on one of these items, we will call you to the desk by text.",
"required": false
},
"CHECKOUT_TEXT": {
"description": "The info text underneath the 'Checkout Required' section",
"value": "Click to request any of these items, and your request will be approved when we have one available. Keep in mind we will ask to hold on to a form of ID until the item is returned.",
"value": "Click to request any of these items. We will text you when your hardware is ready for pickup. Keep in mind we will ask to hold on to a form of ID until the item is returned.",
"required": false
},
"FREE_TEXT": {
"description": "The info text underneath the 'No Checkout Required' section",
"value": "Just come to the hardware desk and ask for any of these items!",
"value": "Pick these up from the tool shop at any time. Please don't take more than you need, and return the items at the end of the event!",
"required": false
},
"MLH_TEXT": {
"description": "The info text underneath the 'MLH Item' section",
"value": "If you would like to sign out any of these items, request them through the MLH portal, then wait in the MLH line.",
"required": false
}
},
Expand Down
48 changes: 35 additions & 13 deletions hardwarecheckout/__init__.py → cog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,40 @@
import pytz
import os
import random
import string

from flask import Flask
from flask_socketio import SocketIO
from urlparse import urlsplit
from flask import Flask, session, request, abort
# from flask_socketio import SocketIO
from urllib.parse import urlsplit
from flaskext.markdown import Markdown

from hardwarecheckout.utils import display_date, deltatimeformat
from hardwarecheckout.models.socket import Socket
from cog.utils import display_date, deltatimeformat
# from cog.models.socket import Socket
from flask_sslify import SSLify

app = Flask(__name__)

import hardwarecheckout.config as config
app.config['SQLALCHEMY_POOL_SIZE'] = 2

import cog.config as config


app.secret_key = config.SECRET

@app.before_request
def csrf_protect():
if request.method == "POST":
token = session['_csrf_token']
if not token or (token != request.form.get('_csrf_token') and token != request.headers.get('x-csrftoken')):
abort(403)

def generate_csrf_token():
if '_csrf_token' not in session:
# generate random CSRF token
session['_csrf_token'] = ''.join([random.choice(string.ascii_letters + string.digits) for n in range(32)])
return session['_csrf_token']

app.jinja_env.globals['csrf_token'] = generate_csrf_token

def get_conf_bool(variable):
val = os.environ.get(variable, getattr(config, variable))
Expand All @@ -39,8 +61,6 @@ def set_conf_int(app, variable):

set_conf_str(app, 'HACKATHON_NAME')
app.config['APP_NAME'] = app.config['HACKATHON_NAME'] + ' Hardware Checkout'
app.config['QUILL_URL'] = config.QUILL_URL
app.config['QUILL_URL_READABLE'] = urlsplit(app.config['QUILL_URL']).netloc

# Debug
app.config['TEMPLATES_AUTO_RELOAD'] = True
Expand All @@ -61,9 +81,10 @@ def set_conf_int(app, variable):
set_conf_str(app, 'LOTTERY_TEXT')
set_conf_str(app, 'CHECKOUT_TEXT')
set_conf_str(app, 'FREE_TEXT')
set_conf_str(app, 'MLH_TEXT')
set_conf_int(app, 'LOTTERY_CHAR_LIMIT')

from hardwarecheckout.models import db
from cog.models import db
db.app = app
db.init_app(app)

Expand All @@ -73,14 +94,15 @@ def set_conf_int(app, variable):
if get_conf_bool("FORCE_SSL"):
SSLify(app)

socketio = SocketIO()
socketio.init_app(app)
# socketio = SocketIO()
# socketio.init_app(app)

import hardwarecheckout.controllers # registers controllers
import cog.controllers # registers controllers
import cog.filters

# delete stale sockets from previous open sessions
try:
Socket.query.delete()
# Socket.query.delete()
db.session.commit()
except:
# exception if DB not yet initialized
Expand Down
Loading