8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-09-21 01:04:07 +00:00

Translation of user app views + remove trailing spaces

This commit is contained in:
Gabriel Detraz 2020-06-01 17:28:48 +02:00 committed by chirac
parent c709a7e8b2
commit b022c98a1c
2 changed files with 662 additions and 149 deletions

View file

@ -27,13 +27,30 @@
# Lara Kermarec, Gabriel Détraz, Lemesle Augustin # Lara Kermarec, Gabriel Détraz, Lemesle Augustin
# Gplv2 # Gplv2
""" """
Module des views. Django users views module.
On définit les vues pour l'ajout, l'edition des users : infos personnelles, Here are defined all functions of views, for the users re2o application. This views
mot de passe, etc allow both edition, creation, deletion and diplay of users objects.
Here are view that allow the addition/deletion/edition of:
* Users (Club/Adherent) and derived settings like EmailSettings of users
* School
* Bans
* Whitelist
* Shell
* ServiceUser
Also add extra views for :
* Ask for reset password by email
* Ask for new email for email confirmation
* Register room and interface on user account with switch web redirection.
All the view must be as simple as possible, with returning the correct form to user during
get, and during post, performing change in database with simple ".save()" function.
The aim is to put all "intelligent" functions in both forms and models functions. In fact, this
will allow to user other frontend (like REST api) to perform editions, creations, etc on database,
without code duplication.
Permet aussi l'ajout, edition et suppression des droits, des bannissements,
des whitelist, des services users et des écoles
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
@ -117,8 +134,17 @@ import os
@can_create(Adherent) @can_create(Adherent)
def new_user(request): def new_user(request):
""" Vue de création d'un nouvel utilisateur, """View for new Adherent/User form creation.
envoie un mail pour le mot de passe""" Then, send an email to the new user, and also if needed to
set its password.
Parameters:
request (django request): Standard django request.
Returns:
Django User form.
"""
user = AdherentCreationForm(request.POST or None, request.FILES or None, user=request.user) user = AdherentCreationForm(request.POST or None, request.FILES or None, user=request.user)
user.request = request user.request = request
@ -167,8 +193,17 @@ def new_user(request):
@login_required @login_required
@can_create(Club) @can_create(Club)
def new_club(request): def new_club(request):
""" Vue de création d'un nouveau club, """View for new Club/User form creation.
envoie un mail pour le mot de passe""" Then, send an email to the new user, and also if needed to
set its password.
Parameters:
request (django request): Standard django request.
Returns:
Django User form.
"""
club = ClubForm(request.POST or None, request.FILES or None, user=request.user) club = ClubForm(request.POST or None, request.FILES or None, user=request.user)
club.request = request club.request = request
@ -192,8 +227,16 @@ def new_club(request):
@login_required @login_required
@can_edit(Club) @can_edit(Club)
def edit_club_admin_members(request, club_instance, **_kwargs): def edit_club_admin_members(request, club_instance, **_kwargs):
"""Vue d'edition de la liste des users administrateurs et """View for editing clubs and administrators.
membres d'un club"""
Parameters:
request (django request): Standard django request.
club_instance: Club instance to edit
Returns:
Django User form.
"""
club = ClubAdminandMembersForm(request.POST or None, request.FILES or None, instance=club_instance) club = ClubAdminandMembersForm(request.POST or None, request.FILES or None, instance=club_instance)
if club.is_valid(): if club.is_valid():
if club.changed_data: if club.changed_data:
@ -212,9 +255,17 @@ def edit_club_admin_members(request, club_instance, **_kwargs):
@login_required @login_required
@can_edit(User) @can_edit(User)
def edit_info(request, user, userid): def edit_info(request, user, userid):
""" Edite un utilisateur à partir de son id, """View for editing base user informations.
si l'id est différent de request.user, vérifie la Perform an acl check on user instance.
possession du droit cableur """
Parameters:
request (django request): Standard django request.
user: User instance to edit
Returns:
Django User form.
"""
if user.is_class_adherent: if user.is_class_adherent:
user_form = AdherentEditForm( user_form = AdherentEditForm(
request.POST or None, request.FILES or None, instance=user.adherent, user=request.user request.POST or None, request.FILES or None, instance=user.adherent, user=request.user
@ -246,7 +297,18 @@ def edit_info(request, user, userid):
@login_required @login_required
@can_edit(User, "state") @can_edit(User, "state")
def state(request, user, userid): def state(request, user, userid):
""" Change the state (active/unactive/archived) of a user""" """View for editing state of user.
Perform an acl check on user instance, and check if editing user
has state edition permission.
Parameters:
request (django request): Standard django request.
user: User instance to edit
Returns:
Django User form.
"""
state_form = StateForm(request.POST or None, instance=user) state_form = StateForm(request.POST or None, instance=user)
if state_form.is_valid(): if state_form.is_valid():
if state_form.changed_data: if state_form.changed_data:
@ -265,7 +327,18 @@ def state(request, user, userid):
@login_required @login_required
@can_edit(User, "groups") @can_edit(User, "groups")
def groups(request, user, userid): def groups(request, user, userid):
""" View to edit the groups of a user """ """View for editing groups of user.
Perform an acl check on user instance, and check if editing user
has groups edition permission.
Parameters:
request (django request): Standard django request.
user: User instance to edit
Returns:
Django User form.
"""
group_form = GroupForm(request.POST or None, instance=user, user=request.user) group_form = GroupForm(request.POST or None, instance=user, user=request.user)
if group_form.is_valid(): if group_form.is_valid():
if group_form.changed_data: if group_form.changed_data:
@ -280,9 +353,20 @@ def groups(request, user, userid):
@login_required @login_required
@can_edit(User, "password") @can_edit(User, "password")
def password(request, user, userid): def password(request, user, userid):
""" Reinitialisation d'un mot de passe à partir de l'userid, """View for editing password of user.
pour self par défaut, pour tous sans droit si droit cableur, Perform an acl check on user instance, and check if editing user
pour tous si droit bureau """ has password edition permission.
If User instance is in critical groups, the edition requires extra
permission.
Parameters:
request (django request): Standard django request.
user: User instance to edit password
Returns:
Django User form.
"""
u_form = PassForm(request.POST or None, instance=user, user=request.user) u_form = PassForm(request.POST or None, instance=user, user=request.user)
if u_form.is_valid(): if u_form.is_valid():
if u_form.changed_data: if u_form.changed_data:
@ -299,7 +383,20 @@ def password(request, user, userid):
@login_required @login_required
@can_edit(User, "groups") @can_edit(User, "groups")
def del_group(request, user, listrightid, **_kwargs): def del_group(request, user, listrightid, **_kwargs):
""" View used to delete a group """ """View for editing groups of user.
Perform an acl check on user instance, and check if editing user
has groups edition permission.
If User instance is in critical groups, the edition requires extra
permission.
Parameters:
request (django request): Standard django request.
user: User instance to edit groups
Returns:
Django User form.
"""
user.groups.remove(ListRight.objects.get(id=listrightid)) user.groups.remove(ListRight.objects.get(id=listrightid))
user.save() user.save()
messages.success(request, _("%s was removed from the group.") % user) messages.success(request, _("%s was removed from the group.") % user)
@ -309,7 +406,18 @@ def del_group(request, user, listrightid, **_kwargs):
@login_required @login_required
@can_edit(User, "is_superuser") @can_edit(User, "is_superuser")
def del_superuser(request, user, **_kwargs): def del_superuser(request, user, **_kwargs):
"""Remove the superuser right of an user.""" """View for editing superuser attribute of user.
Perform an acl check on user instance, and check if editing user
has edition of superuser flag on target user.
Parameters:
request (django request): Standard django request.
user: User instance to edit superuser flag.
Returns:
Django User form.
"""
user.is_superuser = False user.is_superuser = False
user.save() user.save()
messages.success(request, _("%s is no longer superuser.") % user) messages.success(request, _("%s is no longer superuser.") % user)
@ -319,7 +427,18 @@ def del_superuser(request, user, **_kwargs):
@login_required @login_required
@can_create(ServiceUser) @can_create(ServiceUser)
def new_serviceuser(request): def new_serviceuser(request):
""" Vue de création d'un nouvel utilisateur service""" """View for creation of new serviceuser, for external services on
ldap tree for auth purpose (dokuwiki, owncloud, etc).
Perform an acl check on editing user, and check if editing user
has permission of create new serviceuser.
Parameters:
request (django request): Standard django request.
Returns:
Django ServiceUser form.
"""
user = ServiceUserForm(request.POST or None) user = ServiceUserForm(request.POST or None)
if user.is_valid(): if user.is_valid():
user.save() user.save()
@ -333,7 +452,19 @@ def new_serviceuser(request):
@login_required @login_required
@can_edit(ServiceUser) @can_edit(ServiceUser)
def edit_serviceuser(request, serviceuser, **_kwargs): def edit_serviceuser(request, serviceuser, **_kwargs):
""" Edit a ServiceUser """ """View for edition of serviceuser, for external services on
ldap tree for auth purpose (dokuwiki, owncloud, etc).
Perform an acl check on editing user, and check if editing user
has permission of edit target serviceuser.
Parameters:
request (django request): Standard django request.
serviceuser: ServiceUser instance to edit attributes.
Returns:
Django ServiceUser form.
"""
serviceuser = EditServiceUserForm(request.POST or None, instance=serviceuser) serviceuser = EditServiceUserForm(request.POST or None, instance=serviceuser)
if serviceuser.is_valid(): if serviceuser.is_valid():
if serviceuser.changed_data: if serviceuser.changed_data:
@ -348,7 +479,19 @@ def edit_serviceuser(request, serviceuser, **_kwargs):
@login_required @login_required
@can_delete(ServiceUser) @can_delete(ServiceUser)
def del_serviceuser(request, serviceuser, **_kwargs): def del_serviceuser(request, serviceuser, **_kwargs):
"""Suppression d'un ou plusieurs serviceusers""" """View for removing serviceuser, for external services on
ldap tree for auth purpose (dokuwiki, owncloud, etc).
Perform an acl check on editing user, and check if editing user
has permission of deleting target serviceuser.
Parameters:
request (django request): Standard django request.
serviceuser: ServiceUser instance to delete.
Returns:
Django ServiceUser form.
"""
if request.method == "POST": if request.method == "POST":
serviceuser.delete() serviceuser.delete()
messages.success(request, _("The service user was deleted.")) messages.success(request, _("The service user was deleted."))
@ -364,9 +507,19 @@ def del_serviceuser(request, serviceuser, **_kwargs):
@can_create(Ban) @can_create(Ban)
@can_edit(User) @can_edit(User)
def add_ban(request, user, userid): def add_ban(request, user, userid):
""" Ajouter un banissement, nécessite au moins le droit bofh """View for adding a ban object for user instance.
(a fortiori bureau) Perform an acl check on editing user, and check if editing user
Syntaxe : JJ/MM/AAAA , heure optionnelle, prend effet immédiatement""" has permission of adding a ban on target user, add_ban.
Syntaxe: DD/MM/AAAA, the ban takes an immediate effect.
Parameters:
request (django request): Standard django request.
user: User instance to add a ban.
Returns:
Django Ban form.
"""
ban_instance = Ban(user=user) ban_instance = Ban(user=user)
ban = BanForm(request.POST or None, instance=ban_instance) ban = BanForm(request.POST or None, instance=ban_instance)
ban.request = request ban.request = request
@ -383,9 +536,19 @@ def add_ban(request, user, userid):
@login_required @login_required
@can_edit(Ban) @can_edit(Ban)
def edit_ban(request, ban_instance, **_kwargs): def edit_ban(request, ban_instance, **_kwargs):
""" Editer un bannissement, nécessite au moins le droit bofh """View for editing a ban object for user instance.
(a fortiori bureau) Perform an acl check on editing user, and check if editing user
Syntaxe : JJ/MM/AAAA , heure optionnelle, prend effet immédiatement""" has permission of editing a ban on target user, edit_ban.
Syntaxe: DD/MM/AAAA, the ban takes an immediate effect.
Parameters:
request (django request): Standard django request.
ban: Ban instance to edit.
Returns:
Django Ban form.
"""
ban = BanForm(request.POST or None, instance=ban_instance) ban = BanForm(request.POST or None, instance=ban_instance)
ban.request = request ban.request = request
@ -400,7 +563,18 @@ def edit_ban(request, ban_instance, **_kwargs):
@login_required @login_required
@can_delete(Ban) @can_delete(Ban)
def del_ban(request, ban, **_kwargs): def del_ban(request, ban, **_kwargs):
""" Supprime un banissement""" """View for removing a ban object for user instance.
Perform an acl check on editing user, and check if editing user
has permission of deleting a ban on target user, del_ban.
Parameters:
request (django request): Standard django request.
ban: Ban instance to delete.
Returns:
Django Ban form.
"""
if request.method == "POST": if request.method == "POST":
ban.delete() ban.delete()
messages.success(request, _("The ban was deleted.")) messages.success(request, _("The ban was deleted."))
@ -412,10 +586,19 @@ def del_ban(request, ban, **_kwargs):
@can_create(Whitelist) @can_create(Whitelist)
@can_edit(User) @can_edit(User)
def add_whitelist(request, user, userid): def add_whitelist(request, user, userid):
""" Accorder un accès gracieux, temporaire ou permanent. """View for adding a whitelist object for user instance.
Need droit cableur Perform an acl check on editing user, and check if editing user
Syntaxe : JJ/MM/AAAA , heure optionnelle, prend effet immédiatement, has permission of adding a wheitelist on target user, add_whitelist.
raison obligatoire""" Syntaxe: DD/MM/AAAA, the whitelist takes an immediate effect.
Parameters:
request (django request): Standard django request.
user: User instance to add a whitelist.
Returns:
Django Whitelist form.
"""
whitelist_instance = Whitelist(user=user) whitelist_instance = Whitelist(user=user)
whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance) whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance)
if whitelist.is_valid(): if whitelist.is_valid():
@ -434,10 +617,19 @@ def add_whitelist(request, user, userid):
@login_required @login_required
@can_edit(Whitelist) @can_edit(Whitelist)
def edit_whitelist(request, whitelist_instance, **_kwargs): def edit_whitelist(request, whitelist_instance, **_kwargs):
""" Editer un accès gracieux, temporaire ou permanent. """View for editing a whitelist object for user instance.
Need droit cableur Perform an acl check on editing user, and check if editing user
Syntaxe : JJ/MM/AAAA , heure optionnelle, prend effet immédiatement, has permission of editing a whitelist on target user, edit_whitelist.
raison obligatoire""" Syntaxe: DD/MM/AAAA, the whitelist takes an immediate effect.
Parameters:
request (django request): Standard django request.
whitelist: whitelist instance to edit.
Returns:
Django Whitelist form.
"""
whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance) whitelist = WhitelistForm(request.POST or None, instance=whitelist_instance)
if whitelist.is_valid(): if whitelist.is_valid():
if whitelist.changed_data: if whitelist.changed_data:
@ -452,7 +644,18 @@ def edit_whitelist(request, whitelist_instance, **_kwargs):
@login_required @login_required
@can_delete(Whitelist) @can_delete(Whitelist)
def del_whitelist(request, whitelist, **_kwargs): def del_whitelist(request, whitelist, **_kwargs):
""" Supprime un acces gracieux""" """View for removing a whitelist object for user instance.
Perform an acl check on editing user, and check if editing user
has permission of deleting a whitelist on target user, del_whitelist.
Parameters:
request (django request): Standard django request.
whitelist: Whitelist instance to delete.
Returns:
Django Whitelist form.
"""
if request.method == "POST": if request.method == "POST":
whitelist.delete() whitelist.delete()
messages.success(request, _("The whitelist was deleted.")) messages.success(request, _("The whitelist was deleted."))
@ -468,7 +671,18 @@ def del_whitelist(request, whitelist, **_kwargs):
@can_create(EMailAddress) @can_create(EMailAddress)
@can_edit(User) @can_edit(User)
def add_emailaddress(request, user, userid): def add_emailaddress(request, user, userid):
""" Create a new local email account""" """View for adding an emailaddress object for user instance.
Perform an acl check on editing user, and check if editing user
has permission of adding an emailaddress on target user.
Parameters:
request (django request): Standard django request.
user: User instance to add an emailaddress.
Returns:
Django EmailAddress form.
"""
emailaddress_instance = EMailAddress(user=user) emailaddress_instance = EMailAddress(user=user)
emailaddress = EMailAddressForm( emailaddress = EMailAddressForm(
request.POST or None, instance=emailaddress_instance request.POST or None, instance=emailaddress_instance
@ -487,7 +701,18 @@ def add_emailaddress(request, user, userid):
@login_required @login_required
@can_edit(EMailAddress) @can_edit(EMailAddress)
def edit_emailaddress(request, emailaddress_instance, **_kwargs): def edit_emailaddress(request, emailaddress_instance, **_kwargs):
""" Edit a local email account""" """View for edit an emailaddress object for user instance.
Perform an acl check on editing user, and check if editing user
has permission of editing an emailaddress on target user.
Parameters:
request (django request): Standard django request.
emailaddress: Emailaddress to edit.
Returns:
Django EmailAddress form.
"""
emailaddress = EMailAddressForm( emailaddress = EMailAddressForm(
request.POST or None, instance=emailaddress_instance request.POST or None, instance=emailaddress_instance
) )
@ -510,7 +735,18 @@ def edit_emailaddress(request, emailaddress_instance, **_kwargs):
@login_required @login_required
@can_delete(EMailAddress) @can_delete(EMailAddress)
def del_emailaddress(request, emailaddress, **_kwargs): def del_emailaddress(request, emailaddress, **_kwargs):
"""Delete a local email account""" """View for deleting an emailaddress object for user instance.
Perform an acl check on editing user, and check if editing user
has permission of deleting an emailaddress on target user.
Parameters:
request (django request): Standard django request.
emailaddress: Emailaddress to delete.
Returns:
Django EmailAddress form.
"""
if request.method == "POST": if request.method == "POST":
emailaddress.delete() emailaddress.delete()
messages.success(request, _("The local email account was deleted.")) messages.success(request, _("The local email account was deleted."))
@ -527,7 +763,18 @@ def del_emailaddress(request, emailaddress, **_kwargs):
@login_required @login_required
@can_edit(User) @can_edit(User)
def edit_email_settings(request, user_instance, **_kwargs): def edit_email_settings(request, user_instance, **_kwargs):
"""Edit the email settings of a user""" """View for editing User's emailaddress settings for user instance.
Perform an acl check on editing user, and check if editing user
has permission of editing email settings on target user.
Parameters:
request (django request): Standard django request.
user: User instance to edit email settings.
Returns:
Django User form.
"""
email_settings = EmailSettingsForm( email_settings = EmailSettingsForm(
request.POST or None, instance=user_instance, user=request.user request.POST or None, instance=user_instance, user=request.user
) )
@ -559,8 +806,17 @@ def edit_email_settings(request, user_instance, **_kwargs):
@login_required @login_required
@can_create(School) @can_create(School)
def add_school(request): def add_school(request):
""" Ajouter un établissement d'enseignement à la base de donnée, """View for adding a new school object.
need cableur""" Perform an acl check on editing user, and check if editing user
has permission of adding a new school, add_school.
Parameters:
request (django request): Standard django request.
Returns:
Django School form.
"""
school = SchoolForm(request.POST or None) school = SchoolForm(request.POST or None)
if school.is_valid(): if school.is_valid():
school.save() school.save()
@ -574,8 +830,18 @@ def add_school(request):
@login_required @login_required
@can_edit(School) @can_edit(School)
def edit_school(request, school_instance, **_kwargs): def edit_school(request, school_instance, **_kwargs):
""" Editer un établissement d'enseignement à partir du schoolid dans """View for editing a school instance object.
la base de donnée, need cableur""" Perform an acl check on editing user, and check if editing user
has permission of editing a school, edit_school.
Parameters:
request (django request): Standard django request.
school_instance: school instance to edit.
Returns:
Django School form.
"""
school = SchoolForm(request.POST or None, instance=school_instance) school = SchoolForm(request.POST or None, instance=school_instance)
if school.is_valid(): if school.is_valid():
if school.changed_data: if school.changed_data:
@ -590,10 +856,20 @@ def edit_school(request, school_instance, **_kwargs):
@login_required @login_required
@can_delete_set(School) @can_delete_set(School)
def del_school(request, instances): def del_school(request, instances):
""" Supprimer un établissement d'enseignement à la base de donnée, """View for deleting a school instance object.
need cableur Perform an acl check on editing user, and check if editing user
Objet protégé, possible seulement si aucun user n'est affecté à has permission of deleting a school, del_school.
l'établissement """ A school can be deleted only if it is not assigned to a user (mode
protect).
Parameters:
request (django request): Standard django request.
school_instance: school instance to delete.
Returns:
Django School form.
"""
school = DelSchoolForm(request.POST or None, instances=instances) school = DelSchoolForm(request.POST or None, instances=instances)
if school.is_valid(): if school.is_valid():
school_dels = school.cleaned_data["schools"] school_dels = school.cleaned_data["schools"]
@ -619,7 +895,17 @@ def del_school(request, instances):
@login_required @login_required
@can_create(ListShell) @can_create(ListShell)
def add_shell(request): def add_shell(request):
""" Ajouter un shell à la base de donnée""" """View for adding a new linux shell object.
Perform an acl check on editing user, and check if editing user
has permission of adding a new shell, add_school.
Parameters:
request (django request): Standard django request.
Returns:
Django Shell form.
"""
shell = ShellForm(request.POST or None) shell = ShellForm(request.POST or None)
if shell.is_valid(): if shell.is_valid():
shell.save() shell.save()
@ -633,7 +919,18 @@ def add_shell(request):
@login_required @login_required
@can_edit(ListShell) @can_edit(ListShell)
def edit_shell(request, shell_instance, **_kwargs): def edit_shell(request, shell_instance, **_kwargs):
""" Editer un shell à partir du listshellid""" """View for editing a shell instance object.
Perform an acl check on editing user, and check if editing user
has permission of editing a shell, edit_shell.
Parameters:
request (django request): Standard django request.
shell_instance: shell instance to edit.
Returns:
Django Shell form.
"""
shell = ShellForm(request.POST or None, instance=shell_instance) shell = ShellForm(request.POST or None, instance=shell_instance)
if shell.is_valid(): if shell.is_valid():
if shell.changed_data: if shell.changed_data:
@ -648,7 +945,20 @@ def edit_shell(request, shell_instance, **_kwargs):
@login_required @login_required
@can_delete(ListShell) @can_delete(ListShell)
def del_shell(request, shell, **_kwargs): def del_shell(request, shell, **_kwargs):
"""Destruction d'un shell""" """View for deleting a shell instance object.
Perform an acl check on editing user, and check if editing user
has permission of deleting a shell, del_shell.
A shell can be deleted only if it is not assigned to a user (mode
protect).
Parameters:
request (django request): Standard django request.
shell_instance: shell instance to delete.
Returns:
Django Shell form.
"""
if request.method == "POST": if request.method == "POST":
shell.delete() shell.delete()
messages.success(request, _("The shell was deleted.")) messages.success(request, _("The shell was deleted."))
@ -661,8 +971,18 @@ def del_shell(request, shell, **_kwargs):
@login_required @login_required
@can_create(ListRight) @can_create(ListRight)
def add_listright(request): def add_listright(request):
""" Ajouter un droit/groupe, nécessite droit bureau. """View for adding a new group of rights and users (listright linked to groups)
Obligation de fournir un gid pour la synchro ldap, unique """ object for user instance.
Perform an acl check on editing user, and check if editing user
has permission of adding a new listright.
Parameters:
request (django request): Standard django request.
Returns:
Django ListRight form.
"""
listright = NewListRightForm(request.POST or None) listright = NewListRightForm(request.POST or None)
if listright.is_valid(): if listright.is_valid():
listright.save() listright.save()
@ -678,8 +998,18 @@ def add_listright(request):
@login_required @login_required
@can_edit(ListRight) @can_edit(ListRight)
def edit_listright(request, listright_instance, **_kwargs): def edit_listright(request, listright_instance, **_kwargs):
""" Editer un groupe/droit, necessite droit bureau, """View for editing a listright instance object.
à partir du listright id """ Perform an acl check on editing user, and check if editing user
has permission of editing a listright, edit_listright.
Parameters:
request (django request): Standard django request.
listright_instance: listright instance to edit.
Returns:
Django ListRight form.
"""
listright_form = ListRightForm(request.POST or None, instance=listright_instance) listright_form = ListRightForm(request.POST or None, instance=listright_instance)
if listright_form.is_valid(): if listright_form.is_valid():
if listright_form.changed_data: if listright_form.changed_data:
@ -701,8 +1031,20 @@ def edit_listright(request, listright_instance, **_kwargs):
@login_required @login_required
@can_delete_set(ListRight) @can_delete_set(ListRight)
def del_listright(request, instances): def del_listright(request, instances):
""" Supprimer un ou plusieurs groupe, possible si il est vide, need droit """View for deleting a listright instance object.
bureau """ Perform an acl check on editing user, and check if editing user
has permission of deleting a listright, del_listright.
A listright/group can be deleted only if it is empty (mode
protect).
Parameters:
request (django request): Standard django request.
listright_instance: listright instance to delete.
Returns:
Django ListRight form.
"""
listright = DelListRightForm(request.POST or None, instances=instances) listright = DelListRightForm(request.POST or None, instances=instances)
if listright.is_valid(): if listright.is_valid():
listright_dels = listright.cleaned_data["listrights"] listright_dels = listright.cleaned_data["listrights"]
@ -729,7 +1071,17 @@ def del_listright(request, instances):
@can_view_all(User) @can_view_all(User)
@can_change(User, "state") @can_change(User, "state")
def mass_archive(request): def mass_archive(request):
""" Permet l'archivage massif""" """View for performing a mass archive operation.
Check if editing User has the acl for globaly changing "State"
flag on users, and can edit all the users.
Parameters:
request (django request): Standard django request.
Returns:
Django User form.
"""
pagination_number = GeneralOption.get_cached_value("pagination_number") pagination_number = GeneralOption.get_cached_value("pagination_number")
to_archive_form = MassArchiveForm(request.POST or None) to_archive_form = MassArchiveForm(request.POST or None)
to_archive_list = [] to_archive_list = []
@ -764,7 +1116,16 @@ def mass_archive(request):
@login_required @login_required
@can_view_all(Adherent) @can_view_all(Adherent)
def index(request): def index(request):
""" Affiche l'ensemble des adherents, need droit cableur """ """View for displaying the paginated list of all users/adherents in re2o.
Need the global acl for viewing all users, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django Adherent Form.
"""
pagination_number = GeneralOption.get_cached_value("pagination_number") pagination_number = GeneralOption.get_cached_value("pagination_number")
users_list = Adherent.objects.select_related("room") users_list = Adherent.objects.select_related("room")
users_list = SortTable.sort( users_list = SortTable.sort(
@ -780,7 +1141,16 @@ def index(request):
@login_required @login_required
@can_view_all(Club) @can_view_all(Club)
def index_clubs(request): def index_clubs(request):
""" Affiche l'ensemble des clubs, need droit cableur """ """View for displaying the paginated list of all users/clubs in re2o.
Need the global acl for viewing all users, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django Adherent Form.
"""
pagination_number = GeneralOption.get_cached_value("pagination_number") pagination_number = GeneralOption.get_cached_value("pagination_number")
clubs_list = Club.objects.select_related("room") clubs_list = Club.objects.select_related("room")
clubs_list = SortTable.sort( clubs_list = SortTable.sort(
@ -796,7 +1166,16 @@ def index_clubs(request):
@login_required @login_required
@can_view_all(Ban) @can_view_all(Ban)
def index_ban(request): def index_ban(request):
""" Affiche l'ensemble des ban, need droit cableur """ """View for displaying the paginated list of all bans in re2o.
Need the global acl for viewing all bans, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django Ban Form.
"""
pagination_number = GeneralOption.get_cached_value("pagination_number") pagination_number = GeneralOption.get_cached_value("pagination_number")
ban_list = Ban.objects.select_related("user") ban_list = Ban.objects.select_related("user")
ban_list = SortTable.sort( ban_list = SortTable.sort(
@ -812,7 +1191,16 @@ def index_ban(request):
@login_required @login_required
@can_view_all(Whitelist) @can_view_all(Whitelist)
def index_white(request): def index_white(request):
""" Affiche l'ensemble des whitelist, need droit cableur """ """View for displaying the paginated list of all whitelists in re2o.
Need the global acl for viewing all whitelists, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django Whitelist Form.
"""
pagination_number = GeneralOption.get_cached_value("pagination_number") pagination_number = GeneralOption.get_cached_value("pagination_number")
white_list = Whitelist.objects.select_related("user") white_list = Whitelist.objects.select_related("user")
white_list = SortTable.sort( white_list = SortTable.sort(
@ -828,7 +1216,16 @@ def index_white(request):
@login_required @login_required
@can_view_all(School) @can_view_all(School)
def index_school(request): def index_school(request):
""" Affiche l'ensemble des établissement""" """View for displaying the paginated list of all schools in re2o.
Need the global acl for viewing all schools, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django School Form.
"""
school_list = School.objects.order_by("name") school_list = School.objects.order_by("name")
pagination_number = GeneralOption.get_cached_value("pagination_number") pagination_number = GeneralOption.get_cached_value("pagination_number")
school_list = SortTable.sort( school_list = SortTable.sort(
@ -844,7 +1241,16 @@ def index_school(request):
@login_required @login_required
@can_view_all(ListShell) @can_view_all(ListShell)
def index_shell(request): def index_shell(request):
""" Affiche l'ensemble des shells""" """View for displaying the paginated list of all shells in re2o.
Need the global acl for viewing all shells, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django Shell Form.
"""
shell_list = ListShell.objects.order_by("shell") shell_list = ListShell.objects.order_by("shell")
return render(request, "users/index_shell.html", {"shell_list": shell_list}) return render(request, "users/index_shell.html", {"shell_list": shell_list})
@ -852,7 +1258,17 @@ def index_shell(request):
@login_required @login_required
@can_view_all(ListRight) @can_view_all(ListRight)
def index_listright(request): def index_listright(request):
""" Affiche l'ensemble des droits""" """View for displaying the listrights/groups list in re2o.
The listrights are sorted by members users, and individual
acl for a complete display.
Parameters:
request (django request): Standard django request.
Returns:
Django ListRight Form.
"""
rights = {} rights = {}
for right in ( for right in (
ListRight.objects.order_by("name") ListRight.objects.order_by("name")
@ -875,7 +1291,17 @@ def index_listright(request):
@login_required @login_required
@can_view_all(ServiceUser) @can_view_all(ServiceUser)
def index_serviceusers(request): def index_serviceusers(request):
""" Affiche les users de services (pour les accès ldap)""" """View for displaying the paginated list of all serviceusers in re2o
See ServiceUser model for more informations on service users.
Need the global acl for viewing all serviceusers, can_view_all.
Parameters:
request (django request): Standard django request.
Returns:
Django ServiceUser Form.
"""
serviceusers_list = ServiceUser.objects.order_by("pseudo") serviceusers_list = ServiceUser.objects.order_by("pseudo")
return render( return render(
request, request,
@ -886,14 +1312,42 @@ def index_serviceusers(request):
@login_required @login_required
def mon_profil(request): def mon_profil(request):
""" Lien vers profil, renvoie request.id à la fonction """ """Shortcuts view to profil view, with correct arguments.
Returns the view profil with users argument, users is set to
default request.user.
Parameters:
request (django request): Standard django request.
Returns:
Django User Profil Form.
"""
return redirect(reverse("users:profil", kwargs={"userid": str(request.user.id)})) return redirect(reverse("users:profil", kwargs={"userid": str(request.user.id)}))
@login_required @login_required
@can_view(User) @can_view(User)
def profil(request, users, **_kwargs): def profil(request, users, **_kwargs):
""" Affiche un profil, self or cableur, prend un userid en argument """ """Profil view. Display informations on users, the single user.
Informations displayed are:
* Adherent or Club User instance informations
* Interface/Machine belonging to User instance
* Invoice belonging to User instance
* Ban instances belonging to User
* Whitelists instances belonging to User
* Email Settings of User instance
* Tickets belonging to User instance.
Requires the acl can_view on user instance.
Parameters:
request (django request): Standard django request.
users: User instance to display profil
Returns:
Django User Profil Form.
"""
machines = ( machines = (
Machine.objects.filter(user=users) Machine.objects.filter(user=users)
.select_related("user") .select_related("user")
@ -969,7 +1423,17 @@ def profil(request, users, **_kwargs):
def reset_password(request): def reset_password(request):
""" Reintialisation du mot de passe si mdp oublié """ """Reset password form, linked to form forgotten password.
If an user is found, send an email to him with a link
to reset its password.
Parameters:
request (django request): Standard django request.
Returns:
Django ResetPassword Form.
"""
userform = ResetPasswordForm(request.POST or None) userform = ResetPasswordForm(request.POST or None)
if userform.is_valid(): if userform.is_valid():
try: try:
@ -994,8 +1458,17 @@ def reset_password(request):
def process(request, token): def process(request, token):
"""Process, lien pour la reinitialisation du mot de passe """Process view, in case of both reset password, or confirm email in case
et la confirmation de l'email""" of new email set.
This view calls process_passwd or process_email.
Parameters:
request (django request): Standard django request.
Returns:
Correct Django process Form.
"""
valid_reqs = Request.objects.filter(expires_at__gt=timezone.now()) valid_reqs = Request.objects.filter(expires_at__gt=timezone.now())
req = get_object_or_404(valid_reqs, token=token) req = get_object_or_404(valid_reqs, token=token)
@ -1009,8 +1482,16 @@ def process(request, token):
def process_passwd(request, req): def process_passwd(request, req):
"""Process le changeemnt de mot de passe, renvoie le formulaire """Process view, in case of reset password by email. Returns
demandant le nouveau password""" a form to change and reset the password.
Parameters:
request (django request): Standard django request.
Returns:
Correct Django process password Form.
"""
user = req.user user = req.user
u_form = PassForm(request.POST or None, instance=user, user=request.user) u_form = PassForm(request.POST or None, instance=user, user=request.user)
if u_form.is_valid(): if u_form.is_valid():
@ -1031,8 +1512,17 @@ def process_passwd(request, req):
def process_email(request, req): def process_email(request, req):
"""Process la confirmation de mail, renvoie le formulaire """Process view, in case of confirm a new email. Returns
de validation""" a form to notify the success of the email confirmation to
request.User.
Parameters:
request (django request): Standard django request.
Returns:
Correct Django process email Form.
"""
user = req.user user = req.user
if request.method == "POST": if request.method == "POST":
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -1055,7 +1545,16 @@ def process_email(request, req):
@login_required @login_required
@can_edit(User) @can_edit(User)
def resend_confirmation_email(request, logged_user, userid): def resend_confirmation_email(request, logged_user, userid):
""" Renvoi du mail de confirmation """ """View to resend confirm email, for adding a new email.
Check if User has the correct acl.
Parameters:
request (django request): Standard django request.
Returns:
Correct Django resend email Form.
"""
try: try:
user = User.objects.get( user = User.objects.get(
id=userid, id=userid,
@ -1074,6 +1573,20 @@ def resend_confirmation_email(request, logged_user, userid):
@login_required @login_required
def initial_register(request): def initial_register(request):
"""View to register both a new room, and a new interface/machine for a user.
This view is used with switchs function of redirect web after AAA authentication
failed. Then, the users log-in, and the new mac-address and switch port, in order to
get the room, are included in HTTP Headers by the switch redirection functionnality.
This allow to add the new interface with the correct mac-address, and confirm if needed,
the new room of request.user.
Parameters:
request (django request): Standard django request.
Returns:
Initial room and interface/machine register Form.
"""
switch_ip = request.GET.get("switch_ip", None) switch_ip = request.GET.get("switch_ip", None)
switch_port = request.GET.get("switch_port", None) switch_port = request.GET.get("switch_port", None)
client_mac = request.GET.get("client_mac", None) client_mac = request.GET.get("client_mac", None)