Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/recent activity #761

Merged
merged 5 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bothub/api/v2/internal/connect_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
13 changes: 13 additions & 0 deletions bothub/api/v2/repository/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 25 additions & 1 deletion bothub/api/v2/repository/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions bothub/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)