From 002f4e70b2217b6e7bd2fb80109115db89746ff0 Mon Sep 17 00:00:00 2001
From: Victor Salles
@@ -146,7 +146,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| APM_SERVICE_ENVIRONMENT | ```string``` | ```''``` | Environment that APM is running on
| ENVIRONMENT | ```string``` | ```production``` | Specify the environment you are going to run, it is also used for sentry
| SUGGESTION_LANGUAGES | ```string``` | ```en|pt_br``` | Specify the the languages supported by environment for word and intent suggestions
-| N_WORDS_TO_GENERATE | ```int``` | ```4``` | Specify the number of suggestions that will be returned for word suggestions
+| N_WORDS_TO_GENERATE | ```int``` | ```4``` | Specify the number of suggestions that will be returned for word suggestions
| N_SENTENCES_TO_GENERATE | ```int``` | ```10``` | Specify the number of suggestions that will be returned for intent suggestions
| REDIS_TIMEOUT | ```int``` | ```3600``` | Specify a systemwide Redis keys life time
| SECRET_KEY_CHECK_LEGACY_USER | ```string``` | ```None``` | Enables and specifies the token to use for the legacy user endpoint.
@@ -184,6 +184,8 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| GUNICORN_WORKERS | ``` int ``` | ``` multiprocessing.cpu_count() * 2 + 1 ``` | Gunicorn number of workers.
| USE_ELASTICSEARCH | ```boolean``` | ```true``` | Change the logic in requirements_to_train to use either elasticsearch or postgres.
| REPOSITORY_BLOCK_USER_LOGS | ```list``` | ```[]``` | List of repository authorization(api bearer) that won't save logs
+| RUN_AS_DEVELOPMENT_MODE | ```boolean``` | ```false``` | Specifies how to run the server, in production or development mode.
+| TEST_REPOSITORY_ID | ```string``` | ```None``` | The repository from which the RepositoryTokenByUserViewSet will retrieve the logged user's access token.
## Roadmap
@@ -205,4 +207,3 @@ Contributions are what make the open source community such an amazing place to b
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
-
diff --git a/bothub/api/v2/repository/views.py b/bothub/api/v2/repository/views.py
index d988c7f1..386b8ad8 100644
--- a/bothub/api/v2/repository/views.py
+++ b/bothub/api/v2/repository/views.py
@@ -1068,6 +1068,34 @@ def destroy(self, request, *args, **kwargs):
return super().destroy(request, *args, **kwargs)
+class RepositoryTokenByUserViewSet(mixins.ListModelMixin, GenericViewSet):
+ def get_queryset(self):
+ user = self.request.user
+ if user.is_anonymous:
+ return RepositoryAuthorization.objects.none()
+ return RepositoryAuthorization.objects.filter(user=self.request.user)
+
+ def list(self, request, **kwargs):
+ """
+ Get repository access token based on logged user
+ """
+
+ repository_id = settings.TEST_REPOSITORY_ID
+ if not repository_id:
+ return Response(
+ {"TEST_REPOSITORY_ID": "Not set"}, status=status.HTTP_400_BAD_REQUEST
+ )
+ try:
+ repository = Repository.objects.get(pk=repository_id)
+ except Repository.DoesNotExist:
+ return Response(
+ {"Repository": "Does Not Exist"}, status=status.HTTP_404_NOT_FOUND
+ )
+
+ authorization = repository.get_user_authorization(request.user)
+ return Response({"access_token": str(authorization.uuid)})
+
+
class RepositoryExampleViewSet(
mixins.CreateModelMixin,
mixins.RetrieveModelMixin,
diff --git a/bothub/api/v2/routers.py b/bothub/api/v2/routers.py
index fbf67a88..73b8db9a 100644
--- a/bothub/api/v2/routers.py
+++ b/bothub/api/v2/routers.py
@@ -39,6 +39,7 @@
from .repository.views import RepositoriesViewSet
from .repository.views import RepositoryAuthorizationRequestsViewSet
from .repository.views import RepositoryAuthorizationViewSet
+from .repository.views import RepositoryTokenByUserViewSet
from .repository.views import RepositoryCategoriesView
from .repository.views import RepositoryExampleViewSet
from .repository.views import RepositoryMigrateViewSet
@@ -180,6 +181,11 @@ def get_lookup_regex(self, viewset, lookup_prefix=""):
router.register(
"repository/authorization-requests", RepositoryAuthorizationRequestsViewSet
)
+router.register(
+ "repository/authorization-by-user",
+ RepositoryTokenByUserViewSet,
+ basename="authorization-by-user",
+)
router.register("repository/example", RepositoryExampleViewSet)
router.register("repository/example-bulk", RepositoryExamplesBulkViewSet)
router.register("repository/intent", RepositoryIntentViewSet)
diff --git a/bothub/settings.py b/bothub/settings.py
index a4ee2ac6..615f542a 100644
--- a/bothub/settings.py
+++ b/bothub/settings.py
@@ -626,3 +626,5 @@
]
REPOSITORY_BLOCK_USER_LOGS = env.list("REPOSITORY_BLOCK_USER_LOGS", default=[])
+
+TEST_REPOSITORY_ID = env("TEST_REPOSITORY_ID", None)
diff --git a/docker-compose.yml b/docker-compose.yml
index 306cb714..56756893 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -72,6 +72,8 @@ services:
- ELASTICSEARCH_REPOSITORYNLPLOG_INDEX=${ELASTICSEARCH_REPOSITORYNLPLOG_INDEX:-ai_repositorynlplog}
- ELASTICSEARCH_REPOSITORYNLPLOG_INDEX=${ELASTICSEARCH_REPOSITORYQANLPLOG_INDEX:-ai_repositoryqanlplog}
- ELASTICSEARCH_SIGNAL_PROCESSOR=${ELASTICSEARCH_SIGNAL_PROCESSOR:-celery}
+ - RUN_AS_DEVELOPMENT_MODE=${RUN_AS_DEVELOPMENT_MODE:-false}
+ - TEST_REPOSITORY_ID=${TEST_REPOSITORY_ID}
celery:
build:
@@ -118,6 +120,7 @@ services:
- ELASTICSEARCH_REPOSITORYBASICEXAMPLE_INDEX=${ELASTICSEARCH_REPOSITORYBASICEXAMPLE_INDEX:-ai_repositorybasicexample}
- ELASTICSEARCH_SIGNAL_PROCESSOR=${ELASTICSEARCH_SIGNAL_PROCESSOR:-celery}
- USE_ELASTICSEARCH=${USE_ELASTICSEARCH:-true}
+ - TEST_REPOSITORY_ID=${TEST_REPOSITORY_ID}
bothub-engine-celery-redis:
image: redis
From 5b1ee930f7aa39fa2e45645c3a9ef565a9ba65f6 Mon Sep 17 00:00:00 2001
From: Victor Salles