8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +00:00

Protection avancée sur les utilisateurs dotés de droits

This commit is contained in:
Gabriel Detraz 2018-01-07 23:55:27 +01:00 committed by root
parent 23732800b3
commit f52d869b5f
4 changed files with 55 additions and 2 deletions

View file

@ -450,7 +450,7 @@ class ListRightForm(ModelForm):
class Meta:
model = ListRight
fields = ['name', 'unix_name', 'permissions', 'details']
fields = ['name', 'unix_name', 'critical', 'permissions', 'details']
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)

View file

@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-01-07 21:45
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0067_serveurpermission'),
]
def transfer_permissions(apps, schema_editor):
critical_rights = ['adm', 'admin', 'bureau', 'infra', 'tresorier', 'serveur', 'bofh']
db_alias = schema_editor.connection.alias
rights = apps.get_model("users", "ListRight")
for right in critical_rights:
rg = rights.objects.using(db_alias).filter(unix_name=right).first()
rg.critical=True
rg.save()
def untransfer_permissions(apps, schema_editor):
return
operations = [
migrations.AlterModelOptions(
name='user',
options={'permissions': (('change_user_password', "Peut changer le mot de passe d'un user"), ('change_user_state', "Peut éditer l'etat d'un user"), ('change_user_force', 'Peut forcer un déménagement'), ('change_user_shell', "Peut éditer le shell d'un user"), ('change_user_groups', "Peut éditer les groupes d'un user ! Permission critique"), ('change_all_users', 'Peut éditer tous les users, y compris ceux dotés de droits. Superdroit'), ('view_user', 'Peut voir un objet user quelquonque'))},
),
migrations.AddField(
model_name='listright',
name='critical',
field=models.BooleanField(default=False),
),
migrations.RunPython(transfer_permissions, untransfer_permissions),
]

View file

@ -233,6 +233,7 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
("change_user_force", "Peut forcer un déménagement"),
("change_user_shell", "Peut éditer le shell d'un user"),
("change_user_groups", "Peut éditer les groupes d'un user ! Permission critique"),
("change_all_users", "Peut éditer tous les users, y compris ceux dotés de droits. Superdroit"),
("view_user", "Peut voir un objet user quelquonque"),
)
@ -712,7 +713,19 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
else:
return False, u"Vous n'avez pas le droit d'éditer ce club"
else:
if self == user_request or user_request.has_perm('users.change_user'):
options, _created = AssoOption.objects.get_or_create()
if self == user_request:
return True, None
elif user_request.has_perm('users.change_all_users'):
return True, None
elif user_request.has_perm('users.change_user'):
if self.groups.filter(listright__critical=True):
return False, u"Utilisateurs avec droits critiques, ne peut etre édité"
elif self == options.utilisateur_asso:
return False, u"Impossible d'éditer l'utilisateur asso sans droit change_all_users"
else:
return True, None
elif user_request.has_perm('users.change_all_users'):
return True, None
else:
return False, u"Vous ne pouvez éditer un autre utilisateur que vous même"
@ -1112,6 +1125,7 @@ class ListRight(Group):
)]
)
gid = models.PositiveIntegerField(unique=True, null=True)
critical = models.BooleanField(default=False)
details = models.CharField(
help_text="Description",
max_length=255,

View file

@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>Droit</th>
<th>Gid</th>
<th>Groupe/permission critique</th>
<th>Informations</th>
<th>Details</th>
<th></th>
@ -38,6 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{{ listright.name }}
</td>
<td>{{ listright.gid }}</td>
<td>{{ listright.critical }}</td>
<td>
<div class="dropdown">
<button class="btn btn-default" data-parent="#accordion_{{listright.gid}}" type="button" data-toggle="collapse" data-target="#collapseListRight_user_{{listright.gid}}" aria-expanded="true" aria-controls="collapseListRight_user_{{listright.gid}}">