mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Merge branch 'fix_create_club' into 'master'
Dissocie les variables all_can_create entre adherent et club See merge request federez/re2o!80
This commit is contained in:
commit
6dae1af936
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
|
default=10
|
||||||
)
|
)
|
||||||
gpg_fingerprint = models.BooleanField(default=True)
|
gpg_fingerprint = models.BooleanField(default=True)
|
||||||
all_can_create = models.BooleanField(
|
all_can_create_club = models.BooleanField(
|
||||||
default=False,
|
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(
|
self_adhesion = models.BooleanField(
|
||||||
default=False,
|
default=False,
|
||||||
|
|
|
@ -52,8 +52,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Creations d'users par tous</th>
|
<th>Creations d'adhérents par tous</th>
|
||||||
<td>{{ useroptions.all_can_create }}</td>
|
<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>
|
<th>Auto inscription</th>
|
||||||
<td>{{ useroptions.self_adhesion }}</td>
|
<td>{{ useroptions.self_adhesion }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -668,22 +668,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
||||||
"""
|
"""
|
||||||
return User.objects.get(pk=userid)
|
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):
|
def can_edit(self, user_request, *args, **kwargs):
|
||||||
"""Check if an user can edit an user object.
|
"""Check if an user can edit an user object.
|
||||||
|
|
||||||
|
@ -831,6 +815,22 @@ class Adherent(User):
|
||||||
"""
|
"""
|
||||||
return Adherent.objects.get(pk=adherentid)
|
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):
|
class Club(User):
|
||||||
PRETTY_NAME = "Clubs"
|
PRETTY_NAME = "Clubs"
|
||||||
|
@ -851,6 +851,22 @@ class Club(User):
|
||||||
related_name='club_members'
|
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):
|
def can_view_all(user_request, *args, **kwargs):
|
||||||
"""Check if an user can access to the list of every user objects
|
"""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
|
Créer un club/association
|
||||||
</a>
|
</a>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% can_create User %}
|
{% can_create Adherent %}
|
||||||
<a class="list-group-item list-group-item-success" href="{% url "users:new-user" %}">
|
<a class="list-group-item list-group-item-success" href="{% url "users:new-user" %}">
|
||||||
<i class="glyphicon glyphicon-plus"></i>
|
<i class="glyphicon glyphicon-plus"></i>
|
||||||
Créer un adhérent
|
Créer un adhérent
|
||||||
|
|
Loading…
Reference in a new issue