Verified Commit 2bb6d53a authored by erdnaxe's avatar erdnaxe 🎇

Move Mx, Ns, Txt in admin

parent c989130f
Pipeline #1106 passed with stage
in 3 minutes
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 14:48+0200\n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"PO-Revision-Date: 2019-01-07 01:37+0100\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 14:48+0200\n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"PO-Revision-Date: 2018-03-31 16:09+0002\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language: fr_FR\n"
......
......@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 14:48+0200\n"
"POT-Creation-Date: 2019-04-12 15:08+0200\n"
"PO-Revision-Date: 2018-06-23 16:01+0200\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......
......@@ -17,8 +17,11 @@ from reversion.admin import VersionAdmin
from .models import (
MachineType,
Mx,
Nas,
Ns,
SOA,
Txt,
Vlan,
)
......@@ -29,6 +32,12 @@ class MachineTypeAdmin(VersionAdmin):
list_display = ('name', 'ip_type')
@admin.register(Mx)
class MxAdmin(VersionAdmin):
"""Admin view of a Mx object"""
list_display = ('zone', 'priority', 'name')
@admin.register(Nas)
class NasAdmin(VersionAdmin):
"""Admin view of a Nas object"""
......@@ -37,12 +46,24 @@ class NasAdmin(VersionAdmin):
list_filter = ('port_access_mode', 'autocapture_mac')
@admin.register(Ns)
class NsAdmin(VersionAdmin):
"""Admin view of a Ns object"""
list_display = ('zone', 'ns')
@admin.register(SOA)
class SOAAdmin(VersionAdmin):
"""Admin view of a SOA object"""
list_display = ('name', 'mail', 'refresh', 'retry', 'expire', 'ttl')
@admin.register(Txt)
class TxtAdmin(VersionAdmin):
"""Admin view of a Txt object"""
list_display = ('zone', 'field1', 'field2')
@admin.register(Vlan)
class VlanAdmin(VersionAdmin):
"""Admin view of a VLAN object"""
......
......@@ -257,101 +257,6 @@ class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
super(Ipv6ListForm, self).__init__(*args, prefix=prefix, **kwargs)
class MxForm(FormRevMixin, ModelForm):
"""Ajout et edition d'un MX"""
class Meta:
model = Mx
fields = ['zone', 'priority', 'name']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(MxForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['name'].queryset = Domain.objects.exclude(
interface_parent=None
).select_related('extension')
class DelMxForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs MX"""
mx = forms.ModelMultipleChoiceField(
queryset=Mx.objects.none(),
label=_("Current MX records"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelMxForm, self).__init__(*args, **kwargs)
if instances:
self.fields['mx'].queryset = instances
else:
self.fields['mx'].queryset = Mx.objects.all()
class NsForm(FormRevMixin, ModelForm):
"""Ajout d'un NS pour une zone
On exclue les CNAME dans les objets domain (interdit par la rfc)
donc on prend uniquemet """
class Meta:
model = Ns
fields = ['zone', 'ns']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(NsForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['ns'].queryset = Domain.objects.exclude(
interface_parent=None
).select_related('extension')
class DelNsForm(FormRevMixin, Form):
"""Suppresion d'un ou plusieurs NS"""
ns = forms.ModelMultipleChoiceField(
queryset=Ns.objects.none(),
label=_("Current NS records"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelNsForm, self).__init__(*args, **kwargs)
if instances:
self.fields['ns'].queryset = instances
else:
self.fields['ns'].queryset = Ns.objects.all()
class TxtForm(FormRevMixin, ModelForm):
"""Ajout d'un txt pour une zone"""
class Meta:
model = Txt
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(TxtForm, self).__init__(*args, prefix=prefix, **kwargs)
class DelTxtForm(FormRevMixin, Form):
"""Suppression d'un ou plusieurs TXT"""
txt = forms.ModelMultipleChoiceField(
queryset=Txt.objects.none(),
label=_("Current TXT records"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelTxtForm, self).__init__(*args, **kwargs)
if instances:
self.fields['txt'].queryset = instances
else:
self.fields['txt'].queryset = Txt.objects.all()
class DNameForm(FormRevMixin, ModelForm):
"""Add a DNAME entry for a zone"""
......
This diff is collapsed.
......@@ -803,9 +803,19 @@ class Mx(RevMixin, AclMixin, models.Model):
""" Entrées des MX. Enregistre la zone (extension) associée et la
priorité
Todo : pouvoir associer un MX à une interface """
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
priority = models.PositiveIntegerField()
name = models.ForeignKey('Domain', on_delete=models.PROTECT)
zone = models.ForeignKey(
'Extension',
on_delete=models.PROTECT,
verbose_name=_('zone'),
)
priority = models.PositiveIntegerField(
verbose_name=_('priority'),
)
name = models.ForeignKey(
'Domain',
on_delete=models.PROTECT,
verbose_name=_('record'),
)
class Meta:
verbose_name = _("MX record")
......@@ -826,8 +836,17 @@ class Mx(RevMixin, AclMixin, models.Model):
class Ns(RevMixin, AclMixin, models.Model):
"""Liste des enregistrements name servers par zone considéérée"""
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
ns = models.ForeignKey('Domain', on_delete=models.PROTECT)
zone = models.ForeignKey(
'Extension',
on_delete=models.PROTECT,
verbose_name=_('concerned zone'),
)
ns = models.ForeignKey(
'Domain',
on_delete=models.PROTECT,
verbose_name=_('name server'),
help_text=_('Authoritative interface for the zone.'),
)
class Meta:
verbose_name = _("NS record")
......@@ -844,9 +863,19 @@ class Ns(RevMixin, AclMixin, models.Model):
class Txt(RevMixin, AclMixin, models.Model):
""" Un enregistrement TXT associé à une extension"""
zone = models.ForeignKey('Extension', on_delete=models.PROTECT)
field1 = models.CharField(max_length=255)
field2 = models.TextField(max_length=2047)
zone = models.ForeignKey(
'Extension',
on_delete=models.PROTECT,
verbose_name=_('concerned zone'),
)
field1 = models.CharField(
max_length=255,
verbose_name=_('first part of record'),
)
field2 = models.TextField(
max_length=2047,
verbose_name=_('second part of record'),
)
class Meta:
verbose_name = _("TXT record")
......
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Concerned zone" %}</th>
<th>{% trans "Priority" %}</th>
<th>{% trans "Record" %}</th>
<th></th>
</tr>
</thead>
{% for mx in mx_list %}
<tr>
<td>{{ mx.zone }}</td>
<td>{{ mx.priority }}</td>
<td>{{ mx.name }}</td>
<td class="text-right">
{% can_edit mx %}
{% include 'buttons/edit.html' with href='machines:edit-mx' id=mx.id %}
{% acl_end %}
{% history_button mx %}
</td>
</tr>
{% endfor %}
</table>
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Concerned zone" %}</th>
<th>{% trans "Authoritarian interface for the concerned zone" %}</th>
<th></th>
</tr>
</thead>
{% for ns in ns_list %}
<tr>
<td>{{ ns.zone }}</td>
<td>{{ ns.ns }}</td>
<td class="text-right">
{% can_edit ns %}
{% include 'buttons/edit.html' with href='machines:edit-ns' id=ns.id %}
{% acl_end %}
{% history_button ns %}
</td>
</tr>
{% endfor %}
</table>
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Name" %}</th>
<th>{% trans "Mail" %}</th>
<th>{% trans "Refresh" %}</th>
<th>{% trans "Retry" %}</th>
<th>{% trans "Expire" %}</th>
<th>{% trans "TTL" %}</th>
<th></th>
</tr>
</thead>
{% for soa in soa_list %}
<tr>
<td>{{ soa.name }}</td>
<td>{{ soa.mail }}</td>
<td>{{ soa.refresh }}</td>
<td>{{ soa.retry }}</td>
<td>{{ soa.expire }}</td>
<td>{{ soa.ttl }}</td>
<td class="text-right">
{% can_edit soa %}
{% include 'buttons/edit.html' with href='machines:edit-soa' id=soa.id %}
{% acl_end %}
{% history_button soa %}
</td>
</tr>
{% endfor %}
</table>
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
{% load acl %}
{% load logs_extra %}
{% load i18n %}
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Concerned zone" %}</th>
<th>{% trans "Record" %}</th>
<th></th>
</tr>
</thead>
{% for txt in txt_list %}
<tr>
<td>{{ txt.zone }}</td>
<td>{{ txt.dns_entry }}</td>
<td class="text-right">
{% can_edit txt %}
{% include 'buttons/edit.html' with href='machines:edit-txt' id=txt.id %}
{% acl_end %}
{% history_button txt %}
</td>
</tr>
{% endfor %}
</table>
......@@ -41,39 +41,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</a>
{% include 'machines/aff_extension.html' with extension_list=extension_list %}
<h2>{% trans "List of MX records" %}</h2>
{% can_create Mx %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-mx' %}">
<i class="fa fa-plus"></i>{% trans " Add an MX record" %}
</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-mx' %}">
<i class="fa fa-trash"></i>{% trans " Delete one or several MX records" %}
</a>
{% include 'machines/aff_mx.html' with mx_list=mx_list %}
<h2>{% trans "List of NS records" %}</h2>
{% can_create Ns %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-ns' %}">
<i class="fa fa-plus"></i>{% trans " Add an NS record" %}
</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-ns' %}">
<i class="fa fa-trash"></i>{% trans " Delete one or several NS records" %}
</a>
{% include 'machines/aff_ns.html' with ns_list=ns_list %}
<h2>{% trans "List of TXT records" %}</h2>
{% can_create Txt %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-txt' %}">
<i class="fa fa-plus"></i>{% trans " Add a TXT record" %}
</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-txt' %}">
<i class="fa fa-trash"></i>{% trans " Delete one or several TXT records" %}
</a>
{% include 'machines/aff_txt.html' with txt_list=txt_list %}
<h2>{% trans "List of DNAME records" %}</h2>
{% can_create DName %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-dname' %}">
......
......@@ -42,18 +42,9 @@ urlpatterns = [
views.edit_extension,
name='edit-extension'),
url(r'^del_extension/$', views.del_extension, name='del-extension'),
url(r'^add_mx/$', views.add_mx, name='add-mx'),
url(r'^edit_mx/(?P<mxid>[0-9]+)$', views.edit_mx, name='edit-mx'),
url(r'^del_mx/$', views.del_mx, name='del-mx'),
url(r'^add_txt/$', views.add_txt, name='add-txt'),
url(r'^edit_txt/(?P<txtid>[0-9]+)$', views.edit_txt, name='edit-txt'),
url(r'^del_txt/$', views.del_txt, name='del-txt'),
url(r'^add_dname/$', views.add_dname, name='add-dname'),
url(r'^edit_dname/(?P<dnameid>[0-9]+)$', views.edit_dname, name='edit-dname'),
url(r'^del_dname/$', views.del_dname, name='del-dname'),
url(r'^add_ns/$', views.add_ns, name='add-ns'),
url(r'^edit_ns/(?P<nsid>[0-9]+)$', views.edit_ns, name='edit-ns'),
url(r'^del_ns/$', views.del_ns, name='del-ns'),
url(r'^add_srv/$', views.add_srv, name='add-srv'),
url(r'^edit_srv/(?P<srvid>[0-9]+)$', views.edit_srv, name='edit-srv'),
url(r'^del_srv/$', views.del_srv, name='del-srv'),
......
......@@ -56,14 +56,8 @@ from .forms import (
DomainForm,
AliasForm,
DelAliasForm,
NsForm,
DelNsForm,
TxtForm,
DelTxtForm,
DNameForm,
DelDNameForm,
MxForm,
DelMxForm,
RoleForm,
DelRoleForm,
ServiceForm,
......@@ -626,120 +620,6 @@ def del_extension(request, instances):
)
@login_required
@can_create(Mx)
def add_mx(request):
""" View used to add a MX object """
mx = MxForm(request.POST or None)
if mx.is_valid():
mx.save()
messages.success(request, _("The MX record was created."))
return redirect(reverse('machines:index-extension'))
return form(
{'mxform': mx, 'action_name': _("Create an MX record")},
'machines/machine.html',
request
)
@login_required
@can_edit(Mx)
def edit_mx(request, mx_instance, **_kwargs):
""" View used to edit a MX object """
mx = MxForm(request.POST or None, instance=mx_instance)
if mx.is_valid():
if mx.changed_data:
mx.save()
messages.success(request, _("The MX record was edited."))
return redirect(reverse('machines:index-extension'))
return form(
{'mxform': mx, 'action_name': _("Edit")},
'machines/machine.html',
request
)
@login_required
@can_delete_set(Mx)
def del_mx(request, instances):
""" View used to delete a MX object """
mx = DelMxForm(request.POST or None, instances=instances)
if mx.is_valid():
mx_dels = mx.cleaned_data['mx']
for mx_del in mx_dels:
try:
mx_del.delete()
messages.success(request, _("The MX record was deleted."))
except ProtectedError:
messages.error(
request,
(_("Error: the MX record %s can't be deleted.") % mx_del)
)
return redirect(reverse('machines:index-extension'))
return form(
{'mxform': mx, 'action_name': _("Delete")},
'machines/machine.html',
request
)
@login_required
@can_create(Ns)
def add_ns(request):
""" View used to add a NS object """
ns = NsForm(request.POST or None)
if ns.is_valid():
ns.save()
messages.success(request, _("The NS record was created."))
return redirect(reverse('machines:index-extension'))
return form(
{'nsform': ns, 'action_name': _("Create an NS record")},
'machines/machine.html',
request
)
@login_required
@can_edit(Ns)
def edit_ns(request, ns_instance, **_kwargs):
""" View used to edit a NS object """
ns = NsForm(request.POST or None, instance=ns_instance)
if ns.is_valid():
if ns.changed_data:
ns.save()
messages.success(request, _("The NS record was edited."))
return redirect(reverse('machines:index-extension'))
return form(
{'nsform': ns, 'action_name': _("Edit")},
'machines/machine.html',
request
)
@login_required
@can_delete_set(Ns)
def del_ns(request, instances):
""" View used to delete a NS object """
ns = DelNsForm(request.POST or None, instances=instances)
if ns.is_valid():
ns_dels = ns.cleaned_data['ns']
for ns_del in ns_dels:
try:
ns_del.delete()
messages.success(request, _("The NS record was deleted."))
except ProtectedError:
messages.error(
request,
(_("Error: the NS record %s can't be deleted.") % ns_del)
)
return redirect(reverse('machines:index-extension'))