2017-09-10 14:53:02 +00:00
|
|
|
# -*- 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-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2016-06-30 01:39:07 +00:00
|
|
|
from django.contrib import admin
|
2016-07-08 01:12:28 +00:00
|
|
|
from django.contrib.auth.models import Group
|
|
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
2016-07-21 14:58:12 +00:00
|
|
|
from reversion.admin import VersionAdmin
|
2016-06-30 01:39:07 +00:00
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
from .models import User, ServiceUser, School, Right, ListRight, ListShell, Ban, Whitelist, Request, LdapUser, LdapServiceUser, LdapServiceUserGroup, LdapUserGroup
|
2016-07-31 03:03:07 +00:00
|
|
|
from .forms import UserChangeForm, UserCreationForm, ServiceUserChangeForm, ServiceUserCreationForm
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
|
|
|
|
class UserAdmin(admin.ModelAdmin):
|
2016-07-08 01:12:28 +00:00
|
|
|
list_display = (
|
|
|
|
'name',
|
|
|
|
'surname',
|
|
|
|
'pseudo',
|
|
|
|
'room',
|
|
|
|
'email',
|
|
|
|
'school',
|
2016-07-26 00:54:32 +00:00
|
|
|
'shell',
|
2016-07-08 01:12:28 +00:00
|
|
|
'state'
|
|
|
|
)
|
2016-07-26 00:54:32 +00:00
|
|
|
search_fields = ('name','surname','pseudo','room')
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
class LdapUserAdmin(admin.ModelAdmin):
|
2016-07-31 03:03:07 +00:00
|
|
|
list_display = ('name','uidNumber','login_shell')
|
2016-07-27 00:39:19 +00:00
|
|
|
exclude = ('user_password','sambat_nt_password')
|
2016-07-26 00:54:32 +00:00
|
|
|
search_fields = ('name',)
|
|
|
|
|
2016-07-31 03:03:07 +00:00
|
|
|
class LdapServiceUserAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('name',)
|
|
|
|
exclude = ('user_password',)
|
|
|
|
search_fields = ('name',)
|
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
class LdapUserGroupAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('name','members','gid')
|
|
|
|
search_fields = ('name',)
|
|
|
|
|
2017-06-18 12:59:53 +00:00
|
|
|
class LdapServiceUserGroupAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('name',)
|
|
|
|
search_fields = ('name',)
|
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class SchoolAdmin(VersionAdmin):
|
2016-06-30 23:03:28 +00:00
|
|
|
list_display = ('name',)
|
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class ListRightAdmin(VersionAdmin):
|
2016-07-02 00:42:04 +00:00
|
|
|
list_display = ('listright',)
|
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
class ListShellAdmin(VersionAdmin):
|
|
|
|
list_display = ('shell',)
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-10-31 16:52:16 +00:00
|
|
|
class RightAdmin(VersionAdmin):
|
2016-07-02 00:42:04 +00:00
|
|
|
list_display = ('user', 'right')
|
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
class RequestAdmin(admin.ModelAdmin):
|
|
|
|
list_display = ('user', 'type', 'created_at', 'expires_at')
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class BanAdmin(VersionAdmin):
|
2016-07-02 19:57:31 +00:00
|
|
|
list_display = ('user', 'raison', 'date_start', 'date_end')
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class WhitelistAdmin(VersionAdmin):
|
2016-07-04 18:04:11 +00:00
|
|
|
list_display = ('user', 'raison', 'date_start', 'date_end')
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class UserAdmin(VersionAdmin, BaseUserAdmin):
|
2016-07-08 01:12:28 +00:00
|
|
|
# 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.
|
2016-07-26 00:54:32 +00:00
|
|
|
list_display = ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'shell')
|
2016-07-31 03:03:07 +00:00
|
|
|
list_display = ('pseudo',)
|
2016-07-08 01:12:28 +00:00
|
|
|
list_filter = ()
|
|
|
|
fieldsets = (
|
|
|
|
(None, {'fields': ('pseudo', 'password')}),
|
2016-07-31 03:03:07 +00:00
|
|
|
('Personal info', {'fields': ('name', 'surname', 'email', 'school','shell', 'uid_number')}),
|
2016-07-08 01:12:28 +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 = (
|
|
|
|
(None, {
|
|
|
|
'classes': ('wide',),
|
|
|
|
'fields': ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'password1', 'password2')}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
search_fields = ('pseudo',)
|
|
|
|
ordering = ('pseudo',)
|
|
|
|
filter_horizontal = ()
|
|
|
|
|
2016-07-31 03:03:07 +00:00
|
|
|
class ServiceUserAdmin(VersionAdmin, BaseUserAdmin):
|
|
|
|
# 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 = (
|
|
|
|
(None, {
|
|
|
|
'classes': ('wide',),
|
|
|
|
'fields': ('pseudo', 'password1', 'password2')}
|
|
|
|
),
|
|
|
|
)
|
|
|
|
search_fields = ('pseudo',)
|
|
|
|
ordering = ('pseudo',)
|
|
|
|
filter_horizontal = ()
|
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
admin.site.register(User, UserAdmin)
|
2016-07-31 03:03:07 +00:00
|
|
|
admin.site.register(ServiceUser, ServiceUserAdmin)
|
2016-07-26 00:54:32 +00:00
|
|
|
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)
|
2016-06-30 23:03:28 +00:00
|
|
|
admin.site.register(School, SchoolAdmin)
|
2016-07-02 00:42:04 +00:00
|
|
|
admin.site.register(Right, RightAdmin)
|
|
|
|
admin.site.register(ListRight, ListRightAdmin)
|
2016-07-26 00:54:32 +00:00
|
|
|
admin.site.register(ListShell, ListShellAdmin)
|
2016-07-02 19:57:31 +00:00
|
|
|
admin.site.register(Ban, BanAdmin)
|
2016-07-04 18:04:11 +00:00
|
|
|
admin.site.register(Whitelist, WhitelistAdmin)
|
2016-07-20 01:53:46 +00:00
|
|
|
admin.site.register(Request, RequestAdmin)
|
2016-07-08 01:12:28 +00:00
|
|
|
# Now register the new UserAdmin...
|
|
|
|
admin.site.unregister(User)
|
2016-07-31 03:03:07 +00:00
|
|
|
admin.site.unregister(ServiceUser)
|
2016-07-08 01:12:28 +00:00
|
|
|
admin.site.register(User, UserAdmin)
|
2016-07-31 03:03:07 +00:00
|
|
|
admin.site.register(ServiceUser, ServiceUserAdmin)
|
2016-07-08 01:12:28 +00:00
|
|
|
# ... and, since we're not using Django's built-in permissions,
|
|
|
|
# unregister the Group model from admin.
|
|
|
|
admin.site.unregister(Group)
|