Refonte formulaire creation + migrations

This commit is contained in:
Paul Marillonnet 2017-02-28 17:51:33 +01:00
parent 6c62810a26
commit cbc39fbf91
7 changed files with 103 additions and 5 deletions

7
doc.md
View File

@ -902,6 +902,13 @@ L'interface de LDAP n'est pas 'pythonique' et depassée, car basée sur l'idée
Cf ldap3 abstraction layer
Une fois notre cas d'utilisaton spécifique de l'annuaire mis en place, nous tâchons d'implémenter un connecteur LDAP générique, basé sur le connecteur CSV déjà présent dans Passerelle.
Ce connecteur devra supporter un grand nombre d'opérations sur un annuaire du choix de l'utilisateur. Ainsi, l'interface de saisie de la requête LDAP laisse l'utilisateur libre de préciser tous les paramètres de la requête à effectuer sur l'annuaire.
La gestion des droits est laissée aux soins du serveur LDAP qui gère ses propres contrôles d'accès (par des ACL).
TODO Serveur, credentials et DN founis par l'utilisateur à la création du connecteur ?
### Config SMTP
Lors de la réalisation du POC, la phase de demande de création d'un compte invité sur le méta-annuaire
Une configuration SMTP est nécessaire pour l'automatisation des alertes email lorsqu'un

View File

@ -30,6 +30,7 @@ class QueryForm(forms.ModelForm):
'attributes' : forms.Textarea(attrs={'rows': 2}),
'scope' : forms.RadioSelect,
'distinguished_name' : forms.Textarea(attrs={'rows': 2}),
'password' : forms.PasswordInput,
#'projections': forms.Textarea(attrs={'rows': 2}),
#'order': forms.Textarea(attrs={'rows': 2}),
#'distinct': forms.Textarea(attrs={'rows': 2}),

View File

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import jsonfield.fields
class Migration(migrations.Migration):
dependencies = [
('ldap', '0002_auto_20170224_0505'),
]
operations = [
migrations.CreateModel(
name='Query',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('slug', models.SlugField(verbose_name=b'Name (slug)')),
('label', models.CharField(max_length=100, verbose_name=b'Label')),
('description', models.TextField(verbose_name=b'Description', blank=True)),
('server', models.CharField(max_length=200, verbose_name=b'Server')),
('user', models.CharField(max_length=200, verbose_name=b'User')),
('password', models.CharField(max_length=50, verbose_name=b'Password')),
('distinguished_name', models.TextField(help_text=b'Distinguished name for the LDAP operation', verbose_name=b'Distinguished name', blank=True)),
('filters', models.TextField(help_text=b'List of filter clauses (LDAP RFC4515 expression)', verbose_name=b'Filters', blank=True)),
('attributes', models.TextField(help_text=b'List of attributes to retrieve for matching entries.', verbose_name=b'Attributes', blank=True)),
('scope', models.CharField(max_length=1, choices=[(b'1', b'BASE'), (b'2', b'LEVEL'), (b'3', b'SUBTREE')])),
],
options={
'ordering': ['slug'],
},
),
migrations.AddField(
model_name='ldapresource',
name='_dialect_options',
field=jsonfield.fields.JSONField(null=True, editable=False),
),
migrations.AddField(
model_name='ldapresource',
name='ldif_file',
field=models.FileField(upload_to=b'ldif', verbose_name=b'LDIF File', blank=True),
),
migrations.AddField(
model_name='query',
name='resource',
field=models.ForeignKey(to='ldap.LDAPResource'),
),
]

View File

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ldap', '0003_auto_20170228_1019'),
]
operations = [
migrations.AddField(
model_name='ldapresource',
name='password',
field=models.CharField(max_length=50, verbose_name=b'Password', blank=True),
),
migrations.AddField(
model_name='ldapresource',
name='server',
field=models.CharField(default=b'localhost', max_length=200, verbose_name=b'Server name'),
),
migrations.AddField(
model_name='ldapresource',
name='user',
field=models.CharField(max_length=200, verbose_name=b'Username (full DN)', blank=True),
),
]

View File

@ -30,7 +30,12 @@ def get_org_unit(u):
return 0
class LDAPResource(BaseResource):
ldif_file = models.FileField('LDIF File', upload_to='ldif')
# XXX normalize max_length values
ldif_file = models.FileField('LDIF File', upload_to='ldif', blank=True) # For future uses
server = models.CharField('Server name', max_length=200, default='localhost')
user = models.CharField('Username (full DN)', max_length=200, blank=True)
password = models.CharField('Password', max_length=50, blank=True)
#columns_keynames = models.CharField(
# max_length=256,
# verbose_name=_('Column keynames'),
@ -294,14 +299,17 @@ class Query(models.Model):
slug = models.SlugField('Name (slug)')
label = models.CharField('Label', max_length=100)
description = models.TextField('Description', blank=True)
server = models.CharField('Server', max_length=200)
user = models.CharField('User', max_length=200)
password = models.CharField('Password', max_length=50)
distinguished_name = models.TextField('Distinguished name', blank=True, #initial=base,
help_text='Distinguished name for the LDAP operation')
filters = models.TextField('Filters', blank=True,
help_text='List of filter clauses (LDAP RFC4515 expression)')
attributes = models.TextField('Attributes', blank=True, #initial='ALL_ATTRIBUTES',
help_text='List of attributes to retrieve for matching entries.')
scope = models.CharField(choices=CHOICES, max_length=1)
#help_text='Search scope for the query') #FIXME
distinguished_name = models.TextField('Distinguished name', blank=True, #initial=base,
help_text='Distinguished name for the LDAP operation')
#projections = models.TextField('Projections', blank=True,
# help_text='List of projections (name:expression)')
#order = models.TextField('Order', blank=True,

View File

@ -26,7 +26,7 @@ def ldap_init():
# Admin DN:
who = "cn=admin,dc=entrouvert,dc=lan"
# Credentials: XXX
cred = "test"
cred = "test" #FIXME
# The local server:
server = Server('spare.entrouvert.lan')
# Authenticated binding:

View File

@ -19,6 +19,7 @@ from .forms import QueryForm
# derive csv connector
# online LDAP query
# LDIF import
# server name and credentials sent during the creation of the connector
# Create your views here.
def dummy_view(request):
@ -49,9 +50,12 @@ class NewQueryView(CreateView):
def get(self, request, *args, **kwargs):
form = self.form_class
#return HttpResponse("LDAP NewWuery CBV")
#return HttpResponse("LDAP New Query CBV")
return render(request, self.template_name, locals())
def post(self, request, *args, **kwargs):
return HttpResponse("TODO")
def get_context_data(self, **kwargs):
#ctx = super(NewQueryView, self).get_context_data(**kwargs)
#ctx['resource'] = CsvDataSource.objects.get(slug=self.kwargs['connector_slug'])