From 180cd3e1ec8e18ee66a9c32ac829f95681342659 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 14 Sep 2020 09:49:30 +0200 Subject: [PATCH] Fix registration permissions and procedure --- apps/member/models.py | 9 +++- .../member/includes/profile_info.html | 4 +- apps/note/models/notes.py | 4 ++ apps/permission/fixtures/initial.json | 49 +++++++++++++++++-- apps/treasury/models.py | 9 +++- locale/fr/LC_MESSAGES/django.po | 2 +- 6 files changed, 66 insertions(+), 11 deletions(-) diff --git a/apps/member/models.py b/apps/member/models.py index fff32a59..ff8f2b88 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -477,8 +477,13 @@ class Membership(models.Model): # to treasurers. transaction.valid = False from treasury.models import SogeCredit - soge_credit = SogeCredit.objects.get_or_create(user=self.user)[0] - soge_credit.refresh_from_db() + if SogeCredit.objects.filter(user=self.user).exists(): + soge_credit = SogeCredit.objects.get(user=self.user) + else: + soge_credit = SogeCredit(user=self.user) + soge_credit._force_save = True + soge_credit.save(force_insert=True) + soge_credit.refresh_from_db() transaction.save(force_insert=True) transaction.refresh_from_db() soge_credit.transactions.add(transaction) diff --git a/apps/member/templates/member/includes/profile_info.html b/apps/member/templates/member/includes/profile_info.html index 372592d5..b7f2fe70 100644 --- a/apps/member/templates/member/includes/profile_info.html +++ b/apps/member/templates/member/includes/profile_info.html @@ -38,7 +38,7 @@
{% trans 'address'|capfirst %}
{{ user_object.profile.address }}
- {% if "note.view_note"|has_perm:user_object.note %} + {% if user_object.note and "note.view_note"|has_perm:user_object.note %}
{% trans 'balance'|capfirst %}
{{ user_object.note.balance | pretty_money }}
@@ -47,7 +47,7 @@ {% endif %} -{% if user_object.pk == user_object.pk %} +{% if user_object.pk == user.pk %}
{% trans 'API token' %} diff --git a/apps/note/models/notes.py b/apps/note/models/notes.py index 0d58195e..49b9fd58 100644 --- a/apps/note/models/notes.py +++ b/apps/note/models/notes.py @@ -109,12 +109,16 @@ class Note(PolymorphicModel): # Save alias a.note = self + # Consider that if the name of the note could be changed, then the alias can be created. + # It does not mean that any alias can be created. + a._force_save = True a.save(force_insert=True) else: # Check if the name of the note changed without changing the normalized form of the alias alias = Alias.objects.get(normalized_name=Alias.normalize(str(self))) if alias.name != str(self): alias.name = str(self) + alias._force_save = True alias.save() def clean(self, *args, **kwargs): diff --git a/apps/permission/fixtures/initial.json b/apps/permission/fixtures/initial.json index a3db88e8..64c7db5a 100644 --- a/apps/permission/fixtures/initial.json +++ b/apps/permission/fixtures/initial.json @@ -2743,6 +2743,38 @@ "description": "Supprimer une remise" } }, + { + "model": "permission.permission", + "pk": 176, + "fields": { + "model": [ + "auth", + "user" + ], + "query": "{\"profile__registration_valid\": false}", + "type": "change", + "mask": 1, + "field": "", + "permanent": false, + "description": "Modifier n'importe quel utilisateur non encore inscrit" + } + }, + { + "model": "permission.permission", + "pk": 177, + "fields": { + "model": [ + "member", + "profile" + ], + "query": "{\"registration_valid\": false}", + "type": "change", + "mask": 1, + "field": "", + "permanent": false, + "description": "Modifier n'importe quel profil non encore inscrit" + } + }, { "model": "permission.role", "pk": 1, @@ -2952,7 +2984,9 @@ 172, 173, 174, - 175 + 175, + 176, + 177 ] } }, @@ -3132,7 +3166,9 @@ 172, 173, 174, - 175 + 175, + 176, + 177 ] } }, @@ -3164,7 +3200,9 @@ 167, 168, 170, - 171 + 171, + 176, + 177 ] } }, @@ -3330,10 +3368,13 @@ 138, 139, 140, + 143, 145, 146, 147, - 150 + 150, + 176, + 177 ] } }, diff --git a/apps/treasury/models.py b/apps/treasury/models.py index 6e78db48..cabec830 100644 --- a/apps/treasury/models.py +++ b/apps/treasury/models.py @@ -293,7 +293,7 @@ class SogeCredit(models.Model): @property def valid(self): - return self.credit_transaction.valid + return self.credit_transaction and self.credit_transaction.valid @property def amount(self): @@ -323,6 +323,7 @@ class SogeCredit(models.Model): # Refresh credit amount self.save() self.credit_transaction.valid = True + self.credit_transaction._force_save = True self.credit_transaction.save() self.save() @@ -335,7 +336,7 @@ class SogeCredit(models.Model): @transaction.atomic def save(self, *args, **kwargs): if not self.credit_transaction: - self.credit_transaction = SpecialTransaction.objects.create( + credit_transaction = SpecialTransaction( source=NoteSpecial.objects.get(special_type="Virement bancaire"), destination=self.user.note, quantity=1, @@ -346,6 +347,10 @@ class SogeCredit(models.Model): bank="Société générale", valid=False, ) + credit_transaction._force_save = True + credit_transaction.save() + credit_transaction.refresh_from_db() + self.credit_transaction = credit_transaction elif not self.valid: self.credit_transaction.amount = self.amount self.credit_transaction._force_save = True diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 0424f700..a391c4f6 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -1017,7 +1017,7 @@ msgstr "Changer le mot de passe" #: apps/member/templates/member/includes/profile_info.html:53 msgid "API token" -msgstr "Acces API" +msgstr "Accès API" #: apps/member/templates/member/manage_auth_tokens.html:19 msgid "Token"