diff --git a/src/moore/settings/base.py b/src/moore/settings/base.py index b460f1f8..47454e37 100644 --- a/src/moore/settings/base.py +++ b/src/moore/settings/base.py @@ -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 @@ -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='') diff --git a/src/utils/unicore_client.py b/src/utils/unicore_client.py index a52b5f69..0e50149a 100644 --- a/src/utils/unicore_client.py +++ b/src/utils/unicore_client.py @@ -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), @@ -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']