mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-28 09:53:47 +00:00
Dissocie les variables all_can_create entre adherent et club
This commit is contained in:
parent
489439fd63
commit
d74def2ed8
5 changed files with 75 additions and 22 deletions
29
preferences/migrations/0042_auto_20180222_1743.py
Normal file
29
preferences/migrations/0042_auto_20180222_1743.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
|
|
|
@ -52,9 +52,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
{% endif %}
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Creations d'users par tous</th>
|
||||
<td>{{ useroptions.all_can_create }}</td>
|
||||
<th>Auto inscription</th>
|
||||
<th>Creations d'adhérents par tous</th>
|
||||
<td>{{ useroptions.all_can_create_adherent }}</td>
|
||||
<th>Creations de clubs par tous</th>
|
||||
<td>{{ useroptions.all_can_create_club }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Auto inscription</th>
|
||||
<td>{{ useroptions.self_adhesion }}</td>
|
||||
</tr>
|
||||
{% if useroptions.user_solde %}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
Créer un club/association
|
||||
</a>
|
||||
{% acl_end %}
|
||||
{% can_create User %}
|
||||
{% can_create Adherent %}
|
||||
<a class="list-group-item list-group-item-success" href="{% url "users:new-user" %}">
|
||||
<i class="glyphicon glyphicon-plus"></i>
|
||||
Créer un adhérent
|
||||
|
|
Loading…
Reference in a new issue