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

GPII-2966 APIs provided by Preferences Server to support PPT #634

Open
wants to merge 97 commits into
base: master
Choose a base branch
from

Conversation

sgithens
Copy link
Member

Hi @cindyli . There is some cleanup, plus docs and tests needed for this still, but I wanted to at least run the endpoints by you before the weekend and get any comments on them in general. Also there are 3 new couch views for this.

@sgithens sgithens requested a review from cindyli July 20, 2018 02:19
@sgithens sgithens changed the title Gpii 2966 Initial review of endpoints being added GPII-2966 Initial review of endpoints being added Jul 20, 2018
@gpii-bot
Copy link

CI job failed: https://ci.gpii.net/job/universal-tests/973/

@@ -10,6 +10,15 @@
},
"findAuthorizationByAccessToken": {
"map": "function(doc) {if (doc.type === 'gpiiAppInstallationAuthorization' && doc.revoked === false) {emit(doc.accessToken, {'_id': doc.clientId, 'authorization': doc})}}"
},
"listKeysForPrefsSafe": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Most view names starts with "find" and these 2 use "list". Is there a reason in using a different word? If not, can you sync up the view names?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this makes sense @cindyli . I will probably leave listPrefsSafes as it is, since there is not search argument given to it, it really is just a listing.

"map": "function(doc) {if (doc.type === 'gpiiKey') emit(doc.prefsSafeId, null) }"
},
"listPrefsSafes": {
"map": "function(doc) { if (doc.type === 'prefsSafe') emit(doc._id, { 'name': doc.name, 'email': doc.email, 'created': doc.timestampCreated, 'updated': doc.timestampUpdated })}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove extra spaces before "created" and "updated".

});

gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe = function (prefsService, preferencesServer, request, prefsSafeId, view) {
var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a value for prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel? Would it be more straightforward to change this line to:

var directModel = {
    prefsSafeId: prefsSafeId
};

prefsSafeId: prefsSafeId});
var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel);
prefsPromise.then(function (data) {
var togo = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

line 76-81 can be simplified using fluid.transform.


gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId, view) {
// TODO Refactor from above, copied/pasted
var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above on the use of prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel. This type of comment applies across the pull request.

}
});

gpii.preferencesServer.prefsSafeWithKeysGet.handler.get = function (prefsService, preferencesServer, request, prefsSafeId, view) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function does 2 things:

  1. Find keys associated with a prefs safe;
  2. Find the data of this prefs safe and add keys retrieved at step 1 to the data.

A couple of suggestions:

  1. The step 1 is shared by this handler and gpii.preferencesServer.listKeysForPrefsSafe.handler, so it can be extracted into a function to get rid of the duplication;
  2. Use fluid.promise.fireTransformEvent() to chain these 2 promises that the output of the first promise can be passed to the second promise. Using fluid.promise.fireTransformEvent() also helps to reuse the function in the first suggestion.

// TODO Refactor from above, copied/pasted
var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listKeysForPrefsSafeDataSource.options.directModel, {
prefsSafeId: prefsSafeId});
var prefsPromise = prefsService.dataStore.listKeysForPrefsSafeDataSource.get(finalDirectModel);
Copy link
Contributor

Choose a reason for hiding this comment

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

All handlers in this script are accessing prefsService.dataStore directly, which is not recommended. The prefsService acts as a bridge that helps to decouple the database operation from other GPII modules including preferencesServer. prefsService should provide functions that make sense to request handlers instead of having request handlers directly deal with data that are in raw document structure. I would suggest to move the 2 steps handling in this function to prefsService.

This comment applies to other handlers in this script.

@cindyli
Copy link
Contributor

cindyli commented Jul 20, 2018

Nice work, @sgithens. I added "needs work" label as you will continue to add tests and docs. Once those are out of way, please remove this label. Thanks.

@gtirloni
Copy link
Contributor

ok to test

@gpii-bot
Copy link

CI job failed: https://ci.gpii.net/job/universal-tests/980/

@gpii-bot
Copy link

CI job failed: https://ci.gpii.net/job/universal-tests/1044/

sgithens and others added 7 commits August 16, 2018 10:26
- Adding in unit tests
- Adding in usage of gpii-express-user
- Adding endpoints for creating and unlocking cloud safe credentials.
…ch is caused by the wrong merge handling on arrays.
- Rename listKeysForPrefsSafe to findKeysForPrefsSafe per review
@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2064/

@sgithens
Copy link
Member Author

