Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/moore/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@
INSTAGRAM_REDIRECT_URL = config('INSTAGRAM_REDIRECT_URL', default='')

try:
UNICORE_URL = config('UNICORE_URL')
UNICORE_ADMIN = config('UNICORE_ADMIN')
except UndefinedValueError:
# This allows the tests to be runned without having to have UNICORE_URL and
Expand All @@ -256,11 +255,18 @@
# not filled in the variables in their .env. I.e. The variables are still
# required, except for when the tests are runned.
if not IS_RUNNING_TEST:
raise UndefinedValueError(
"You must add UNICORE_URL and UNICORE_ADMIN to you .env file"
)
print(UndefinedValueError(
"You are missing UNICORE_ADMIN in your .env file, which means "
+ "user data cannot be retrieved from Unicore. All users will "
+ "be assumed to be members of UTN (is_member returns True)."
))

UNICORE_ADMIN = config('UNICORE_ADMIN', default='')
UNICORE_ORG_ID = config('UNICORE_ORG_ID', default='')
UNICORE_URL = config(
'UNICORE_URL',
default='https://unicorecustomapi.mecenat.com/utn'
)

# Google API
GOOGLE_API_KEY = config('GOOGLE_API_KEY', default='')
Expand Down
7 changes: 7 additions & 0 deletions src/utils/unicore_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def request_get(self, path, params=None):
if params is not None:
params['orgId'] = settings.UNICORE_ORG_ID

if settings.UNICORE_ADMIN == '':
raise requests.exceptions.RequestException(
"Missing token to make requests to the Unicore API."
)

return requests.get(
settings.UNICORE_URL + "/" + path,
auth=HTTPBasicAuth('admin', settings.UNICORE_ADMIN),
Expand All @@ -51,6 +56,8 @@ def get_user_data(self, unicore_id):
}

def is_member(self, ssn):
if settings.UNICORE_ADMIN == '':
return True
r = self.request_get('is-member/' + ssn)
if r.status_code == 200:
return r.json()['Member']
Expand Down