Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
14
Issues
14
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
La Quadrature du Net
rpteam
rp
Commits
91a68fd6
Commit
91a68fd6
authored
Mar 13, 2019
by
Okhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moar jedis
parent
a85b9a07
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
4 deletions
+16
-4
apps/core/management/commands/init_groups.py
apps/core/management/commands/init_groups.py
+10
-3
apps/userprofile/admin.py
apps/userprofile/admin.py
+3
-1
apps/userprofile/views/users.py
apps/userprofile/views/users.py
+3
-0
No files found.
apps/core/management/commands/init_groups.py
View file @
91a68fd6
...
...
@@ -5,14 +5,18 @@ groups = ["droid", "jedi", "padawan"]
permissions
=
{
"droid"
:
[],
"jedi"
:
[
"can_change_status"
,
"can_change_priority"
,
"can_vote"
,
"can_edit"
,
"can_edit_users"
,
"can_delete_users"
,
"can_create_user"
,
"can_change_status"
,
"can_change_priority"
,
"can_vote"
,
"can_edit"
,
"can_edit_users"
,
"can_delete_users"
,
"can_create_user"
,
],
"padawan"
:
[
"can_vote"
,
"add_article"
]
}
class
Command
(
BaseCommand
):
help
=
"Adds initial groups for the application (jedis and padawans). Existing user are promoted as padawans."
help
=
"""
Adds initial groups for the application (jedis, droids and padawans).
Existing user are promoted as padawans and Superuser are promoted to jedi.
"""
def
handle
(
self
,
*
args
,
**
options
):
...
...
@@ -24,4 +28,7 @@ class Command(BaseCommand):
users
=
User
.
objects
.
all
()
for
user
in
users
:
user
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
"padawan"
))
if
user
.
is_superuser
():
user
.
group
.
adds
(
Group
.
objects
.
get
(
name
=
'jedi'
))
else
:
user
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
"padawan"
))
apps/userprofile/admin.py
View file @
91a68fd6
...
...
@@ -23,7 +23,8 @@ class UserProfileInline(admin.StackedInline):
class
UserProfileAdmin
(
UserAdmin
):
inlines
=
[
UserProfileInline
]
list_display
=
(
"username"
,
"email"
,
"first_name"
,
"last_name"
,
"is_staff"
,
"get_groups"
)
list_display
=
(
"username"
,
"email"
,
"first_name"
,
"last_name"
,
"is_staff"
,
"get_groups"
)
fieldsets
=
(
(
None
,
{
"fields"
:
(
"username"
,
"password"
)}),
...
...
@@ -36,5 +37,6 @@ class UserProfileAdmin(UserAdmin):
return
", "
.
join
(
sorted
([
g
.
name
for
g
in
obj
.
groups
.
all
()]))
get_groups
.
short_description
=
_
(
"Groups"
)
admin
.
site
.
unregister
(
User
)
admin
.
site
.
register
(
User
,
UserProfileAdmin
)
apps/userprofile/views/users.py
View file @
91a68fd6
...
...
@@ -6,6 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMix
from
django.views.generic.list
import
ListView
from
django.views.generic.edit
import
DeleteView
,
UpdateView
class
UserListView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
ListView
):
model
=
User
paginate_by
=
20
...
...
@@ -22,6 +23,7 @@ class UserListView(LoginRequiredMixin, PermissionRequiredMixin, ListView):
return
context
class
UserEditView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
UpdateView
):
model
=
User
permission_required
=
'userprofile.can_edit_users'
...
...
@@ -31,6 +33,7 @@ class UserEditView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
fields
=
[
'groups'
]
success_url
=
reverse_lazy
(
"users:list"
)
class
UserDeleteView
(
LoginRequiredMixin
,
PermissionRequiredMixin
,
DeleteView
):
model
=
User
permission_required
=
'userprofile.can_delete_users'
...
...
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