Skip to content

Commit

Permalink
Merge branch 'develop' into feature/update_python_version
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-salles committed Aug 15, 2022
2 parents 8846c98 + 21ba8e9 commit fadbc1f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ You can set environment variables in your OS, write on ```.env``` file or pass v
| 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
Expand Down
28 changes: 28 additions & 0 deletions bothub/api/v2/repository/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions bothub/api/v2/routers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions bothub/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,5 @@
]

REPOSITORY_BLOCK_USER_LOGS = env.list("REPOSITORY_BLOCK_USER_LOGS", default=[])

TEST_REPOSITORY_ID = env("TEST_REPOSITORY_ID", default=None)
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ services:
- 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:
Expand Down Expand Up @@ -119,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
Expand Down

0 comments on commit fadbc1f

Please sign in to comment.