Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unique email address handling #27652

Closed
wants to merge 2 commits into from
Closed

Fix unique email address handling #27652

wants to merge 2 commits into from

Conversation

PVince81
Copy link
Contributor

@PVince81 PVince81 commented Apr 18, 2017

Description

Fixes upgrade and user:sync issues when one user backend provides multiple users with the same email address, or multiple backends provide different users with the same email address.

Related Issue

Fixes critical part of #27626

Motivation and Context

See ticket

How Has This Been Tested?

  • TEST: upgrade with duplicate email => second user must have empty email, no failures
  • TEST: user:sync of new users where LDAP has duplicate email => second user has empty email
  • TEST: user:sync of existing users where one's email is changed to a duplicate in LDAP => user with modified email receives an empty email address instead of failing
  • TEST: same as above with two backends where the second user is in a separate backend

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

TODOs

  • testing (see above)
  • test with multiple
  • add / adjust unit tests
  • integration test if possible ?

Because email addresses must be unique so there can be only a single
account entry for each email address.
@PVince81
Copy link
Contributor Author

openLDAP doesn't let me set multiple duplicate email addresses, which is good. So couldn't test.
I'd would need to cheat by setting the email in a different field.

As for having a duplicate email, one in DB and then one in LDAP, this fix is not testable because LDAP already tries to write the email earlier, bug raised here owncloud/user_ldap#72

When trying to insert/update a user with a duplicate email address,
change that one to empty to avoid failure or loss of access.
return $this->findEntities($qb->getSQL(), $qb->getParameters());
$results = $this->findEntities($qb->getSQL(), $qb->getParameters());
if (empty($results)) {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced about these changes: if the plan is to support duplicated emails at some point, I think it's better to keep this as it is and handle the duplication at a higher level. As long as the callers are aware that several accounts can be returned by the same email, it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if the plan is to support duplicated emails at some point

It's not, see #27626 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DeepDiver1975 your feedback ? This will tell whether to revert the above and use the below appraoch instead.

throw $ex;
}
// find out if there is another account with the same email address
$existingAccount = $this->mapper->getByEmail($email);
Copy link
Member

Choose a reason for hiding this comment

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

I'd fetch the accounts, check the number of accounts, and if it's only one then verify it's the same account or another account than the one we're trying to insert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm... that could be another approach, yes.

}

// it's a duplicate email, so clear the field and try again
$a->setEmail(null);
Copy link
Member

Choose a reason for hiding this comment

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

❗️ Note that it will set an empty email instead of null in the DB, which will likely cause trouble. I'm affraid this could lead to an infinite loop if there are 3 or more users with the same email.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I'll replace this to an empty string. Would that prevent the infinite loop ?

When testing this worked for me with null, but better be safe.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so. You'll be setting an empty email for the first duplicate; for the next duplicate you'll set another empty email causing another duplication exception because you've already set an empty email for another user.
On a second thought, it might not cause an infinite loop, but I don't think that will be handled properly. There is no progress other than "skip one duplicated email"

@PVince81
Copy link
Contributor Author

Obsoleted by #27662 (comment)

@PVince81 PVince81 closed this Apr 20, 2017
@PVince81 PVince81 deleted the unique-email branch April 20, 2017 07:43
@lock
Copy link

lock bot commented Aug 3, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants