Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a0a784e7
authored
May 28, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-create-user' into 'master'
Feature Create User tests
🆗
~~
👷
👷
~~
parents
e6f7e48a
ea6124b3
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
1 deletions
+111
-1
circle/dashboard/forms.py
+23
-0
circle/dashboard/templates/dashboard/group-detail.html
+5
-0
circle/dashboard/templates/dashboard/user-create.html
+7
-0
circle/dashboard/tests/test_views.py
+41
-0
circle/dashboard/urls.py
+4
-0
circle/dashboard/views.py
+31
-1
No files found.
circle/dashboard/forms.py
View file @
a0a784e7
...
@@ -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
circle/dashboard/templates/dashboard/group-detail.html
View file @
a0a784e7
...
@@ -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>
...
...
circle/dashboard/templates/dashboard/user-create.html
0 → 100644
View file @
a0a784e7
{% extends "dashboard/base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block content %}
{% crispy form %}
{% endblock %}
circle/dashboard/tests/test_views.py
View file @
a0a784e7
...
@@ -1475,6 +1475,47 @@ class GroupDetailTest(LoginMixin, TestCase):
...
@@ -1475,6 +1475,47 @@ class GroupDetailTest(LoginMixin, TestCase):
self
.
assertEqual
(
acl_groups
-
1
,
len
(
gp
.
get_groups_with_level
()))
self
.
assertEqual
(
acl_groups
-
1
,
len
(
gp
.
get_groups_with_level
()))
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
response
.
status_code
,
302
)
def
test_unpermitted_user_add_wo_group_perm
(
self
):
user_count
=
self
.
g1
.
user_set
.
count
()
c
=
Client
()
self
.
login
(
c
,
'user1'
)
self
.
u1
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can add user'
))
response
=
c
.
post
(
'/dashboard/group/
%
d/create/'
%
self
.
g1
.
pk
,
{
'username'
:
'userx1'
,
'password1'
:
'test123'
,
'password2'
:
'test123'
})
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
user_count
,
self
.
g1
.
user_set
.
count
())
def
test_permitted_user_add_wo_can_add_user_perm
(
self
):
user_count
=
self
.
g1
.
user_set
.
count
()
c
=
Client
()
self
.
login
(
c
,
'user0'
)
response
=
c
.
post
(
'/dashboard/group/
%
d/create/'
%
self
.
g1
.
pk
,
{
'username'
:
'userx2'
,
'password1'
:
'test123'
,
'password2'
:
'test123'
})
self
.
assertRedirects
(
response
,
'/accounts/login/?next=/dashboard/group/
%
d/create/'
%
self
.
g1
.
pk
)
self
.
assertEqual
(
response
.
status_code
,
302
)
self
.
assertEqual
(
user_count
,
self
.
g1
.
user_set
.
count
())
def
test_permitted_user_add
(
self
):
user_count
=
self
.
g1
.
user_set
.
count
()
self
.
u0
.
user_permissions
.
add
(
Permission
.
objects
.
get
(
name
=
'Can add user'
))
c
=
Client
()
self
.
login
(
c
,
'user0'
)
response
=
c
.
post
(
'/dashboard/group/
%
d/create/'
%
self
.
g1
.
pk
,
{
'username'
:
'userx2'
,
'password1'
:
'test123'
,
'password2'
:
'test123'
})
self
.
assertRedirects
(
response
,
'/dashboard/group/
%
d/'
%
self
.
g1
.
pk
)
self
.
assertEqual
(
user_count
+
1
,
self
.
g1
.
user_set
.
count
())
self
.
assertEqual
(
response
.
status_code
,
302
)
class
GroupListTest
(
LoginMixin
,
TestCase
):
class
GroupListTest
(
LoginMixin
,
TestCase
):
fixtures
=
[
'test-vm-fixture.json'
,
'node.json'
]
fixtures
=
[
'test-vm-fixture.json'
,
'node.json'
]
...
...
circle/dashboard/urls.py
View file @
a0a784e7
...
@@ -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"
),
)
)
circle/dashboard/views.py
View file @
a0a784e7
...
@@ -48,12 +48,14 @@ from django.template import RequestContext
...
@@ -48,12 +48,14 @@ from django.template import RequestContext
from
django.forms.models
import
inlineformset_factory
from
django.forms.models
import
inlineformset_factory
from
django_tables2
import
SingleTableView
from
django_tables2
import
SingleTableView
from
braces.views
import
LoginRequiredMixin
,
SuperuserRequiredMixin
from
braces.views
import
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
PermissionRequiredMixin
)
from
braces.views._access
import
AccessMixin
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 +2578,34 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView):
...
@@ -2576,6 +2578,34 @@ class InstanceActivityDetail(SuperuserRequiredMixin, DetailView):
return
ctx
return
ctx
class
UserCreationView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
CreateView
):
form_class
=
UserCreationForm
model
=
User
template_name
=
'dashboard/user-create.html'
permission_required
=
"auth.add_user"
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
):
self
.
get_group
(
kwargs
.
pop
(
'group_pk'
))
return
super
(
UserCreationView
,
self
)
.
get
(
*
args
,
**
kwargs
)
def
post
(
self
,
*
args
,
**
kwargs
):
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment