fix: [user:checkPermissionRestriction] Refactor the function to support more edge-cases
parent
9a2e94989f
commit
b121399304
|
@ -88,22 +88,33 @@ class UsersTable extends AppTable
|
||||||
if (!isset($this->PermissionLimitations)) {
|
if (!isset($this->PermissionLimitations)) {
|
||||||
$this->PermissionLimitations = TableRegistry::get('PermissionLimitations');
|
$this->PermissionLimitations = TableRegistry::get('PermissionLimitations');
|
||||||
}
|
}
|
||||||
$new = $entity->isNew();
|
|
||||||
$permissions = $this->PermissionLimitations->getListOfLimitations($entity);
|
$permissions = $this->PermissionLimitations->getListOfLimitations($entity);
|
||||||
foreach ($permissions as $permission_name => $permission) {
|
foreach ($permissions as $permission_name => $permission) {
|
||||||
foreach ($permission as $scope => $permission_data) {
|
foreach ($permission as $scope => $permission_data) {
|
||||||
if (!empty($entity['meta_fields'])) {
|
$valueToCompareTo = $permission_data['current'];
|
||||||
$enabled = false;
|
|
||||||
|
$enabled = false;
|
||||||
|
if (!empty($entity->meta_fields)) {
|
||||||
foreach ($entity['meta_fields'] as $metaField) {
|
foreach ($entity['meta_fields'] as $metaField) {
|
||||||
if ($metaField['field'] === $permission_name) {
|
if ($metaField['field'] === $permission_name) {
|
||||||
$enabled = true;
|
$enabled = true;
|
||||||
|
if ($metaField->isNew()) {
|
||||||
|
$valueToCompareTo += !empty($metaField->value) ? 1 : 0;
|
||||||
|
} else {
|
||||||
|
$valueToCompareTo += !empty($metaField->value) ? 0 : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$enabled) {
|
}
|
||||||
continue;
|
|
||||||
|
if (!$enabled && !empty($entity->_metafields_to_delete)) {
|
||||||
|
foreach ($entity->_metafields_to_delete as $metaFieldToDelete) {
|
||||||
|
if ($metaFieldToDelete['field'] === $permission_name) {
|
||||||
|
$valueToCompareTo += !empty($metaFieldToDelete->value) ? -1 : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$valueToCompareTo = $permission_data['current'] + ($new ? 1 : 0);
|
|
||||||
if ($valueToCompareTo > $permission_data['limit']) {
|
if ($valueToCompareTo > $permission_data['limit']) {
|
||||||
return [
|
return [
|
||||||
$permission_name =>
|
$permission_name =>
|
||||||
|
|
Loading…
Reference in New Issue