Skip to content

Commit 6c0c250

Browse files
authored
Merge pull request #216 from ComputerScienceHouse/local-dev
2 parents 9377a65 + 44a2a8e commit 6c0c250

File tree

9 files changed

+342
-226
lines changed

9 files changed

+342
-226
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ If it doesn't work for some reason, you may have to globally install gulp throug
4747
npm install -g gulp
4848
```
4949

50+
### Local Development
51+
* PostgreSQL
52+
You'll need a postgres instance to use as a development DB.
53+
You can use an existing database, like the instance used for the dev branch, use a database on another server, or spin up a container using docker or podman.
54+
To get setup using docker, run
55+
```bash
56+
docker run --name packet-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
57+
```
58+
After the container starts up, you should be able to connect with the connection string `postgresql://postgres:mysecretpassword@localhost:5432/postgres`, which is the default connection string in `config.env.py`.
59+
Once the container is up, run the following to set up the database tables.
60+
```bash
61+
flask db upgrade
62+
```
63+
5064
### Secrets and configuration
5165
Packet supports 2 primary configuration methods:
5266
1. Environment variables - See `config.env.py` for the expected names and default values.

config.env.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
See the readme for more information
44
"""
55
from distutils.util import strtobool
6-
from os import environ
6+
from os import environ, path, getcwd
77

88
# Flask config
99
DEBUG = False
@@ -25,12 +25,25 @@
2525
OIDC_CLIENT_SECRET = environ.get("PACKET_OIDC_CLIENT_SECRET", "PLEASE_REPLACE_ME")
2626

2727
# SQLAlchemy config
28-
SQLALCHEMY_DATABASE_URI = environ.get("PACKET_DATABASE_URI", None)
28+
SQLALCHEMY_DATABASE_URI = environ.get("PACKET_DATABASE_URI", "postgresql://postgres:mysecretpassword@localhost:5432/postgres")
2929
SQLALCHEMY_TRACK_MODIFICATIONS = False
3030

3131
# LDAP config
3232
LDAP_BIND_DN = environ.get("PACKET_LDAP_BIND_DN", None)
3333
LDAP_BIND_PASS = environ.get("PACKET_LDAP_BIND_PASS", None)
34+
LDAP_MOCK_MEMBERS = [
35+
{'uid':'evals', 'groups': ['eboard', 'eboard-evaluations', 'active']},
36+
{'uid':'imps-3da', 'groups': ['eboard', 'eboard-imps', '3da', 'active']},
37+
{
38+
'uid':'rtp-cm-webs-onfloor',
39+
'groups': ['active-rtp', 'rtp', 'constitutional_maintainers', 'webmaster', 'active', 'onfloor'],
40+
'room_number': 1024
41+
},
42+
{'uid':'misc-rtp', 'groups': ['rtp']},
43+
{'uid':'onfloor', 'groups': ['active', 'onfloor'], 'room_number': 1024},
44+
{'uid':'active-offfloor', 'groups': ['active']},
45+
{'uid':'alum', 'groups': ['member']},
46+
]
3447

3548
# Mail Config
3649
MAIL_PROD = strtobool(environ.get("PACKET_MAIL_PROD", "False"))

packet/__init__.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,41 @@
5050
app.config['OIDC_CLIENT_SECRET']))
5151

5252
# Initialize Onesignal Notification apps
53-
csh_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
54-
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
55-
app_id=app.config['ONESIGNAL_CSH_APP_ID'])
56-
57-
intro_onesignal_client = onesignal.Client(user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
58-
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
59-
app_id=app.config['ONESIGNAL_INTRO_APP_ID'])
53+
csh_onesignal_client = None
54+
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
55+
app.config['ONESIGNAL_CSH_APP_AUTH_KEY'] and \
56+
app.config['ONESIGNAL_CSH_APP_ID']:
57+
csh_onesignal_client = onesignal.Client(
58+
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
59+
app_auth_key=app.config['ONESIGNAL_CSH_APP_AUTH_KEY'],
60+
app_id=app.config['ONESIGNAL_CSH_APP_ID']
61+
)
62+
app.logger.info('CSH Onesignal configured and notifications enabled')
63+
64+
intro_onesignal_client = None
65+
if app.config['ONESIGNAL_USER_AUTH_KEY'] and \
66+
app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'] and \
67+
app.config['ONESIGNAL_INTRO_APP_ID']:
68+
intro_onesignal_client = onesignal.Client(
69+
user_auth_key=app.config['ONESIGNAL_USER_AUTH_KEY'],
70+
app_auth_key=app.config['ONESIGNAL_INTRO_APP_AUTH_KEY'],
71+
app_id=app.config['ONESIGNAL_INTRO_APP_ID']
72+
)
73+
app.logger.info('Intro Onesignal configured and notifications enabled')
6074

6175
# OIDC Auth
6276
auth = OIDCAuthentication({'app': APP_CONFIG}, app)
63-
64-
# LDAP
65-
_ldap = csh_ldap.CSHLDAP(app.config['LDAP_BIND_DN'], app.config['LDAP_BIND_PASS'])
77+
app.logger.info('OIDCAuth configured')
6678

6779
# Sentry
6880
sentry_sdk.init(
6981
dsn=app.config['SENTRY_DSN'],
7082
integrations=[FlaskIntegration(), SqlalchemyIntegration()]
7183
)
7284

73-
app.logger.info('OIDCAuth and LDAP configured')
7485

7586
# pylint: disable=wrong-import-position
87+
from .ldap import ldap
7688
from . import models
7789
from . import context_processors
7890
from . import commands

packet/context_processors.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
from functools import lru_cache
77
from datetime import datetime
88

9-
from packet.ldap import ldap_get_member
109
from packet.models import Freshman
11-
from packet import app
10+
from packet import app, ldap
1211

1312

1413
# pylint: disable=bare-except
1514
@lru_cache(maxsize=128)
1615
def get_csh_name(username):
1716
try:
18-
member = ldap_get_member(username)
17+
member = ldap.get_member(username)
1918
return member.cn + ' (' + member.uid + ')'
2019
except:
2120
return username

0 commit comments

Comments
 (0)