"""Recipient related logic.""" from collaborator.constants import error from collaborator.models.rds.collaborator_persister import CollaboratorPersister from collaborator.models.rds.recipient_persister import RecipientPersister from collaborator.utils.error import OwsError from collaborator.utils.helpers import check_vendors_authorization def check_can_access_recipient_data(authorized_resources, recipient_ids): """Check if this profile can access recipient data. Args: authorized_resources (AuthorizedResources): list of authorized resources for this profile. recipient_id (list[int]): the ID of the recipient this request wants to access. """ collaborators = CollaboratorPersister.get_by_recipient_ids(recipient_ids) if not collaborators: raise OwsError.not_found( code=error.ERROR_CODE_COLLABORATOR_NOT_FOUND, message=error.ERROR_MESSAGE_COLLABORATOR_NOT_FOUND, ) vendor_ids = [collaborator.get("vendor_id", None) for collaborator in collaborators] check_vendors_authorization(authorized_resources, vendor_ids) def get_by_id(recipient_id: int) -> dict: """Get a single recipient based on its ID. Args: recipient_id (int): ID of the recipient. Returns: dict: a single recipient """ return RecipientPersister.get_recipient(recipient_id) def get_by_ids(recipient_ids: list) -> list: """Get recipients based on given IDs. Args: recipient_ids (list[int]): List of recipient IDs. Returns: list: a list of recipients """ return RecipientPersister.get_recipients_by_id(recipient_ids)