UseMuffin / Footprint

CakePHP plugin to allow passing currently logged in user to model layer.
MIT License
95 stars 23 forks source link

Is this plugin actually working? #41

Closed xavier83ar closed 7 years ago

xavier83ar commented 7 years ago

I've installed and set it up, everything seems to be ok, the user is properly loaded into FootprintAwareTrait::_currentUserInstance but _footprint option key is empty when Model.beforeSave happens.

I've debugging it (with xdebug) and it seems that FootprintListener::handleEvent gets fired after Model.beforeSave, so then '_footprint' option key gets populated with current user, but it's useless as Model events already happened.

I don't know if I'm doing something wrong or what, there is no config issues, no error, just it doesn't work. Does anybody get this plugin working?

Spriz commented 7 years ago

We're using it in production, are you working in plugins or only in src? We have the auth magic happening in controller.initialize if that changes anything.

xavier83ar commented 7 years ago

Well, I feel somewhat fool. In order to recreate the issue and provide a (not) working example, I've created a fresh new cakephp project from composer, created some basic database schema and added footprint plugin... and voalá, it's worked. So, I guess the issue is in my other project.

Nevertheless, I should mention that to make FootprintBehavior::beforeFind callback to work I had to dig in into plugin's code because I didn't found it in documentation. Using a user_id field to track "owner", behavior setup looks something like this:

$this->addBehavior('Muffin/Footprint.Footprint', [
            'events' => [
                'Model.beforeSave' => [
                    'user_id' => 'new',
                ],
                'Model.beforeFind' => [
                    'user_id' => '_footprint.id'
                ]
            ],
        ]);

I leave the example here as may be usefull for someone else.

inoas commented 7 years ago

Could you add it to https://github.com/UseMuffin/Footprint/blob/master/README.md ?