Commit a7ae6242 by Bach Dániel

dashboard: add UserCreationView

parent e6f7e48a
...@@ -32,6 +32,7 @@ from crispy_forms.layout import ( ...@@ -32,6 +32,7 @@ from crispy_forms.layout import (
from crispy_forms.utils import render_field from crispy_forms.utils import render_field
from django import forms from django import forms
from django.contrib.auth.forms import UserCreationForm as OrgUserCreationForm
from django.forms.widgets import TextInput from django.forms.widgets import TextInput
from django.template import Context from django.template import Context
from django.template.loader import render_to_string from django.template.loader import render_to_string
...@@ -1086,3 +1087,25 @@ class CirclePasswordChangeForm(PasswordChangeForm): ...@@ -1086,3 +1087,25 @@ class CirclePasswordChangeForm(PasswordChangeForm):
css_class="btn btn-primary", css_class="btn btn-primary",
css_id="submit-password-button")) css_id="submit-password-button"))
return helper return helper
class UserCreationForm(OrgUserCreationForm):
class Meta:
model = User
fields = ("username", 'email', 'first_name', 'last_name')
@property
def helper(self):
helper = FormHelper()
helper.layout = Layout('username', 'password1', 'password2', 'email',
'first_name', 'last_name')
helper.add_input(Submit("submit", _("Save")))
return helper
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<table class="table table-striped table-with-form-fields table-bordered" id="group-detail-user-table"> <table class="table table-striped table-with-form-fields table-bordered" id="group-detail-user-table">
<tbody> <tbody>
{% if perms.auth.add_user %}
<p class="pull-right">
<a href="{% url "dashboard.views.create-user" group.pk %}" class="btn btn-success">{% trans "Create user" %}</a>
</p>
{% endif %}
<thead><tr><th></th><th>{% trans "Who" %}</th><th>{% trans "Remove" %}</th></tr></thead> <thead><tr><th></th><th>{% trans "Who" %}</th><th>{% trans "Remove" %}</th></tr></thead>
{% for i in users %} {% for i in users %}
<tr> <tr>
......
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}
...@@ -33,6 +33,7 @@ from .views import ( ...@@ -33,6 +33,7 @@ from .views import (
GroupRemoveAclUserView, GroupRemoveAclGroupView, GroupRemoveUserView, GroupRemoveAclUserView, GroupRemoveAclGroupView, GroupRemoveUserView,
GroupCreate, GroupCreate,
TemplateChoose, TemplateChoose,
UserCreationView,
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -144,4 +145,7 @@ urlpatterns = patterns( ...@@ -144,4 +145,7 @@ urlpatterns = patterns(
name="dashboard.views.remove-user"), name="dashboard.views.remove-user"),
url(r'^group/create/$', GroupCreate.as_view(), url(r'^group/create/$', GroupCreate.as_view(),
name='dashboard.views.group-create'), name='dashboard.views.group-create'),
url(r'^group/(?P<group_pk>\d+)/create/$',
UserCreationView.as_view(),
name="dashboard.views.create-user"),
) )
...@@ -54,6 +54,7 @@ from braces.views._access import AccessMixin ...@@ -54,6 +54,7 @@ from braces.views._access import AccessMixin
from .forms import ( from .forms import (
CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, MyProfileForm, CircleAuthenticationForm, DiskAddForm, HostForm, LeaseForm, MyProfileForm,
NodeForm, TemplateForm, TraitForm, VmCustomizeForm, GroupCreateForm, NodeForm, TemplateForm, TraitForm, VmCustomizeForm, GroupCreateForm,
UserCreationForm,
CirclePasswordChangeForm CirclePasswordChangeForm
) )
...@@ -2576,6 +2577,36 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView): ...@@ -2576,6 +2577,36 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView):
return ctx return ctx
class UserCreationView(CreateView):
form_class = UserCreationForm
model = User
template_name = 'dashboard/user-create.html'
def get_group(self, group_pk):
self.group = get_object_or_404(Group, pk=group_pk)
if not self.group.profile.has_level(self.request.user, 'owner'):
raise PermissionDenied()
def get(self, *args, **kwargs):
if not self.request.user.has_perm('auth.add_user'):
raise PermissionDenied()
self.get_group(kwargs.pop('group_pk'))
return super(UserCreationView, self).get(*args, **kwargs)
def post(self, *args, **kwargs):
if not self.request.user.has_perm('auth.add_user'):
raise PermissionDenied()
group_pk = kwargs.pop('group_pk')
self.get_group(group_pk)
ret = super(UserCreationView, self).post(*args, **kwargs)
if self.object:
self.object.groups.add(self.group)
return redirect(
reverse('dashboard.views.group-detail', args=[group_pk]))
else:
return ret
class InterfaceDeleteView(DeleteView): class InterfaceDeleteView(DeleteView):
model = Interface model = Interface
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment