acantepie/umbrella

make:admin:user and BaseAdminUser should support doctrine attributes

tacman opened this issue · 5 comments

Umbrella version affected

all

Description

If a project is using doctrine attributes (rather than annotations), generating the admin user should generate attributes and not annotations.

How to reproduce

Configure doctrine for attributes

# config/packages/doctrine.yaml

doctrine:
  orm:
    mappings:
      App:
        type: attribute

make the admin user class and clear the cache

php bin/console make:admin:user
php bin/console cache:clear

The error is

Class "App\Entity\AdminUser" sub class of "Umbrella\AdminBundle\Entity\BaseAdminUser" is not a valid entity or mapped super class.  

The BaseAdminUser needs to support both annotations and attributes, which should be possible:

https://tomasvotruba.com/blog/how-to-refactor-custom-doctrine-annotations-to-attributes/

Additional Context

No response

I will take a look.
I think the right way of doing that is to use XML or php instead of annotation to declare doctrine mapping ( https://symfony.com/doc/current/bundles/best_practices.html#doctrine-entities-documents )

I'm not completely understanding why the admin user is a separate entity.
I've just been using the out-of-the-box Symfony security / authentication
system, and setting ROLE_ADMIN or ROLE_SUPER_ADMIN as necessary

You speak about BaseAdminUser and AdminUser created by maker ?
BaseAdminUser contains all fields required by admin to deal with User (email, password, active, ...).
BaseAdminUser is not a concrete class because in some app you have to add extra fields on user. The only way of doing that is to declare BaseAdminUser as MappedSuperclass and define the concrete class on app.

(This is the same behaviour on FOSUserBundle for example : https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.rst )

Edit : https://symfony.com/doc/current/bundles/override.html#entities-entity-mapping

Ah, I think I understand my confusion.

I was under the impression that AdminUser was a under with admin rights (like ROLE_ADMIN in Symfony). But really AdminUser refers to a User that was created and managed by the AdminBundle. So I could be thinking of it as UmbrellaUser -- a user of the system.

If this is correct, then I don't need to run make:user (the Symfony maker), since your maker creates a user that can be used within the Symfony security system.

I think my problem was creating Users and AdminUsers.

Php 8.0 attributes is now fully supported on last version :)