diff --git a/config/permissions.yaml b/config/permissions.yaml index a423cb6f..5dad5f3b 100644 --- a/config/permissions.yaml +++ b/config/permissions.yaml @@ -24,15 +24,19 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co edit: label: "perm.edit" bit: 2 + alsoSet: 'read' create: label: "perm.create" bit: 4 + alsoSet: ['read', 'edit'] move: label: "perm.part.move" bit: 6 + alsoSet: 'read' delete: label: "perm.delete" bit: 8 + alsoSet: ['read', 'edit'] search: label: "perm.part.search" bit: 10 @@ -74,6 +78,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co edit: label: "perm.edit" bit: 2 + alsoSet: 'read' parts_description: <<: *PART_ATTRIBUTE @@ -129,15 +134,18 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co edit: label: "perm.edit" bit: 2 + alsoSet: 'read' create: label: "perm.create" bit: 4 + alsoSet: ['read', 'edit'] move: label: "perm.move" bit: 6 delete: label: "perm.delete" bit: 8 + alsoSet: ['read', 'edit'] list_parts: label: "perm.list_parts" bit: 10 @@ -201,17 +209,21 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co edit: label: "perm.edit" bit: 2 + alsoSet: 'read' create: label: "perm.create" bit: 4 + alsoSet: ['read', 'edit'] move: label: "perm.move" bit: 6 delete: label: "perm.delete" bit: 8 + alsoSet: ['read', 'delete'] edit_permissions: label: "perm.edit_permissions" + alsoSet: ['read', 'edit'] bit: 10 users: @@ -223,24 +235,31 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co bit: 0 create: label: "perm.create" + alsoSet: ['read', 'edit_username', 'edit_infos'] bit: 4 delete: label: "perm.delete" + alsoSet: ['read', 'edit'] bit: 8 edit_username: label: "perm.users.edit_user_name" + alsoSet: ['read'] bit: 2 change_group: label: "perm.users.edit_change_group" + alsoSet: 'read' bit: 6 edit_infos: label: "perm.users.edit_infos" + alsoSet: 'read' bit: 10 edit_permissions: label: "perm.users.edit_permissions" + alsoSet: 'read' bit: 12 set_password: label: "perm.users.set_password" + alsoSet: 'set_read' bit: 14 change_user_settings: label: "perm.users.change_user_settings" @@ -256,11 +275,13 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co update_db: label: "perm.database.update_db" bit: 2 + alsoSet: 'see_status' read_db_settings: label: "perm.database.read_db_settings" bit: 4 write_db_settings: label: "perm.database.write_db_settings" + alsoSet: ['read_db_settings', 'see_status'] bit: 2 config: @@ -272,6 +293,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co bit: 0 edit_config: label: "perm.config.edit_config" + alsoSet: 'read_config' bit: 2 server_info: label: "perm.config.server_info" @@ -289,6 +311,7 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co bit: 2 delete_logs: label: "perm.delete_logs" + alsoSet: 'show_logs' bit: 4 devices_parts: @@ -300,12 +323,15 @@ perms: # Here comes a list with all Permission names (they have a perm_[name] co bit: 0 edit: label: "perm.edit" + alsoSet: 'read' bit: 2 create: label: "perm.create" + alsoSet: ['edit', 'read'] bit: 6 delete: label: "perm.delete" + alsoSet: ['edit', 'read'] bit: 8 self: diff --git a/src/Configuration/PermissionsConfiguration.php b/src/Configuration/PermissionsConfiguration.php index 0c34b2ef..09c1fb7b 100644 --- a/src/Configuration/PermissionsConfiguration.php +++ b/src/Configuration/PermissionsConfiguration.php @@ -61,7 +61,9 @@ class PermissionsConfiguration implements ConfigurationInterface ->children() ->scalarNode('name')->end() ->scalarNode('label')->end() - ->scalarNode('bit')->end(); + ->scalarNode('bit')->end() + ->arrayNode('alsoSet') + ->beforeNormalization()->castToArray()->end()->scalarPrototype()->end(); return $treeBuilder; } diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index 5fe135b4..d9bea4ff 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -64,6 +64,7 @@ namespace App\Entity\UserSystem; use App\Entity\Base\NamedDBElement; use App\Security\Interfaces\HasPermissionsInterface; use App\Validator\Constraints\Selectable; +use App\Validator\Constraints\ValidPermission; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Validator\Constraints as Assert; @@ -163,6 +164,7 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf /** @var PermissionsEmbed * @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_") + * @ValidPermission() */ protected $permissions; diff --git a/src/Validator/Constraints/ValidPermission.php b/src/Validator/Constraints/ValidPermission.php new file mode 100644 index 00000000..a94cedca --- /dev/null +++ b/src/Validator/Constraints/ValidPermission.php @@ -0,0 +1,46 @@ +resolver = $resolver; + $this->perm_structure = $resolver->getPermissionStructure(); + } + + /** + * Checks if the passed value is valid. + * + * @param mixed $value The value that should be validated + * @param Constraint $constraint The constraint for the validation + */ + public function validate($value, Constraint $constraint) + { + if (!$constraint instanceof ValidPermission) { + throw new UnexpectedTypeException($constraint, ValidPermission::class); + } + + /** @var HasPermissionsInterface $perm_holder */ + $perm_holder = $this->context->getObject(); + + //Check for each permission and operation, for an alsoSet attribute + foreach ($this->perm_structure['perms'] as $perm_key => $permission) { + foreach ($permission['operations'] as $op_key => $op) { + if (!empty($op['alsoSet']) && + $this->resolver->dontInherit($perm_holder, $perm_key, $op_key) === true) { + //Set every op listed in also Set + foreach ($op['alsoSet'] as $set_also) { + $this->resolver->setPermission($perm_holder, $perm_key, $set_also, true); + } + } + } + } + } +} \ No newline at end of file diff --git a/templates/AdminPages/EntityAdminBase.html.twig b/templates/AdminPages/EntityAdminBase.html.twig index 3c05d5c4..e1736cf9 100644 --- a/templates/AdminPages/EntityAdminBase.html.twig +++ b/templates/AdminPages/EntityAdminBase.html.twig @@ -38,6 +38,8 @@ {% endif %} + {{ form_errors(form) }} +