8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00

Fonction can_create sur un user

This commit is contained in:
Gabriel Detraz 2017-11-21 05:47:05 +01:00 committed by root
parent 5221927717
commit 47059c5f6b
6 changed files with 48 additions and 9 deletions

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-11-21 04:42
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('preferences', '0023_auto_20171015_2033'),
]
operations = [
migrations.AddField(
model_name='optionaluser',
name='all_can_create',
field=models.BooleanField(default=False, help_text="Tous les users peuvent en créer d'autres"),
),
]

View file

@ -42,6 +42,10 @@ class OptionalUser(models.Model):
default=0 default=0
) )
gpg_fingerprint = models.BooleanField(default=True) gpg_fingerprint = models.BooleanField(default=True)
all_can_create = models.BooleanField(
default=False,
help_text="Tous les users peuvent en créer d'autres",
)
def clean(self): def clean(self):
"""Creation du mode de paiement par solde""" """Creation du mode de paiement par solde"""

View file

@ -52,6 +52,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ useroptions.solde_negatif }}</td> <td>{{ useroptions.solde_negatif }}</td>
{% endif %} {% endif %}
</tr> </tr>
<tr>
<th>Creations d'users par tous</th>
<td>{{ useroptions.all_can_create }}</td>
</tr>
</table> </table>
<h4>Préférences machines</h4> <h4>Préférences machines</h4>
{% if is_bureau %} {% if is_bureau %}

View file

@ -758,16 +758,23 @@ class User(AbstractBaseUser):
num += 1 num += 1
return composed_pseudo(num) return composed_pseudo(num)
def can_create(user):
options, _created = OptionalUser.objects.get_or_create()
if options.all_can_create:
return True
else:
return user.has_perms(('cableur',))
def can_edit(self, user): def can_edit(self, user):
if self.is_class_club and user.is_class_adherent: if self.is_class_club and user.is_class_adherent:
return self == user or user.has_perms(('cableur',))or\ return self == user or user.has_perms(('cableur',)) or\
user.adherent in self.club.administrators.all() user.adherent in self.club.administrators.all()
else: else:
return self == user or user.has_perms(('cableur',)) return self == user or user.has_perms(('cableur',))
def can_view(self, user): def can_view(self, user):
if self.is_class_club and user.is_class_adherent: if self.is_class_club and user.is_class_adherent:
return self == user or user.has_perms(('cableur',))or\ return self == user or user.has_perms(('cableur',)) or\
user.adherent in self.club.administrators.all() or\ user.adherent in self.club.administrators.all() or\
user.adherent in self.club.members.all() user.adherent in self.club.members.all()
else: else:

View file

@ -26,21 +26,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block sidebar %} {% block sidebar %}
{% if is_cableur %} {% if is_cableur %}
<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
</a>
<a class="list-group-item list-group-item-success" href="{% url "users:new-club" %}"> <a class="list-group-item list-group-item-success" href="{% url "users:new-club" %}">
<i class="glyphicon glyphicon-plus"></i> <i class="glyphicon glyphicon-plus"></i>
Créer un club/association Créer un club/association
</a> </a>
{% endif %} {% endif %}
{% if is_cableur %} <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
</a>
<a class="list-group-item list-group-item-info" href="{% url "users:index-clubs" %}"> <a class="list-group-item list-group-item-info" href="{% url "users:index-clubs" %}">
<i class="glyphicon glyphicon-list"></i> <i class="glyphicon glyphicon-list"></i>
Clubs et assos Clubs et assos
</a> </a>
{% if is_cableur %}
<a class="list-group-item list-group-item-info" href="{% url "users:index" %}"> <a class="list-group-item list-group-item-info" href="{% url "users:index" %}">
<i class="glyphicon glyphicon-list"></i> <i class="glyphicon glyphicon-list"></i>
Adherents Adherents

View file

@ -111,10 +111,15 @@ def password_change_action(u_form, user, request, req=False):
@login_required @login_required
@permission_required('cableur')
def new_user(request): def new_user(request):
""" Vue de création d'un nouvel utilisateur, """ Vue de création d'un nouvel utilisateur,
envoie un mail pour le mot de passe""" envoie un mail pour le mot de passe"""
if not User.can_create(request.user):
messages.error(request, "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse(
'users:profil',
kwargs={'userid':str(request.user.id)}
))
user = AdherentForm(request.POST or None) user = AdherentForm(request.POST or None)
if user.is_valid(): if user.is_valid():
user = user.save(commit=False) user = user.save(commit=False)