8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +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
)
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):
"""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>
{% endif %}
</tr>
<tr>
<th>Creations d'users par tous</th>
<td>{{ useroptions.all_can_create }}</td>
</tr>
</table>
<h4>Préférences machines</h4>
{% if is_bureau %}

View file

@ -758,16 +758,23 @@ class User(AbstractBaseUser):
num += 1
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):
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()
else:
return self == user or user.has_perms(('cableur',))
def can_view(self, user):
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.members.all()
else:

View file

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

View file

@ -111,10 +111,15 @@ def password_change_action(u_form, user, request, req=False):
@login_required
@permission_required('cableur')
def new_user(request):
""" Vue de création d'un nouvel utilisateur,
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)
if user.is_valid():
user = user.save(commit=False)