2017-09-10 14:53:02 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2017-06-25 22:50:55 +00:00
|
|
|
# Re2o un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
|
|
|
# Copyright © 2017 Goulven Kermarec
|
|
|
|
# Copyright © 2017 Augustin Lemesle
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2017-10-14 04:03:53 +00:00
|
|
|
"""
|
|
|
|
Reglages généraux, machines, utilisateurs, mail, general pour l'application.
|
|
|
|
"""
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
from django.utils.functional import cached_property
|
2017-06-25 22:50:55 +00:00
|
|
|
from django.db import models
|
2017-11-28 22:33:47 +00:00
|
|
|
import cotisations.models
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2018-01-15 00:06:54 +00:00
|
|
|
from .aes_field import AESEncryptedField
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
class OptionalUser(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options pour l'user : obligation ou nom du telephone,
|
|
|
|
activation ou non du solde, autorisation du negatif, fingerprint etc"""
|
2017-08-24 19:36:59 +00:00
|
|
|
PRETTY_NAME = "Options utilisateur"
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
is_tel_mandatory = models.BooleanField(default=True)
|
|
|
|
user_solde = models.BooleanField(default=False)
|
2017-10-14 04:03:53 +00:00
|
|
|
solde_negatif = models.DecimalField(
|
|
|
|
max_digits=5,
|
|
|
|
decimal_places=2,
|
|
|
|
default=0
|
|
|
|
)
|
2018-01-12 00:07:25 +00:00
|
|
|
max_solde = models.DecimalField(
|
2018-01-11 18:25:41 +00:00
|
|
|
max_digits=5,
|
|
|
|
decimal_places=2,
|
2018-01-12 00:07:25 +00:00
|
|
|
default=50
|
2018-01-11 18:25:41 +00:00
|
|
|
)
|
2018-01-14 19:15:21 +00:00
|
|
|
min_online_payment = models.DecimalField(
|
|
|
|
max_digits=5,
|
|
|
|
decimal_places=2,
|
|
|
|
default=10
|
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
gpg_fingerprint = models.BooleanField(default=True)
|
2017-11-21 04:47:05 +00:00
|
|
|
all_can_create = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text="Tous les users peuvent en créer d'autres",
|
|
|
|
)
|
2018-01-14 19:15:21 +00:00
|
|
|
self_adhesion = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
help_text="Un nouvel utilisateur peut se créer son compte sur re2o"
|
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_optionaluser", "Peut voir les options de l'user"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return OptionalUser.objects.get_or_create()
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a OptionalUser object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
: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.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.add_optionaluser'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de créer les préférences concernant les users"
|
2017-12-11 21:02:32 +00:00
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a OptionalUser object.
|
|
|
|
|
|
|
|
:param self: The OptionalUser which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.change_optionaluser'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
d'éditer les préférences concernant les users"
|
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a OptionalUser object.
|
|
|
|
|
|
|
|
:param self: The OptionalUser which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.delete_optionaluser'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de supprimer les préférences concernant les users"
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every OptionalUser objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_optionaluser'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les préférences concernant les utilisateurs"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a OptionalUser object.
|
|
|
|
|
|
|
|
:param self: The targeted OptionalUser.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_optionaluser'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les préférences concernant les utilisateurs"
|
|
|
|
|
2017-06-26 17:23:01 +00:00
|
|
|
def clean(self):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Creation du mode de paiement par solde"""
|
2017-06-26 17:23:01 +00:00
|
|
|
if self.user_solde:
|
2018-01-11 18:25:41 +00:00
|
|
|
p = cotisations.models.Paiement.objects.filter(moyen="Solde")
|
|
|
|
if not len(p):
|
|
|
|
c = cotisations.models.Paiement(moyen="Solde")
|
|
|
|
c.save()
|
2017-06-26 17:23:01 +00:00
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
class OptionalMachine(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options pour les machines : maximum de machines ou d'alias par user
|
|
|
|
sans droit, activation de l'ipv6"""
|
2017-08-24 19:36:59 +00:00
|
|
|
PRETTY_NAME = "Options machines"
|
|
|
|
|
2018-01-29 02:53:49 +00:00
|
|
|
SLAAC = 'SLAAC'
|
|
|
|
DHCPV6 = 'DHCPV6'
|
|
|
|
DISABLED = 'DISABLED'
|
|
|
|
CHOICE_IPV6 = (
|
|
|
|
(SLAAC, 'Autoconfiguration par RA'),
|
|
|
|
(DHCPV6, 'Attribution des ip par dhcpv6'),
|
|
|
|
(DISABLED, 'Désactivé'),
|
|
|
|
)
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
password_machine = models.BooleanField(default=False)
|
|
|
|
max_lambdauser_interfaces = models.IntegerField(default=10)
|
|
|
|
max_lambdauser_aliases = models.IntegerField(default=10)
|
2018-01-29 02:53:49 +00:00
|
|
|
ipv6_mode = models.CharField(
|
|
|
|
max_length=32,
|
|
|
|
choices=CHOICE_IPV6,
|
|
|
|
default='DISABLED'
|
|
|
|
)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def ipv6(self):
|
|
|
|
return not self.ipv6_mode == 'DISABLED'
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_optionalmachine", "Peut voir les options de machine"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return OptionalMachine.objects.get_or_create()
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a OptionalMachine object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
:param user_request: The user who wants to create an object.
|
|
|
|
:return: a message and a boolean which is True if the user can create.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.add_optionalmachine'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de créer les préférences concernant les machines"
|
2017-12-11 21:02:32 +00:00
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a OptionalMachine object.
|
|
|
|
|
|
|
|
:param self: The OptionalMachine which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.change_optionalmachine'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
d'éditer les préférences concernant les machines"
|
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a OptionalMachine object.
|
|
|
|
|
|
|
|
:param self: The OptionalMachine which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.delete_optionalmachine'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de supprimer les préférences concernant les machines"
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every OptionalMachine objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_optionalmachine'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les préférences concernant les machines"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a OptionalMachine object.
|
|
|
|
|
|
|
|
:param self: The targeted OptionalMachine.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_optionalmachine'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les préférences concernant les machines"
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-08-26 13:10:18 +00:00
|
|
|
class OptionalTopologie(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Reglages pour la topologie : mode d'accès radius, vlan où placer
|
|
|
|
les machines en accept ou reject"""
|
2017-08-26 13:10:18 +00:00
|
|
|
PRETTY_NAME = "Options topologie"
|
2017-09-02 13:20:44 +00:00
|
|
|
MACHINE = 'MACHINE'
|
|
|
|
DEFINED = 'DEFINED'
|
|
|
|
CHOICE_RADIUS = (
|
2017-10-14 04:03:53 +00:00
|
|
|
(MACHINE, 'Sur le vlan de la plage ip machine'),
|
|
|
|
(DEFINED, 'Prédéfini dans "Vlan où placer les machines\
|
|
|
|
après acceptation RADIUS"'),
|
2017-09-02 13:20:44 +00:00
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
radius_general_policy = models.CharField(
|
|
|
|
max_length=32,
|
|
|
|
choices=CHOICE_RADIUS,
|
|
|
|
default='DEFINED'
|
|
|
|
)
|
|
|
|
vlan_decision_ok = models.OneToOneField(
|
|
|
|
'machines.Vlan',
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name='decision_ok',
|
|
|
|
blank=True,
|
|
|
|
null=True
|
|
|
|
)
|
|
|
|
vlan_decision_nok = models.OneToOneField(
|
|
|
|
'machines.Vlan',
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
related_name='decision_nok',
|
|
|
|
blank=True,
|
|
|
|
null=True
|
|
|
|
)
|
2017-09-10 16:16:59 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_optionaltopologie", "Peut voir les options de topologie"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return OptionalTopologie.objects.get_or_create()
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a OptionalTopologie object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
:param user_request: The user who wants to create an object.
|
|
|
|
:return: a message and a boolean which is True if the user can create.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.add_optionaltopologie'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de créer les préférences concernant la topologie"
|
2017-12-11 21:02:32 +00:00
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a OptionalTopologie object.
|
|
|
|
|
|
|
|
:param self: The OptionalTopologie which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.change_optionaltopologie'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
d'éditer les préférences concernant la topologie"
|
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a OptionalTopologie object.
|
|
|
|
|
|
|
|
:param self: The OptionalTopologie which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.delete_optionaltoplogie'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
d'éditer les préférences concernant la topologie"
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every OptionalTopologie objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_optionaltopologie'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les préférences concernant la topologie"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a OptionalTopologie object.
|
|
|
|
|
|
|
|
:param self: The targeted OptionalTopologie.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_optionaltopologie'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les préférences concernant la topologie"
|
|
|
|
|
2017-06-25 22:50:55 +00:00
|
|
|
|
|
|
|
class GeneralOption(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options générales : nombre de resultats par page, nom du site,
|
|
|
|
temps où les liens sont valides"""
|
2017-08-24 19:36:59 +00:00
|
|
|
PRETTY_NAME = "Options générales"
|
|
|
|
|
2017-12-16 03:01:39 +00:00
|
|
|
general_message = models.TextField(
|
|
|
|
default="",
|
|
|
|
blank=True,
|
|
|
|
help_text="Message général affiché sur le site (maintenance, etc"
|
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
search_display_page = models.IntegerField(default=15)
|
|
|
|
pagination_number = models.IntegerField(default=25)
|
|
|
|
pagination_large_number = models.IntegerField(default=8)
|
2017-08-26 14:04:51 +00:00
|
|
|
req_expire_hrs = models.IntegerField(default=48)
|
|
|
|
site_name = models.CharField(max_length=32, default="Re2o")
|
|
|
|
email_from = models.EmailField(default="www-data@serveur.net")
|
2018-01-14 22:47:44 +00:00
|
|
|
GTU_sum_up = models.TextField(
|
|
|
|
default="",
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
GTU = models.FileField(
|
|
|
|
upload_to = '',
|
|
|
|
default="",
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
)
|
2017-06-25 22:50:55 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_generaloption", "Peut voir les options générales"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return GeneralOption.objects.get_or_create()
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a GeneralOption object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
:param user_request: The user who wants to create an object.
|
|
|
|
:return: a message and a boolean which is True if the user can create.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.add_generaloption'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de créer les préférences générales"
|
2017-12-11 21:02:32 +00:00
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a GeneralOption object.
|
|
|
|
|
|
|
|
:param self: The GeneralOption which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.change_generaloption'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
d'éditer les préférences générales"
|
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a GeneralOption object.
|
|
|
|
|
|
|
|
:param self: The GeneralOption which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.delete_generaloption'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
d'éditer les préférences générales"
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every GeneralOption objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_generaloption'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les préférences générales"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a GeneralOption object.
|
|
|
|
|
|
|
|
:param self: The targeted GeneralOption.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_generaloption'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les préférences générales"
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class Service(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Liste des services affichés sur la page d'accueil : url, description,
|
|
|
|
image et nom"""
|
2017-08-24 19:36:59 +00:00
|
|
|
name = models.CharField(max_length=32)
|
|
|
|
url = models.URLField()
|
|
|
|
description = models.TextField()
|
2017-10-14 04:03:53 +00:00
|
|
|
image = models.ImageField(upload_to='logo', blank=True)
|
2017-08-24 19:36:59 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_service", "Peut voir les options de service"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(serviceid, *args, **kwargs):
|
|
|
|
return Service.objects.get(pk=serviceid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a Service object.
|
|
|
|
|
|
|
|
:param user_request: The user who wants to create an object.
|
|
|
|
:return: a message and a boolean which is True if the user can create.
|
|
|
|
"""
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.add_service'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
de créer un service pour la page d'accueil"
|
2017-12-11 21:02:32 +00:00
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a Service object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
:param self: The Service which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.change_service'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
d'éditer les services pour la page d'accueil"
|
2017-12-11 21:02:32 +00:00
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a Service object.
|
|
|
|
|
|
|
|
:param self: The Right which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.delete_service'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de supprimer les services pour la page d'accueil"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every Service objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_service'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les services pour la page d'accueil"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a Service object.
|
|
|
|
|
|
|
|
:param self: The targeted Service.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_service'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les services pour la page d'accueil"
|
|
|
|
|
2017-08-25 02:35:49 +00:00
|
|
|
def __str__(self):
|
|
|
|
return str(self.name)
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-08-24 19:36:59 +00:00
|
|
|
class AssoOption(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Options générales de l'asso : siret, addresse, nom, etc"""
|
2017-08-24 19:36:59 +00:00
|
|
|
PRETTY_NAME = "Options de l'association"
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
name = models.CharField(
|
|
|
|
default="Association réseau école machin",
|
|
|
|
max_length=256
|
|
|
|
)
|
2017-08-24 19:36:59 +00:00
|
|
|
siret = models.CharField(default="00000000000000", max_length=32)
|
|
|
|
adresse1 = models.CharField(default="1 Rue de exemple", max_length=128)
|
|
|
|
adresse2 = models.CharField(default="94230 Cachan", max_length=128)
|
|
|
|
contact = models.EmailField(default="contact@example.org")
|
|
|
|
telephone = models.CharField(max_length=15, default="0000000000")
|
|
|
|
pseudo = models.CharField(default="Asso", max_length=32)
|
2017-10-14 04:03:53 +00:00
|
|
|
utilisateur_asso = models.OneToOneField(
|
|
|
|
'users.User',
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
blank=True,
|
|
|
|
null=True
|
|
|
|
)
|
2018-01-11 18:25:41 +00:00
|
|
|
PAYMENT = (
|
|
|
|
('NONE', 'NONE'),
|
|
|
|
('COMNPAY', 'COMNPAY'),
|
|
|
|
)
|
|
|
|
payment = models.CharField(max_length=255,
|
|
|
|
choices=PAYMENT,
|
|
|
|
default='NONE',
|
|
|
|
)
|
2018-01-15 00:06:54 +00:00
|
|
|
payment_id = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
default='',
|
|
|
|
)
|
|
|
|
payment_pass = AESEncryptedField(
|
|
|
|
max_length=255,
|
2018-01-29 16:46:46 +00:00
|
|
|
null=True,
|
|
|
|
blank=True,
|
2018-01-15 00:06:54 +00:00
|
|
|
)
|
|
|
|
|
2017-10-14 04:03:53 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_assooption", "Peut voir les options de l'asso"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return AssoOption.objects.get_or_create()
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a AssoOption object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
:param user_request: The user who wants to create an object.
|
|
|
|
:return: a message and a boolean which is True if the user can create.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.add_assooption'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
d'éditer les préférences concernant l'association"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a AssoOption object.
|
|
|
|
|
|
|
|
:param self: The AssoOption which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.change_assooption'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
d'éditer les préférences concernant l'association"
|
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a AssoOption object.
|
|
|
|
|
|
|
|
:param self: The AssoOption which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.delete_assooption'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
d'éditer les préférences concernant l'association"
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every AssoOption objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_assooption'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les préférences concernant l'association"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a AssoOption object.
|
|
|
|
|
|
|
|
:param self: The targeted AssoOption.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2017-12-31 20:43:59 +00:00
|
|
|
return user_request.has_perm('preferences.view_assooption'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les préférences concernant l'association"
|
|
|
|
|
2017-09-08 20:53:13 +00:00
|
|
|
|
|
|
|
class MailMessageOption(models.Model):
|
2017-10-14 04:03:53 +00:00
|
|
|
"""Reglages, mail de bienvenue et autre"""
|
2017-09-08 20:53:13 +00:00
|
|
|
PRETTY_NAME = "Options de corps de mail"
|
|
|
|
|
|
|
|
welcome_mail_fr = models.TextField(default="")
|
|
|
|
welcome_mail_en = models.TextField(default="")
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-31 20:43:59 +00:00
|
|
|
class Meta:
|
|
|
|
permissions = (
|
|
|
|
("view_mailmessageoption", "Peut voir les options de mail"),
|
|
|
|
)
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def get_instance(*args, **kwargs):
|
|
|
|
return MailMessageOption.objects.get_or_create()
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can create a MailMessageOption object.
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-27 22:40:27 +00:00
|
|
|
:param user_request: The user who wants to create an object.
|
|
|
|
:return: a message and a boolean which is True if the user can create.
|
|
|
|
"""
|
2018-01-01 01:39:45 +00:00
|
|
|
return user_request.has_perm('preferences.add_mailmessageoption'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
d'éditer les préférences concernant les mails"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can edit a MailMessageOption object.
|
|
|
|
|
|
|
|
:param self: The MailMessageOption which is to be edited.
|
|
|
|
:param user_request: The user who requests to edit self.
|
|
|
|
:return: a message and a boolean which is True if edition is granted.
|
|
|
|
"""
|
|
|
|
|
2018-01-01 01:39:45 +00:00
|
|
|
return user_request.has_perm('preferences.change_mailmessageoption'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
d'éditer les préférences concernant les mails"
|
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can delete a AssoOption object.
|
|
|
|
|
|
|
|
:param self: The AssoOption which is to be deleted.
|
|
|
|
:param user_request: The user who requests deletion.
|
|
|
|
:return: True if deletion is granted, and a message.
|
|
|
|
"""
|
2018-01-01 01:39:45 +00:00
|
|
|
return user_request.has_perm('preferences.delete_mailmessageoption'), u"Vous n'avez pas le droit\
|
2017-12-27 22:40:27 +00:00
|
|
|
d'éditer les préférences concernant les mails"
|
2017-12-08 23:41:16 +00:00
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can access to the list of every AssoOption objects
|
|
|
|
|
|
|
|
:param user_request: The user who wants to view the list.
|
|
|
|
:return: True if the user can view the list and an explanation message.
|
|
|
|
"""
|
2018-01-01 01:39:45 +00:00
|
|
|
return user_request.has_perm('preferences.view_mailmessageoption'), u"Vous n'avez pas le droit\
|
2017-12-11 21:02:32 +00:00
|
|
|
de voir les préférences concernant les mails"
|
|
|
|
|
2017-12-08 23:41:16 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
2017-12-27 22:40:27 +00:00
|
|
|
"""Check if an user can view a AssoOption object.
|
|
|
|
|
|
|
|
:param self: The targeted AssoOption.
|
|
|
|
:param user_request: The user who ask for viewing the target.
|
|
|
|
:return: A boolean telling if the acces is granted and an explanation
|
|
|
|
text
|
|
|
|
"""
|
2018-01-01 01:39:45 +00:00
|
|
|
return user_request.has_perm('preferences.view_mailmessageoption'), u"Vous n'avez pas le droit\
|
2017-12-08 23:41:16 +00:00
|
|
|
de voir les préférences concernant les mails"
|