Skip to content

Conversation

@mtancoigne
Copy link
Contributor

Added some config keys to allow a simpler configuration through loadComponent and

  • Changed the behaviour of undefined pivot tables(role plugin name, pivot table plugin name).
  • Changed the behavior for undefined pivot tables : user_roles instead of roles_users (seems more logical to me, as users have roles)
  • Updated the docs
  • removed the CLASS_USER constant : custom plugin is handled with the pivotTablePlugin option.

I can't run the tests as i'm not at home, but as far as I tried, it works.

@bravo-kernel
Copy link
Contributor

Nice starting point.

I personally do not like making non-CakePHP defaults the "defaults" for this plugin. For example; the original roles_users pivot table name follows Cake naming standards, changing it to user_roles does not.

@dereuromark
Copy link
Owner

I agree with you in general on the user_roles (use that myself), but the former was and is convention. So I am with @bravo-kernel .

@mtancoigne
Copy link
Contributor Author

ok, and the build is not passing, so... :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be Users, sure this needs to be singular now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure but I recall discussing this with you before (and reverting the exact same thing). Might be totally unrelated though 😜

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was stuck with an habit of naming my pivot tables in a singular_plural form... I was sure to read that in cake doc some years ago, but it appears i'm totally wrong :) I'm reverting this now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

singular_plural is fine in general, just not for HABTM. And this pivot table is HABTM.
People can use their own convention as custom config.

@dereuromark
Copy link
Owner

Yes, the builds break because you changed config but not the fixtures
https://github.com/el-cms/cakephp-tinyauth/blob/master/tests/TestCase/Auth/TinyAuthorizeTest.php#L23
Just revert the default back to roles_user and it should all be green again.

@bravo-kernel
Copy link
Contributor

roles_users

@dereuromark
Copy link
Owner

Yes :P

…d added missing spaces... to correct previous failing PR
docs/README.md Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overridden

@mtancoigne
Copy link
Contributor Author

Thanks for your remarks :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no spacing after cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn autoformat...

@mtancoigne
Copy link
Contributor Author

... If there is anything else, i'll do one commit to fix the remaining things instead of small multiple ones...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please look into your changes again and only change whats necessary, those lines are neither correct nor necessary to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that, I use an autoformat feature on my IDE to keep my code clean between all of my projects... But as it depends from one project to another, I should have checked the spaces changes before commiting.

@bravo-kernel
Copy link
Contributor

And more importantly... hang in there buddy, almost there :wink

@dereuromark
Copy link
Owner

@bravo-kernel I am OK with the changes. What do you think?

@mtancoigne Can you please squash all commits?

@bravo-kernel
Copy link
Contributor

I think we should make the doc about loading the plugin more explanatory (and consistent with other plugin readmes). Copy-paste from this example if you like https://gist.github.com/bravo-kernel/7219d5bd8295b265b893.

Other than that I just dropped it in my app and no issues there so looks good to me.

@dereuromark
Copy link
Owner

@bravo-kernel That can be added after the PR mege.

@bravo-kernel
Copy link
Contributor

True, ship it

README.md Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please keep the loadAll() part?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need for that now that bootstrap is no longer there?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point ;) Derp
Never mind then.

@bravo-kernel
Copy link
Contributor

Thanks for including the plugin load Mr. @mtancoigne

dereuromark added a commit that referenced this pull request Jan 5, 2016
@dereuromark dereuromark merged commit dd45ad2 into dereuromark:master Jan 5, 2016
@dereuromark
Copy link
Owner

Thank you! I will soon tag a new 1.2.0 release.

@bravo-kernel
Copy link
Contributor

👏

@dereuromark
Copy link
Owner

I am still a little bit hesitant regarding the new plugin keys 'pivotTablePlugin' and 'rolesTablePlugin'.
And what about plugin for Users table?
IMO those should all 3 work as the rest of CakePHP using the prefix dot syntax:

// App
'usersTable' => 'Users',

// User plugin
'usersTable' => 'User.Users',

Those two keys are not necessary then. And Users table can also be pluginized if desired.

@mtancoigne
Copy link
Contributor Author

