Skip to content

Commit

Permalink
Fixed issue with editing bypass attribute + Added visualisation to fr…
Browse files Browse the repository at this point in the history
…ontend
  • Loading branch information
pixup1 committed Nov 24, 2024
1 parent 12fc7ab commit e381a70
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
6 changes: 5 additions & 1 deletion backend/langate/network/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ def edit_device(device: Device, mac=None, name=None, mark=None, bypass=None):
device.mark = mark
else:
mark = device.mark
if bypass is None:

if bypass is not None and bypass != device.bypass:
device.bypass = bypass
else:
bypass = device.bypass

try:
netcontrol.set_mark(device.mac, mark, bypass)
except requests.HTTPError as e:
Expand Down
3 changes: 2 additions & 1 deletion backend/langate/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def patch(self, request, *args, **kwargs):
)
if "bypass" in request.data:
user = UserSerializer(request.user, context={"request": request}).data
for d in user.devices:
user_devices = UserDevice.objects.filter(user=request.user)
for d in user_devices:
DeviceManager.edit_device(d, bypass=request.data["bypass"])
return self.partial_update(request, *args, **kwargs)

Expand Down
13 changes: 10 additions & 3 deletions frontend/src/views/Management/Devices.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const queryParams = window.location.search;
key: 'user',
ordering: false,
},
{
name: 'Accès aux sites bloqués',
key: 'bypass',
ordering: false,
},
]"
:pagination="true"
:search="true"
Expand All @@ -72,11 +77,13 @@ const queryParams = window.location.search;
],
},
function: async (device, fields) => {
return await deleteDevice((device as unknown as Device).id);
if (await deleteDevice((device as unknown as Device).id)) {
addNotification('L\'appareil a bien été supprimé', 'info');
}
},
},
{
hint: 'Modifier la mark',
hint: 'Modifier l\'appareil',
icon: 'pencil',
key: 'update',
modal: {
Expand All @@ -97,7 +104,7 @@ const queryParams = window.location.search;
function: async (device, fields) => {
const success = await editDevice((device as unknown as Device).id, fields as unknown as Device)
if (success) {
addNotification('L\'appareil a bien été modifiée', 'info');
addNotification('L\'appareil a bien été modifié', 'info');
}
return success;
},
Expand Down
20 changes: 14 additions & 6 deletions frontend/src/views/Management/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const { addNotification } = useNotificationStore();
key: 'team',
ordering: false,
},
{
name: 'Accès aux sites bloqués',
key: 'bypass',
ordering: false,
},
]"
:create="{
modal: {
Expand Down Expand Up @@ -125,7 +130,7 @@ const { addNotification } = useNotificationStore();
required: false,
},
{
name: 'Bypass',
name: 'Donner accès aux sites bloqués',
key: 'bypass',
type: 'checkbox',
required: false,
Expand Down Expand Up @@ -194,15 +199,17 @@ const { addNotification } = useNotificationStore();
type: 'text',
},
{
name: 'Bypass',
name: 'Donner accès aux sites bloqués',
key: 'bypass',
type: 'checkbox',
required: false,
},
],
},
function: async (device, fields) => {
return await edit_user((device as unknown as User).id, fields as unknown as User);
if (await edit_user((device as unknown as User).id, fields as unknown as User)) {
addNotification('L\'utilisateur a bien été mis à jour', 'info');
}
},
},
{
Expand All @@ -221,7 +228,7 @@ const { addNotification } = useNotificationStore();
},
function: async (device, fields) => {
if (await reset_password((device as unknown as User).id, fields.password)) {
return 'Le mot de passe a bien été changé';
addNotification('Le mot de passe a bien été changé', 'info');
}
},
},
Expand Down Expand Up @@ -263,8 +270,9 @@ const { addNotification } = useNotificationStore();
],
},
function: async (device, fields) => {
await delete_user((device as unknown as User).id);
return 'l\'utilisateur a été supprimé';
if (await delete_user((device as unknown as User).id)) {
addNotification('L\'utilisateur a bien été supprimé', 'info');
}
},
},
]"
Expand Down

0 comments on commit e381a70

Please sign in to comment.