new: [metafield restrictions] not enforced on a user edit that doesn't change the state of the offending value

- if a user is already over the limit of a restriction, they should still be editable
dependabot/npm_and_yarn/webroot/theme/braces-3.0.3
iglocska 2024-06-04 14:10:32 +02:00
parent deae8bad3b
commit dee43d8d51
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
1 changed files with 9 additions and 1 deletions

View File

@ -89,11 +89,19 @@ class UsersTable extends AppTable
foreach ($permissions as $permission_name => $permission) {
foreach ($permission as $scope => $permission_data) {
$valueToCompareTo = $permission_data['current'];
$enabled = false;
if (!empty($entity->meta_fields)) {
foreach ($entity['meta_fields'] as $metaField) {
if ($metaField['field'] === $permission_name) {
if (!$entity->new) {
$conditions = [
'field' => $permission_name, 'scope' => 'user', 'parent_id' => $entity->id
];
$existing = $this->MetaFields->find()->where($conditions)->select(['value'])->first();
if ($existing && (bool)$metaField['value'] === (bool)$existing['value']) {
continue 2;
}
}
$enabled = true;
if ($metaField->isNew()) {
$valueToCompareTo += !empty($metaField->value) ? 1 : 0;