Skip to content

Commit

Permalink
Spread mark on suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBloodMan49 committed Nov 27, 2024
1 parent b31849c commit a845605
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lib64
share
pyvenv.cfg
env
.venv/

langate/static/partners

Expand Down
19 changes: 17 additions & 2 deletions backend/langate/network/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ def get(self, request):

def patch(self, request):
"""
Create a new mark
Modify the list of marks
"""
if request.data is None or len(request.data) == 0:
return Response({"error": _("No data provided")}, status=status.HTTP_400_BAD_REQUEST)

if not validate_marks(request.data):
return Response({"error": _("Invalid mark")}, status=status.HTTP_400_BAD_REQUEST)

Expand All @@ -320,11 +323,23 @@ def patch(self, request):
"priority": mark["priority"]
})

# If some marks are removed, add the new marks first, spread the devices and then remove the old marks
old_marks = [m["value"] for m in SETTINGS["marks"]]
new_marks = [m["value"] for m in marks]
removed_marks = [m for m in old_marks if m not in new_marks]

SETTINGS["marks"] = marks

if removed_marks:
for mark in removed_marks:
devices = Device.objects.filter(mark=mark)
for device in devices:
new = get_mark(excluded_marks=[mark])
DeviceManager.edit_device(device, device.mac, device.name, new)

save_settings(SETTINGS)

return Response(SETTINGS["marks"], status=status.HTTP_201_CREATED)
return Response(SETTINGS["marks"], status=status.HTTP_200_OK)

class MarkMove(APIView):
"""
Expand Down

0 comments on commit a845605

Please sign in to comment.