from flask import g from auth.auth_view import RegisteredAuthorizedView from connectors.schemas import create_connector_schema, create_connector_response, connector_response from constants.http_status import HTTP_201_CREATED from utils.test_helpers import sync from flask_apispec import marshal_with, use_kwargs, doc from connectors.services.connectors_service import ConnectorsService @doc(tags=['Connectors']) class ConnectorsView(RegisteredAuthorizedView): connectors_service = ConnectorsService() @doc(description='Create new connector and generate url for login into ads account') @use_kwargs(create_connector_schema) @marshal_with(create_connector_response, code=201, description='Connect cards URL and data for new connector') @marshal_with(None, code=401, description='User is not authenticated.') @marshal_with(None, code=403, description='User does not have access to the label.') @marshal_with(None, code=404, description='Label is not found.') @sync async def post(self, params, label_id): self.permissions.can_manage_ad_accounts(label_id) return await self.connectors_service.get_connect_card(g.user_id, label_id, params.platform), HTTP_201_CREATED @doc(description='List of connectors for the label') @marshal_with(connector_response(many=True), code=200, description='List of connectors') @marshal_with(None, code=401, description='User is not authenticated.') @marshal_with(None, code=403, description='User does not have access to the label.') @marshal_with(None, code=404, description='Label is not found.') def get(self, label_id): self.permissions.can_access_label(label_id) return self.connectors_service.get_label_connectors(label_id)