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

Use the front page to delete the agent #271

Merged
merged 2 commits into from
Jul 23, 2021
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
2 changes: 1 addition & 1 deletion src/api-engine/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class Node(models.Model):
Agent,
help_text="Agent of node",
null=True,
related_name="agent",
related_name="node",
on_delete=models.CASCADE
)
# network = models.ForeignKey(
Expand Down
20 changes: 13 additions & 7 deletions src/api-engine/api/routes/agent/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ def update(self, request, pk=None):
serializer = AgentUpdateBody(data=request.data)
if serializer.is_valid(raise_exception=True):
name = serializer.validated_data.get("name")
urls = serializer.validated_data.get("urls")
organization = serializer.validated_data.get("organization")
#urls = serializer.validated_data.get("urls")
#organization = request.user.organization
try:
Agent.objects.get(name=name)
except ObjectDoesNotExist:
pass
Agent.objects.filter(id=pk).update(name=name, urls=urls, organization=organization)
Agent.objects.filter(id=pk).update(name=name)

return Response(status=status.HTTP_202_ACCEPTED)

Expand Down Expand Up @@ -281,16 +281,22 @@ def partial_update(self, request, pk=None):
)
def destroy(self, request, pk=None):
"""
Delete Agent

Delete agent

:param request: destory parameter
:param pk: primary key
:return: none
:rtype: rest_framework.status
"""
try:
agent = Agent.objects.get(id=pk)
if request.user.is_administrator:
agent = Agent.objects.get(id=pk)
else:
raise CustomError("User can't delete agent!")
except ObjectDoesNotExist:
raise ResourceNotFound
else:
if agent.organization is not None:
if agent.node.count():
raise ResourceInUse
agent.delete()

Expand Down
2 changes: 1 addition & 1 deletion src/dashboard/src/pages/Operator/Agent/Agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Agent extends PureComponent {
});
} else {
dispatch({
type: 'agent/releaseAgent',
type: 'agent/deleteAgent',
payload: agent.id,
callback: this.deleteCallback,
});
Expand Down