Browse Source

Merge branch 'create_machine_users' into 'master'

Création d'un réglage permettant de modifier le droit de créer une machine

See merge request federez/re2o!82
squash_migration
chirac 8 years ago
parent
commit
d8005624f5
  1. 4
      machines/models.py
  2. 20
      preferences/migrations/0043_optionalmachine_create_machine.py
  3. 4
      preferences/models.py
  4. 4
      preferences/templates/preferences/display_preferences.html
  5. 2
      users/templates/users/profil.html

4
machines/models.py

@ -96,6 +96,8 @@ class Machine(FieldPermissionModelMixin, models.Model):
return False, u"Utilisateur inexistant"
max_lambdauser_interfaces = preferences.models.OptionalMachine.get_cached_value('max_lambdauser_interfaces')
if not user_request.has_perm('machines.add_machine'):
if not preferences.models.OptionalMachine.get_cached_value('create_machine'):
return False, u"Vous ne pouvez pas ajouter une machine"
if user != user_request:
return False, u"Vous ne pouvez pas ajouter une machine à un\
autre user que vous sans droit"
@ -1335,6 +1337,8 @@ class Interface(FieldPermissionModelMixin,models.Model):
except Machine.DoesNotExist:
return False, u"Machine inexistante"
if not user_request.has_perm('machines.add_interface'):
if not preferences.models.OptionalMachine.get_cached_value('create_machine'):
return False, u"Vous ne pouvez pas ajouter une machine"
max_lambdauser_interfaces = preferences.models.OptionalMachine.get_cached_value('max_lambdauser_interfaces')
if machine.user != user_request:
return False, u"Vous ne pouvez pas ajouter une interface à une\

20
preferences/migrations/0043_optionalmachine_create_machine.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-02-28 13:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0042_auto_20180222_1743'),
]
operations = [
migrations.AddField(
model_name='optionalmachine',
name='create_machine',
field=models.BooleanField(default=True, help_text="Permet à l'user de créer une machine"),
),
]

4
preferences/models.py

@ -185,6 +185,10 @@ class OptionalMachine(PreferencesModel):
choices=CHOICE_IPV6,
default='DISABLED'
)
create_machine = models.BooleanField(
default=True,
help_text="Permet à l'user de créer une machine"
)
@cached_property
def ipv6(self):

4
preferences/templates/preferences/display_preferences.html

@ -90,6 +90,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Support de l'ipv6</th>
<td>{{ machineoptions.ipv6_mode }}</td>
</tr>
<tr>
<th>Creation de machines</th>
<td>{{ machineoptions.create_machine }}</td>
</tr>
</table>
<h4>Préférences topologie</h4>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'preferences:edit-options' 'OptionalTopologie' %}">

2
users/templates/users/profil.html

@ -189,7 +189,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</table>
{% endif %}
<h2>Machines</h2>
{% can_create Machine users.id %}
<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' users.id %}"><i class="glyphicon glyphicon-phone"></i> Ajouter une machine</a></h4>
{% acl_end %}
{% if machines_list %}
{% include "machines/aff_machines.html" with machines_list=machines_list %}
{% else %}

Loading…
Cancel
Save