Skip to content

Ability to add/update user email #921

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

Merged
merged 27 commits into from
Aug 3, 2017

Conversation

natboehm
Copy link
Contributor

This PR addresses issue #808, allow editing your own email address. This is the first step in a three part implementation, adding a field to edit an email address. Yet to be implemented before the issue is resolved is (1) the ability to verify emails with users and (2) figuring out how to get everyone to add their email to their account. This PR only implements the addition of a button to the email field such that a user's email can be added or updated, as well as hiding the email field from public view by separating EncodableUser into EncodablePublicUser and EncodablePrivateUser.

natboehm added 21 commits July 28, 2017 16:16
… email field then is updated in the database
… in order to try to keep user emails private, update tests to pass
… stored in database

specifically problematic if GitHub email were private and crates.io user had added an email, upon signing in the next time the user's email would go back to null as that is the value GitHub passes each time. This means that if users update their email, it must be updated through both GitHub and Crates.io
src/tests/all.rs Outdated
@@ -189,6 +189,19 @@ fn new_user(login: &str) -> NewUser {
}
}

// I want to be able to seed the github id for use in test
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is only used in one place, how about just having that place just do:

NewUser { gh_id: whatever, ..new_user(login) }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, that makes more sense, thanks!

let user = ::mock_user(&mut req, ::user("foo"));

// with GET /me update gives 404 response
// let user = ::mock_user(&mut req, ::user("foo"));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about ::sign_in(&mut req, &app)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand the difference, could you clarify? I forgot to delete these commented out lines, what I was getting at is that mock_user() seems to do the same thing as calling new_user() and sign_in_as(user) used below except below doesn't cause the 404.

Copy link
Member

Choose a reason for hiding this comment

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

@sgrif sign_in doesn't let us pass in a user, nor does it return the user, and we need the user on line 84 for the last assertion in this test that checks that the user's email is correctly in the JSON.

Copy link
Member

@carols10cents carols10cents left a comment

Choose a reason for hiding this comment

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

Tried this out-- it works great! Just a few small things! :)

{{/if}}
{{#if emailIsNull }}
<p class='small-text'> Please add your email address. We need this in
order to contact you just in case anything goes wrong. We promise
Copy link
Member

Choose a reason for hiding this comment

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

Thinking about this phrasing a little bit more, especially since we just came up with a potential use case in ownership notifications that we might want to use email for, which isn't really something going wrong... how about something like "Please add your email address. We will only use it to contact you about your account. We promise we'll never share it!"?

editEmail() {
let email = this.get('value');
let isEmailNull = function(email) {
if (email == 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 think we can shorten this by doing:

let isEmailNull = function(email) {
    return email == null;
}

Does that work? My javascript is a bit rusty...

Copy link
Member

Choose a reason for hiding this comment

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

OOH WAIT what's this empty function on line 9? could we do empty(email)? or is that special for models?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this might be special for models? I'm not sure exactly how it works on line 9 but when I print out the result of empty it isn't just a boolean type.


this.set('emailIsNull', isEmailNull(email));
this.set('isEditing', true);
this.set('prevEmail', this.get('value'));
Copy link
Member

Choose a reason for hiding this comment

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

Since we've got this.get('value') in the email variable from line 16, could we use the email var here too?

let user = ::mock_user(&mut req, ::user("foo"));

// with GET /me update gives 404 response
// let user = ::mock_user(&mut req, ::user("foo"));
Copy link
Member

Choose a reason for hiding this comment

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

@sgrif sign_in doesn't let us pass in a user, nor does it return the user, and we need the user on line 84 for the last assertion in this test that checks that the user's email is correctly in the JSON.

src/user/mod.rs Outdated
let user_id = req.user()?.id;
let conn = req.db_conn()?;
let user = users.filter(id.eq(user_id)).first::<User>(&*conn)?;
println!("user id: {:?} user_id: {:?}", user.id, user_id);
Copy link
Member

Choose a reason for hiding this comment

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

Println snuck in there! :)

let user = this.get('user');

let emailIsProperFormat = function(userEmail) {
let regExp = /\S+@\S+\.\S+/;
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 remembering a thing.... where if you don't put "beginning of value" and "end of value" things in the regex, somehow people could put newlines in and the regex would match when it shouldn't have? I forget if javascript is vulnerable to this or not, and if it is, if the things we want at the beginning and end are \A and \z or if it's something different. Let's investigate tomorrow!

<dt>Email</dt>
</div>
{{#if isEditing }}
{{#if isEditing }}
Copy link
Member

Choose a reason for hiding this comment

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

Good call on moving the check for editing out to be able to separate the markup between editing and not editing :) 💯

@@ -291,3 +297,76 @@ fn updating_existing_user_doesnt_change_api_token() {
assert_eq!("bar", user.gh_login);
assert_eq!("bar_token", user.gh_access_token);
}

/* Email GitHub private overwrite bug
Please find a better description, that is not english
Copy link
Member

Choose a reason for hiding this comment

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

😂 I know that feel :)

assert_eq!(r.user.email, None);
assert_eq!(r.user.login, "mango");

let body = r#"{"user":{"email":"[email protected]","name":"Mango McMangoface","login":"mango","avatar":"https://avatars0.githubusercontent.com","url":"https://github.com/mango","kind":null}}"#;
Copy link
Member

Choose a reason for hiding this comment

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

lolololol @ "Mango McMangoface" :) :) :)

// database
// This change is not preferable, we'd rather fix the request,
// perhaps adding `req.mut_extensions().insert(user)` to the
// update_user route, however this somehow does not seem to work
Copy link
Member

Choose a reason for hiding this comment

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

This is a great comment!! I'm so excited to find this later when I'm trying to remember why we had to do this this way and this will explain everything ❤️

…potentially add their email, then garbage on a newline, which would still evaluate as valid
Copy link
Member

@carols10cents carols10cents left a comment

Choose a reason for hiding this comment

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

Looks great!!!! Thank you!!!

bors r+

@carols10cents
Copy link
Member

hmmm

bors: r+

bors-voyager bot added a commit that referenced this pull request Aug 2, 2017
921: Ability to add/update user email r=carols10cents

This PR addresses issue #808, allow editing your own email address. This is the first step in a three part implementation, adding a field to edit an email address. Yet to be implemented before the issue is resolved is (1) the ability to verify emails with users and (2) figuring out how to get everyone to add their email to their account. This PR only implements the addition of a button to the email field such that a user's email can be added or updated, as well as hiding the email field from public view by separating `EncodableUser` into `EncodablePublicUser` and `EncodablePrivateUser`.
@bors-voyager
Copy link
Contributor

bors-voyager bot commented Aug 3, 2017

Build succeeded

@bors-voyager bors-voyager bot merged commit 45b6669 into rust-lang:master Aug 3, 2017
@natboehm natboehm deleted the add-user-email branch August 3, 2017 14:20
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.

4 participants