diff --git a/bothub/api/v2/internal/connect_rest_client.py b/bothub/api/v2/internal/connect_rest_client.py index df2409d0..cdb2d4db 100644 --- a/bothub/api/v2/internal/connect_rest_client.py +++ b/bothub/api/v2/internal/connect_rest_client.py @@ -79,3 +79,10 @@ def create_classifier(self, **kwargs): params={**kwargs, "classifier_type": "bothub"}, ) return request.json() + + def create_recent_activity(self, recent_activity_data): + requests.post( + url=f"{self.base_url}/v1/recent-activity", + headers=self.headers, + json=recent_activity_data + ) diff --git a/bothub/api/v2/repository/serializers.py b/bothub/api/v2/repository/serializers.py index 30b6b615..90d11ac2 100644 --- a/bothub/api/v2/repository/serializers.py +++ b/bothub/api/v2/repository/serializers.py @@ -1016,6 +1016,19 @@ def create(self, validated_data): is_default=True, created_by=self.context["request"].user ) + celery_app.send_task( + "send_recent_activity", + [ + { + "user": self.context["request"].user.email, + "entity": "AI", + "action": "CREATE", + "entity_name": repository.name, + "intelligence_id": repository.owner.organization.id + } + ] + ) + return repository def get_intents(self, obj): diff --git a/bothub/api/v2/repository/views.py b/bothub/api/v2/repository/views.py index bc9c2332..5c05b0aa 100644 --- a/bothub/api/v2/repository/views.py +++ b/bothub/api/v2/repository/views.py @@ -439,7 +439,18 @@ def add_repository_project(self, request, **kwargs): organization_authorization = ( organization.organization_authorizations.filter(uuid__in=task) ) - + task = celery_app.send_task( + "send_recent_activity", + [ + { + "user": request.user.email, + "entity": "AI", + "action": "INTEGRATE", + "entity_name": repository.name, + "project_uuid": project_uuid + } + ] + ) if organization_authorization.exists(): raise ValidationError(_("Repository already added")) @@ -525,6 +536,7 @@ def train(self, request, **kwargs): user_authorization = repository.get_user_authorization(request.user) serializer = TrainSerializer(data=request.data) # pragma: no cover serializer.is_valid(raise_exception=True) # pragma: no cover + user = request.user if not user_authorization.can_write: raise PermissionDenied() request = repository.request_nlp_train( @@ -534,6 +546,18 @@ def train(self, request, **kwargs): raise APIException( # pragma: no cover {"status_code": request.status_code}, code=request.status_code ) + celery_app.send_task( + "send_recent_activity", + [ + { + "user": user.email, + "entity": "AI", + "action": "TRAIN", + "entity_name": repository.name, + "intelligence_id": repository.owner.organization.id + } + ] + ) return Response(request.json()) # pragma: no cover @action( diff --git a/bothub/common/tasks.py b/bothub/common/tasks.py index 50135c54..0e60b9e0 100644 --- a/bothub/common/tasks.py +++ b/bothub/common/tasks.py @@ -677,3 +677,9 @@ def create_repository_project(**kwargs): grpc_client = ConnectClient() grpc_client.create_classifier(**kwargs) return kwargs + + +@app.task(name="send_recent_activity") +def send_recent_activity(recent_activity_data): + connect_client = ConnectClient() + connect_client.create_recent_activity(recent_activity_data=recent_activity_data)