@cindyli @amb26 @klown Hi everyone. This should be ready for another review now. To recap, this branch contains the initial work necessary for username/password account credentials. Previously Cindy had reviewed the entire branch and ok'd it, but the remaining item was not having a migration to remove the password field from prefsSafes. (Which isn't actually necessary for it to operate but it's nice to clean up.)

For the migration, I've largely cloned the previous GPII-4011 migration Joseph did. Since we're going to be migrating from couchdb shortly I didn't spend a lot of time trying to refactor the common code from the 2 migrations since it seems like it won't be necessary in the future.

@cindyli
Copy link
Contributor

cindyli commented Dec 29, 2019

Regarding the problem I had with not being able to unlock a credential, the debug shows it's because the views json file from gpii-express-user is not loaded into the database so the query on the view "byUsernameOrEmail" returns missing error.

I noticed a duplicate of this view json file is used for preference server tests. Do you think it makes sense to replace this strategy with using the real json from gpii-express-user module for both tests and manual testing configs. Thanks.

This comment doesn't seem to be addressed.

@sgithens
Copy link
Member Author

@cindyli Ok, here is what I've done, with a little explanation.

I removed the custom userLookup.json views from the branch. I had on previous occasions thought also that it would be better to use the actual file from gpii-express-user, except that gpii-express-user uses a slightly different method of loading it's data. It's json views are in a single top level JSON object in the file, where-as ours are contained within a top level JSON array. So our dataloader won't load it. I had looked at possibly just loading and transforming the data, expect that the dataloader many layers down expects a file name rather than the JSON, and it would be quite a bit of refactoring to change this I think.

Given that we are planning on shortly moving off of couchdb, it didn't seem as if this was worth my time, so I have just included the necessary views along ours in the views.json. I also think this makes the provisioning code simpler, as it works as it, and I don't need to fix the dataloader to load more view files from other node_modules. If we weren't in our last days with couch I would say maybe we should work more on loading views from 3rd party modules but it doesn't seem worth it right now.

Also... based on our in flux requirements for user accounts and authentication, I can see us actually wanting to customize these couchdb views slightly for universal. For instance we might want to change the byUsernameOrEmail view a bit to tighten up how the credentialLogin documents are found. I'm not sure if we'll do that, but I wouldn't be surprised if we did.

Anyways, this is not perfect, but it's very simple, doesn't change any of our deployment scripts, and I think would work best for our current database trajectory.

@cindyli
Copy link
Contributor

cindyli commented Jan 23, 2020

Thanks for the explanation, @sgithens. I'm fine with this approach. As you said, we're moving off of CouchDB soon.

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2091/

// TODO This will have json schema validation when the scaffolding is all in.
dataStore.updatePrefsSafe(prefsSafeData.id, prefsSafeData).then(
function (/* updatedReturn */) {
that.getPrefsSafe(prefsSafeData.id).then(
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 too deeply nested promise chain and needs to be broken up

Copy link
Member Author

Choose a reason for hiding this comment

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

This has been converted to a transforming promise chain.


fluid.defaults("gpii.preferencesServer.preferencesService", {
gradeNames: ["fluid.component"],
components: {
dataStore: {
type: "gpii.dbOperation.dataStore"
},
expressUserUtils: {
type: "gpii.express.user.utils",
Copy link
Member

Choose a reason for hiding this comment

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

I am very suspicious of a component named "utils" ...... what does it do?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a component in the gpii-express-user module that contains the routines for creating and unlocking users.

https://github.com/GPII/gpii-express-user/blob/010bbaf83ae2e43558878f77b43e13c60223a0e3/src/js/server/utils.js#L29

@amb26
Copy link
Member

amb26 commented Mar 3, 2020

Please could you try out merging this against #833 to flush out whether it happens to perform any modification of component options which will be prohibited under the new framework

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2239/

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2247/

@sgithens
Copy link
Member Author

@amb26 I've address the couple comments above. I'm investigating a test error when merging in your FLUID-6145 branch, which may or may not be related to gpii-express-user. But in general I believe this is ready for another review.

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2248/

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2249/

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2271/

@gpii-bot
Copy link

CI job passed: https://ci.gpii.net/job/universal-tests/2340/

@gpii-bot
Copy link

CI job failed: https://ci.gpii.net/job/universal-tests/2341/

@gpii-bot
Copy link

CI job failed: https://ci.gpii.net/job/universal-tests/2370/

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.

6 participants