translate user role on HasMinimumRole rule (because of arcadia !!)
This commit is contained in:
parent
981119da29
commit
09805a3443
1 changed files with 24 additions and 1 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue