"""Request access utility functions.""" from flask import request from owsrequest.context import get_request_context_from_headers from sound_recordings.models import permissions def check_access(entity_ids=None, entity_type=None): """Check request access. Args: entity_ids list(Int): entity ids entity_type (str): entity type Returns: tuple: 0 (bool): has access 1 (tuple): Profile (profile_type, profile_id)) """ context_headers = get_request_context_from_headers(request.headers) if context_headers.context_type == 'account': return (True, None) elif context_headers.context_type == 'profile': profile_type = context_headers.profile_type profile_id = context_headers.profile_id if profile_id and profile_type: profile = (profile_type, profile_id) has_profile_access = permissions.has_profile_access( profile, entity_ids, entity_type ) return (has_profile_access, profile) return (False, None) else: return (False, None)