For usersTable, there seems to be no need, as i did not see any probe to it in the code. The only place where it's used is on lines 368/383 (sorry, I don't know how to reference those in this comment), to create the pivot table name... So if a pivotTablePlugin is specified it will precede the UsersRoles class name. If we use an userTablePlugin, that would make a strange PivotPlugin.UserPlugin.UsersRoles table. As the user object is passed to validate() any fetch on the users table seems useless...

But I may be wrong.

@dereuromark
Copy link
Owner

Why PivotPlugin.UserPlugin.UsersRoles? You can only have one plugin per class name.
And the pivot table must in in one of those (or a totally different one).

@mtancoigne
Copy link
Contributor Author

Just to be sure, creating a usersTablePlugin, even if it's unused, may be useless as there is no naming convention for that kind of thing. A line in the doc to explain that users should NOT include the plugin name in the usersTableName may be enough... If cake had some standards about naming configuration options in those particular cases, it would be obvious to add it, but it's not the case...

I want the advice of @bravo-kernel to push me in :)

(Or someone else too)

@bravo-kernel
Copy link
Contributor

Re-reading the comments and looking at the code I believe must side with @dereuromark here if I understand correctly that the starting point of the logic is that there always can/should be:

  • only one single roles table
  • only one single pivot table.

If this is indeed the case then the new rolesTablePlugin and pivotTablePlugin do not make much sense anymore, are indeed redundant IMO and should thus be removed.

Where I am lost is how the a plugin is even related to the two tables. As far as I know there (unfortunately) is no way to prefix/distinguish plugin tables so.... what are we even trying to support here in the first case? In all honesty.... I might be totally wrong here so some feedback from @dereuromark would be welcome.

@mtancoigne
Copy link
Contributor Author

As far as I understand the code, there is, for now three config key/values, used in different setups (all for multi-group support):

  • usersTable to define the users model. It's used when the Users model us not... Users or when the pivotTable is not defined.
  • rolesTable to define the roles model. It's used when the Roles model us not... well... Roles or when the pivotTable is not defined.
  • pivotTable is the pivot model.

Then, as the userTable, rolesTable and pivotTable may have been defined in a custom plugin, we need a userTablePlugin, rolesTablePlugin and pivotTablePlugin, to fetch the right models in the right place.

In the code, we have this :

// line 365
// multi-role: reverse engineer name of the pivot table IF NOT DEFINED.
        $rolesTableName = $this->_config['rolesTable'];
        $pivotTableName = $this->_config['pivotTable'];
        $usersTableName = $this->_config['usersTable'];
        if (!$pivotTableName) {
            $tables = [
                $usersTableName,
                $rolesTableName
            ];
            asort($tables);
            $pivotTableName = implode('', $tables);
        }

        // fetch roles directly from the pivot table
        $pivotTablePlugin = $this->_config['pivotTablePlugin'];
        if (!$pivotTablePlugin) {
            $pivotTableName = $pivotTablePlugin . '.' . $pivotTableName;
        }
        $pivotTable = TableRegistry::get($pivotTableName);

So : If the pivot table is not defined it is created from users and role tables. Then the pivotTablePlugin is added, if defined. (note: It should be clear to users in docs, a point on this may be good)

roleTablePlugin and rolesTablePlugin are used to get the available roles in db (_getAvailableRoles())

But usersTable is only used to create a pivot model name if none is given. @dereuromark's idea was to keep a userTablePlugin config key to not disappoint users, but i don't find this pertinent as there are nothing like a standard or convention in cakephp that would make users less disappointed with a key like this. The doc should be enough...

@bravo-kernel
Copy link
Contributor

Hmmm, I guess I was a bit too quick with the last point there Mr @mtancoigne . Seems we are not talking about the table but about figuring out which Table class to load in this line and this line correct?

In that light I totally agree with what @dereuromark suggested in #18 (comment) so all we seem to need is just a way to filter/parse the value of the three "old" keys userTable, rolesTable and pivotTable to support CakePHP dotted plugin notation.

Jump on to irc if you like to discuss more efficiently. Good to see you getting involved 👍

@bravo-kernel
Copy link
Contributor

ps: check http://book.cakephp.org/3.0/en/appendices/glossary.html and find plugin syntax

@dereuromark
Copy link
Owner

Yes, plugin syntax should be accepted, so people using it won't trip over it, making the additional config keys unncessary :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants