diff --git a/preferences/migrations/0042_auto_20180222_1743.py b/preferences/migrations/0042_auto_20180222_1743.py
new file mode 100644
index 00000000..b7ab7abe
--- /dev/null
+++ b/preferences/migrations/0042_auto_20180222_1743.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.7 on 2018-02-22 16:43
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('preferences', '0041_merge_20180130_0052'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='optionaluser',
+ name='all_can_create',
+ ),
+ migrations.AddField(
+ model_name='optionaluser',
+ name='all_can_create_adherent',
+ field=models.BooleanField(default=False, help_text="Les users peuvent créer d'autres adhérents"),
+ ),
+ migrations.AddField(
+ model_name='optionaluser',
+ name='all_can_create_club',
+ field=models.BooleanField(default=False, help_text='Les users peuvent créer un club'),
+ ),
+ ]
diff --git a/preferences/models.py b/preferences/models.py
index 9dc75fbc..f9410cb5 100644
--- a/preferences/models.py
+++ b/preferences/models.py
@@ -77,9 +77,13 @@ class OptionalUser(PreferencesModel):
default=10
)
gpg_fingerprint = models.BooleanField(default=True)
- all_can_create = models.BooleanField(
+ all_can_create_club = models.BooleanField(
default=False,
- help_text="Tous les users peuvent en créer d'autres",
+ help_text="Les users peuvent créer un club"
+ )
+ all_can_create_adherent = models.BooleanField(
+ default=False,
+ help_text="Les users peuvent créer d'autres adhérents",
)
self_adhesion = models.BooleanField(
default=False,
diff --git a/preferences/templates/preferences/display_preferences.html b/preferences/templates/preferences/display_preferences.html
index 222a7921..6bfd1640 100644
--- a/preferences/templates/preferences/display_preferences.html
+++ b/preferences/templates/preferences/display_preferences.html
@@ -52,9 +52,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endif %}
- Creations d'users par tous |
- {{ useroptions.all_can_create }} |
- Auto inscription |
+ Creations d'adhérents par tous |
+ {{ useroptions.all_can_create_adherent }} |
+ Creations de clubs par tous |
+ {{ useroptions.all_can_create_club }} |
+
+
+ Auto inscription |
{{ useroptions.self_adhesion }} |
{% if useroptions.user_solde %}
diff --git a/users/models.py b/users/models.py
index 5c145f54..c74a2145 100644
--- a/users/models.py
+++ b/users/models.py
@@ -668,22 +668,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
"""
return User.objects.get(pk=userid)
- def can_create(user_request, *args, **kwargs):
- """Check if an user can create an user object.
-
- :param user_request: The user who wants to create a user object.
- :return: a message and a boolean which is True if the user can create
- an user or if the `options.all_can_create` is set.
- """
- if(not user_request.is_authenticated and not OptionalUser.get_cached_value('self_adhesion')):
- return False, None
- else:
- if(OptionalUser.get_cached_value('all_can_create') or OptionalUser.get_cached_value('self_adhesion')):
- return True, None
- else:
- return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
- droit de créer un utilisateur"
-
def can_edit(self, user_request, *args, **kwargs):
"""Check if an user can edit an user object.
@@ -831,6 +815,22 @@ class Adherent(User):
"""
return Adherent.objects.get(pk=adherentid)
+ def can_create(user_request, *args, **kwargs):
+ """Check if an user can create an user object.
+
+ :param user_request: The user who wants to create a user object.
+ :return: a message and a boolean which is True if the user can create
+ an user or if the `options.all_can_create` is set.
+ """
+ if(not user_request.is_authenticated and not OptionalUser.get_cached_value('self_adhesion')):
+ return False, None
+ else:
+ if(OptionalUser.get_cached_value('all_can_create_adherent') or OptionalUser.get_cached_value('self_adhesion')):
+ return True, None
+ else:
+ return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
+ droit de créer un utilisateur"
+
class Club(User):
PRETTY_NAME = "Clubs"
@@ -851,6 +851,22 @@ class Club(User):
related_name='club_members'
)
+ def can_create(user_request, *args, **kwargs):
+ """Check if an user can create an user object.
+
+ :param user_request: The user who wants to create a user object.
+ :return: a message and a boolean which is True if the user can create
+ an user or if the `options.all_can_create` is set.
+ """
+ if not user_request.is_authenticated:
+ return False, None
+ else:
+ if OptionalUser.get_cached_value('all_can_create_club'):
+ return True, None
+ else:
+ return user_request.has_perm('users.add_user'), u"Vous n'avez pas le\
+ droit de créer un club"
+
def can_view_all(user_request, *args, **kwargs):
"""Check if an user can access to the list of every user objects
diff --git a/users/templates/users/sidebar.html b/users/templates/users/sidebar.html
index 71727243..fa2f2c76 100644
--- a/users/templates/users/sidebar.html
+++ b/users/templates/users/sidebar.html
@@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
Créer un club/association
{% acl_end %}
- {% can_create User %}
+ {% can_create Adherent %}
Créer un adhérent