mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-22 15:03:45 +00:00
TODO : offrir des cours d'anglais au cr@ns.
This commit is contained in:
parent
ed91cdcfe5
commit
0b86dc1ec4
5 changed files with 118 additions and 108 deletions
|
@ -121,7 +121,7 @@ in their own Payment models.
|
|||
|
||||
To have a closer look on how the payments works, please go to the wiki.
|
||||
|
||||
## MR xxx: Add role models
|
||||
## MR 182: Add role models
|
||||
|
||||
Adds the Role model.
|
||||
You need to ensure that your database character set is utf-8.
|
||||
|
|
|
@ -37,6 +37,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.forms import ModelForm, Form
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _l
|
||||
|
||||
from re2o.field_permissions import FieldPermissionFormMixin
|
||||
from re2o.mixins import FormRevMixin
|
||||
|
@ -499,7 +500,7 @@ class DelNasForm(FormRevMixin, Form):
|
|||
|
||||
|
||||
class RoleForm(FormRevMixin, ModelForm):
|
||||
"""Ajout et edition d'un role"""
|
||||
"""Add and edit role."""
|
||||
class Meta:
|
||||
model = Role
|
||||
fields = '__all__'
|
||||
|
@ -514,10 +515,10 @@ class RoleForm(FormRevMixin, ModelForm):
|
|||
|
||||
|
||||
class DelRoleForm(FormRevMixin, Form):
|
||||
"""Suppression d'un ou plusieurs service"""
|
||||
"""Deletion of one or several roles."""
|
||||
role = forms.ModelMultipleChoiceField(
|
||||
queryset=Role.objects.none(),
|
||||
label="Roles actuels",
|
||||
label=_l("Current roles"),
|
||||
widget=forms.CheckboxSelectMultiple
|
||||
)
|
||||
|
||||
|
@ -527,9 +528,7 @@ class DelRoleForm(FormRevMixin, Form):
|
|||
if instances:
|
||||
self.fields['role'].queryset = instances
|
||||
else:
|
||||
self.fields['role'].queryset = role.objects.all()
|
||||
|
||||
|
||||
self.fields['role'].queryset = Role.objects.all()
|
||||
|
||||
|
||||
class ServiceForm(FormRevMixin, ModelForm):
|
||||
|
|
|
@ -42,6 +42,7 @@ from django.forms import ValidationError
|
|||
from django.utils.functional import cached_property
|
||||
from django.utils import timezone
|
||||
from django.core.validators import MaxValueValidator
|
||||
from django.utils.translation import ugettext_lazy as _l
|
||||
|
||||
from macaddress.fields import MACAddressField
|
||||
|
||||
|
@ -158,7 +159,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
user_request,
|
||||
*args,
|
||||
**kwargs
|
||||
)[0]):
|
||||
)[0]):
|
||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
@ -176,7 +177,7 @@ class Machine(RevMixin, FieldPermissionModelMixin, models.Model):
|
|||
user_request,
|
||||
*args,
|
||||
**kwargs
|
||||
)[0]):
|
||||
)[0]):
|
||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
@ -338,10 +339,10 @@ class IpType(RevMixin, AclMixin, models.Model):
|
|||
return
|
||||
else:
|
||||
for ipv6 in Ipv6List.objects.filter(
|
||||
interface__in=Interface.objects.filter(
|
||||
type__in=MachineType.objects.filter(ip_type=self)
|
||||
)
|
||||
):
|
||||
interface__in=Interface.objects.filter(
|
||||
type__in=MachineType.objects.filter(ip_type=self)
|
||||
)
|
||||
):
|
||||
ipv6.check_and_replace_prefix(prefix=self.prefix_v6)
|
||||
|
||||
def clean(self):
|
||||
|
@ -713,7 +714,7 @@ class Srv(RevMixin, AclMixin, models.Model):
|
|||
choices=(
|
||||
(TCP, 'TCP'),
|
||||
(UDP, 'UDP'),
|
||||
),
|
||||
),
|
||||
default=TCP,
|
||||
)
|
||||
extension = models.ForeignKey('Extension', on_delete=models.PROTECT)
|
||||
|
@ -1047,7 +1048,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
user_request,
|
||||
*args,
|
||||
**kwargs
|
||||
)[0]):
|
||||
)[0]):
|
||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
@ -1064,7 +1065,7 @@ class Interface(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
user_request,
|
||||
*args,
|
||||
**kwargs
|
||||
)[0]):
|
||||
)[0]):
|
||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
@ -1165,7 +1166,7 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
user_request,
|
||||
*args,
|
||||
**kwargs
|
||||
)[0]):
|
||||
)[0]):
|
||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
@ -1182,7 +1183,7 @@ class Ipv6List(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
user_request,
|
||||
*args,
|
||||
**kwargs
|
||||
)[0]):
|
||||
)[0]):
|
||||
return False, (u"Vous ne pouvez pas éditer une machine "
|
||||
"d'un autre user que vous sans droit")
|
||||
return True, None
|
||||
|
@ -1358,11 +1359,11 @@ class Domain(RevMixin, AclMixin, models.Model):
|
|||
return False, (u"Vous ne pouvez pas ajouter un alias à une "
|
||||
"machine d'un autre user que vous sans droit")
|
||||
if Domain.objects.filter(
|
||||
cname__in=Domain.objects.filter(
|
||||
interface_parent__in=(interface.machine.user
|
||||
.user_interfaces())
|
||||
)
|
||||
).count() >= max_lambdauser_aliases:
|
||||
cname__in=Domain.objects.filter(
|
||||
interface_parent__in=(interface.machine.user
|
||||
.user_interfaces())
|
||||
)
|
||||
).count() >= max_lambdauser_aliases:
|
||||
return False, (u"Vous avez atteint le maximum d'alias "
|
||||
"autorisés que vous pouvez créer vous même "
|
||||
"(%s) " % max_lambdauser_aliases)
|
||||
|
@ -1441,27 +1442,25 @@ class IpList(RevMixin, AclMixin, models.Model):
|
|||
return self.ipv4
|
||||
|
||||
|
||||
|
||||
class Role(RevMixin, AclMixin, models.Model):
|
||||
""" Definition d'un role (routeur principal, routeur de backkup)"""
|
||||
""" Sert à la génération automatique de la conf des serveurs"""
|
||||
PRETTY_NAME = "Roles des serveurs"
|
||||
"""Define the role of a machine.
|
||||
Allow automated generation of the server configuration.
|
||||
"""
|
||||
|
||||
ROLE = (
|
||||
('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'),
|
||||
('dhcp-server', _l('DHCP server')),
|
||||
('switch-conf-server', _l('Switches configuration server')),
|
||||
('dns-recursif-server', _l('Recursive DNS server')),
|
||||
('ntp-server', _l('NTP server')),
|
||||
('radius-server', _l('Radius server')),
|
||||
('log-server', _l('Log server')),
|
||||
('ldap-master-server', _l('LDAP master server')),
|
||||
('ldap-backup-server', _l('LDAP backup server')),
|
||||
('smtp-server', _l('SMTP server')),
|
||||
('postgresql-server', _l('postgreSQL server')),
|
||||
('mysql-server', _l('mySQL server')),
|
||||
('sql-client', _l('SQL client')),
|
||||
('gateway', _l('Gatewaw')),
|
||||
)
|
||||
|
||||
role_type = models.CharField(max_length=255, unique=True)
|
||||
|
@ -1475,21 +1474,28 @@ class Role(RevMixin, AclMixin, models.Model):
|
|||
|
||||
class Meta:
|
||||
permissions = (
|
||||
("view_role", "Peut voir un objet service"),
|
||||
("view_role", _l("Can view a role.")),
|
||||
)
|
||||
verbose_name = _l("Server role")
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls, machineid, *_args, **_kwargs):
|
||||
"""Get the Machine instance with machineid.
|
||||
:param userid: The id
|
||||
:return: The user
|
||||
def get_instance(cls, roleid, *_args, **_kwargs):
|
||||
"""Get the Role instance with roleid.
|
||||
|
||||
Args:
|
||||
roleid: The id
|
||||
|
||||
Returns:
|
||||
The role.
|
||||
"""
|
||||
return cls.objects.get(pk=machineid)
|
||||
return cls.objects.get(pk=roleid)
|
||||
|
||||
@classmethod
|
||||
def interface_for_roletype(cls, roletype):
|
||||
"""Return interfaces for a roletype"""
|
||||
return Interface.objects.filter(role=cls.objects.filter(specific_role=roletype))
|
||||
return Interface.objects.filter(
|
||||
role=cls.objects.filter(specific_role=roletype)
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Role, self).save(*args, **kwargs)
|
||||
|
@ -1497,6 +1503,7 @@ class Role(RevMixin, AclMixin, models.Model):
|
|||
def __str__(self):
|
||||
return str(self.role_type)
|
||||
|
||||
|
||||
class Service(RevMixin, AclMixin, models.Model):
|
||||
""" Definition d'un service (dhcp, dns, etc)"""
|
||||
PRETTY_NAME = "Services à générer (dhcp, dns, etc)"
|
||||
|
@ -1527,8 +1534,8 @@ class Service(RevMixin, AclMixin, models.Model):
|
|||
""" Django ne peut créer lui meme les relations manytomany avec table
|
||||
intermediaire explicite"""
|
||||
for serv in servers.exclude(
|
||||
pk__in=Interface.objects.filter(service=self)
|
||||
):
|
||||
pk__in=Interface.objects.filter(service=self)
|
||||
):
|
||||
link = Service_link(service=self, server=serv)
|
||||
link.save()
|
||||
Service_link.objects.filter(service=self).exclude(server__in=servers)\
|
||||
|
@ -1686,7 +1693,7 @@ class OuverturePort(RevMixin, AclMixin, models.Model):
|
|||
choices=(
|
||||
(TCP, 'TCP'),
|
||||
(UDP, 'UDP'),
|
||||
),
|
||||
),
|
||||
default=TCP,
|
||||
)
|
||||
io = models.CharField(
|
||||
|
@ -1694,7 +1701,7 @@ class OuverturePort(RevMixin, AclMixin, models.Model):
|
|||
choices=(
|
||||
(IN, 'IN'),
|
||||
(OUT, 'OUT'),
|
||||
),
|
||||
),
|
||||
default=OUT,
|
||||
)
|
||||
|
||||
|
|
|
@ -23,29 +23,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endcomment %}
|
||||
|
||||
{% load acl %}
|
||||
{% load i18n %}
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom du role</th>
|
||||
<th>Role spécifique</th>
|
||||
<th>Serveurs inclus</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for role in role_list %}
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{{ role.role_type }}</td>
|
||||
<td>{{ role.specific_role }}</td>
|
||||
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit role %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-role' id=role.id %}
|
||||
{% acl_end %}
|
||||
{% include 'buttons/history.html' with href='machines:history' name='role' id=role.id %}
|
||||
</td>
|
||||
<th>{% trans "Role name" %}</th>
|
||||
<th>{% trans "Specific role" %}</th>
|
||||
<th>{% trans "Servers" %}</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</thead>
|
||||
{% for role in role_list %}
|
||||
<tr>
|
||||
<td>{{ role.role_type }}</td>
|
||||
<td>{{ role.specific_role }}</td>
|
||||
<td>{% for serv in role.servers.all %}{{ serv }}, {% endfor %}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit role %}
|
||||
{% include 'buttons/edit.html' with href='machines:edit-role' id=role.id %}
|
||||
{% acl_end %}
|
||||
{% include 'buttons/history.html' with href='machines:history' name='role' id=role.id %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|||
from django.db.models import ProtectedError, F
|
||||
from django.forms import modelformset_factory
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
|
||||
|
@ -181,14 +182,14 @@ def generate_ipv4_engine(is_type_tt):
|
|||
"""
|
||||
return (
|
||||
'new Bloodhound( {{'
|
||||
'datumTokenizer: Bloodhound.tokenizers.obj.whitespace( "value" ),'
|
||||
'queryTokenizer: Bloodhound.tokenizers.whitespace,'
|
||||
'local: choices_ipv4[ $( "#{type_id}" ).val() ],'
|
||||
'identify: function( obj ) {{ return obj.key; }}'
|
||||
'datumTokenizer: Bloodhound.tokenizers.obj.whitespace( "value" ),'
|
||||
'queryTokenizer: Bloodhound.tokenizers.whitespace,'
|
||||
'local: choices_ipv4[ $( "#{type_id}" ).val() ],'
|
||||
'identify: function( obj ) {{ return obj.key; }}'
|
||||
'}} )'
|
||||
).format(
|
||||
type_id=f_type_id(is_type_tt)
|
||||
)
|
||||
).format(
|
||||
type_id=f_type_id(is_type_tt)
|
||||
)
|
||||
|
||||
|
||||
def generate_ipv4_match_func(is_type_tt):
|
||||
|
@ -196,17 +197,17 @@ def generate_ipv4_match_func(is_type_tt):
|
|||
"""
|
||||
return (
|
||||
'function(q, sync) {{'
|
||||
'if (q === "") {{'
|
||||
'var first = choices_ipv4[$("#{type_id}").val()].slice(0, 5);'
|
||||
'first = first.map( function (obj) {{ return obj.key; }} );'
|
||||
'sync(engine_ipv4.get(first));'
|
||||
'}} else {{'
|
||||
'engine_ipv4.search(q, sync);'
|
||||
'}}'
|
||||
'if (q === "") {{'
|
||||
'var first = choices_ipv4[$("#{type_id}").val()].slice(0, 5);'
|
||||
'first = first.map( function (obj) {{ return obj.key; }} );'
|
||||
'sync(engine_ipv4.get(first));'
|
||||
'}} else {{'
|
||||
'engine_ipv4.search(q, sync);'
|
||||
'}}'
|
||||
).format(
|
||||
type_id=f_type_id(is_type_tt)
|
||||
)
|
||||
'}}'
|
||||
).format(
|
||||
type_id=f_type_id(is_type_tt)
|
||||
)
|
||||
|
||||
|
||||
def generate_ipv4_mbf_param(form_obj, is_type_tt):
|
||||
|
@ -1168,10 +1169,10 @@ def edit_role(request, role_instance, **_kwargs):
|
|||
if role.is_valid():
|
||||
if role.changed_data:
|
||||
role.save()
|
||||
messages.success(request, "Role modifié")
|
||||
messages.success(request, _("Role updated"))
|
||||
return redirect(reverse('machines:index-role'))
|
||||
return form(
|
||||
{'roleform': role, 'action_name': 'Editer'},
|
||||
{'roleform': role, 'action_name': _('Edit')},
|
||||
'machines/machine.html',
|
||||
request
|
||||
)
|
||||
|
@ -1187,22 +1188,22 @@ def del_role(request, instances):
|
|||
for role_del in role_dels:
|
||||
try:
|
||||
role_del.delete()
|
||||
messages.success(request, "Le role a été supprimée")
|
||||
messages.success(request, _("The role has been deleted."))
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le role suivant %s ne peut être supprimé"
|
||||
% role_del)
|
||||
(_("Error: The following role cannot be deleted: %(role)")
|
||||
% {'role': role_del}
|
||||
)
|
||||
)
|
||||
return redirect(reverse('machines:index-role'))
|
||||
return form(
|
||||
{'roleform': role, 'action_name': 'Supprimer'},
|
||||
{'roleform': role, 'action_name': _('Delete')},
|
||||
'machines/machine.html',
|
||||
request
|
||||
)
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(Service)
|
||||
def add_service(request):
|
||||
|
@ -1548,9 +1549,9 @@ def index_ipv6(request, interface, interfaceid):
|
|||
def index_role(request):
|
||||
""" View used to display the list of existing roles """
|
||||
role_list = (Role.objects
|
||||
.prefetch_related(
|
||||
'servers__domain__extension'
|
||||
).all())
|
||||
.prefetch_related(
|
||||
'servers__domain__extension'
|
||||
).all())
|
||||
return render(
|
||||
request,
|
||||
'machines/index_role.html',
|
||||
|
@ -1647,12 +1648,12 @@ def add_portlist(request):
|
|||
""" View used to add a port policy """
|
||||
port_list = EditOuverturePortListForm(request.POST or None)
|
||||
port_formset = modelformset_factory(
|
||||
OuverturePort,
|
||||
fields=('begin', 'end', 'protocole', 'io'),
|
||||
extra=0,
|
||||
can_delete=True,
|
||||
min_num=1,
|
||||
validate_min=True,
|
||||
OuverturePort,
|
||||
fields=('begin', 'end', 'protocole', 'io'),
|
||||
extra=0,
|
||||
can_delete=True,
|
||||
min_num=1,
|
||||
validate_min=True,
|
||||
)(request.POST or None, queryset=OuverturePort.objects.none())
|
||||
if port_list.is_valid() and port_formset.is_valid():
|
||||
pl = port_list.save()
|
||||
|
@ -1699,11 +1700,12 @@ def configure_ports(request, interface_instance, **_kwargs):
|
|||
)
|
||||
|
||||
|
||||
## Framework Rest
|
||||
# Framework Rest
|
||||
|
||||
|
||||
class JSONResponse(HttpResponse):
|
||||
""" Class to build a JSON response. Used for API """
|
||||
|
||||
def __init__(self, data, **kwargs):
|
||||
content = JSONRenderer().render(data)
|
||||
kwargs['content_type'] = 'application/json'
|
||||
|
|
Loading…
Reference in a new issue