From f9c87088fc3954eb5101cda91b9433b24a303a6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Mon, 8 Aug 2016 03:49:10 +0200 Subject: [PATCH] =?UTF-8?q?Validation=20commande=20K-Psul=20(compte=20gel?= =?UTF-8?q?=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Empêche l'enregistrement de commande sur un compte gelé sans la permission 'kfet.override_frozen_protection' - Modifie les noms de deux permissions pour éviter d'avoir des 'can_...' partout --- kfet/migrations/0018_auto_20160808_0341.py | 18 ++++++++++++++++++ kfet/migrations/0019_auto_20160808_0343.py | 18 ++++++++++++++++++ kfet/models.py | 13 ++++++++----- 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 kfet/migrations/0018_auto_20160808_0341.py create mode 100644 kfet/migrations/0019_auto_20160808_0343.py diff --git a/kfet/migrations/0018_auto_20160808_0341.py b/kfet/migrations/0018_auto_20160808_0341.py new file mode 100644 index 00000000..384e82b2 --- /dev/null +++ b/kfet/migrations/0018_auto_20160808_0341.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0017_auto_20160808_0234'), + ] + + operations = [ + migrations.AlterModelOptions( + name='globalpermissions', + options={'permissions': (('is_team', 'Is part of the team'), ('can_perform_deposit', 'Effectuer une charge'), ('can_perform_negative_operations', 'Enregistrer des commandes en négatif'), ('override_frozen_protection', "Forcer le gel d'un compte")), 'managed': False}, + ), + ] diff --git a/kfet/migrations/0019_auto_20160808_0343.py b/kfet/migrations/0019_auto_20160808_0343.py new file mode 100644 index 00000000..6512b7ea --- /dev/null +++ b/kfet/migrations/0019_auto_20160808_0343.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('kfet', '0018_auto_20160808_0341'), + ] + + operations = [ + migrations.AlterModelOptions( + name='globalpermissions', + options={'managed': False, 'permissions': (('is_team', 'Is part of the team'), ('perform_deposit', 'Effectuer une charge'), ('perform_negative_operations', 'Enregistrer des commandes en négatif'), ('override_frozen_protection', "Forcer le gel d'un compte"))}, + ), + ] diff --git a/kfet/models.py b/kfet/models.py index 672a2b0b..5f740d27 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -94,10 +94,12 @@ class Account(models.Model): return data def perms_to_perform_operation(self, amount): - new_balance = self.balance + amount perms = [] + if self.is_frozen: + perms.append('kfet.override_frozen_protection') + new_balance = self.balance + amount if new_balance < 0: - perms.append('kfet.can_perform_negative_operations') + perms.append('kfet.perform_negative_operations') return perms # Surcharge Méthode save() avec gestions de User et CofProfile @@ -422,9 +424,10 @@ class GlobalPermissions(models.Model): managed = False permissions = ( ('is_team', 'Is part of the team'), - ('can_perform_deposit', 'Peut effectuer une charge'), - ('can_perform_negative_operations', - 'Peut enregistrer des commandes en négatif') + ('perform_deposit', 'Effectuer une charge'), + ('perform_negative_operations', + 'Enregistrer des commandes en négatif'), + ('override_frozen_protection', "Forcer le gel d'un compte"), ) class Settings(models.Model):