From 09805a34436ec50f91dd70c33da557e91b89f757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 28 Mar 2022 17:19:47 +0200 Subject: [PATCH] translate user role on HasMinimumRole rule (because of arcadia !!) --- app/Rules/HasMinimumRole.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/Rules/HasMinimumRole.php b/app/Rules/HasMinimumRole.php index ee8092d..94cc932 100644 --- a/app/Rules/HasMinimumRole.php +++ b/app/Rules/HasMinimumRole.php @@ -38,6 +38,29 @@ class HasMinimumRole implements Rule $this->minimumRole = \intval($this->roles[$role]); } + /** + * Convert Arcadia role to usable roles + * + * 1 (ADMIN) => 1 + * 2 (LECTEUR) => 4 + * 3 (ADMIN) => 3 + * 4 (REDACTEUR) => 2 + * + * Donc : + * 1 (ADMIN) + * 2 (REDACTEUR) + * 3 (ADMIN) + * 4 (LECTEUR) + * + * @param integer $value + * @return integer + */ + private function translateRoleValue(int $value): int + { + $translation = [2 => 4, 4 => 2]; + return in_array($value, $translation) ? $translation[$value] : $value; + } + /** * Determine if the validation rule passes. * @@ -51,7 +74,7 @@ class HasMinimumRole implements Rule if (!\ctype_digit(strval($value))) { return false; }; - return \intval($value) <= $this->minimumRole; + return $this->translateRoleValue(\intval($value)) <= $this->minimumRole; } /**