diff --git a/app/main/forms.py b/app/main/forms.py index f256ee6..d591e72 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -54,6 +54,8 @@ class ProfileForm(PasswordCheckMixin, forms.Form): passwd = passwd_field(required=False) passwd_confirm = passwd_confirm_field(required=False) +class ProfilePosixForm(ProfileForm): + shell = forms.CharField(max_length=100, label="Shell") class RequestAccountForm(forms.ModelForm): uid = uid_field() @@ -81,3 +83,7 @@ class ProcessAccountForm(PasswordCheckMixin, forms.Form): class ProcessPasswdForm(PasswordCheckMixin, forms.Form): passwd = passwd_field() passwd_confirm = passwd_confirm_field() + +class NewOrgForm(forms.Form): + name = forms.CharField(max_length=100, label="Nom de l'association en minuscules") + complete_name = forms.CharField(max_length=100, label="Nom complet de l'association") diff --git a/app/main/urls.py b/app/main/urls.py index a364e5c..763dbbe 100644 --- a/app/main/urls.py +++ b/app/main/urls.py @@ -8,6 +8,7 @@ url(r'^logout/$', 'logout'), url(r'^passwd/$', 'passwd'), url(r'^admin/$', 'admin'), + url(r'^new_org/$', 'new_org'), url(r'^org/(?P[A-Za-z0-9-_]+)/$', 'org'), url(r'^org/(?P[A-Za-z0-9-_]+)/add/$', 'org_add'), url(r'^org/(?P[A-Za-z0-9-_]+)/promote/(?P[a-z-.]+)/$', 'org_promote'), diff --git a/app/main/views.py b/app/main/views.py index 3f31a24..e9b390d 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -8,8 +8,8 @@ from django.utils import timezone from django.contrib import messages -from .forms import (LoginForm, ProfileForm, RequestAccountForm, RequestPasswdForm, - ProcessAccountForm, ProcessPasswdForm) +from .forms import (LoginForm, ProfileForm, ProfilePosixForm, RequestAccountForm, RequestPasswdForm, + ProcessAccountForm, ProcessPasswdForm, NewOrgForm) from .models import Request from webldap import settings @@ -126,20 +126,40 @@ def profile(request, l): @connect_ldap def profile_edit(request, l): me = l.get_entry(request.session['ldap_binddn']) + posix = 'posixAccount' in me.objectClass if request.method != 'POST': - f = ProfileForm(label_suffix='', initial={'email': one(me.mail), + if not posix: + f = ProfileForm(label_suffix='', initial={'email': one(me.mail), 'name': me.displayName, 'nick': one(me.cn)}) + else: + f = ProfilePosixForm(label_suffix='', initial={'email': one(me.mail), + 'name': me.displayName, + 'nick': one(me.cn), + 'shell': me.loginShell}) ctx = {'form': f, 'name': me.displayName, 'nick': one(me.cn), 'email': one(me.mail)} return form(ctx, 'main/edit.html', request) - f = ProfileForm(request.POST) + if not posix: + f = ProfileForm(request.POST) + else: + f = ProfilePosixForm(request.POST) ctx = {'form': f, 'name': me.displayName, 'nick': one(me.cn), 'email': one(me.mail)} if not f.is_valid(): return form(ctx, 'main/edit.html', request) + if posix: + shell = f.cleaned_data['shell'] + if shell != me.loginShell: + try: + me.loginShell = shell + me.save() + except ldapom.error.LDAPError: + messages.error(request, 'Shell invalide ?') + return form(ctx, 'main/edit.html', request) + name = f.cleaned_data['name'] nick = f.cleaned_data['nick'] @@ -183,6 +203,26 @@ def profile_edit(request, l): return form(ctx, 'main/edit.html', request) +@connect_ldap +def new_org(request, l): + if not request.session['is_admin']: + messages.error(request, 'Vous n\'êtes pas admin') + return HttpResponseRedirect('/org/{}'.format(uid)) + + if request.method == 'POST': + req = NewOrgForm(request.POST) + if req.is_valid(): + me = l.get_entry(request.session['ldap_binddn']) + new_org = l.get_entry('o={},ou=associations,{}'.format(req.cleaned_data['name'], settings.LDAP_BASE)) + new_org.objectClass='groupOfUniqueNames' + new_org.cn = req.cleaned_data['complete_name'] + new_org.uniqueMember.add(me.dn) + new_org.save() + messages.success(request, 'Association créée') + return HttpResponseRedirect('/') + + f = NewOrgForm() + return form({'form': f}, 'main/new_org.html', request) @connect_ldap def org(request, l, uid): @@ -250,7 +290,6 @@ def org_relegate(request, l, uid, user_uid): messages.success(request, '{} n\'est plus gérant'.format(user.displayName)) return HttpResponseRedirect('/org/{}'.format(uid)) - @connect_ldap def org_add(request, l, uid): org = l.get_entry('o={},ou=associations,{}'.format(uid, settings.LDAP_BASE)) diff --git a/app/templates/main/admin.html b/app/templates/main/admin.html index 0c3a5c9..b8534bc 100644 --- a/app/templates/main/admin.html +++ b/app/templates/main/admin.html @@ -4,6 +4,7 @@

Administration

{% if error_message %}

{{ error_message }}

{% endif %}

Associations

+Ajouter une association
    {% for org in orgs %}
  • diff --git a/app/templates/main/new_org.html b/app/templates/main/new_org.html new file mode 100644 index 0000000..77ab525 --- /dev/null +++ b/app/templates/main/new_org.html @@ -0,0 +1,18 @@ +{% extends "main/base.html" %} +{% block title %}Ajouter une organisation{% endblock %} +{% block content %} +

    Ajouter une organisation

    +{% if error_msg %}

    {{ error_msg }}

    {% endif %} +
    + {% csrf_token %} + + {{ form.as_table }} + + + + +
    + +
    +
    +{% endblock %}