8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 06:32:26 +00:00

Fix bugs et simplifie les migrations de switchs

This commit is contained in:
detraz 2018-09-19 23:24:03 +02:00 committed by Alexandre Iooss
parent 83222080c2
commit e62554263d
17 changed files with 212 additions and 271 deletions

View file

@ -1,25 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-08 18:18
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0091_auto_20180707_2040'),
]
operations = [
migrations.AddField(
model_name='vlan',
name='igmp',
field=models.BooleanField(default=False, help_text='Gestion multicast v4'),
),
migrations.AddField(
model_name='vlan',
name='mld',
field=models.BooleanField(default=False, help_text='Gestion multicast v6'),
),
]

View file

@ -1,16 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-10 00:26
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('machines', '0092_auto_20180708_2018'),
('machines', '0083_remove_duplicate_rights'),
]
operations = [
]

View file

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-11 16:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0093_merge_20180710_0226'),
]
operations = [
migrations.AddField(
model_name='role',
name='specific_role',
field=models.CharField(blank=True, choices=[('dhcp-server', 'dhcp-server'), ('switch-conf-server', 'switch-conf-server'), ('dns-recursif-server', 'dns-recursif-server'), ('ntp-server', 'ntp-server'), ('radius-server', 'radius-server'), ('ntp-server', 'ntp-server'), ('log-server', 'log-server'), ('ldap-master-server', 'ldap-master-server'), ('ldap-backup-server', 'ldap-backup-server'), ('smtp-server', 'smtp-server'), ('postgresql-server', 'postgresql-server'), ('mysql-server', 'mysql-server'), ('sql-client', 'sql-client'), ('gateway', 'gateway')], max_length=32, null=True),
),
]

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-07 18:40
# Generated by Django 1.10.7 on 2018-09-19 20:25
from __future__ import unicode_literals
from django.db import migrations, models
@ -8,7 +8,7 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('machines', '0090_auto_20180625_1706'),
('machines', '0094_auto_20180815_1918'),
]
operations = [
@ -27,4 +27,14 @@ class Migration(migrations.Migration):
name='dhcpv6_snooping',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='vlan',
name='igmp',
field=models.BooleanField(default=False, help_text='Gestion multicast v4'),
),
migrations.AddField(
model_name='vlan',
name='mld',
field=models.BooleanField(default=False, help_text='Gestion multicast v6'),
),
]

View file

@ -39,7 +39,8 @@ from .models import (
MailMessageOption,
HomeOption,
RadiusKey,
SwitchManagementCred
SwitchManagementCred,
Reminder
)
@ -96,6 +97,9 @@ class SwitchManagementCredAdmin(VersionAdmin):
"""Class managementcred for switch"""
pass
class ReminderAdmin(VersionAdmin):
"""Class reminder for switch"""
pass
admin.site.register(OptionalUser, OptionalUserAdmin)
admin.site.register(OptionalMachine, OptionalMachineAdmin)

View file

@ -38,11 +38,12 @@ from .models import (
MailMessageOption,
HomeOption,
Service,
MailContact
MailContact,
Reminder,
RadiusKey,
SwitchManagementCred
SwitchManagementCred,
)
from topologie.models import Switch
class EditOptionalUserForm(ModelForm):
@ -242,11 +243,21 @@ class DelServiceForm(Form):
else:
self.fields['services'].queryset = Service.objects.all()
class ReminderForm(FormRevMixin, ModelForm):
"""Edition, ajout de services sur la page d'accueil"""
class Meta:
model = Reminder
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ReminderForm, self).__init__(*args, prefix=prefix, **kwargs)
class RadiusKeyForm(FormRevMixin, ModelForm):
"""Edition, ajout de clef radius"""
members = forms.ModelMultipleChoiceField(
Switch.objects.all(),
queryset=Switch.objects.all(),
required=False
)

View file

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-09 21:50
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0044_auto_20180709_2237'),
]
operations = [
migrations.AddField(
model_name='optionaltopologie',
name='switchs_web_management_ssl',
field=models.BooleanField(default=False, help_text='Web management ssl. Assurez-vous que un certif est installé sur le switch !'),
),
]

View file

@ -1,16 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-10 13:33
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('preferences', '0045_remove_unused_payment_fields'),
('preferences', '0045_optionaltopologie_switchs_web_management_ssl'),
]
operations = [
]

View file

@ -1,40 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-10 22:15
from __future__ import unicode_literals
from django.db import migrations, models
import re2o.aes_field
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('preferences', '0046_merge_20180710_1533'),
]
operations = [
migrations.CreateModel(
name='RadiusKey',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('radius_key', re2o.aes_field.AESEncryptedField(help_text='Clef radius', max_length=255)),
('comment', models.CharField(blank=True, help_text='Commentaire de cette clef', max_length=255, null=True)),
('default_switch', models.BooleanField(default=True, help_text='Clef par défaut des switchs', unique=True)),
],
options={
'permissions': (('view_radiuskey', 'Peut voir un objet radiuskey'),),
},
bases=(re2o.mixins.AclMixin, models.Model),
),
migrations.AlterField(
model_name='optionaluser',
name='gpg_fingerprint',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='optionaluser',
name='is_tel_mandatory',
field=models.BooleanField(default=True),
),
]

