diff --git a/machines/models.py b/machines/models.py index 16d387a9..43906bab 100644 --- a/machines/models.py +++ b/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\ diff --git a/preferences/migrations/0043_optionalmachine_create_machine.py b/preferences/migrations/0043_optionalmachine_create_machine.py new file mode 100644 index 00000000..e01a5878 --- /dev/null +++ b/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"), + ), + ] diff --git a/preferences/models.py b/preferences/models.py index f9410cb5..a04fd351 100644 --- a/preferences/models.py +++ b/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): diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html index 6bfd1640..c4b0d76b 100644 --- a/preferences/templates/preferences/display_preferences.html +++ b/preferences/templates/preferences/display_preferences.html @@ -90,6 +90,10 @@ with this program; if not, write to the Free Software Foundation, Inc., Support de l'ipv6 {{ machineoptions.ipv6_mode }} + + Creation de machines + {{ machineoptions.create_machine }} +

Préférences topologie

diff --git a/users/templates/users/profil.html b/users/templates/users/profil.html index 8d72b983..53056e95 100644 --- a/users/templates/users/profil.html +++ b/users/templates/users/profil.html @@ -189,7 +189,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endif %}

Machines

+ {% can_create Machine users.id %}

Ajouter une machine

+ {% acl_end %} {% if machines_list %} {% include "machines/aff_machines.html" with machines_list=machines_list %} {% else %}