From 7205602bf4028d057fc7915d09b81651faae03be Mon Sep 17 00:00:00 2001 From: ludvigalden Date: Tue, 23 Jan 2024 12:27:02 +0100 Subject: [PATCH] remove unicore env requirements --- src/moore/settings/base.py | 14 ++++++++++---- src/utils/unicore_client.py | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) 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..25b25c58 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), @@ -89,6 +94,8 @@ def get_user_data(unicore_id): @staticmethod def is_member(ssn): + if settings.UNICORE_ADMIN == '': + return True UnicoreClient.__setup() return UnicoreClient.client.is_member(ssn)