View file

@ -1,30 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-10 23:57
from __future__ import unicode_literals
from django.db import migrations, models
import re2o.aes_field
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('preferences', '0047_auto_20180711_0015'),
]
operations = [
migrations.CreateModel(
name='SwitchManagementCred',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('management_id', models.CharField(help_text='Login du switch', max_length=63)),
('management_pass', re2o.aes_field.AESEncryptedField(help_text='Mot de passe', max_length=63)),
('default_switch', models.BooleanField(default=True, help_text='Creds par défaut des switchs', unique=True)),
],
options={
'permissions': (('view_switchmanagementcred', 'Peut voir un objet switchmanagementcred'),),
},
bases=(re2o.mixins.AclMixin, models.Model),
),
]

View file

@ -1,31 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-12 15:13
from __future__ import unicode_literals
from django.db import migrations, models
import re2o.aes_field
class Migration(migrations.Migration):
dependencies = [
('preferences', '0048_switchmanagementcred'),
]
operations = [
migrations.AddField(
model_name='optionaltopologie',
name='sftp_login',
field=models.CharField(blank=True, help_text='Login sftp des switchs', max_length=32, null=True),
),
migrations.AddField(
model_name='optionaltopologie',
name='sftp_pass',
field=re2o.aes_field.AESEncryptedField(blank=True, help_text='Mot de passe sftp', max_length=63, null=True),
),
migrations.AddField(
model_name='optionaltopologie',
name='switchs_provision',
field=models.CharField(choices=[('sftp', 'sftp'), ('tftp', 'tftp')], default='tftp', help_text='Mode de récupération des confs par les switchs', max_length=32),
),
]

View file

@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-09-19 20:25
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
import re2o.aes_field
import re2o.mixins
class Migration(migrations.Migration):
dependencies = [
('machines', '0095_auto_20180919_2225'),
('preferences', '0050_auto_20180818_1329'),
]
operations = [
migrations.CreateModel(
name='RadiusKey',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('radius_key', re2o.aes_field.AESEncryptedField(help_text='Clef radius', max_length=255)),
('comment', models.CharField(blank=True, help_text='Commentaire de cette clef', max_length=255, null=True)),
('default_switch', models.BooleanField(default=True, help_text='Clef par défaut des switchs', unique=True)),
],
options={
'permissions': (('view_radiuskey', 'Peut voir un objet radiuskey'),),
},
bases=(re2o.mixins.AclMixin, models.Model),
),
migrations.CreateModel(
name='Reminder',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('days', models.IntegerField(default=7, help_text="Délais entre le mail et la fin d'adhésion", unique=True)),
('message', models.CharField(blank=True, default='', help_text='Message affiché spécifiquement pour ce rappel', max_length=255, null=True)),
],
options={
'permissions': (('view_reminder', 'Peut voir un objet reminder'),),
},
bases=(re2o.mixins.AclMixin, models.Model),
),
migrations.CreateModel(
name='SwitchManagementCred',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('management_id', models.CharField(help_text='Login du switch', max_length=63)),
('management_pass', re2o.aes_field.AESEncryptedField(help_text='Mot de passe', max_length=63)),
('default_switch', models.BooleanField(default=True, help_text='Creds par défaut des switchs', unique=True)),
],
options={
'permissions': (('view_switchmanagementcred', 'Peut voir un objet switchmanagementcred'),),
},
bases=(re2o.mixins.AclMixin, models.Model),
),
migrations.AddField(
model_name='optionaltopologie',
name='sftp_login',
field=models.CharField(blank=True, help_text='Login sftp des switchs', max_length=32, null=True),
),
migrations.AddField(
model_name='optionaltopologie',
name='sftp_pass',
field=re2o.aes_field.AESEncryptedField(blank=True, help_text='Mot de passe sftp', max_length=63, null=True),
),
migrations.AddField(
model_name='optionaltopologie',
name='switchs_ip_type',
field=models.OneToOneField(blank=True, help_text="Plage d'ip de management des switchs", null=True, on_delete=django.db.models.deletion.PROTECT, to='machines.IpType'),
),
migrations.AddField(
model_name='optionaltopologie',
name='switchs_provision',
field=models.CharField(choices=[('sftp', 'sftp'), ('tftp', 'tftp')], default='tftp', help_text='Mode de récupération des confs par les switchs', max_length=32),
),
migrations.AddField(
model_name='optionaltopologie',
name='switchs_rest_management',
field=models.BooleanField(default=False, help_text='Rest management, activé si provision auto'),
),
migrations.AddField(
model_name='optionaltopologie',
name='switchs_web_management',
field=models.BooleanField(default=False, help_text='Web management, activé si provision automatique'),
),
migrations.AddField(
model_name='optionaltopologie',
name='switchs_web_management_ssl',
field=models.BooleanField(default=False, help_text='Web management ssl. Assurez-vous que un certif est installé sur le switch !'),
),
migrations.AlterField(
model_name='mailmessageoption',
name='welcome_mail_en',
field=models.TextField(default='', help_text='Mail de bienvenue en anglais'),
),
migrations.AlterField(
model_name='mailmessageoption',
name='welcome_mail_fr',
field=models.TextField(default='', help_text='Mail de bienvenue en français'),
),
]

