models.py 24.1 KB
Newer Older
1
# -*- mode: python; coding: utf-8 -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 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.
23 24 25
"""
Reglages généraux, machines, utilisateurs, mail, general pour l'application.
"""
26
from __future__ import unicode_literals
27 28

from django.db import models
Maël Kervella's avatar
Maël Kervella committed
29
import cotisations.models
30

31 32
from .aes_field import AESEncryptedField

33 34

class OptionalUser(models.Model):
35 36
    """Options pour l'user : obligation ou nom du telephone,
    activation ou non du solde, autorisation du negatif, fingerprint etc"""
37 38
    PRETTY_NAME = "Options utilisateur"

39 40
    is_tel_mandatory = models.BooleanField(default=True)
    user_solde = models.BooleanField(default=False)
41 42 43 44 45
    solde_negatif = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        default=0
    )
46
    max_solde = models.DecimalField(
47 48
        max_digits=5,
        decimal_places=2,
49
        default=50
50
    )
51 52 53 54 55
    min_online_payment = models.DecimalField(
        max_digits=5,
        decimal_places=2,
        default=10
    )
56
    gpg_fingerprint = models.BooleanField(default=True)
57 58 59 60
    all_can_create = models.BooleanField(
        default=False,
        help_text="Tous les users peuvent en créer d'autres",
    )
61 62 63 64
    self_adhesion = models.BooleanField(
        default=False,
        help_text="Un nouvel utilisateur peut se créer son compte sur re2o"
    )
65

66 67 68 69 70
    class Meta:
        permissions = (
            ("view_optionaluser", "Peut voir les options de l'user"),
        )

71 72 73 74
    def get_instance(*args, **kwargs):
        return OptionalUser.objects.get_or_create()

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
75
        """Check if an user can create a OptionalUser object.
76

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
77 78 79
        :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.
        """
