mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2025-04-19 00:45:16 +00:00
Add peer group model
This commit is contained in:
parent
c79c587945
commit
797058b29b
19
user_manager/migrations/0004_useracl_peer_groups.py
Normal file
19
user_manager/migrations/0004_useracl_peer_groups.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.1.5 on 2025-01-20 12:45
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('user_manager', '0003_authenticationtoken'),
|
||||
('wireguard', '0023_peergroup'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='useracl',
|
||||
name='peer_groups',
|
||||
field=models.ManyToManyField(blank=True, to='wireguard.peergroup'),
|
||||
),
|
||||
]
|
@ -1,6 +1,7 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
import uuid
|
||||
from wireguard.models import PeerGroup
|
||||
|
||||
|
||||
class UserAcl(models.Model):
|
||||
@ -12,6 +13,7 @@ class UserAcl(models.Model):
|
||||
(40, 'Wireguard Manager'),
|
||||
(50, 'Administrator'),
|
||||
))
|
||||
peer_groups = models.ManyToManyField(PeerGroup, blank=True)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
|
24
wireguard/migrations/0023_peergroup.py
Normal file
24
wireguard/migrations/0023_peergroup.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by Django 5.1.5 on 2025-01-20 12:39
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('wireguard', '0022_alter_wireguardinstance_dns_primary'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='PeerGroup',
|
||||
fields=[
|
||||
('name', models.CharField(max_length=100, unique=True)),
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('updated', models.DateTimeField(auto_now=True)),
|
||||
('uuid', models.UUIDField(editable=False, primary_key=True, serialize=False)),
|
||||
('peer', models.ManyToManyField(blank=True, to='wireguard.peer')),
|
||||
('server_instance', models.ManyToManyField(blank=True, to='wireguard.wireguardinstance')),
|
||||
],
|
||||
),
|
||||
]
|
@ -1,3 +1,4 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
import uuid
|
||||
|
||||
@ -119,4 +120,21 @@ class PeerAllowedIP(models.Model):
|
||||
|
||||
def __str__(self):
|
||||
return str(self.allowed_ip) + '/' + str(self.netmask)
|
||||
|
||||
|
||||
|
||||
class PeerGroup(models.Model):
|
||||
name = models.CharField(max_length=100, unique=True)
|
||||
peer = models.ManyToManyField(Peer, blank=True)
|
||||
server_instance = models.ManyToManyField(WireGuardInstance, blank=True)
|
||||
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
updated = models.DateTimeField(auto_now=True)
|
||||
uuid = models.UUIDField(primary_key=True, editable=False)
|
||||
|
||||
def clean(self):
|
||||
if self.peer.exists() and self.server_instance.exists():
|
||||
raise ValidationError("Please choose either WireGuard Instances or Peers, not both.")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.clean()
|
||||
super().save(*args, **kwargs)
|
||||
|
Loading…
x
Reference in New Issue
Block a user