Disambiguation in kfet's permission handling

In some places we used to refer to permissions based on their codename
only (the part after the dot "." in the following examples) which can be
ambiguous. Typically, we might define permissions like "bds.is_team" or
"cof.is_team" in the near future ;)
This commit is contained in:
Martin Pépin 2019-12-21 16:26:59 +01:00
parent 67e28c704f
commit 64c792b11f
No known key found for this signature in database
GPG key ID: E7520278B1774448
5 changed files with 37 additions and 25 deletions

View file

@ -18,7 +18,7 @@ class TestStats(TestCase):
user.set_password("foobar")
user.save()
Account.objects.create(trigramme="FOO", cofprofile=user.profile)
perm = Permission.objects.get(codename="is_team")
perm = Permission.objects.get_by_natural_key("is_team", "kfet", "account")
user.user_permissions.add(perm)
user2 = User.objects.create(username="Barfoo")

View file

@ -1855,7 +1855,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(
json_data["errors"]["missing_perms"],
["Enregistrer des commandes avec commentaires"],
["[kfet] Enregistrer des commandes avec commentaires"],
)
def test_group_on_acc_frozen(self):
@ -1898,7 +1898,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
self.assertEqual(resp.status_code, 403)
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(
json_data["errors"]["missing_perms"], ["Forcer le gel d'un compte"]
json_data["errors"]["missing_perms"], ["[kfet] Forcer le gel d'un compte"]
)
def test_invalid_group_checkout(self):
@ -2373,7 +2373,9 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
self.assertEqual(resp.status_code, 403)
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(json_data["errors"]["missing_perms"], ["Effectuer une charge"])
self.assertEqual(
json_data["errors"]["missing_perms"], ["[kfet] Effectuer une charge"]
)
def test_withdraw(self):
data = dict(
@ -2648,7 +2650,8 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
self.assertEqual(resp.status_code, 403)
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(
json_data["errors"]["missing_perms"], ["Modifier la balance d'un compte"]
json_data["errors"]["missing_perms"],
["[kfet] Modifier la balance d'un compte"],
)
def test_invalid_edit_expects_comment(self):
@ -2956,7 +2959,7 @@ class KPsulPerformOperationsViewTests(ViewTestCaseMixin, TestCase):
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(
json_data["errors"],
{"missing_perms": ["Enregistrer des commandes en négatif"]},
{"missing_perms": ["[kfet] Enregistrer des commandes en négatif"]},
)
def test_invalid_negative_exceeds_allowed_duration_from_config(self):
@ -3780,7 +3783,7 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(
json_data["errors"],
{"missing_perms": ["Annuler des commandes non récentes"]},
{"missing_perms": ["[kfet] Annuler des commandes non récentes"]},
)
def test_already_canceled(self):
@ -3926,7 +3929,7 @@ class KPsulCancelOperationsViewTests(ViewTestCaseMixin, TestCase):
json_data = json.loads(resp.content.decode("utf-8"))
self.assertEqual(
json_data["errors"],
{"missing_perms": ["Enregistrer des commandes en négatif"]},
{"missing_perms": ["[kfet] Enregistrer des commandes en négatif"]},
)
def test_partial_0(self):