"""ows-notifications connector.""" from flask import g from owsrequest import request from permissions import config from permissions.types import AdminIdentity, Tenant def send_user_permissions_updated( identity_id: str, tenant: Tenant, brand: str, admin: AdminIdentity ) -> bool: """Generate the context for a user permissions updated email. Args: identity_id (str): Identity ID of the user. tenant (Tenant): Target tenant. brand (str): Brand associated with the tenant. admin (AdminIdentity): Identity of the admin. Returns: bool: True if email sent successfully. """ payload = { 'identity_id': identity_id, 'tenant_type': tenant.tenant_type.value, 'tenant_uuid': tenant.tenant_uuid, 'brand': brand, } headers = { 'Content-Type': 'application/json', 'Orchard-Profile-Id': str(admin.settings_profile.profile_id), 'Orchard-Profile-Type': admin.settings_profile.profile_type, 'Orchard-Identity-Id': admin.id, } if config.ENVIRONMENT == config.DEV_ENVIRONMENT: headers['authorization'] = g.request_context.authorization res = request.post( service_name='ows-notifications', path='/private/permissions/updated', json=payload, headers=headers, ) if res.status_code != 204: # We don't want to raise an error here as this is not critical g.log.error( 'Can not send permissions updated notification.', resources=payload, ) return False return True