"""Logic for Checking Ownership of the Project. Set of logic methods that verifies ownership for specific set of data (for instance: project). """ from oto import response from ows_product_physical.constant import error from ows_product_physical.models import ows_project def check_project_ownership(project_id, account_type, account_id): """Check ownership of a project. Args: project_id: containing a unique identifier of a project id. account_type (str): account type (either “subaccount” or “vendor”). account_id (str): account id. Cannot be empty. Returns: response.Response: result of checking the ownership. """ project_ownership_response = ows_project.check_project_ownership( project_id, account_type, account_id) if project_ownership_response.status == 200: return response.Response(status=project_ownership_response.status) if project_ownership_response.status == 403: return response.create_error_response( status=403, code=error.FORBIDDEN_CODE, message='The project is not owned by this user.') return project_ownership_response def check_track_ownership(track_id, product_tracks_response): """Check ownership of a track. Args: track_id: containing a unique identifier of a track id. product_tracks_response (Response): a response of tracks that belongs to a product Returns: response.Response: result of checking the ownership. """ if product_tracks_response: tracks = product_tracks_response.message['items'] product_track_ids = [track['track_id'] for track in tracks] if track_id in product_track_ids: return response.Response(status=200) return response.create_error_response( code=error.OWNERSHIP_ERROR, message="The track doesn't belong to the product", status=400)