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

Duplicate members #40

Open
kaj opened this issue Jan 20, 2022 · 1 comment
Open

Duplicate members #40

kaj opened this issue Jan 20, 2022 · 1 comment

Comments

@kaj
Copy link
Member

kaj commented Jan 20, 2022

Changing some fields in the finger.json source seems to create duplicate users. I'm not alert enough to find the actual problem at the moment, but we need to investigate this. I think some change is needed here:

# We need to uniqily identify a member in finger.json and map it to Member.
# Use the special key fingerweb_identifier if found in finger.json, if not
# found use the username.
#
# We have members without identifier and usernames, for these use the
# following fallbacks:
# - User provided email address
# - Stacken email adress (will be generated from the username (if it's exists))
# - First and last name
#
# If the above causes conflicts, add and fingerweb_identifier key to the member.
if fields["identifier"]:
member, _ = self.update_or_create(identifier__exact=fields["identifier"], defaults=fields)
else:
user_from_db = User.objects.filter(username__exact=user.get("användarnamn")).first()
if self.is_valid_user(user) and user_from_db:
member, _ = self.update_or_create(id=user_from_db.id, defaults=fields)
elif "@" in fields.get("email", ""):
member, _ = self.update_or_create(email__exact=fields["email"], defaults=fields)
else:
member, _ = self.update_or_create(
first_name__exact=fields["first_name"], last_name__exact=fields["last_name"], defaults=fields
)
# Create and/or update an account for the member
if fields.get("has_signed") and self.is_valid_user(user):
user_fields = {
"member": member,
"date_joined": fields.get("date_joined"),
}
User.objects.update_or_create(username=user.get("användarnamn"), defaults=user_fields)

@kaj
Copy link
Member Author

kaj commented Dec 8, 2023

I have improved this situation a bit, in e.g. 4e65864 ..1f25270 .

Some problems remain. I think "upgrading" a member to have a user will probably create a new member object, which will conflict with the existing one.

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

No branches or pull requests

1 participant