Verified Commit 7bbef849 authored by erdnaxe's avatar erdnaxe 🎇

Move Extensions to admin

parent 8b0653d9
Pipeline #1111 passed with stage
in 3 minutes
......@@ -14,6 +14,7 @@ from django.contrib import admin
from reversion.admin import VersionAdmin
from .models import (
Extension,
DName,
MachineType,
Mx,
......@@ -26,6 +27,12 @@ from .models import (
)
@admin.register(Extension)
class ExtensionAdmin(VersionAdmin):
"""Admin view of a Extension object"""
list_display = ('name', 'need_infra', 'origin', 'soa', 'dnssec')
@admin.register(DName)
class DNameAdmin(VersionAdmin):
"""Admin view of a DName object"""
......
......@@ -205,40 +205,6 @@ class DelIpTypeForm(FormRevMixin, Form):
self.fields['iptypes'].queryset = IpType.objects.all()
class ExtensionForm(FormRevMixin, ModelForm):
"""Formulaire d'ajout et edition d'une extension"""
class Meta:
model = Extension
fields = '__all__'
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ExtensionForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['name'].label = _("Extension to add")
self.fields['origin'].label = _("A record origin")
self.fields['origin_v6'].label = _("AAAA record origin")
self.fields['soa'].label = _("SOA record to use")
self.fields['dnssec'].label = _("Sign with DNSSEC")
class DelExtensionForm(FormRevMixin, Form):
"""Suppression d'une ou plusieurs extensions"""
extensions = forms.ModelMultipleChoiceField(
queryset=Extension.objects.none(),
label=_("Current extensions"),
widget=forms.CheckboxSelectMultiple
)
def __init__(self, *args, **kwargs):
instances = kwargs.pop('instances', None)
super(DelExtensionForm, self).__init__(*args, **kwargs)
if instances:
self.fields['extensions'].queryset = instances
else:
self.fields['extensions'].queryset = Extension.objects.all()
class Ipv6ListForm(FormRevMixin, FieldPermissionFormMixin, ModelForm):
"""Gestion des ipv6 d'une machine"""
......
This diff is collapsed.
......@@ -706,34 +706,47 @@ class SOA(RevMixin, AclMixin, models.Model):
class Extension(RevMixin, AclMixin, models.Model):
""" Extension dns type example.org. Précise si tout le monde peut
l'utiliser, associé à un origin (ip d'origine)"""
"""Extension dns type .example.org
Précise si tout le monde peut l'utiliser,
associé à un origin (ip d'origine)
"""
name = models.CharField(
max_length=255,
unique=True,
help_text=_("Zone name, must begin with a dot (.example.org)")
verbose_name=_("extension to add"),
help_text=_("Zone name, must begin with a dot (.example.org)."),
)
need_infra = models.BooleanField(
default=False,
verbose_name=_("need infra role"),
help_text=_("When active, only users with the \"use_all_extension\" "
"permission will be able to use this extension."),
)
need_infra = models.BooleanField(default=False)
origin = models.ForeignKey(
'IpList',
on_delete=models.PROTECT,
blank=True,
null=True,
help_text=_("A record associated with the zone")
verbose_name=_("A record origin"),
help_text=_("A record associated with this zone."),
)
origin_v6 = models.GenericIPAddressField(
protocol='IPv6',
null=True,
blank=True,
help_text=_("AAAA record associated with the zone")
verbose_name=_("AAAA record origin"),
help_text=_("AAAA record associated with this zone."),
)
soa = models.ForeignKey(
'SOA',
on_delete=models.CASCADE
on_delete=models.CASCADE,
verbose_name=_("SOA record to use"),
)
dnssec = models.BooleanField(
default=False,
help_text=_("Should the zone be signed with DNSSEC")
verbose_name=_("DNSSEC"),
help_text=_("Should this zone be signed with DNSSEC."),
)
class Meta:
......@@ -780,7 +793,7 @@ class Extension(RevMixin, AclMixin, models.Model):
.prefetch_related('cname'))
def get_associated_dname_records(self):
return (DName.objects.filter(alias=self))
return DName.objects.filter(alias=self)
@staticmethod
def can_use_all(user_request, *_args, **_kwargs):
......
{% 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 design %}
{% load i18n %}
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Extension" %}</th>
<th>{% trans "'infra' right required" %}</th>
<th>{% trans "SOA record" %}</th>
<th>{% trans "A record origin" %}</th>
{% if ipv6_enabled %}
<th>{% trans "AAAA record origin" %}</th>
{% endif %}
<th>{% trans "DNSSEC" %}</th>
<th></th>
</tr>
</thead>
{% for extension in extension_list %}
<tr>
<td>{{ extension.name }}</td>
<td>{{ extension.need_infra|tick }}</td>
<td>{{ extension.soa }}</td>
<td>{{ extension.origin }}</td>
{% if ipv6_enabled %}
<td>{{ extension.origin_v6 }}</td>
{% endif %}
<td>{{ extension.dnssec|tick }}</td>
<td class="text-right">
{% can_edit extension %}
{% include 'buttons/edit.html' with href='machines:edit-extension' id=extension.id %}
{% acl_end %}
{% history_button extension %}
</td>
</tr>
{% endfor %}
</table>
</div>
{% extends 'machines/sidebar.html' %}
{% 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 bootstrap3 %}
{% load acl %}
{% load i18n %}
{% block title %}{% trans "Machines" %}{% endblock %}
{% block content %}
<h2>{% trans "List of extensions" %}</h2>
{% can_create Extension %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:add-extension' %}">
<i class="fa fa-plus"></i>
{% trans " Add an extension" %}</a>
{% acl_end %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'machines:del-extension' %}">
<i class="fa fa-trash"></i>{% trans " Delete one or several extensions" %}
</a>
{% include 'machines/aff_extension.html' with extension_list=extension_list %}
{% endblock %}
......@@ -33,12 +33,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% trans "Machines" %}
</a>
{% acl_end %}
{% can_view_all Extension %}
<a class="list-group-item list-group-item-info" href="{% url 'machines:index-extension' %}">
<i class="fa fa-list-ul"></i>
{% trans "Extensions and zones" %}
</a>
{% acl_end %}
{% can_view_all IpType %}
<a class="list-group-item list-group-item-info" href="{% url 'machines:index-iptype' %}">
<i class="fa fa-list-ul"></i>
......
......@@ -37,11 +37,6 @@ urlpatterns = [
name='edit-iptype'),
url(r'^del_iptype/$', views.del_iptype, name='del-iptype'),
url(r'^index_iptype/$', views.index_iptype, name='index-iptype'),
url(r'^add_extension/$', views.add_extension, name='add-extension'),
url(r'^edit_extension/(?P<extensionid>[0-9]+)$',
views.edit_extension,
name='edit-extension'),
url(r'^del_extension/$', views.del_extension, name='del-extension'),
url(r'^new_sshfp/(?P<machineid>[0-9]+)$',
views.new_sshfp,
name='new-sshfp'),
......@@ -54,7 +49,6 @@ urlpatterns = [
url(r'^index_sshfp/(?P<machineid>[0-9]+)$',
views.index_sshfp,
name='index-sshfp'),
url(r'^index_extension/$', views.index_extension, name='index-extension'),
url(r'^add_alias/(?P<interfaceid>[0-9]+)$',
views.add_alias,
name='add-alias'),
......
......@@ -48,8 +48,6 @@ from .forms import (
EditMachineForm,
EditInterfaceForm,
AddInterfaceForm,
ExtensionForm,
DelExtensionForm,
EditIpTypeForm,
IpTypeForm,
DelIpTypeForm,
......@@ -555,67 +553,6 @@ def del_iptype(request, instances):
)
@login_required
@can_create(Extension)
def add_extension(request):
""" View used to add an Extension object """
extension = ExtensionForm(request.POST or None)
if extension.is_valid():
extension.save()
messages.success(request, _("The extension was created."))
return redirect(reverse('machines:index-extension'))
return form(
{'extensionform': extension, 'action_name': _("Create an extension")},
'machines/machine.html',
request
)
@login_required
@can_edit(Extension)
def edit_extension(request, extension_instance, **_kwargs):
""" View used to edit an Extension object """
extension = ExtensionForm(
request.POST or None,
instance=extension_instance
)
if extension.is_valid():
if extension.changed_data:
extension.save()
messages.success(request, _("The extension was edited."))
return redirect(reverse('machines:index-extension'))
return form(
{'extensionform': extension, 'action_name': _("Edit")},
'machines/machine.html',
request
)
@login_required
@can_delete_set(Extension)
def del_extension(request, instances):
""" View used to delete an Extension object """
extension = DelExtensionForm(request.POST or None, instances=instances)
if extension.is_valid():
extension_dels = extension.cleaned_data['extensions']
for extension_del in extension_dels:
try:
extension_del.delete()
messages.success(request, _("The extension was deleted."))
except ProtectedError:
messages.error(
request,
(_("The extension %s is assigned to at least one machine"
" type, you can't delete it." % extension_del))
)
return redirect(reverse('machines:index-extension'))
return form(
{'extensionform': extension, 'action_name': _("Delete")},
'machines/machine.html',
request
)
@login_required
@can_create(Domain)
@can_edit(Interface)
......@@ -866,47 +803,6 @@ def index_iptype(request):
)
@login_required
@can_view_all(SOA, Mx, Ns, Txt, DName, Srv, Extension)
def index_extension(request):
""" View displaying the list of existing extensions, the list of
existing SOA records, the list of existing MX records , the list of
existing NS records, the list of existing TXT records and the list of
existing SRV records """
extension_list = (Extension.objects
.select_related('origin')
.select_related('soa')
.order_by('name'))
soa_list = SOA.objects.order_by('name')
mx_list = (Mx.objects
.order_by('zone')
.select_related('zone')
.select_related('name__extension'))
ns_list = (Ns.objects
.order_by('zone')
.select_related('zone')
.select_related('ns__extension'))
txt_list = Txt.objects.all().select_related('zone')
dname_list = DName.objects.all().select_related('zone')
srv_list = (Srv.objects
.all()
.select_related('extension')
.select_related('target__extension'))
return render(
request,
'machines/index_extension.html',
{
'extension_list': extension_list,
'soa_list': soa_list,
'mx_list': mx_list,
'ns_list': ns_list,
'txt_list': txt_list,
'dname_list': dname_list,
'srv_list': srv_list
}
)
@login_required
@can_edit(Interface)
def index_alias(request, interface, interfaceid):
......
......@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 2.5\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-04-12 18:51+0200\n"
"POT-Creation-Date: 2019-04-12 19:09+0200\n"
"PO-Revision-Date: 2018-03-31 16:09+0002\n"
"Last-Translator: Laouen Fernet <laouen.fernet@supelec.fr>\n"
"Language-Team: \n"
......@@ -91,7 +91,8 @@ msgstr ""
msgid ""
"To go back to the main site, click \"View site\" button in top right menu."
msgstr ""
"Pour retournez sur le site principal, cliquez sur « Voir le site » dans le menu en haut à droite."
"Pour retournez sur le site principal, cliquez sur « Voir le site » dans le "
"menu en haut à droite."
#: templates/admin/custom_index.html:29
msgid "My account"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment