collective / dexterity.membrane

enables dexterity content items to be used as users and groups in Plone sites
3 stars 14 forks source link

Support login by email even when not using UUID userids fixes #26 #27

Closed gyst closed 7 years ago

gyst commented 7 years ago

It took me a dozen hours to prove this one-line fix :-(.

Summary: when using email logins without UUID, as is required when working with LDAP, dexterity.membrane breaks. Users are not enumerated, because the enumeration queries on exact_getUserId, which relies on the indexed return value of getUserId, which returns the email address instead of the actual userid. To further complicate matters, the userid is stored in a field called username but the username (login name) in this scenario is actually the email address stored in the email field.

mauritsvanrees commented 7 years ago

Current status: confused. But that has more to do with the current code than with your pull request.

Your change makes sense. The user id should be stable, preferably even not change at all ever. So linking it to a changeable email address is not good. So pick a user id once and stick to it.

My confusion:

I haven't looked at the git history yet to see if that makes things clearer.

Okay, change in current status: going home before it starts raining. :-)

gyst commented 7 years ago

Some extra info:

So, in summary: the confusion between userid and username is a case of deep rottenness in the Plone code base.

I don't think that's fixable. Even in the context of the dx.membrane schema, the actual getUserName() may be the email address while the actual getUserId() may be the UUID, leaving any field which is called either userid or username in a limbo where toggling a registry setting renders it semantically incorrect. Indeed, in the default config both getters bypass schema attributes completely, which explains how this code base can exist without actually having a username attribute.

This PR is essentially a one-line fix, where getUserId() defaults to returning username instead of email. While that may not be perfect, it's clearly superior to the existing situation.

gyst commented 7 years ago

Hold the merge. After doing some more code auditing, I'm reaching the conclusion we should just return self.context.id or self.context.getId() instead of self.context.username.

As to changing settings, that requires a reindex of the profiles. I should add utility methods for that.

gyst commented 7 years ago

OK this is now ready for merge. Username and Userid accessors are now completely decoupled.

gyst commented 7 years ago

As to adding migration utility calls: I've wasted enough of my life in this rabbithole by now :-(. Maybe in another life...

mauritsvanrees commented 7 years ago

Perfect! Thanks a lot. I will merge manually, so I don't include the internal version bumps.

I will add a note in the readme that the user may need to reindex manually.

Also, some of the tests don't work on Python 2.6. I will add a note that we drop support for that officially. Unofficially it may still work: the non-test code should still be fine. But we are only running Travis tests on Python 2.7.

mauritsvanrees commented 7 years ago

Merged. I have released dexterity.membrane 1.2 with this.