mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-19 05:58:34 +02:00
We add an intermediate role : Reseller. It is somewhere between a super administrator and a domain administrator. A reseller can create objects (a limited or not amount) and then define permissions on those objects: * Create a domain admins, * Assign limits to those admins, * ... see #105
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
# coding: utf-8
|
|
|
|
from django import forms
|
|
from django.utils.translation import ugettext_noop as _
|
|
from django.contrib.auth.models import User, Group
|
|
from models import *
|
|
|
|
class ResellerForm(forms.ModelForm):
|
|
class Meta:
|
|
model = User
|
|
fields = ("username", "first_name", "last_name", "email")
|
|
|
|
def save(self, commit=True):
|
|
user = super(ResellerForm, self).save(commit=False)
|
|
if self.cleaned_data.has_key("password1"):
|
|
user.set_password(self.cleaned_data["password1"])
|
|
if commit:
|
|
user.save()
|
|
grp = Group.objects.get(name="Resellers")
|
|
if not grp in user.groups.all():
|
|
user.groups.add(grp)
|
|
user.save()
|
|
try:
|
|
pool = LimitsPool.objects.get(user=user)
|
|
except LimitsPool.DoesNotExist:
|
|
pool = LimitsPool()
|
|
pool.user = user
|
|
pool.save()
|
|
return user
|
|
|
|
class ResellerWithPasswordForm(ResellerForm):
|
|
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
|
|
password2 = forms.CharField(label=_("Confirmation"),
|
|
widget=forms.PasswordInput,
|
|
help_text = _("Enter the same password as above, for verification."))
|
|
|
|
def clean_password2(self):
|
|
password1 = self.cleaned_data.get("password1", "")
|
|
password2 = self.cleaned_data["password2"]
|
|
if password1 != password2:
|
|
raise forms.ValidationError(_("The two password fields didn't match."))
|
|
return password2
|
|
|
|
class LimitsPoolForm(forms.ModelForm):
|
|
class Meta:
|
|
model = LimitsPool
|
|
fields = ("maxdomains", "maxdomaliases", "maxmboxes", "maxmbaliases")
|
|
|
|
|
|
|