80
        return user_request.has_perm('preferences.add_optionaluser'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
81
            de créer les préférences concernant les users"
82

83
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
84 85 86 87 88 89
        """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.
        """
90
        return user_request.has_perm('preferences.change_optionaluser'), u"Vous n'avez pas le droit\
91 92 93
            d'éditer les préférences concernant les users"

    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
94 95 96 97 98 99
        """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.
        """
100
        return user_request.has_perm('preferences.delete_optionaluser'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
101
            de supprimer les préférences concernant les users"
102

103
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
104 105 106 107 108
        """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.
        """
109
        return user_request.has_perm('preferences.view_optionaluser'), u"Vous n'avez pas le droit\
110 111
            de voir les préférences concernant les utilisateurs"

112
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
113 114 115 116 117 118 119
        """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
        """
120
        return user_request.has_perm('preferences.view_optionaluser'), u"Vous n'avez pas le droit\
121 122
            de voir les préférences concernant les utilisateurs"

chibrac's avatar
chibrac committed
123
    def clean(self):
124
        """Creation du mode de paiement par solde"""
chibrac's avatar
chibrac committed
125
        if self.user_solde:
126 127 128 129
            p = cotisations.models.Paiement.objects.filter(moyen="Solde")
            if not len(p):
                c = cotisations.models.Paiement(moyen="Solde")
                c.save()
chibrac's avatar
chibrac committed
130

131

132
class OptionalMachine(models.Model):
133 134
    """Options pour les machines : maximum de machines ou d'alias par user
    sans droit, activation de l'ipv6"""
135 136
    PRETTY_NAME = "Options machines"

137 138 139
    password_machine = models.BooleanField(default=False)
    max_lambdauser_interfaces = models.IntegerField(default=10)
    max_lambdauser_aliases = models.IntegerField(default=10)
140
    ipv6 = models.BooleanField(default=False)
141

142 143 144 145 146
    class Meta:
        permissions = (
            ("view_optionalmachine", "Peut voir les options de machine"),
        )

147 148 149 150
    def get_instance(*args, **kwargs):
        return OptionalMachine.objects.get_or_create()

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
151
        """Check if an user can create a OptionalMachine object.
152

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
153 154 155
        :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.
        """
156
        return user_request.has_perm('preferences.add_optionalmachine'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
157
            de créer les préférences concernant les machines"
158

159
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
160 161 162 163 164 165
        """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.
        """
166
        return user_request.has_perm('preferences.change_optionalmachine'), u"Vous n'avez pas le droit\
167 168 169
            d'éditer les préférences concernant les machines"

    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
170 171 172 173 174 175 176
        """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.
        """

177
        return user_request.has_perm('preferences.delete_optionalmachine'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
178
            de supprimer les préférences concernant les machines"
179

180
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
181 182 183 184 185
        """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.
        """
186
        return user_request.has_perm('preferences.view_optionalmachine'), u"Vous n'avez pas le droit\
187 188
            de voir les préférences concernant les machines"

189
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
190 191 192 193 194 195 196
        """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
        """
197
        return user_request.has_perm('preferences.view_optionalmachine'), u"Vous n'avez pas le droit\
198 199
            de voir les préférences concernant les machines"

200

201
class OptionalTopologie(models.Model):
202 203
    """Reglages pour la topologie : mode d'accès radius, vlan où placer
    les machines en accept ou reject"""
204
    PRETTY_NAME = "Options topologie"
205 206 207
    MACHINE = 'MACHINE'
    DEFINED = 'DEFINED'
    CHOICE_RADIUS = (
208 209 210
        (MACHINE, 'Sur le vlan de la plage ip machine'),
        (DEFINED, 'Prédéfini dans "Vlan où placer les machines\
            après acceptation RADIUS"'),
211
    )
212

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
    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
    )
232

233 234 235 236 237
    class Meta:
        permissions = (
            ("view_optionaltopologie", "Peut voir les options de topologie"),
        )

238 239 240 241
    def get_instance(*args, **kwargs):
        return OptionalTopologie.objects.get_or_create()

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
242
        """Check if an user can create a OptionalTopologie object.
243

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
244 245 246
        :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.
        """
247
        return user_request.has_perm('preferences.add_optionaltopologie'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
248
            de créer les préférences concernant la topologie"
249

250
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
251 252 253 254 255 256
        """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.
        """
257
        return user_request.has_perm('preferences.change_optionaltopologie'), u"Vous n'avez pas le droit\
258 259 260
            d'éditer les préférences concernant la topologie"

    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
261 262 263 264 265 266
        """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.
        """
267
        return user_request.has_perm('preferences.delete_optionaltoplogie'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
268
            d'éditer les préférences concernant la topologie"
269

270
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
271 272 273 274 275
        """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.
        """
276
        return user_request.has_perm('preferences.view_optionaltopologie'), u"Vous n'avez pas le droit\
277 278
            de voir les préférences concernant la topologie"

279
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
280 281 282 283 284 285 286
        """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
        """
287
        return user_request.has_perm('preferences.view_optionaltopologie'), u"Vous n'avez pas le droit\
288 289
            de voir les préférences concernant la topologie"

290 291

class GeneralOption(models.Model):
292 293
    """Options générales : nombre de resultats par page, nom du site,
    temps où les liens sont valides"""
294 295
    PRETTY_NAME = "Options générales"

296 297 298 299 300
    general_message = models.TextField(
        default="",
        blank=True,
        help_text="Message général affiché sur le site (maintenance, etc"
    )
301 302 303
    search_display_page = models.IntegerField(default=15)
    pagination_number = models.IntegerField(default=25)
    pagination_large_number = models.IntegerField(default=8)
304 305 306
    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")
307 308 309 310 311 312 313 314 315 316
    GTU_sum_up = models.TextField(
        default="",
        blank=True,
    )
    GTU = models.FileField(
        upload_to = '',
        default="",
        null=True,
        blank=True,
    )
317

318 319 320 321 322
    class Meta:
        permissions = (
            ("view_generaloption", "Peut voir les options générales"),
        )

323 324 325 326
    def get_instance(*args, **kwargs):
        return GeneralOption.objects.get_or_create()

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
327
        """Check if an user can create a GeneralOption object.
328

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
329 330 331
        :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.
        """
332
        return user_request.has_perm('preferences.add_generaloption'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
333
            de créer les préférences générales"
334

335
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
336 337 338 339 340 341
        """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.
        """
342
        return user_request.has_perm('preferences.change_generaloption'), u"Vous n'avez pas le droit\
343 344 345
            d'éditer les préférences générales"

    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
346 347 348 349 350 351
        """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.
        """
352
        return user_request.has_perm('preferences.delete_generaloption'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
353
            d'éditer les préférences générales"
354

355
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
356 357 358 359 360 361
        """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.
        """

362
        return user_request.has_perm('preferences.view_generaloption'), u"Vous n'avez pas le droit\
363 364
            de voir les préférences générales"

365
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
366 367 368 369 370 371 372
        """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
        """
373
        return user_request.has_perm('preferences.view_generaloption'), u"Vous n'avez pas le droit\
374 375
            de voir les préférences générales"

376

377
class Service(models.Model):
378 379
    """Liste des services affichés sur la page d'accueil : url, description,
    image et nom"""
380 381 382
    name = models.CharField(max_length=32)
    url = models.URLField()
    description = models.TextField()
383
    image = models.ImageField(upload_to='logo', blank=True)
384

385 386 387 388 389
    class Meta:
        permissions = (
            ("view_service", "Peut voir les options de service"),
        )

390 391 392 393
    def get_instance(serviceid, *args, **kwargs):
        return Service.objects.get(pk=serviceid)

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
394 395 396 397 398
        """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.
        """
399

400
        return user_request.has_perm('preferences.add_service'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
401
            de créer un service pour la page d'accueil"
402

403
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
404
        """Check if an user can edit a Service object.
405

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
406 407 408 409
        :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.
        """
410
        return user_request.has_perm('preferences.change_service'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
411
            d'éditer les services pour la page d'accueil"
412

413
    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
414 415 416 417 418 419
        """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.
        """
420
        return user_request.has_perm('preferences.delete_service'), u"Vous n'avez pas le droit\
421 422
            de supprimer les services pour la page d'accueil"

423
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
424 425 426 427 428 429
        """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.
        """

430
        return user_request.has_perm('preferences.view_service'), u"Vous n'avez pas le droit\
431 432
            de voir les services pour la page d'accueil"

433
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
434 435 436 437 438 439 440
        """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
        """
441
        return user_request.has_perm('preferences.view_service'), u"Vous n'avez pas le droit\
442 443
            de voir les services pour la page d'accueil"

444 445 446
    def __str__(self):
        return str(self.name)

447

448
class AssoOption(models.Model):
449
    """Options générales de l'asso : siret, addresse, nom, etc"""
450 451
    PRETTY_NAME = "Options de l'association"

452 453 454 455
    name = models.CharField(
        default="Association réseau école machin",
        max_length=256
    )
456 457 458 459 460 461
    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)
462 463 464 465 466 467
    utilisateur_asso = models.OneToOneField(
        'users.User',
        on_delete=models.PROTECT,
        blank=True,
        null=True
    )
468 469 470 471 472 473 474 475
    PAYMENT = (
        ('NONE', 'NONE'),
        ('COMNPAY', 'COMNPAY'),
    )
    payment = models.CharField(max_length=255,
        choices=PAYMENT,
        default='NONE',
    )
476 477 478 479 480 481 482 483 484 485
    payment_id = models.CharField(
        max_length=255,
        default='',
    )
    payment_pass = AESEncryptedField(
        max_length=255,
        default='',
    )


486 487 488 489 490
    class Meta:
        permissions = (
            ("view_assooption", "Peut voir les options de l'asso"),
        )

491 492 493 494
    def get_instance(*args, **kwargs):
        return AssoOption.objects.get_or_create()

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
495
        """Check if an user can create a AssoOption object.
496

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
497 498 499
        :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.
        """
500
        return user_request.has_perm('preferences.add_assooption'), u"Vous n'avez pas le droit\
501 502
            d'éditer les préférences concernant l'association"

503
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
504 505 506 507 508 509
        """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.
        """
510
        return user_request.has_perm('preferences.change_assooption'), u"Vous n'avez pas le droit\
511 512 513
            d'éditer les préférences concernant l'association"

    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
514 515 516 517 518 519
        """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.
        """
520
        return user_request.has_perm('preferences.delete_assooption'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
521
            d'éditer les préférences concernant l'association"
522

523
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
524 525 526 527 528
        """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.
        """
529
        return user_request.has_perm('preferences.view_assooption'), u"Vous n'avez pas le droit\
530 531
            de voir les préférences concernant l'association"

532
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
533 534 535 536 537 538 539
        """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
        """
540
        return user_request.has_perm('preferences.view_assooption'), u"Vous n'avez pas le droit\
541 542
            de voir les préférences concernant l'association"

543 544

class MailMessageOption(models.Model):
545
    """Reglages, mail de bienvenue et autre"""
546 547 548 549
    PRETTY_NAME = "Options de corps de mail"

    welcome_mail_fr = models.TextField(default="")
    welcome_mail_en = models.TextField(default="")
550

551 552 553 554 555
    class Meta:
        permissions = (
            ("view_mailmessageoption", "Peut voir les options de mail"),
        )

556 557 558 559
    def get_instance(*args, **kwargs):
        return MailMessageOption.objects.get_or_create()

    def can_create(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
560
        """Check if an user can create a MailMessageOption object.
561

LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
562 563 564
        :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.
        """
565
        return user_request.has_perm('preferences.add_mailmessageoption'), u"Vous n'avez pas le droit\
566 567
            d'éditer les préférences concernant les mails"

568
    def can_edit(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
569 570 571 572 573 574 575
        """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.
        """

576
        return user_request.has_perm('preferences.change_mailmessageoption'), u"Vous n'avez pas le droit\
577 578 579
            d'éditer les préférences concernant les mails"

    def can_delete(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
580 581 582 583 584 585
        """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.
        """
586
        return user_request.has_perm('preferences.delete_mailmessageoption'), u"Vous n'avez pas le droit\
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
587
            d'éditer les préférences concernant les mails"
588

589
    def can_view_all(user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
590 591 592 593 594
        """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.
        """
595
        return user_request.has_perm('preferences.view_mailmessageoption'), u"Vous n'avez pas le droit\
596 597
            de voir les préférences concernant les mails"

598
    def can_view(self, user_request, *args, **kwargs):
LEVY-FALK Hugo's avatar
LEVY-FALK Hugo committed
599 600 601 602 603 604 605
        """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
        """
606
        return user_request.has_perm('preferences.view_mailmessageoption'), u"Vous n'avez pas le droit\
607
            de voir les préférences concernant les mails"