View file

@ -41,7 +41,7 @@ from django.utils.translation import ugettext as _
from reversion import revisions as reversion
from re2o.views import form
from re2o.acl import can_create, can_edit, can_delete_set, can_view_all
from re2o.acl import can_create, can_edit, can_delete_set, can_view_all, can_delete
from .forms import MailContactForm, DelMailContactForm
from .forms import (
@ -95,9 +95,8 @@ def display_options(request):
'homeoptions': homeoptions,
'mailmessageoptions': mailmessageoptions,
'service_list': service_list,
'mailcontact_list': mailcontact_list
'reminder_list': reminder_list,
'mailcontact_list': mailcontact_list,
'reminder_list': reminder_list,
'radiuskey_list' : radiuskey_list,
'switchmanagementcred_list': switchmanagementcred_list,
}, 'preferences/display_preferences.html', request)
@ -210,6 +209,51 @@ def del_service(request, instances):
request
)
@login_required
@can_create(Reminder)
def add_reminder(request):
"""Ajout d'un service de la page d'accueil"""
reminder = ReminderForm(request.POST or None, request.FILES or None)
if service.is_valid():
with transaction.atomic(), reversion.create_revision():
reminder.save()
reversion.set_user(request.user)
reversion.set_comment("Creation")
messages.success(request, _("The service was added."))
return redirect(reverse('preferences:display-options'))
return form(
{'preferenceform': service, 'action_name': _("Add a service")},
'preferences/preferences.html',
request
)
@login_required
@can_edit(Reminder)
def edit_reminder(request, service_instance, **_kwargs):
"""Edition des services affichés sur la page d'accueil"""
reminder = ReminderForm(
request.POST or None,
request.FILES or None,
instance=reminder_instance
)
if reminder.is_valid():
with transaction.atomic(), reversion.create_revision():
reminder.save()
reversion.set_user(request.user)
reversion.set_comment(
"Field(s) edited: %s" % ', '.join(
field for field in reminder.changed_data
)
)
messages.success(request, _("The service was edited."))
return redirect(reverse('preferences:display-options'))
return form(
{'preferenceform': service, 'action_name': _("Edit")},
'preferences/preferences.html',
request
)
@login_required
@can_delete(Reminder)

View file

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-09-19 20:25
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('preferences', '0051_auto_20180919_2225'),
('topologie', '0062_auto_20180815_1918'),
]
operations = [
migrations.AddField(
model_name='modelswitch',
name='firmware',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='switch',
name='management_creds',
field=models.ForeignKey(blank=True, help_text='Identifiant de management de ce switch', null=True, on_delete=django.db.models.deletion.PROTECT, to='preferences.SwitchManagementCred'),
),
migrations.AddField(
model_name='switch',
name='radius_key',
field=models.ForeignKey(blank=True, help_text='Clef radius du switch', null=True, on_delete=django.db.models.deletion.PROTECT, to='preferences.RadiusKey'),
),
]

View file

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-08 19:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('topologie', '0067_auto_20180701_0016'),
]
operations = [
migrations.AddField(
model_name='modelswitch',
name='firmware',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View file

@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-10 22:20
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('preferences', '0047_auto_20180711_0015'),
('topologie', '0069_switch_automatic_provision'),
]
operations = [
migrations.AddField(
model_name='switch',
name='radius_key',
field=models.ForeignKey(blank=True, help_text='Clef radius du switch', null=True, on_delete=django.db.models.deletion.PROTECT, to='preferences.RadiusKey'),
),
]

View file

@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-07-10 23:57
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('preferences', '0048_switchmanagementcred'),
('topologie', '0070_switch_radius_key'),
]
operations = [
migrations.AddField(
model_name='switch',
name='management_creds',
field=models.ForeignKey(blank=True, help_text='Identifiant de management de ce switch', null=True, on_delete=django.db.models.deletion.PROTECT, to='preferences.SwitchManagementCred'),
),
]