diff --git a/bothub/api/v2/nlp/views.py b/bothub/api/v2/nlp/views.py index db6bdeaf5..4cb970210 100644 --- a/bothub/api/v2/nlp/views.py +++ b/bothub/api/v2/nlp/views.py @@ -203,7 +203,7 @@ class RepositoryAuthorizationParseViewSet(mixins.RetrieveModelMixin, GenericView queryset = RepositoryAuthorization.objects serializer_class = NLPSerializer permission_classes = [AllowAny] - authentication_classes = [NLPAuthentication] + authentication_classes = [] def retrieve(self, request, *args, **kwargs): check_auth(request) @@ -573,7 +573,7 @@ class RepositoryUpdateInterpretersViewSet( queryset = RepositoryVersionLanguage.objects serializer_class = NLPSerializer permission_classes = [AllowAny] - authentication_classes = [NLPAuthentication] + authentication_classes = [] def retrieve(self, request, *args, **kwargs): check_auth(request) diff --git a/bothub/authentication/authorization.py b/bothub/authentication/authorization.py index 187597e63..30fe70498 100644 --- a/bothub/authentication/authorization.py +++ b/bothub/authentication/authorization.py @@ -41,9 +41,6 @@ class NLPAuthentication(TokenAuthentication): model = RepositoryAuthorization def authenticate(self, request): - from bothub.api.v2.nlp.views import RepositoryAuthorizationParseViewSet - from bothub.api.v2.nlp.views import RepositoryUpdateInterpretersViewSet - auth = get_authorization_header(request).split() if not auth or auth[0].lower() != self.keyword.lower().encode(): @@ -64,20 +61,13 @@ def authenticate(self, request): ) raise exceptions.AuthenticationFailed(msg) - if isinstance( - request.parser_context.get("view"), RepositoryAuthorizationParseViewSet - ) or isinstance( - request.parser_context.get("view"), RepositoryUpdateInterpretersViewSet - ): - return self.authenticate_credentials(token, validation=False) - - return self.authenticate_credentials(token, validation=True) + return self.authenticate_credentials(token) - def authenticate_credentials(self, key, **kwargs): + def authenticate_credentials(self, key): model = self.get_model() try: authorization = model.objects.get(uuid=key) - if not authorization.can_translate and kwargs.get("validation"): + if not authorization.can_translate: raise exceptions.PermissionDenied() return (authorization.user, authorization) diff --git a/bothub/common/models.py b/bothub/common/models.py index 28a35c2a7..28759da4a 100644 --- a/bothub/common/models.py +++ b/bothub/common/models.py @@ -431,31 +431,16 @@ def validate_if_can_run_automatic_evaluate(self, language: str) -> None: def request_nlp_train(self, user_authorization, data): try: # pragma: no cover - if data.get("repository_version"): - r = requests.post( # pragma: no cover - "{}train/".format( - self.nlp_server - if self.nlp_server - else settings.BOTHUB_NLP_BASE_URL - ), - data={"repository_version": data.get("repository_version")}, - headers={ - "Authorization": "Bearer {}".format(user_authorization.uuid) - }, - ) - else: - r = requests.post( # pragma: no cover - "{}train/".format( - self.nlp_server - if self.nlp_server - else settings.BOTHUB_NLP_BASE_URL - ), - data={}, - headers={ - "Authorization": "Bearer {}".format(user_authorization.uuid) - }, - ) + url = f"{self.nlp_server if self.nlp_server else settings.BOTHUB_NLP_BASE_URL}train/" + data = { + "repository_version": data.get("repository_version") + } + headers = {"Authorization": f"Bearer {user_authorization.uuid}"} + + r = requests.post(url, data=json.dumps(data), headers=headers) + return r # pragma: no cover + except requests.exceptions.ConnectionError: # pragma: no cover raise APIException( # pragma: no cover {"status_code": status.HTTP_503_SERVICE_UNAVAILABLE}, diff --git a/bothub/urls.py b/bothub/urls.py index 5f28d2c1c..4b513f210 100644 --- a/bothub/urls.py +++ b/bothub/urls.py @@ -21,7 +21,7 @@ schema_view = get_schema_view( openapi.Info( title="API Documentation", - default_version="v2.1.15", + default_version="v2.1.18", description="Documentation", terms_of_service="https://bothub.it/terms", contact=openapi.Contact(email="bothub@ilhasoft.com.br"),