diff --git a/legal-api/src/legal_api/services/bootstrap.py b/legal-api/src/legal_api/services/bootstrap.py index 21363eb4ef..7720cddb8d 100644 --- a/legal-api/src/legal_api/services/bootstrap.py +++ b/legal-api/src/legal_api/services/bootstrap.py @@ -344,8 +344,8 @@ def get_contacts(cls, config, org_id: str, user_token: Optional[str] = None): else: token = cls.get_bearer_token() - membership_response = requests.get( - url=f"{auth_url}/users/orgs/{org_id}/membership", + user_response = requests.get( + url=f"{auth_url}/users/@me", headers={**cls.CONTENT_TYPE_JSON, "Authorization": cls.BEARER + token}, timeout=cls.timeout @@ -358,37 +358,40 @@ def get_contacts(cls, config, org_id: str, user_token: Optional[str] = None): timeout=cls.timeout ) - if membership_response.status_code != HTTPStatus.OK or org_info_response.status_code != HTTPStatus.OK: + if user_response.status_code != HTTPStatus.OK or org_info_response.status_code != HTTPStatus.OK: return None try: - membership_data = membership_response.json() + user_data = user_response.json() org_info = org_info_response.json() - user_info = membership_data.get("user", {}) - first_name = user_info.get("firstname", "") - last_name = user_info.get("lastname", "") - - user_contacts = user_info.get("contacts", []) - user_contact = user_contacts[0] if user_contacts else {} - email = user_contact.get("email", "") - phone = user_contact.get("phone", "") - - org_contacts = org_info.get("contacts", []) - org_contact = org_contacts[0] if org_contacts else {} - + first_name = user_data.get("firstname", "") + last_name = user_data.get("lastname", "") + + user_contacts = user_data.get("contacts", []) + email = "" + if user_contacts and len(user_contacts) > 0 and user_contacts[0].get("email"): + # BCSC + email = user_contacts[0].get("email", "") + elif user_data.get("email"): + # IDIR + email = user_data.get("email", "") + + mailing_address = org_info.get("mailingAddress", {}) + if not mailing_address: + current_app.logger.warning(f"No mailing address found for org {org_id}") + mailing_address = {} contact = { - "street": org_contact.get("street", ""), - "city": org_contact.get("city", ""), - "region": org_contact.get("region", ""), - "country": org_contact.get("country", ""), - "postalCode": org_contact.get("postalCode", ""), + "street": mailing_address.get("street", ""), + "city": mailing_address.get("city", ""), + "region": mailing_address.get("region", ""), + "country": mailing_address.get("country", ""), + "postalCode": mailing_address.get("postalCode", ""), "firstName": first_name, "lastName": last_name, "email": email, - "phone": phone, - "streetAdditional": org_contact.get("streetAdditional", ""), - "delieveryInstructions": org_contact.get("deliveryInstructions", "") + "streetAdditional": mailing_address.get("streetAdditional", ""), + "deliveryInstructions": mailing_address.get("deliveryInstructions", "") } return {"contacts": [contact]} except Exception as e: diff --git a/legal-api/src/legal_api/services/filings/validations/common_validations.py b/legal-api/src/legal_api/services/filings/validations/common_validations.py index 0df22b2a0d..fbc576678f 100644 --- a/legal-api/src/legal_api/services/filings/validations/common_validations.py +++ b/legal-api/src/legal_api/services/filings/validations/common_validations.py @@ -1148,20 +1148,21 @@ def validate_permission_and_completing_party(business: Optional[Business], filin account_id = request.headers.get("account-id", request.headers.get("accountId", None)) if account_id and completing_party_exists and filing_json.get("filing", {}).get(filing_type, {}).get("parties"): - completing_party_result = validate_completing_party(filing_json, filing_type, account_id) - if completing_party_result.get("error"): - msg.extend(completing_party_result["error"]) + permission_error = check_completing_party_permission(msg, filing_type) - # Check if any relevant fields changed - should_check_permission = ( - (check_email and completing_party_result.get("email_changed")) or - (check_name and completing_party_result.get("name_changed")) or - (check_address and completing_party_result.get("address_changed")) - ) - if should_check_permission: - error = check_completing_party_permission(msg, filing_type) - if error: - return error + if permission_error: + completing_party_result = validate_completing_party(filing_json, filing_type, account_id) + if completing_party_result.get("error"): + msg.extend(completing_party_result["error"]) + + # Check if any relevant fields changed + should_check_permission = ( + (check_email and completing_party_result.get("email_changed")) or + (check_name and completing_party_result.get("name_changed")) or + (check_address and completing_party_result.get("address_changed")) + ) + if should_check_permission and permission_error: + return permission_error if check_document_email: return check_document_email_changes(filing_json, filing_type, account_id, msg)