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

Support User: Add Support User libraries #2368

Merged
merged 2 commits into from
Jan 17, 2016
Merged

Conversation

jordwest
Copy link
Contributor

This PR adds libraries that will be used in the support user functionality (ref p195om-2GO-p2)

An access token is granted when a support user and password are provided; the token can be revoked during a restore operation, or will expire after a set period of time. Once granted, the support username and token are passed along all queries to the API.

This is a subset of the original PR #1202 (props to @jmdodd), separated out for easier progressive review.

@jordwest jordwest added Framework [Status] In Progress [Feature Group] Support All things related to WordPress.com customer support. labels Jan 13, 2016
@jordwest jordwest self-assigned this Jan 13, 2016
@jordwest jordwest added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Jan 13, 2016
@dllh
Copy link
Member

dllh commented Jan 14, 2016

I've tested this a bit and it seemed to work as expected. Elsewhere I've noted some js errors that began appearing in the console after I do the logout. I'm not 100% sure they're even related to this code but figured I'd bring 'em up just in case.

I'm squinting at code in two different tabs and trying to sort out whether the feedback offered here has been dealt with. There's a followup comment suggesting that it has, but the code looks kind of the same to me. I may be just failing to properly read the diff github offers, so if I'm off the mark here, just ignore the comment.

The code looks reasonable to me, but I think it'd be good to get another set of eyes on it before we merge.

/**
* Expose `User`
*/
module.exports = User;

require( './dev-support-user' );
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of the require here. Is it possible to move this to a more appropriate boot section?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to /client/boot/index.js -> boot()

@gwwar
Copy link
Contributor

gwwar commented Jan 14, 2016

👍 Works as advertised in Chrome

@jordwest
Copy link
Contributor Author

Thanks for the feedback! I've made some changes to clarify the code a bit, but I'm still thinking about ways to improve it some more.

While pondering, I realized this whole process of intercepting every single Calypso request and extending it would be much simpler and less breakage prone if wpcom.js had support for middleware. I'll have a go at implementing it and see if we can't get something like that merged into wpcom.js to greatly reduce the changes required here.

@dllh: Strange, I know @jmdodd and I worked on that section and made some changes, but it seems to be showing the new copy on GitHub. There was a force push in there though so GitHub may have lost the original code we discussed. There's no double binding happening at the moment, as removing the bind call causes many errors. I've just done a refactor that tidies that section up and hopefully makes it a bit easier to follow.

@jordwest
Copy link
Contributor Author

After spending most of the day digging deep into wpcom.js and playing with various 'middleware' ideas, it dawned on me that there's an even easier way to simplify the token injection logic. Rather than overriding the get, post, put, and del functions, it's possible to override the wpcom.request function which operates at a much lower level. This has cut down the size of the PR considerably. @gwwar: Thanks for prompting me to take a deeper look at this!

@dllh, @gwwar: It'd be much appreciated if you could have another look over it. The changes have all occurred in shared/lib/wp/support.js - everything else is unchanged.

@dllh
Copy link
Member

dllh commented Jan 15, 2016

This looks like a nice improvement to me, but I'd like to get @gwwar's final stamp of approval before we merge.

},
request: ( params, callback ) => {
if ( supportUser && supportToken ) {
return request( addSupportData( params ), callback );
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Great improvement here. This is much more readable.

@gwwar
Copy link
Contributor

gwwar commented Jan 15, 2016

:shipit:

return Object.assign( {}, params, {
query: qs.stringify( query )
} );
};
Copy link
Member

Choose a reason for hiding this comment

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

Using qs.parse instead of a hacked-in version is smart; if the params change, we won't have to rewrite parts of addSupportData.

jmdodd and others added 2 commits January 18, 2016 08:39
Squashed:
Support User: Spread returned array into appropriate parameters
Support User: Add development conditional
This change simplifies the injection of the credentials by
overriding the wpcom request function at a lower level. By injecting
the token directly into the query string directly before the XHR
call is made, previous logic that determined the type and format of
the request is no longer necessary.
jordwest added a commit that referenced this pull request Jan 17, 2016
Support User: Add Support User libraries
@jordwest jordwest merged commit 0698c5d into master Jan 17, 2016
@scruffian scruffian removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 17, 2016
@jordwest jordwest deleted the add/support-user-libs branch January 17, 2016 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Support All things related to WordPress.com customer support. Framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants