translate user role on HasMinimumRole rule (because of arcadia !!)

This commit is contained in:
Jérémy Munsch 2022-03-28 17:19:47 +02:00
parent 981119da29
commit 09805a3443
No known key found for this signature in database
GPG key ID: 55196BEE445F6049

View file

@ -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;
}
/**