"""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 sales_goals.constants import error from sales_goals.models import ows_product from sales_goals.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. 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=error.FORBIDDEN_CODE, code=error.FORBIDDEN_CODE, message='The project is not owned by this user.') return project_ownership_response def check_product_ownership(product_id, account_type, account_id): """Check ownership of a project. Args: product_id: containing a unique identifier of a project id. account_type (str): account type (either “subaccount” or “vendor”). account_id (str): account id. Returns: response.Response: result of checking the ownership. """ if not account_type and not account_id: return response.Response(status=200) return ows_product.get_product_ownership_by_account( account_type=account_type, account_id=account_id, product_id=str(product_id))