8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 08:23:46 +00:00
re2o/users/admin.py

238 lines
6.8 KiB
Python
Raw Normal View History

# -*- mode: python; coding: utf-8 -*-
2017-01-15 23:01:18 +00:00
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2017-10-14 20:46:21 +00:00
"""
2018-10-28 14:56:37 +00:00
Admin views definition
2017-10-14 20:46:21 +00:00
"""
2017-01-15 23:01:18 +00:00
from __future__ import unicode_literals
2016-06-30 01:39:07 +00:00
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
2018-10-28 14:32:31 +00:00
from django.contrib.auth.models import Group
from reversion.admin import VersionAdmin
2016-06-30 01:39:07 +00:00
2018-10-28 14:32:31 +00:00
from .forms import (
UserChangeForm,
UserCreationForm,
ServiceUserChangeForm,
ServiceUserCreationForm
)
from .models import (
User,
2018-08-01 11:06:25 +00:00
EMailAddress,
ServiceUser,
School,
ListRight,
ListShell,
Adherent,
Club,
Ban,
Whitelist,
Request,
LdapUser,
LdapServiceUser,
LdapServiceUserGroup,
LdapUserGroup
)
class LdapUserAdmin(admin.ModelAdmin):
2018-10-28 14:56:37 +00:00
"""LDAP users admin page"""
2017-10-14 20:46:21 +00:00
list_display = ('name', 'uidNumber', 'login_shell')
exclude = ('user_password', 'sambat_nt_password')
search_fields = ('name',)
2017-10-14 20:46:21 +00:00
2016-07-31 03:03:07 +00:00
class LdapServiceUserAdmin(admin.ModelAdmin):
2018-10-28 14:56:37 +00:00
"""LDAP service users admin page"""
2016-07-31 03:03:07 +00:00
list_display = ('name',)
exclude = ('user_password',)
search_fields = ('name',)
2017-10-14 20:46:21 +00:00
class LdapUserGroupAdmin(admin.ModelAdmin):
2018-10-28 14:56:37 +00:00
"""LDAP user groups admin page"""
2017-10-14 20:46:21 +00:00
list_display = ('name', 'members', 'gid')
search_fields = ('name',)
2017-10-14 20:46:21 +00:00
2017-06-18 12:59:53 +00:00
class LdapServiceUserGroupAdmin(admin.ModelAdmin):
2018-10-28 14:56:37 +00:00
"""LDAP service user groups admin page"""
2017-06-18 12:59:53 +00:00
list_display = ('name',)
search_fields = ('name',)
2017-10-14 20:46:21 +00:00
class SchoolAdmin(VersionAdmin):
2018-10-28 14:56:37 +00:00
"""Schools admin page (with revisions)"""
2017-10-14 20:46:21 +00:00
pass
class ListRightAdmin(VersionAdmin):
2018-10-28 14:56:37 +00:00
"""Existing right admin page (with revisions)
Can not edit gid because it is a primary key for LDAP
"""
list_display = ('unix_name',)
2017-10-14 20:46:21 +00:00
class ListShellAdmin(VersionAdmin):
2018-10-28 14:56:37 +00:00
"""Shells admin page (with revisions)"""
2017-10-14 20:46:21 +00:00
pass
class RequestAdmin(admin.ModelAdmin):
2018-10-28 14:56:37 +00:00
"""User request admin page
It contains tickets for password reinitialisation.
"""
list_display = ('user', 'type', 'created_at', 'expires_at')
2017-10-14 20:46:21 +00:00
class BanAdmin(VersionAdmin):
2018-10-28 14:56:37 +00:00
"""Banned user admin page (with revisions)"""
2017-10-14 20:46:21 +00:00
pass
2016-07-02 19:57:31 +00:00
2018-08-01 11:06:25 +00:00
class EMailAddressAdmin(VersionAdmin):
2018-10-28 14:56:37 +00:00
"""Mail aliases admin page (with revisions)"""
2018-06-30 20:56:34 +00:00
pass
class WhitelistAdmin(VersionAdmin):
2018-10-28 14:56:37 +00:00
"""Whitelist admin page"""
2017-10-14 20:46:21 +00:00
pass
2016-07-04 18:04:11 +00:00
class UserAdmin(VersionAdmin, BaseUserAdmin):
2018-10-28 14:56:37 +00:00
"""User admin page (with revisions, based on Django user admin page)"""
# The forms to add and change user instances
form = UserChangeForm
add_form = UserCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
2017-10-14 20:46:21 +00:00
list_display = (
'pseudo',
'surname',
2018-07-30 15:00:41 +00:00
'email',
'local_email_redirect',
'local_email_enabled',
2017-10-14 20:46:21 +00:00
'school',
'is_admin',
'shell'
)
# Need to reset the settings from BaseUserAdmin
# They are using fields we don't use like 'is_staff'
2018-04-14 23:16:49 +00:00
list_filter = ()
fieldsets = (
(None, {'fields': ('pseudo', 'password')}),
2017-10-14 20:46:21 +00:00
(
'Personal info',
{
'fields':
2018-10-28 14:32:31 +00:00
('surname', 'email', 'school', 'shell', 'uid_number')
2017-10-14 20:46:21 +00:00
}
),
2018-10-28 14:32:31 +00:00
('Permissions', {'fields': ('is_admin',)}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
2017-10-14 20:46:21 +00:00
(
None,
{
'classes': ('wide',),
'fields': (
'pseudo',
'surname',
2018-07-30 15:00:41 +00:00
'email',
2017-10-14 20:46:21 +00:00
'school',
'is_admin',
'password1',
'password2'
2018-10-28 14:32:31 +00:00
)
2017-10-14 20:46:21 +00:00
}
),
)
search_fields = ('pseudo', 'surname')
ordering = ('pseudo',)
filter_horizontal = ()
2017-10-14 20:46:21 +00:00
2016-07-31 03:03:07 +00:00
class ServiceUserAdmin(VersionAdmin, BaseUserAdmin):
2018-10-28 14:56:37 +00:00
"""Service user admin page (with revisions, based on Django user admin page)"""
2016-07-31 03:03:07 +00:00
# The forms to add and change user instances
form = ServiceUserChangeForm
add_form = ServiceUserCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
2017-06-18 12:59:53 +00:00
list_display = ('pseudo', 'access_group')
2016-07-31 03:03:07 +00:00
list_filter = ()
fieldsets = (
2017-06-18 12:59:53 +00:00
(None, {'fields': ('pseudo', 'password', 'access_group')}),
2016-07-31 03:03:07 +00:00
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
2017-10-14 20:46:21 +00:00
(
None,
{
'classes': ('wide',),
'fields': ('pseudo', 'password1', 'password2')
}
2016-07-31 03:03:07 +00:00
),
)
search_fields = ('pseudo',)
ordering = ('pseudo',)
filter_horizontal = ()
2017-10-14 20:46:21 +00:00
admin.site.register(User, UserAdmin)
admin.site.register(Adherent, UserAdmin)
admin.site.register(Club, UserAdmin)
2016-07-31 03:03:07 +00:00
admin.site.register(ServiceUser, ServiceUserAdmin)
admin.site.register(LdapUser, LdapUserAdmin)
admin.site.register(LdapUserGroup, LdapUserGroupAdmin)
2016-07-31 03:03:07 +00:00
admin.site.register(LdapServiceUser, LdapServiceUserAdmin)
2017-06-18 12:59:53 +00:00
admin.site.register(LdapServiceUserGroup, LdapServiceUserGroupAdmin)
admin.site.register(School, SchoolAdmin)
admin.site.register(ListRight, ListRightAdmin)
admin.site.register(ListShell, ListShellAdmin)
2016-07-02 19:57:31 +00:00
admin.site.register(Ban, BanAdmin)
2018-08-01 11:06:25 +00:00
admin.site.register(EMailAddress, EMailAddressAdmin)
2016-07-04 18:04:11 +00:00
admin.site.register(Whitelist, WhitelistAdmin)
admin.site.register(Request, RequestAdmin)
2018-10-28 14:56:37 +00:00
# Now register the new UserAdmin and ServiceUser (replacing Django default ones)...
admin.site.unregister(User)
2016-07-31 03:03:07 +00:00
admin.site.unregister(ServiceUser)
admin.site.register(User, UserAdmin)
2016-07-31 03:03:07 +00:00
admin.site.register(ServiceUser, ServiceUserAdmin)
# ... and, since we're not using Django's built-in permissions,
# unregister the Group model from admin.
admin.site.unregister(Group)