Sylius / RbacPlugin

Sylius roles and permissions management plugin
32 stars 38 forks source link

"Expected a value other than null." (AdministrationRole is null) #55

Open itinance opened 5 years ago

itinance commented 5 years ago

After installation of RBAC following the Docs, i run into the following issue:

Expected a value other than null.

throwed in:

http://localhost/_profiler/open?file=vendor/sylius/rbac-plugin/src/Access/Checker/AdministratorAccessChecker.php&line=19#line19

public function canAccessSection(AdminUserInterface $admin, AccessRequest $accessRequest): bool
    {
        $administrationRole = $admin->getAdministrationRole();
        Assert::notNull($administrationRole);

The reason is that the getAdministrationRole() returns null as a null value is stored in the sylius_admin_user-table for the column administrationRole_id.

Which ID should be inserted there to make it work with an existing admin-user? This way no admin-section can be reached to configure the roles within the Backend. Therefor an initial value needs to be inserted in the foreground while installing the Plugin.

We should also be more clear here in the README.

Any help is appreciated.

itinance commented 5 years ago

Since there is already a record in the table sylius_rbac_administration_role for a configuration-setup, i entered their ID (2) into the field administrationRole_id.

One step further, the relation could not be resolved as the ORM-Tags within the AdministrationRoleTrait are not used when orm.yml files are present.

So i configured the ORM-relation in my AdminUser.orm.yml as follows:

AppBundle\Entity\AdminUser:
    type: entity
    table: sylius_admin_user
    fields:
    manyToOne:
        administrationRole:
            targetEntity: Sylius\RbacPlugin\Entity\AdministrationRole
            joinColumn:
                name: administrationRole_id
                referencedColumnName: id
                nullable: false

Now i can access the Admin Dashboard again. But when i press "Edit" in the Administrators-Tabelle, the following error is thrown:

User has no field or association named administration_role

SELECT o FROM AppBundle\Entity\AdminUser o ORDER BY o.administration_role desc

And indeed, there is a mixed naming switched from underscore-delemiter to camelCase in administrationRole_id.

Has anyone used this Plugin and can share AdminUser-Class with Migration-Files and orm.yml-Definition?

bartoszpietrzak1994 commented 5 years ago

Hello Hagen!

Have you run the command sylius-rbac:install-plugin after adding the plugin dependency to your project? It adds two roles (Configurator and No Sections Access) and then ask you to provide the email of the administrator that will have the Configurator role assigned. The rest of system administrators will have the No Sections Access role assigned.