Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[#2838] Email unique validator#5100

Merged
amercader merged 3 commits into
ckan:masterfrom
mutantsan:2838-validate-email-for-unique
Jan 27, 2020
Merged

[#2838] Email unique validator#5100
amercader merged 3 commits into
ckan:masterfrom
mutantsan:2838-validate-email-for-unique

Conversation

@mutantsan
Copy link
Copy Markdown
Contributor

@mutantsan mutantsan commented Nov 26, 2019

At the moment, there is no validation for the uniqueness of the email, which does not allow us to use login via email. And it's also can be a vulnerability to spam attacks.

This changes implements the is_email_unique validator, which prevents from creation two or more users with the same email. Also, it's a step to provide authentication via email. Since this changes doesn't touch the models, there are shouldn't be conflicts with existing portals.

Features:

  • includes tests covering changes
  • includes updated documentation
  • includes user-visible changes
  • includes API changes
  • includes bugfix for possible backport

Please [X] all the boxes above that apply

@sivang
Copy link
Copy Markdown
Member

sivang commented Nov 28, 2019

@wardi @amercader would it make sense to have a script actually emailing the dups asking to consolidate the accounts to one account?

@amercader
Copy link
Copy Markdown
Member

@mutantsan yes, as @sivang points out having unique emails is definitely a desired behaviour. But as uniqueness has not been enforced until now, there might be an issue with existing duplicates. You will get an exception when trying to edit one of the users with the same email.

We need to provide guidance on how to migrate. Touching the actual emails is probably too risky so clear warnings in the changelog plus some helpers like the script @sivang suggests is probably safer, and we leave up to maintainers to decide how to fix the duplicates.

The script could be a new command ckan db check-duplicate-emails that returns the user details of those accounts with duplicated emails.
@mutantsan want to add this as part of this PR?

@mutantsan
Copy link
Copy Markdown
Contributor Author

@mutantsan want to add this as part of this PR?
Yes, I will work on it.

@mutantsan
Copy link
Copy Markdown
Contributor Author

@wardi @amercader I'm just thinking about what the command should do. I don't think that emailing to users is a great idea. Can we just update all duplicate emails to empty and let users change it, since they can just update their own profiles and even delete the email?

@amercader
Copy link
Copy Markdown
Member

@mutantsan sorry, I wasn't clear. The command should not do anything to the database or send any email. It should only show a list of users with duplicated emails so the site maintainers can decide what to with them

@davidread
Copy link
Copy Markdown

This probably shouldn't be a top level cli command. Can it be moved to be under db, as @amercader suggested? And maybe calling it duplicate_emails or something is clearer than email_check.

@mutantsan mutantsan closed this Dec 3, 2019
@mutantsan mutantsan deleted the 2838-validate-email-for-unique branch December 3, 2019 10:24
@mutantsan mutantsan restored the 2838-validate-email-for-unique branch December 3, 2019 10:26
@mutantsan mutantsan reopened this Dec 3, 2019
@mutantsan mutantsan force-pushed the 2838-validate-email-for-unique branch from c15e5bd to 3ffe476 Compare December 3, 2019 10:56
@mutantsan
Copy link
Copy Markdown
Contributor Author

Sorry, this PR history looks like a mess. I've add duplicate_emails subcommand under db.

@davidread
Copy link
Copy Markdown

Many thanks @mutantsan! All LGTM, but I'll leave it to the assignees to confirm/merge.

@mutantsan mutantsan force-pushed the 2838-validate-email-for-unique branch from 07ea100 to cec6c83 Compare December 24, 2019 15:15
Comment thread ckan/logic/validators.py Outdated
'''Validate email is unique'''
model = context['model']
session = context['session']
user = session.query(model.User).filter_by(email=data[key]).first()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Oh, if the existing user shows up first, then it won't detect any duplicates. I think you need to filter out the user in this query i.e. .filter(model.User.name != data[('name',)]) rather than in the if in the next statement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@davidread , thank you! I've changed the validator logic. But, since the validator used in two cases (registration and update), I've chose another approach.

@mutantsan mutantsan changed the base branch from master to 2.5 January 10, 2020 13:18
@mutantsan mutantsan changed the base branch from 2.5 to master January 10, 2020 13:18
Comment thread ckan/logic/validators.py Outdated
if not users:
return
else:
# allow user to update his own email
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
# allow user to update his own email
# allow user to update their own email

@amercader
Copy link
Copy Markdown
Member

@mutantsan This all looks great. I was going to merge but after merging master I'm getting two failures in the tests involved in this PR. Would you mind having a look? https://circleci.com/gh/ckan/ckan/6311#tests/containers/1

@mutantsan mutantsan force-pushed the 2838-validate-email-for-unique branch from d5da609 to aef247b Compare January 27, 2020 13:26
@mutantsan
Copy link
Copy Markdown
Contributor Author

@amercader Hi, I've fixed the tests. test_request_reset_when_duplicate_emails was deleted, cause I think it's makes no sense to test reset with duplicate emails when we want to get away from it.

@amercader amercader merged commit bb36a33 into ckan:master Jan 27, 2020
@amercader
Copy link
Copy Markdown
Member

Thanks a lot @mutantsan

@avdata99 avdata99 mentioned this pull request Oct 23, 2024
5 tasks
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.

5 participants