|
|
@ -20,6 +20,10 @@ |
|
|
# You should have received a copy of the GNU General Public License along |
|
|
# 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., |
|
|
# with this program; if not, write to the Free Software Foundation, Inc., |
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
|
|
|
|
""" |
|
|
|
|
|
Definition des vues pour les admin. Classique, sauf pour users, |
|
|
|
|
|
où on fait appel à UserChange et ServiceUserChange, forms custom |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
from __future__ import unicode_literals |
|
|
from __future__ import unicode_literals |
|
|
|
|
|
|
|
|
@ -28,11 +32,15 @@ from django.contrib.auth.models import Group |
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin |
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin |
|
|
from reversion.admin import VersionAdmin |
|
|
from reversion.admin import VersionAdmin |
|
|
|
|
|
|
|
|
from .models import User, ServiceUser, School, Right, ListRight, ListShell, Ban, Whitelist, Request, LdapUser, LdapServiceUser, LdapServiceUserGroup, LdapUserGroup |
|
|
from .models import User, ServiceUser, School, Right, ListRight, ListShell |
|
|
from .forms import UserChangeForm, UserCreationForm, ServiceUserChangeForm, ServiceUserCreationForm |
|
|
from .models import Ban, Whitelist, Request, LdapUser, LdapServiceUser |
|
|
|
|
|
from .models import LdapServiceUserGroup, LdapUserGroup |
|
|
|
|
|
from .forms import UserChangeForm, UserCreationForm |
|
|
|
|
|
from .forms import ServiceUserChangeForm, ServiceUserCreationForm |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserAdmin(admin.ModelAdmin): |
|
|
class UserAdmin(admin.ModelAdmin): |
|
|
|
|
|
"""Administration d'un user""" |
|
|
list_display = ( |
|
|
list_display = ( |
|
|
'name', |
|
|
'name', |
|
|
'surname', |
|
|
'surname', |
|
|
@ -43,51 +51,73 @@ class UserAdmin(admin.ModelAdmin): |
|
|
'shell', |
|
|
'shell', |
|
|
'state' |
|
|
'state' |
|
|
) |
|
|
) |
|
|
search_fields = ('name','surname','pseudo','room') |
|
|
search_fields = ('name', 'surname', 'pseudo', 'room') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LdapUserAdmin(admin.ModelAdmin): |
|
|
class LdapUserAdmin(admin.ModelAdmin): |
|
|
list_display = ('name','uidNumber','login_shell') |
|
|
"""Administration du ldapuser""" |
|
|
exclude = ('user_password','sambat_nt_password') |
|
|
list_display = ('name', 'uidNumber', 'login_shell') |
|
|
|
|
|
exclude = ('user_password', 'sambat_nt_password') |
|
|
search_fields = ('name',) |
|
|
search_fields = ('name',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LdapServiceUserAdmin(admin.ModelAdmin): |
|
|
class LdapServiceUserAdmin(admin.ModelAdmin): |
|
|
|
|
|
"""Administration du ldapserviceuser""" |
|
|
list_display = ('name',) |
|
|
list_display = ('name',) |
|
|
exclude = ('user_password',) |
|
|
exclude = ('user_password',) |
|
|
search_fields = ('name',) |
|
|
search_fields = ('name',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LdapUserGroupAdmin(admin.ModelAdmin): |
|
|
class LdapUserGroupAdmin(admin.ModelAdmin): |
|
|
list_display = ('name','members','gid') |
|
|
"""Administration du ldapusergroupe""" |
|
|
|
|
|
list_display = ('name', 'members', 'gid') |
|
|
search_fields = ('name',) |
|
|
search_fields = ('name',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class LdapServiceUserGroupAdmin(admin.ModelAdmin): |
|
|
class LdapServiceUserGroupAdmin(admin.ModelAdmin): |
|
|
|
|
|
"""Administration du ldap serviceusergroup""" |
|
|
list_display = ('name',) |
|
|
list_display = ('name',) |
|
|
search_fields = ('name',) |
|
|
search_fields = ('name',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SchoolAdmin(VersionAdmin): |
|
|
class SchoolAdmin(VersionAdmin): |
|
|
list_display = ('name',) |
|
|
"""Administration, gestion des écoles""" |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListRightAdmin(VersionAdmin): |
|
|
class ListRightAdmin(VersionAdmin): |
|
|
|
|
|
"""Gestion de la liste des droits existants |
|
|
|
|
|
Ne permet pas l'edition du gid (primarykey pour ldap)""" |
|
|
list_display = ('listright',) |
|
|
list_display = ('listright',) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ListShellAdmin(VersionAdmin): |
|
|
class ListShellAdmin(VersionAdmin): |
|
|
list_display = ('shell',) |
|
|
"""Gestion de la liste des shells coté admin""" |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RightAdmin(VersionAdmin): |
|
|
class RightAdmin(VersionAdmin): |
|
|
list_display = ('user', 'right') |
|
|
"""Gestion de la liste des droits affectés""" |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RequestAdmin(admin.ModelAdmin): |
|
|
class RequestAdmin(admin.ModelAdmin): |
|
|
|
|
|
"""Gestion des request objet, ticket pour lien de reinit mot de passe""" |
|
|
list_display = ('user', 'type', 'created_at', 'expires_at') |
|
|
list_display = ('user', 'type', 'created_at', 'expires_at') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BanAdmin(VersionAdmin): |
|
|
class BanAdmin(VersionAdmin): |
|
|
list_display = ('user', 'raison', 'date_start', 'date_end') |
|
|
"""Gestion des bannissements""" |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class WhitelistAdmin(VersionAdmin): |
|
|
class WhitelistAdmin(VersionAdmin): |
|
|
list_display = ('user', 'raison', 'date_start', 'date_end') |
|
|
"""Gestion des whitelist""" |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserAdmin(VersionAdmin, BaseUserAdmin): |
|
|
class UserAdmin(VersionAdmin, BaseUserAdmin): |
|
|
|
|
|
"""Gestion d'un user : modification des champs perso, mot de passe, etc""" |
|
|
# The forms to add and change user instances |
|
|
# The forms to add and change user instances |
|
|
form = UserChangeForm |
|
|
form = UserChangeForm |
|
|
add_form = UserCreationForm |
|
|
add_form = UserCreationForm |
|
|
@ -95,27 +125,56 @@ class UserAdmin(VersionAdmin, BaseUserAdmin): |
|
|
# The fields to be used in displaying the User model. |
|
|
# The fields to be used in displaying the User model. |
|
|
# These override the definitions on the base UserAdmin |
|
|
# These override the definitions on the base UserAdmin |
|
|
# that reference specific fields on auth.User. |
|
|
# that reference specific fields on auth.User. |
|
|
list_display = ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'shell') |
|
|
list_display = ( |
|
|
|
|
|
'pseudo', |
|
|
|
|
|
'name', |
|
|
|
|
|
'surname', |
|
|
|
|
|
'email', |
|
|
|
|
|
'school', |
|
|
|
|
|
'is_admin', |
|
|
|
|
|
'shell' |
|
|
|
|
|
) |
|
|
list_display = ('pseudo',) |
|
|
list_display = ('pseudo',) |
|
|
list_filter = () |
|
|
list_filter = () |
|
|
fieldsets = ( |
|
|
fieldsets = ( |
|
|
(None, {'fields': ('pseudo', 'password')}), |
|
|
(None, {'fields': ('pseudo', 'password')}), |
|
|
('Personal info', {'fields': ('name', 'surname', 'email', 'school','shell', 'uid_number')}), |
|
|
( |
|
|
|
|
|
'Personal info', |
|
|
|
|
|
{ |
|
|
|
|
|
'fields': |
|
|
|
|
|
('name', 'surname', 'email', 'school', 'shell', 'uid_number') |
|
|
|
|
|
} |
|
|
|
|
|
), |
|
|
('Permissions', {'fields': ('is_admin', )}), |
|
|
('Permissions', {'fields': ('is_admin', )}), |
|
|
) |
|
|
) |
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin |
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin |
|
|
# overrides get_fieldsets to use this attribute when creating a user. |
|
|
# overrides get_fieldsets to use this attribute when creating a user. |
|
|
add_fieldsets = ( |
|
|
add_fieldsets = ( |
|
|
(None, { |
|
|
( |
|
|
'classes': ('wide',), |
|
|
None, |
|
|
'fields': ('pseudo', 'name', 'surname', 'email', 'school', 'is_admin', 'password1', 'password2')} |
|
|
{ |
|
|
|
|
|
'classes': ('wide',), |
|
|
|
|
|
'fields': ( |
|
|
|
|
|
'pseudo', |
|
|
|
|
|
'name', |
|
|
|
|
|
'surname', |
|
|
|
|
|
'email', |
|
|
|
|
|
'school', |
|
|
|
|
|
'is_admin', |
|
|
|
|
|
'password1', |
|
|
|
|
|
'password2' |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
), |
|
|
), |
|
|
) |
|
|
) |
|
|
search_fields = ('pseudo',) |
|
|
search_fields = ('pseudo',) |
|
|
ordering = ('pseudo',) |
|
|
ordering = ('pseudo',) |
|
|
filter_horizontal = () |
|
|
filter_horizontal = () |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ServiceUserAdmin(VersionAdmin, BaseUserAdmin): |
|
|
class ServiceUserAdmin(VersionAdmin, BaseUserAdmin): |
|
|
|
|
|
"""Gestion d'un service user admin : champs personnels, |
|
|
|
|
|
mot de passe; etc""" |
|
|
# The forms to add and change user instances |
|
|
# The forms to add and change user instances |
|
|
form = ServiceUserChangeForm |
|
|
form = ServiceUserChangeForm |
|
|
add_form = ServiceUserCreationForm |
|
|
add_form = ServiceUserCreationForm |
|
|
@ -131,15 +190,19 @@ class ServiceUserAdmin(VersionAdmin, BaseUserAdmin): |
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin |
|
|
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin |
|
|
# overrides get_fieldsets to use this attribute when creating a user. |
|
|
# overrides get_fieldsets to use this attribute when creating a user. |
|
|
add_fieldsets = ( |
|
|
add_fieldsets = ( |
|
|
(None, { |
|
|
( |
|
|
'classes': ('wide',), |
|
|
None, |
|
|
'fields': ('pseudo', 'password1', 'password2')} |
|
|
{ |
|
|
|
|
|
'classes': ('wide',), |
|
|
|
|
|
'fields': ('pseudo', 'password1', 'password2') |
|
|
|
|
|
} |
|
|
), |
|
|
), |
|
|
) |
|
|
) |
|
|
search_fields = ('pseudo',) |
|
|
search_fields = ('pseudo',) |
|
|
ordering = ('pseudo',) |
|
|
ordering = ('pseudo',) |
|
|
filter_horizontal = () |
|
|
filter_horizontal = () |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
admin.site.register(User, UserAdmin) |
|
|
admin.site.register(User, UserAdmin) |
|
|
admin.site.register(ServiceUser, ServiceUserAdmin) |
|
|
admin.site.register(ServiceUser, ServiceUserAdmin) |
|
|
admin.site.register(LdapUser, LdapUserAdmin) |
|
|
admin.site.register(LdapUser, LdapUserAdmin) |
|
|
|