8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-23 11:53:12 +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
parent 564851feda
commit 7824083a55
2 changed files with 662 additions and 149 deletions

View file

@ -100,7 +100,7 @@ from PIL import Image
from io import BytesIO from io import BytesIO
import sys import sys
# General utilities # General utilities
def linux_user_check(login): def linux_user_check(login):
"""Check if a login comply with unix base login policy """Check if a login comply with unix base login policy
@ -109,7 +109,7 @@ def linux_user_check(login):
login (string): Login to check login (string): Login to check
Returns: Returns:
boolean: True if login comply with policy boolean: True if login comply with policy
""" """
UNIX_LOGIN_PATTERN = re.compile("^[a-z][a-z0-9-]*[$]?$") UNIX_LOGIN_PATTERN = re.compile("^[a-z][a-z0-9-]*[$]?$")
return UNIX_LOGIN_PATTERN.match(login) return UNIX_LOGIN_PATTERN.match(login)
@ -123,7 +123,7 @@ def linux_user_validator(login):
login (string): Login to check login (string): Login to check
Returns: Returns:
ValidationError if login comply with policy ValidationError if login comply with policy
""" """
if not linux_user_check(login): if not linux_user_check(login):
raise forms.ValidationError( raise forms.ValidationError(
@ -307,7 +307,7 @@ class User(
) )
email_change_date = models.DateTimeField(auto_now_add=True) email_change_date = models.DateTimeField(auto_now_add=True)
profile_image = models.ImageField(upload_to='profile_image', blank=True) profile_image = models.ImageField(upload_to='profile_image', blank=True)
USERNAME_FIELD = "pseudo" USERNAME_FIELD = "pseudo"
REQUIRED_FIELDS = ["surname", "email"] REQUIRED_FIELDS = ["surname", "email"]
@ -515,7 +515,7 @@ class User(
@property @property
def is_staff(self): def is_staff(self):
"""Shortcuts, used by django for admin pannel access, shortcuts to """Shortcuts, used by django for admin pannel access, shortcuts to
is_admin. is_admin.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -676,7 +676,7 @@ class User(
self (user instance): user to return infos self (user instance): user to return infos
Returns: Returns:
email_address (django queryset) : Returns a queryset containing email_address (django queryset) : Returns a queryset containing
EMailAddress of this user. EMailAddress of this user.
""" """
if ( if (
@ -690,7 +690,7 @@ class User(
"""Methods, calculate and returns the end of membership value date of """Methods, calculate and returns the end of membership value date of
this user with aggregation of Cotisation objects linked to user this user with aggregation of Cotisation objects linked to user
instance. instance.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -711,7 +711,7 @@ class User(
def end_connexion(self): def end_connexion(self):
"""Methods, calculate and returns the end of connection subscription value date """Methods, calculate and returns the end of connection subscription value date
of this user with aggregation of Cotisation objects linked to user instance. of this user with aggregation of Cotisation objects linked to user instance.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -732,7 +732,7 @@ class User(
def is_adherent(self): def is_adherent(self):
"""Methods, calculate and returns if the user has a valid membership by testing """Methods, calculate and returns if the user has a valid membership by testing
if end_adherent is after now or not. if end_adherent is after now or not.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -751,7 +751,7 @@ class User(
"""Methods, calculate and returns if the user has a valid membership AND a """Methods, calculate and returns if the user has a valid membership AND a
valid connection subscription by testing if end_connexion is after now or not. valid connection subscription by testing if end_connexion is after now or not.
If true, returns is_adherent() method value. If true, returns is_adherent() method value.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -769,7 +769,7 @@ class User(
def end_ban(self): def end_ban(self):
"""Methods, calculate and returns the end of a ban value date """Methods, calculate and returns the end of a ban value date
of this user with aggregation of ban objects linked to user instance. of this user with aggregation of ban objects linked to user instance.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -784,7 +784,7 @@ class User(
def end_whitelist(self): def end_whitelist(self):
"""Methods, calculate and returns the end of a whitelist value date """Methods, calculate and returns the end of a whitelist value date
of this user with aggregation of whitelists objects linked to user instance. of this user with aggregation of whitelists objects linked to user instance.
Parameters: Parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -799,7 +799,7 @@ class User(
def is_ban(self): def is_ban(self):
"""Methods, calculate and returns if the user is banned by testing """Methods, calculate and returns if the user is banned by testing
if end_ban is after now or not. if end_ban is after now or not.
parameters: parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -815,9 +815,9 @@ class User(
return True return True
def is_whitelisted(self): def is_whitelisted(self):
"""Methods, calculate and returns if the user has a whitelist free connection """Methods, calculate and returns if the user has a whitelist free connection
if end_whitelist is after now or not. if end_whitelist is after now or not.
parameters: parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -836,7 +836,7 @@ class User(
"""Methods, returns if the user has an internet access. """Methods, returns if the user has an internet access.
Return True if user is active and has a verified email, is not under a ban Return True if user is active and has a verified email, is not under a ban
decision and has a valid membership and connection or a whitelist. decision and has a valid membership and connection or a whitelist.
parameters: parameters:
self (user instance): user to return infos self (user instance): user to return infos
@ -921,7 +921,7 @@ class User(
Also make an archived user fully active. Also make an archived user fully active.
Parameters: Parameters:
self (user instance): user to set active self (user instance): user to set active
""" """
if self.state == self.STATE_NOT_YET_ACTIVE: if self.state == self.STATE_NOT_YET_ACTIVE:
@ -941,7 +941,7 @@ class User(
hashed, and also the NTLM hashed pwd_ntlm password. hashed, and also the NTLM hashed pwd_ntlm password.
Parameters: Parameters:
self (user instance): user to set password self (user instance): user to set password
password (string): new password (cleatext) to set. password (string): new password (cleatext) to set.
""" """
@ -952,19 +952,19 @@ class User(
return return
def confirm_mail(self): def confirm_mail(self):
"""Method, set the email_state to VERIFIED when the email has been verified. """Method, set the email_state to VERIFIED when the email has been verified.
Parameters: Parameters:
self (user instance): user to set password self (user instance): user to set password
""" """
self.email_state = self.EMAIL_STATE_VERIFIED self.email_state = self.EMAIL_STATE_VERIFIED
def assign_ips(self): def assign_ips(self):
"""Method, assigns ipv4 to all interfaces related to a user. """Method, assigns ipv4 to all interfaces related to a user.
Parameters: Parameters:
self (user instance): user which interfaces have to be assigned self (user instance): user which interfaces have to be assigned
""" """
interfaces = self.user_interfaces() interfaces = self.user_interfaces()
@ -977,7 +977,7 @@ class User(
(set ipv4 field to null) (set ipv4 field to null)
Parameters: Parameters:
self (user instance): user which interfaces have to be assigned self (user instance): user which interfaces have to be assigned
""" """
interfaces = self.user_interfaces() interfaces = self.user_interfaces()
@ -988,11 +988,11 @@ class User(
@classmethod @classmethod
def mass_unassign_ips(cls, users_list): def mass_unassign_ips(cls, users_list):
"""Class method, unassigns and remove ipv4 to all interfaces related """Class method, unassigns and remove ipv4 to all interfaces related
to a list of users. to a list of users.
Parameters: Parameters:
users_list (list of users or queryset): users which interfaces users_list (list of users or queryset): users which interfaces
have to be unassigned have to be unassigned
""" """
interfaces = cls.users_interfaces(users_list) interfaces = cls.users_interfaces(users_list)
@ -1005,7 +1005,7 @@ class User(
an user. an user.
Parameters: Parameters:
self (user instance): user to disabled email. self (user instance): user to disabled email.
""" """
self.local_email_enabled = False self.local_email_enabled = False
@ -1030,7 +1030,7 @@ class User(
Called during full archive process. Called during full archive process.
Parameters: Parameters:
self (user instance): user to delete data. self (user instance): user to delete data.
""" """
self.disable_email() self.disable_email()
@ -1052,10 +1052,10 @@ class User(
cls.ldap_delete_users(queryset_users) cls.ldap_delete_users(queryset_users)
def archive(self): def archive(self):
"""Method, archive user by unassigning ips. """Method, archive user by unassigning ips.
Parameters: Parameters:
self (user instance): user to archive. self (user instance): user to archive.
""" """
self.unassign_ips() self.unassign_ips()
@ -1079,10 +1079,10 @@ class User(
def full_archive(self): def full_archive(self):
"""Method, full archive an user by unassigning ips, deleting data """Method, full archive an user by unassigning ips, deleting data
and ldap deletion. and ldap deletion.
Parameters: Parameters:
self (user instance): user to full archive. self (user instance): user to full archive.
""" """
self.archive() self.archive()
@ -1112,7 +1112,7 @@ class User(
ldap user associated. ldap user associated.
Parameters: Parameters:
self (user instance): user to unarchive. self (user instance): user to unarchive.
""" """
self.assign_ips() self.assign_ips()
@ -1123,7 +1123,7 @@ class User(
on an user when state is changed, based on previous state. on an user when state is changed, based on previous state.
Parameters: Parameters:
self (user instance): user to sync state. self (user instance): user to sync state.
""" """
if ( if (
@ -1149,7 +1149,7 @@ class User(
Each User instance is copy into ldap, via a LdapUser virtual objects. Each User instance is copy into ldap, via a LdapUser virtual objects.
This method performs a copy of several attributes (name, surname, mail, This method performs a copy of several attributes (name, surname, mail,
hashed SSHA password, ntlm password, shell, homedirectory). hashed SSHA password, ntlm password, shell, homedirectory).
Update, or create if needed a ldap entry related with the User instance. Update, or create if needed a ldap entry related with the User instance.
Parameters: Parameters:
@ -1224,7 +1224,7 @@ class User(
"""Method, delete an user in ldap. """Method, delete an user in ldap.
Parameters: Parameters:
self (user instance): user to delete in Ldap. self (user instance): user to delete in Ldap.
""" """
try: try:
@ -1235,7 +1235,7 @@ class User(
@classmethod @classmethod
def ldap_delete_users(cls, queryset_users): def ldap_delete_users(cls, queryset_users):
"""Class method, delete several users in ldap (queryset). """Class method, delete several users in ldap (queryset).
Parameters: Parameters:
queryset_users (list of users queryset): users to delete queryset_users (list of users queryset): users to delete
@ -1377,7 +1377,7 @@ class User(
def confirm_email_before_date(self): def confirm_email_before_date(self):
"""Method/function, calculate the maximum date for confirmation """Method/function, calculate the maximum date for confirmation
of the new email address of the new email address
Parameters: Parameters:
self (user instance): user to calculate maximum date self (user instance): user to calculate maximum date
for confirmation for confirmation
@ -1448,7 +1448,7 @@ class User(
self (user instance): user to register new interface self (user instance): user to register new interface
mac_address (string): New mac address to add on the new interface mac_address (string): New mac address to add on the new interface
nas_type (Django Nas object instance): The nas object calling nas_type (Django Nas object instance): The nas object calling
request: Optional django request request: Optional django request
Returns: Returns:
interface (Interface instance): The new interface registered interface (Interface instance): The new interface registered
@ -1488,7 +1488,7 @@ class User(
registered on user instance account. registered on user instance account.
Parameters: Parameters:
self (user instance): user to notify new registration self (user instance): user to notify new registration
interface (interface instance): new interface registered interface (interface instance): new interface registered
Returns: Returns:
@ -1519,7 +1519,7 @@ class User(
in case of unconfirmed email address. in case of unconfirmed email address.
Parameters: Parameters:
self (user instance): user to notif disabled decision self (user instance): user to notif disabled decision
request (django request): request to build email request (django request): request to build email
Returns: Returns:
@ -1544,7 +1544,7 @@ class User(
return return
def get_next_domain_name(self): def get_next_domain_name(self):
"""Function/method, provide a unique name for a new interface. """Function/method, provide a unique name for a new interface.
Parameters: Parameters:
self (user instance): user to get a new domain name self (user instance): user to get a new domain name
@ -1818,7 +1818,7 @@ class User(
:param user_request: The user who request :param user_request: The user who request
:returns: a message and a boolean which is True if permission is granted. :returns: a message and a boolean which is True if permission is granted.
""" """
can = user_request.is_superuser can = user_request.is_superuser
return ( return (
@ -1836,7 +1836,7 @@ class User(
:param user_request: The user who ask for viewing the target. :param user_request: The user who ask for viewing the target.
:return: A boolean telling if the acces is granted and an explanation :return: A boolean telling if the acces is granted and an explanation
text text
""" """
if self.is_class_club and user_request.is_class_adherent: if self.is_class_club and user_request.is_class_adherent:
if ( if (
@ -1869,7 +1869,7 @@ class User(
:param user_request: The user who wants to view the list. :param user_request: The user who wants to view the list.
:return: True if the user can view the list and an explanation :return: True if the user can view the list and an explanation
message. message.
""" """
can = user_request.has_perm("users.view_user") can = user_request.has_perm("users.view_user")
return ( return (
@ -1969,7 +1969,7 @@ class User(
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.profile_image: if self.profile_image:
im = Image.open(self.profile_image) im = Image.open(self.profile_image)
output = BytesIO() output = BytesIO()
im = im.resize( (100,100) ) im = im.resize( (100,100) )
@ -1991,7 +1991,7 @@ class Adherent(User):
name: name of the user name: name of the user
room: room of the user room: room of the user
gpg_fingerprint: The gpgfp of the user gpg_fingerprint: The gpgfp of the user
""" """
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
@ -2043,7 +2043,7 @@ class Adherent(User):
:param adherentid: The id of the adherent we are looking for. :param adherentid: The id of the adherent we are looking for.
:return: An adherent. :return: An adherent.
""" """
return cls.objects.get(pk=adherentid) return cls.objects.get(pk=adherentid)
@ -2054,7 +2054,7 @@ class Adherent(User):
:param user_request: The user who wants to create a user object. :param user_request: The user who wants to create a user object.
:return: a message and a boolean which is True if the user can create :return: a message and a boolean which is True if the user can create
a user or if the `options.all_can_create` is set. a user or if the `options.all_can_create` is set.
""" """
if not user_request.is_authenticated: if not user_request.is_authenticated:
if not OptionalUser.get_cached_value( if not OptionalUser.get_cached_value(
@ -2064,7 +2064,7 @@ class Adherent(User):
else: else:
return True, None, None return True, None, None
else: else:
if OptionalUser.get_cached_value("all_can_create_adherent"): if OptionalUser.get_cached_value("all_can_create_adherent"):
return True, None, None return True, None, None
else: else:
can = user_request.has_perm("users.add_user") can = user_request.has_perm("users.add_user")
@ -2091,14 +2091,14 @@ class Adherent(User):
class Club(User): class Club(User):
""" A class representing a club (it is considered as a user """ A class representing a club (it is considered as a user
with special informations) with special informations)
Attributes: Attributes:
administrators: administrators of the club administrators: administrators of the club
members: members of the club members: members of the club
room: room(s) of the club room: room(s) of the club
mailing: Boolean, activate mailing list for this club. mailing: Boolean, activate mailing list for this club.
""" """
room = models.ForeignKey( room = models.ForeignKey(
@ -2231,12 +2231,12 @@ class ServiceUser(RevMixin, AclMixin, AbstractBaseUser):
its only usefullness, and service user can't connect to re2o. its only usefullness, and service user can't connect to re2o.
Each service connected to ldap for auth (ex dokuwiki, owncloud, etc) should Each service connected to ldap for auth (ex dokuwiki, owncloud, etc) should
have a different service user with special acl (readonly, auth) and password. have a different service user with special acl (readonly, auth) and password.
Attributes: Attributes:
pseudo: login of the serviceuser pseudo: login of the serviceuser
access_group: acl for this serviceuser access_group: acl for this serviceuser
comment: Comment for this serviceuser. comment: Comment for this serviceuser.
""" """
readonly = "readonly" readonly = "readonly"
@ -2263,7 +2263,7 @@ class ServiceUser(RevMixin, AclMixin, AbstractBaseUser):
"""Shortcuts, return a pretty name for the serviceuser. """Shortcuts, return a pretty name for the serviceuser.
Parameters: Parameters:
self (ServiceUser instance): serviceuser to return infos. self (ServiceUser instance): serviceuser to return infos.
""" """
return _("Service user <{name}>").format(name=self.pseudo) return _("Service user <{name}>").format(name=self.pseudo)
@ -2272,7 +2272,7 @@ class ServiceUser(RevMixin, AclMixin, AbstractBaseUser):
"""Shortcuts, return the shortname (pseudo) of the serviceuser. """Shortcuts, return the shortname (pseudo) of the serviceuser.
Parameters: Parameters:
self (ServiceUser instance): serviceuser to return infos. self (ServiceUser instance): serviceuser to return infos.
""" """
return self.pseudo return self.pseudo
@ -2281,7 +2281,7 @@ class ServiceUser(RevMixin, AclMixin, AbstractBaseUser):
"""Method ldap_sync, sync the serviceuser in ldap with its attributes. """Method ldap_sync, sync the serviceuser in ldap with its attributes.
Each ServiceUser instance is copy into ldap, via a LdapServiceUser virtual object. Each ServiceUser instance is copy into ldap, via a LdapServiceUser virtual object.
This method performs a copy of several attributes (pseudo, access). This method performs a copy of several attributes (pseudo, access).
Update, or create if needed a mirror ldap entry related with the ServiceUserinstance. Update, or create if needed a mirror ldap entry related with the ServiceUserinstance.
Parameters: Parameters:
@ -2300,7 +2300,7 @@ class ServiceUser(RevMixin, AclMixin, AbstractBaseUser):
"""Method, delete an ServiceUser in ldap. """Method, delete an ServiceUser in ldap.
Parameters: Parameters:
self (ServiceUser instance): serviceuser to delete in Ldap. self (ServiceUser instance): serviceuser to delete in Ldap.
""" """
try: try:
@ -2317,7 +2317,7 @@ class ServiceUser(RevMixin, AclMixin, AbstractBaseUser):
Called by ldap_sync and ldap_del. Called by ldap_sync and ldap_del.
Parameters: Parameters:
self (ServiceUser instance): serviceuser to update groups in LDAP. self (ServiceUser instance): serviceuser to update groups in LDAP.
""" """
try: try:
@ -2385,7 +2385,7 @@ class ListRight(RevMixin, AclMixin, Group):
rights, like can_view, can_edit, etc. rights, like can_view, can_edit, etc.
Moreover, a ListRight is also a standard unix group, usefull for creating linux Moreover, a ListRight is also a standard unix group, usefull for creating linux
unix groups for servers access or re2o single rights, or both. unix groups for servers access or re2o single rights, or both.
Gid is used as a primary key, and can't be changed. Gid is used as a primary key, and can't be changed.
Attributes: Attributes:
name: Inherited from Group, name of the ListRight name: Inherited from Group, name of the ListRight
@ -2421,7 +2421,7 @@ class ListRight(RevMixin, AclMixin, Group):
Each ListRight/Group instance is copy into ldap, via a LdapUserGroup virtual objects. Each ListRight/Group instance is copy into ldap, via a LdapUserGroup virtual objects.
This method performs a copy of several attributes (name, members, gid, etc). This method performs a copy of several attributes (name, members, gid, etc).
The primary key is the gid, and should never change. The primary key is the gid, and should never change.
Update, or create if needed a ldap entry related with the ListRight/Group instance. Update, or create if needed a ldap entry related with the ListRight/Group instance.
Parameters: Parameters:
@ -2440,7 +2440,7 @@ class ListRight(RevMixin, AclMixin, Group):
"""Method, delete an ListRight/Group in ldap. """Method, delete an ListRight/Group in ldap.
Parameters: Parameters:
self (listright/Group instance): group to delete in Ldap. self (listright/Group instance): group to delete in Ldap.
""" """
try: try:
@ -2493,7 +2493,7 @@ class ListShell(RevMixin, AclMixin, models.Model):
self (listshell): Shell to return a pretty name. self (listshell): Shell to return a pretty name.
Returns: Returns:
pretty_name (string): Return a pretty name string for this shell. pretty_name (string): Return a pretty name string for this shell.
""" """
return self.shell.split("/")[-1] return self.shell.split("/")[-1]
@ -2541,7 +2541,7 @@ class Ban(RevMixin, AclMixin, models.Model):
decided and internet access disabled. decided and internet access disabled.
Parameters: Parameters:
self (ban instance): ban to notif disabled decision self (ban instance): ban to notif disabled decision
request (django request): request to build email request (django request): request to build email
Returns: Returns:
@ -2572,7 +2572,7 @@ class Ban(RevMixin, AclMixin, models.Model):
self (ban): Ban to test if is active. self (ban): Ban to test if is active.
Returns: Returns:
is_active (boolean): Return True if the ban is active. is_active (boolean): Return True if the ban is active.
""" """
return self.date_end > timezone.now() return self.date_end > timezone.now()
@ -2660,7 +2660,7 @@ class Whitelist(RevMixin, AclMixin, models.Model):
self (whitelist): Whitelist to test if is active. self (whitelist): Whitelist to test if is active.
Returns: Returns:
is_active (boolean): Return True if the whistelist is active. is_active (boolean): Return True if the whistelist is active.
""" """
return self.date_end > timezone.now() return self.date_end > timezone.now()
@ -2760,7 +2760,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
Attributes: Attributes:
user: parent user address for this email user: parent user address for this email
local_part: local extension of the email local_part: local extension of the email
""" """
user = models.ForeignKey( user = models.ForeignKey(
@ -2952,7 +2952,7 @@ class EMailAddress(RevMixin, AclMixin, models.Model):
class LdapUser(ldapdb.models.Model): class LdapUser(ldapdb.models.Model):
"""A class representing a LdapUser in LDAP, its LDAP conterpart. """A class representing a LdapUser in LDAP, its LDAP conterpart.
Synced from re2o django User model, (User django models), Synced from re2o django User model, (User django models),
with a copy of its attributes/fields into LDAP, so this class is a mirror with a copy of its attributes/fields into LDAP, so this class is a mirror
of the classic django User model. of the classic django User model.
The basedn userdn is specified in settings. The basedn userdn is specified in settings.
@ -3036,7 +3036,7 @@ class LdapUser(ldapdb.models.Model):
class LdapUserGroup(ldapdb.models.Model): class LdapUserGroup(ldapdb.models.Model):
"""A class representing a LdapUserGroup in LDAP, its LDAP conterpart. """A class representing a LdapUserGroup in LDAP, its LDAP conterpart.
Synced from UserGroup, (ListRight/Group django models), Synced from UserGroup, (ListRight/Group django models),
with a copy of its attributes/fields into LDAP, so this class is a mirror with a copy of its attributes/fields into LDAP, so this class is a mirror
of the classic django ListRight model. of the classic django ListRight model.
The basedn usergroupdn is specified in settings. The basedn usergroupdn is specified in settings.

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)