2017-09-10 14:53:02 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2020-11-23 16:06:37 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il
|
2017-01-15 23:01:18 +00:00
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
2019-09-29 14:02:28 +00:00
|
|
|
# Copyright © 2017 Lara Kermarec
|
2017-01-15 23:01:18 +00:00
|
|
|
# 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
|
|
|
"""
|
2020-05-29 22:33:29 +00:00
|
|
|
Admin views basic definition, include basic definition of admin view.
|
|
|
|
|
|
|
|
Except for Admin edition and creation of users and services users;
|
|
|
|
with AdherentAdmin, ClubAdmin and ServiceUserAdmin.
|
2017-10-14 20:46:21 +00:00
|
|
|
"""
|
2017-01-15 23:01:18 +00:00
|
|
|
|
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
|
|
|
|
2018-04-02 01:35:07 +00:00
|
|
|
from .models import (
|
|
|
|
User,
|
2018-08-01 11:06:25 +00:00
|
|
|
EMailAddress,
|
2018-04-02 01:35:07 +00:00
|
|
|
ServiceUser,
|
|
|
|
School,
|
|
|
|
ListRight,
|
|
|
|
ListShell,
|
|
|
|
Adherent,
|
|
|
|
Club,
|
|
|
|
Ban,
|
|
|
|
Whitelist,
|
|
|
|
Request,
|
|
|
|
)
|
|
|
|
from .forms import (
|
2020-05-28 20:08:16 +00:00
|
|
|
UserAdminForm,
|
2020-05-28 20:24:07 +00:00
|
|
|
ServiceUserAdminForm,
|
2018-04-02 01:35:07 +00:00
|
|
|
)
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class SchoolAdmin(VersionAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""School Admin view and management.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
pass
|
|
|
|
|
2016-06-30 23:03:28 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class ListRightAdmin(VersionAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""ListRight and groups Admin view and management.
|
|
|
|
Even if it is possible, gid should NOT be changed
|
|
|
|
as it is the ldap primary key.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
list_display = ("unix_name",)
|
2016-07-02 00:42:04 +00:00
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
|
2016-07-26 00:54:32 +00:00
|
|
|
class ListShellAdmin(VersionAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""Users Shell Admin view and management.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
pass
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2016-07-20 01:53:46 +00:00
|
|
|
class RequestAdmin(admin.ModelAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""User Request Admin view and management, for
|
|
|
|
change password and email validation.
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
|
|
|
list_display = ("user", "type", "created_at", "expires_at")
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class BanAdmin(VersionAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""Ban Admin view and management, for
|
|
|
|
User Ban
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
pass
|
2016-07-02 19:57:31 +00:00
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2018-08-01 11:06:25 +00:00
|
|
|
class EMailAddressAdmin(VersionAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""EmailAddress Admin view and management, for
|
|
|
|
auxiliary and local email addresses
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2018-06-30 20:56:34 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-07-21 14:58:12 +00:00
|
|
|
class WhitelistAdmin(VersionAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""Whitelist Admin view and management, for
|
|
|
|
free access whitelisted users
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
pass
|
2016-07-04 18:04:11 +00:00
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
|
2020-05-28 20:08:16 +00:00
|
|
|
class AdherentAdmin(VersionAdmin, BaseUserAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""Adherent Admin view and management, for
|
|
|
|
Adherent fields : password, pseudo, etc, admin can
|
|
|
|
edit all fields on user instance.
|
|
|
|
Inherit from django BaseUserAdmin
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
# The forms to add and change user instances
|
|
|
|
|
2020-05-28 20:08:16 +00:00
|
|
|
add_form = UserAdminForm
|
|
|
|
form = UserAdminForm
|
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
list_display = (
|
2019-11-04 16:55:03 +00:00
|
|
|
"pseudo",
|
2020-05-28 20:08:16 +00:00
|
|
|
"name",
|
2019-11-04 16:55:03 +00:00
|
|
|
"surname",
|
|
|
|
"email",
|
|
|
|
"local_email_redirect",
|
|
|
|
"local_email_enabled",
|
|
|
|
"school",
|
|
|
|
"shell",
|
2017-10-14 20:46:21 +00:00
|
|
|
)
|
2018-04-14 23:16:49 +00:00
|
|
|
list_filter = ()
|
2016-07-08 01:12:28 +00:00
|
|
|
fieldsets = (
|
2020-05-28 20:08:16 +00:00
|
|
|
(None, {"fields": ("pseudo",)}),
|
2017-10-14 20:46:21 +00:00
|
|
|
(
|
2019-11-04 16:55:03 +00:00
|
|
|
"Personal info",
|
2020-10-22 13:39:30 +00:00
|
|
|
{"fields": ("surname", "name", "email", "school", "shell", "uid_number", "password1", "password2")},
|
2017-10-14 20:46:21 +00:00
|
|
|
),
|
2016-07-08 01:12:28 +00:00
|
|
|
)
|
|
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
|
|
|
|
# overrides get_fieldsets to use this attribute when creating a user.
|
2020-05-28 20:08:16 +00:00
|
|
|
add_fieldsets = (
|
|
|
|
(
|
|
|
|
None,
|
|
|
|
{
|
|
|
|
"classes": ("wide",),
|
|
|
|
"fields": (
|
|
|
|
"pseudo",
|
|
|
|
"surname",
|
|
|
|
"name",
|
|
|
|
"email",
|
|
|
|
"school",
|
|
|
|
"password1",
|
|
|
|
"password2",
|
|
|
|
"is_superuser",
|
|
|
|
),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
search_fields = ("pseudo", "surname", "name")
|
|
|
|
ordering = ("pseudo",)
|
|
|
|
filter_horizontal = ()
|
|
|
|
|
|
|
|
|
|
|
|
class ClubAdmin(VersionAdmin, BaseUserAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""Club Admin view and management, for
|
|
|
|
Club fields : password, pseudo, etc, admin can
|
|
|
|
edit all fields on user instance.
|
|
|
|
Inherit from django BaseUserAdmin
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2020-05-28 20:08:16 +00:00
|
|
|
# The forms to add and change user instances
|
|
|
|
add_form = UserAdminForm
|
|
|
|
form = UserAdminForm
|
|
|
|
|
|
|
|
list_display = (
|
|
|
|
"pseudo",
|
|
|
|
"surname",
|
|
|
|
"email",
|
|
|
|
"local_email_redirect",
|
|
|
|
"local_email_enabled",
|
|
|
|
"school",
|
|
|
|
"shell",
|
|
|
|
)
|
|
|
|
list_filter = ()
|
|
|
|
fieldsets = (
|
|
|
|
(None, {"fields": ("pseudo",)}),
|
|
|
|
(
|
|
|
|
"Personal info",
|
2020-10-22 13:39:30 +00:00
|
|
|
{"fields": ("surname", "email", "school", "shell", "uid_number", "password1", "password2")},
|
2020-05-28 20:08:16 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2016-07-08 01:12:28 +00:00
|
|
|
add_fieldsets = (
|
2017-10-14 20:46:21 +00:00
|
|
|
(
|
|
|
|
None,
|
|
|
|
{
|
2019-11-04 16:55:03 +00:00
|
|
|
"classes": ("wide",),
|
|
|
|
"fields": (
|
|
|
|
"pseudo",
|
|
|
|
"surname",
|
|
|
|
"email",
|
|
|
|
"school",
|
|
|
|
"password1",
|
|
|
|
"password2",
|
2020-05-28 20:08:16 +00:00
|
|
|
"is_superuser",
|
2019-11-04 16:55:03 +00:00
|
|
|
),
|
|
|
|
},
|
2016-07-08 01:12:28 +00:00
|
|
|
),
|
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
search_fields = ("pseudo", "surname")
|
|
|
|
ordering = ("pseudo",)
|
2016-07-08 01:12:28 +00:00
|
|
|
filter_horizontal = ()
|
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
|
2016-07-31 03:03:07 +00:00
|
|
|
class ServiceUserAdmin(VersionAdmin, BaseUserAdmin):
|
2020-05-01 14:29:26 +00:00
|
|
|
"""ServiceUser Admin view and management, for
|
|
|
|
User fields : password, pseudo, etc, admin can
|
|
|
|
edit all fields on user instance.
|
|
|
|
Inherit from django BaseUserAdmin
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
Django ModelAdmin: Apply on django ModelAdmin
|
|
|
|
|
|
|
|
"""
|
2019-11-04 16:55:03 +00:00
|
|
|
|
2016-07-31 03:03:07 +00:00
|
|
|
# The forms to add and change user instances
|
2020-05-28 20:24:07 +00:00
|
|
|
form = ServiceUserAdminForm
|
|
|
|
add_form = ServiceUserAdminForm
|
2016-07-31 03:03:07 +00:00
|
|
|
|
|
|
|
# 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.
|
2019-11-04 16:55:03 +00:00
|
|
|
list_display = ("pseudo", "access_group")
|
2016-07-31 03:03:07 +00:00
|
|
|
list_filter = ()
|
2020-05-28 20:24:07 +00:00
|
|
|
fieldsets = ((None, {"fields": ("pseudo", "access_group", "comment", "password1", "password2")}),)
|
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 = (
|
2019-11-04 16:55:03 +00:00
|
|
|
(None, {"classes": ("wide",), "fields": ("pseudo", "password1", "password2")}),
|
2016-07-31 03:03:07 +00:00
|
|
|
)
|
2019-11-04 16:55:03 +00:00
|
|
|
search_fields = ("pseudo",)
|
|
|
|
ordering = ("pseudo",)
|
2016-07-31 03:03:07 +00:00
|
|
|
filter_horizontal = ()
|
|
|
|
|
2017-10-14 20:46:21 +00:00
|
|
|
|
2020-05-28 20:08:16 +00:00
|
|
|
admin.site.register(Adherent, AdherentAdmin)
|
|
|
|
admin.site.register(Club, ClubAdmin)
|
2016-07-31 03:03:07 +00:00
|
|
|
admin.site.register(ServiceUser, ServiceUserAdmin)
|
2016-06-30 23:03:28 +00:00
|
|
|
admin.site.register(School, SchoolAdmin)
|
2016-07-02 00:42:04 +00:00
|
|
|
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)
|
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)
|
2016-07-20 01:53:46 +00:00
|
|
|
admin.site.register(Request, RequestAdmin)
|
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)
|