From f6a287c4b8033a72dc54bfb73cce24f817aae1ee Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 12 Oct 2016 12:24:01 +0200 Subject: [PATCH] Corrige l'assignation des UID --- .../migrations/0022_auto_20161011_1829.py | 19 +++++++++++++++++++ re2o/settings.py | 2 +- users/migrations/0039_merge.py | 15 +++++++++++++++ users/models.py | 19 ++++++++++++++----- 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 machines/migrations/0022_auto_20161011_1829.py create mode 100644 users/migrations/0039_merge.py diff --git a/machines/migrations/0022_auto_20161011_1829.py b/machines/migrations/0022_auto_20161011_1829.py new file mode 100644 index 00000000..76d7c8e7 --- /dev/null +++ b/machines/migrations/0022_auto_20161011_1829.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0021_auto_20161006_1943'), + ] + + operations = [ + migrations.AlterField( + model_name='interface', + name='dns', + field=models.CharField(help_text="Obligatoire et unique, doit se terminer par exemple en .rez et ne pas comporter d'autres points", unique=True, max_length=255), + ), + ] diff --git a/re2o/settings.py b/re2o/settings.py index cc8437bf..a23744b8 100644 --- a/re2o/settings.py +++ b/re2o/settings.py @@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/1.8/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, LDAP, MAIN_EXTENSION, UID_RANGES +from .settings_local import SECRET_KEY, DATABASES, DEBUG, ALLOWED_HOSTS, ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH, services_urls, REQ_EXPIRE_HRS, REQ_EXPIRE_STR, EMAIL_FROM, SITE_NAME, LDAP, MAIN_EXTENSION, GID_RANGES, UID_RANGES BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/users/migrations/0039_merge.py b/users/migrations/0039_merge.py new file mode 100644 index 00000000..9f534227 --- /dev/null +++ b/users/migrations/0039_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', '0038_user_rezo_rez_uid'), + ('users', '0038_auto_20161006_1952'), + ] + + operations = [ + ] diff --git a/users/models.py b/users/models.py index 019d6098..4ce3f1c8 100644 --- a/users/models.py +++ b/users/models.py @@ -8,7 +8,7 @@ from django.dispatch import receiver import ldapdb.models import ldapdb.models.fields -from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, LDAP, UID_RANGES +from re2o.settings import RIGHTS_LINK, REQ_EXPIRE_HRS, LDAP, GID_RANGES,UID_RANGES import re, uuid import datetime @@ -42,12 +42,24 @@ def linux_user_validator(login): params={'label': login}, ) +def get_fresh_user_uid(): + uids = list(range(int(min(UID_RANGES['users'])),int(max(UID_RANGES['users'])))) + used_uids = [ user.uid_number for user in User.objects.all()] + free_uids = [ id for id in uids if id not in used_uids] + return min(free_uids) + +def get_fresh_gid(): + gids = list(range(int(min(GID_RANGES['posix'])),int(max(GID_RANGES['posix'])))) + used_gids = [ right.gid for right in ListRight.objects.all()] + free_gids = [ id for id in gids if id not in used_gids] + return min(free_gids) def get_admin_right(): try: admin_right = ListRight.objects.get(listright="admin") except ListRight.DoesNotExist: admin_right = ListRight(listright="admin") + admin_right.gid = get_fresh_gid() admin_right.save() return admin_right @@ -99,10 +111,7 @@ class User(AbstractBaseUser): ) def auto_uid(): - uids = list(range(int(min(UID_RANGES['users'])),int(max(UID_RANGES['users'])))) - used_uids = [ user.id for user in User.objects.all()] - free_uids = [ id for id in uids if id not in used_uids] - return min(free_uids) + return get_fresh_user_uid() name = models.CharField(max_length=255) surname = models.CharField(max_length=255)