diff --git a/install_utils/schema.ldiff b/install_utils/schema.ldiff index 662f8850..aa17263b 100644 --- a/install_utils/schema.ldiff +++ b/install_utils/schema.ldiff @@ -219,7 +219,7 @@ olcObjectClasses: {6}( 2.5.6.8 NAME 'organizationalRole' DESC 'RFC2256: an o street $ postOfficeBox $ postalCode $ postalAddress $ physicalDeliveryOffic eName $ ou $ st $ l $ description ) ) olcObjectClasses: {7}( 2.5.6.9 NAME 'groupOfNames' DESC 'RFC2256: a group of - names (DNs)' SUP top STRUCTURAL MUST ( member $ cn ) MAY ( businessCategor + names (DNs)' SUP top STRUCTURAL MUST ( cn ) MAY ( member $ businessCategor y $ seeAlso $ owner $ ou $ o $ description ) ) olcObjectClasses: {8}( 2.5.6.10 NAME 'residentialPerson' DESC 'RFC2256: an r esidential person' SUP person STRUCTURAL MUST l MAY ( businessCategory $ x1 diff --git a/users/admin.py b/users/admin.py index 78c53c41..1b3c7d5c 100644 --- a/users/admin.py +++ b/users/admin.py @@ -25,7 +25,7 @@ from django.contrib.auth.models import Group from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from reversion.admin import VersionAdmin -from .models import User, ServiceUser, School, Right, ListRight, ListShell, Ban, Whitelist, Request, LdapUser, LdapServiceUser, LdapUserGroup +from .models import User, ServiceUser, School, Right, ListRight, ListShell, Ban, Whitelist, Request, LdapUser, LdapServiceUser, LdapServiceUserGroup, LdapUserGroup from .forms import UserChangeForm, UserCreationForm, ServiceUserChangeForm, ServiceUserCreationForm @@ -57,6 +57,10 @@ class LdapUserGroupAdmin(admin.ModelAdmin): list_display = ('name','members','gid') search_fields = ('name',) +class LdapServiceUserGroupAdmin(admin.ModelAdmin): + list_display = ('name',) + search_fields = ('name',) + class SchoolAdmin(VersionAdmin): list_display = ('name',) @@ -116,10 +120,10 @@ class ServiceUserAdmin(VersionAdmin, BaseUserAdmin): # The fields to be used in displaying the User model. # These override the definitions on the base UserAdmin # that reference specific fields on auth.User. - list_display = ('pseudo',) + list_display = ('pseudo', 'access_group') list_filter = () fieldsets = ( - (None, {'fields': ('pseudo', 'password')}), + (None, {'fields': ('pseudo', 'password', 'access_group')}), ) # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin # overrides get_fieldsets to use this attribute when creating a user. @@ -138,6 +142,7 @@ admin.site.register(ServiceUser, ServiceUserAdmin) admin.site.register(LdapUser, LdapUserAdmin) admin.site.register(LdapUserGroup, LdapUserGroupAdmin) admin.site.register(LdapServiceUser, LdapServiceUserAdmin) +admin.site.register(LdapServiceUserGroup, LdapServiceUserGroupAdmin) admin.site.register(School, SchoolAdmin) admin.site.register(Right, RightAdmin) admin.site.register(ListRight, ListRightAdmin) diff --git a/users/migrations/0043_auto_20161224_1156.py b/users/migrations/0043_auto_20161224_1156.py new file mode 100644 index 00000000..18aa1e35 --- /dev/null +++ b/users/migrations/0043_auto_20161224_1156.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0042_auto_20161126_2028'), + ] + + operations = [ + migrations.AlterField( + model_name='ldapserviceuser', + name='dn', + field=models.CharField(max_length=200), + ), + migrations.AlterField( + model_name='ldapuser', + name='dn', + field=models.CharField(max_length=200), + ), + migrations.AlterField( + model_name='ldapusergroup', + name='dn', + field=models.CharField(max_length=200), + ), + ] diff --git a/users/migrations/0044_user_ssh_public_key.py b/users/migrations/0044_user_ssh_public_key.py new file mode 100644 index 00000000..e25194d2 --- /dev/null +++ b/users/migrations/0044_user_ssh_public_key.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0043_auto_20161224_1156'), + ] + + operations = [ + migrations.AddField( + model_name='user', + name='ssh_public_key', + field=models.CharField(max_length=2047, null=True, blank=True), + ), + ] diff --git a/users/migrations/0045_merge.py b/users/migrations/0045_merge.py new file mode 100644 index 00000000..fa8b8712 --- /dev/null +++ b/users/migrations/0045_merge.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0043_ban_state'), + ('users', '0044_user_ssh_public_key'), + ] + + operations = [ + ] diff --git a/users/migrations/0046_auto_20170617_1433.py b/users/migrations/0046_auto_20170617_1433.py new file mode 100644 index 00000000..7b846abf --- /dev/null +++ b/users/migrations/0046_auto_20170617_1433.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-17 12:33 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0045_merge'), + ] + + operations = [ + migrations.RemoveField( + model_name='user', + name='ssh_public_key', + ), + migrations.AlterField( + model_name='ban', + name='state', + field=models.IntegerField(choices=[(0, 'HARD (aucun accès)'), (1, 'SOFT (accès local seulement)'), (2, 'BRIDAGE (bridage du débit)')], default=0), + ), + migrations.AlterField( + model_name='ldapserviceuser', + name='dn', + field=models.CharField(max_length=200, primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name='ldapuser', + name='dn', + field=models.CharField(max_length=200, primary_key=True, serialize=False), + ), + migrations.AlterField( + model_name='ldapusergroup', + name='dn', + field=models.CharField(max_length=200, primary_key=True, serialize=False), + ), + ] diff --git a/users/migrations/0047_auto_20170618_0156.py b/users/migrations/0047_auto_20170618_0156.py new file mode 100644 index 00000000..dc19b38a --- /dev/null +++ b/users/migrations/0047_auto_20170618_0156.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-17 23:56 +from __future__ import unicode_literals + +from django.db import migrations, models +import ldapdb.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0046_auto_20170617_1433'), + ] + + operations = [ + migrations.CreateModel( + name='LdapServiceUserGroup', + fields=[ + ('dn', models.CharField(max_length=200, primary_key=True, serialize=False)), + ('name', ldapdb.models.fields.CharField(db_column='cn', max_length=200, serialize=False)), + ('members', ldapdb.models.fields.ListField(blank=True, db_column='member')), + ], + options={ + 'abstract': False, + }, + ), + migrations.AddField( + model_name='serviceuser', + name='access_group', + field=models.IntegerField(choices=[(0, 'auth'), (1, 'readonly'), (2, 'usermgmt')], default=1), + ), + ] diff --git a/users/migrations/0048_auto_20170618_0210.py b/users/migrations/0048_auto_20170618_0210.py new file mode 100644 index 00000000..7ef8c397 --- /dev/null +++ b/users/migrations/0048_auto_20170618_0210.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-18 00:10 +from __future__ import unicode_literals + +from django.db import migrations +import ldapdb.models.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0047_auto_20170618_0156'), + ] + + operations = [ + migrations.AlterField( + model_name='ldapserviceusergroup', + name='name', + field=ldapdb.models.fields.CharField(db_column='cn', max_length=200, primary_key=True, serialize=False), + ), + ] diff --git a/users/migrations/0049_auto_20170618_1424.py b/users/migrations/0049_auto_20170618_1424.py new file mode 100644 index 00000000..773544a0 --- /dev/null +++ b/users/migrations/0049_auto_20170618_1424.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-06-18 12:24 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0048_auto_20170618_0210'), + ] + + operations = [ + migrations.AlterField( + model_name='serviceuser', + name='access_group', + field=models.CharField(choices=[('auth', 'auth'), ('readonly', 'readonly'), ('usermgmt', 'usermgmt')], default='readonly', max_length=32), + ), + ] diff --git a/users/models.py b/users/models.py index 31247d30..c69a8b0c 100644 --- a/users/models.py +++ b/users/models.py @@ -38,6 +38,7 @@ import datetime from django.utils import timezone from django.contrib.auth.models import AbstractBaseUser, BaseUserManager +from django.core.validators import MinLengthValidator from topologie.models import Room from cotisations.models import Cotisation, Facture, Vente from machines.models import Interface, Machine @@ -373,9 +374,17 @@ def user_post_delete(sender, **kwargs): user.ldap_del() class ServiceUser(AbstractBaseUser): + readonly = 'readonly' + ACCESS = ( + ('auth', 'auth'), + ('readonly', 'readonly'), + ('usermgmt', 'usermgmt'), + ) + PRETTY_NAME = "Utilisateurs de service" pseudo = models.CharField(max_length=32, unique=True, help_text="Doit contenir uniquement des lettres, chiffres, ou tirets", validators=[linux_user_validator]) + access_group = models.CharField(choices=ACCESS, default=readonly, max_length=32) USERNAME_FIELD = 'pseudo' @@ -386,8 +395,9 @@ class ServiceUser(AbstractBaseUser): user_ldap = LdapServiceUser.objects.get(name=self.pseudo) except LdapServiceUser.DoesNotExist: user_ldap = LdapServiceUser(name=self.pseudo) - user_ldap.user_password = self.password + user_ldap.user_password = self.password[:6] + self.password[7:] user_ldap.save() + self.serviceuser_group_sync() def ldap_del(self): try: @@ -395,6 +405,15 @@ class ServiceUser(AbstractBaseUser): user_ldap.delete() except LdapUser.DoesNotExist: pass + self.serviceuser_group_sync() + + def serviceuser_group_sync(self): + try: + group = LdapServiceUserGroup.objects.get(name=self.access_group) + except: + group = LdapServiceUserGroup(name=self.access_group) + group.members = [serviceuser.dn for serviceuser in LdapServiceUser.objects.filter(name__in=[user.pseudo for user in ServiceUser.objects.filter(access_group=self.access_group)])] + group.save() def __str__(self): return self.pseudo @@ -402,12 +421,12 @@ class ServiceUser(AbstractBaseUser): @receiver(post_save, sender=ServiceUser) def service_user_post_save(sender, **kwargs): service_user = kwargs['instance'] -# service_user.ldap_sync() + service_user.ldap_sync() @receiver(post_delete, sender=ServiceUser) def service_user_post_delete(sender, **kwargs): service_user = kwargs['instance'] -# service_user.ldap_del() + service_user.ldap_del() class Right(models.Model): PRETTY_NAME = "Droits affectés à des users" @@ -624,6 +643,24 @@ class LdapServiceUser(ldapdb.models.Model): name = ldapdb.models.fields.CharField(db_column='cn', max_length=200, primary_key=True) user_password = ldapdb.models.fields.CharField(db_column='userPassword', max_length=200, blank=True, null=True) + def __str__(self): + return self.name + +class LdapServiceUserGroup(ldapdb.models.Model): + """ + Class for representing an LDAP userservice entry. + """ + # LDAP meta-data + base_dn = LDAP['base_userservicegroup_dn'] + object_classes = ['groupOfNames'] + + # attributes + name = ldapdb.models.fields.CharField(db_column='cn', max_length=200, primary_key=True) + members = ldapdb.models.fields.ListField(db_column='member', blank=True) + + def __str__(self): + return self.name + class BaseInfoForm(ModelForm): def __init__(self, *args, **kwargs): super(BaseInfoForm, self).__init__(*args, **kwargs) @@ -678,14 +715,15 @@ class PasswordForm(ModelForm): fields = ['password', 'pwd_ntlm'] class ServiceUserForm(ModelForm): + password = forms.CharField(label=u'Nouveau mot de passe', max_length=255, validators=[MinLengthValidator(8)], widget=forms.PasswordInput, required=False) + class Meta: model = ServiceUser - fields = ('pseudo','password') + fields = ('pseudo','access_group') -class ServicePasswordForm(ModelForm): - class Meta: - model = ServiceUser - fields = ('password',) +class EditServiceUserForm(ServiceUserForm): + class Meta(ServiceUserForm.Meta): + fields = ['access_group'] class StateForm(ModelForm): class Meta: diff --git a/users/templates/users/aff_serviceusers.html b/users/templates/users/aff_serviceusers.html new file mode 100644 index 00000000..217892b0 --- /dev/null +++ b/users/templates/users/aff_serviceusers.html @@ -0,0 +1,45 @@ +{% comment %} +Re2o est un logiciel d'administration développé initiallement au rezometz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2017 Gabriel Détraz +Copyright © 2017 Goulven Kermarec +Copyright © 2017 Augustin Lemesle + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +
Nom | +Rôle | ++ |
---|---|---|
{{ serviceuser.pseudo }} | +{{ serviceuser.access_group }} | ++ {% include 'buttons/suppr.html' with href='users:del-serviceuser' id=serviceuser.id %} + {% include 'buttons/edit.html' with href='users:edit-serviceuser' id=serviceuser.id %} + {% include 'buttons/history.html' with href='users:history' name='serviceuser' id=serviceuser.id %} + | +