From fe754090b72d81d371cec88ae36153e4a472baf1 Mon Sep 17 00:00:00 2001 From: chirac Date: Fri, 29 Apr 2016 01:10:59 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Permet=20la=20cr=C3=A9ation=20d'assos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main/forms.py | 4 ++++ app/main/urls.py | 1 + app/main/views.py | 22 +++++++++++++++++++++- app/templates/main/admin.html | 1 + app/templates/main/new_org.html | 18 ++++++++++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/templates/main/new_org.html diff --git a/app/main/forms.py b/app/main/forms.py index f256ee6..b85a819 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -81,3 +81,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..f7b4855 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -9,7 +9,7 @@ from django.contrib import messages from .forms import (LoginForm, ProfileForm, RequestAccountForm, RequestPasswdForm, - ProcessAccountForm, ProcessPasswdForm) + ProcessAccountForm, ProcessPasswdForm, NewOrgForm) from .models import Request from webldap import settings @@ -183,6 +183,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): 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 %} From b3e872e9e57aa7e4d3f0c420f97cef13b98f83d9 Mon Sep 17 00:00:00 2001 From: chirac Date: Sat, 30 Apr 2016 01:55:58 +0200 Subject: [PATCH 2/2] Permet de modifier son shell --- app/main/forms.py | 2 ++ app/main/views.py | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/main/forms.py b/app/main/forms.py index b85a819..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() diff --git a/app/main/views.py b/app/main/views.py index f7b4855..e9b390d 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -8,7 +8,7 @@ from django.utils import timezone from django.contrib import messages -from .forms import (LoginForm, ProfileForm, RequestAccountForm, RequestPasswdForm, +from .forms import (LoginForm, ProfileForm, ProfilePosixForm, RequestAccountForm, RequestPasswdForm, ProcessAccountForm, ProcessPasswdForm, NewOrgForm) from .models import Request @@ -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'] @@ -270,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))