diff --git a/dandiapi/api/models/user.py b/dandiapi/api/models/user.py index db20eec9a..7a206814f 100644 --- a/dandiapi/api/models/user.py +++ b/dandiapi/api/models/user.py @@ -27,7 +27,7 @@ def should_register_webknossos_account(self, api_url=None) -> bool: not self.webknossos_credential and api_url) - def register_webknossos_account(self, webknossos_api_url: str) -> None: + def register_webknossos_account(self, webknossos_api_url: str, webknossos_credential: str) -> None: webknossos_organization_name = os.getenv('WEBKNOSSOS_ORGANIZATION_NAME', None) webknossos_organization_display_name = os.getenv('WEBKNOSSOS_ORGANIZATION_DISPLAY_NAME', @@ -38,16 +38,16 @@ def register_webknossos_account(self, webknossos_api_url: str) -> None: register_external_api_request_task.delay( method='POST', - external_endpoint=f'{webknossos_api_url}/api/auth/register', + external_endpoint='https://webknossos.lincbrain.org/api/auth/register', payload={ "firstName": self.user.first_name, "lastName": self.user.last_name, "email": self.user.email, - "organization": webknossos_organization_name, - "organizationDisplayName": webknossos_organization_display_name, + "organization": "LINC", + "organizationName": "LINC", "password": { - "password1": self.webknossos_credential, - "password2": self.webknossos_credential + "password1": webknossos_credential, + "password2": webknossos_credential } } ) @@ -66,7 +66,7 @@ def save(self, *args, **kwargs): random_password = get_random_string(length=12) self.webknossos_credential = random_password - self.register_webknossos_account(webknossos_api_url=webknossos_api_url) + self.register_webknossos_account(webknossos_api_url=webknossos_api_url, webknossos_credential=random_password) # Slightly recursive call, but will halt with WebKNOSSOS logic super().save(*args, **kwargs) diff --git a/dandiapi/api/tasks/__init__.py b/dandiapi/api/tasks/__init__.py index d8b374261..2bcdc7aa0 100644 --- a/dandiapi/api/tasks/__init__.py +++ b/dandiapi/api/tasks/__init__.py @@ -81,39 +81,32 @@ def publish_dandiset_task(dandiset_id: int): @shared_task def register_external_api_request_task(method: str, external_endpoint: str, payload: dict = None, - query_params: dict = None): - """ - Register a celery task that performs an API request to an external service. - - :param method: HTTP method to use for the request ('GET' or 'POST') - :param external_endpoint: URL of the external API endpoint - :param payload: Dictionary payload to send in the POST request (for 'POST' method) - :param query_params: Dictionary of query parameters to send in the GET request - (for 'GET' method) - """ + query_params: dict = None): headers = { 'Content-Type': 'application/json', } try: if method.upper() == 'POST': - requests.post(external_endpoint, json=payload, headers=headers, timeout=10) + response = requests.post(external_endpoint, json=payload, headers=headers, timeout=10) + response.raise_for_status() + logger.info(f"POST to {external_endpoint} successful with payload: {payload}") + logger.info(f"Response: {response.status_code}, {response.text}") elif method.upper() == 'GET': response = requests.get(external_endpoint, params=query_params, headers=headers, timeout=10) - try: - return {'status_code': response.status_code, 'headers': response.headers} - except Exception: - logger.warning("Issue with GET response to %s", external_endpoint) + logger.info(f"GET to {external_endpoint} successful") + logger.info(f"Response: {response.status_code}, {response.headers}") + return {'status_code': response.status_code, 'headers': response.headers} else: logger.error("Unsupported HTTP method: %s", method) return - - except requests.exceptions.HTTPError: - logger.exception("HTTP error occurred") - except requests.exceptions.RequestException: - logger.exception("Request exception occurred") - except Exception: - logger.exception("An unexpected error occurred") + except requests.exceptions.HTTPError as http_err: + logger.error(f"HTTP error occurred: {http_err}") + logger.error(f"Response content: {response.text}") # Log response in case of error + except requests.exceptions.RequestException as req_err: + logger.error(f"Request exception occurred: {req_err}") + except Exception as err: + logger.error(f"An unexpected error occurred: {err}") @shared_task(soft_time_limit=1200) def unembargo_dandiset_task(dandiset_id: int): diff --git a/web/src/components/AppBar/AppBar.vue b/web/src/components/AppBar/AppBar.vue index f03d0ca46..7fe6a7b2f 100644 --- a/web/src/components/AppBar/AppBar.vue +++ b/web/src/components/AppBar/AppBar.vue @@ -94,17 +94,19 @@