Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
c7ad172
GPII-2966 In progress work for prefsSafe CRUD
sgithens Jul 13, 2018
1252d6b
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Jul 18, 2018
9cb199d
GPII-2966 Removing prototype safe password unlocking which will be ha…
sgithens Jul 18, 2018
897e41c
GPII-2966 Removing pouchdb prefs server config, Cindy has added an of…
sgithens Jul 19, 2018
61d906f
GPII-2966 Seperating Prefs Safes endpoints from Prefs Sets Endpoints
sgithens Jul 20, 2018
abae292
GPII-2966 Using dbstoreutils cleandoc function.
sgithens Jul 20, 2018
49adad7
GPII-2966 Removing changes from prefs post handler
sgithens Jul 20, 2018
56da240
GPII-2966 Code for creating keys and minor fixes for saving prefsSafes.
sgithens Aug 12, 2018
1ac7a4f
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Aug 16, 2018
dd187de
GPII-2966 Next sprint of accounts work
sgithens Aug 26, 2018
39160ce
GPII-3193: Fixed the issue with saving supporting tool dictionary whi…
cindyli Aug 2, 2018
6a8e564
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Aug 30, 2018
ecd08b8
GPII-2966 GPII-3193 Temporary removing the patch needed for QSS save …
sgithens Aug 31, 2018
d3c5caf
GPII-2966 Rename listKeysForPrefsSafe
sgithens Aug 31, 2018
b1c3693
GPII-2966 Removing extra white space
sgithens Aug 31, 2018
fbe91e4
GPII-2966 Cleanup based on PR Review
sgithens Sep 18, 2018
db02d36
GPII-2966 Clean up and safe creation work
sgithens Sep 19, 2018
0f07b8a
GPII-2966 Branch cleanup
sgithens Sep 19, 2018
a55a043
GPII-2966 Clean up of cloud safe promise sequences.
sgithens Sep 20, 2018
1808d3b
GPII-2966 Doco
sgithens Sep 21, 2018
e30021d
GPII-2966 Removing audit-demo patch
sgithens Sep 21, 2018
0cb4998
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Sep 21, 2018
34eccda
GPII-2966 Document types Doco
sgithens Sep 21, 2018
65e1732
GPII-2966 Minor doco formatting
sgithens Sep 21, 2018
4cf8eed
GPII-2966 Event chains for Cloudsafe operations
sgithens Oct 7, 2018
9dcab0c
GPII-2966 Adding user lookup views to testdata
sgithens Oct 9, 2018
af796ee
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Oct 9, 2018
5810582
GPII-2966 Adding prefsafe id to return payload.
sgithens Oct 24, 2018
176b3bc
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Oct 24, 2018
0fe1208
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Oct 29, 2018
ff232fb
GPII-2966 Unit tests updates
sgithens Nov 6, 2018
da79bce
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Nov 6, 2018
2f8b396
GPII-2966 Minor fix to use strict and upping gpii-pouchdb
sgithens Nov 6, 2018
203a62f
GPII-2966 Backing gpii-pouchdb back to 1.0.12 for now
sgithens Nov 7, 2018
c5846cd
Merge remote-tracking branch 'GPII' into GPII-2966
sgithens Nov 7, 2018
c21c2e1
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Nov 14, 2018
9fa93fd
GPII-2966 Minor changes from PR Review
sgithens Nov 15, 2018
ff1a8bd
GPII-2966 Updated version of gpii-express-user
sgithens Nov 15, 2018
33b28aa
GPII-2966 Adding preferencesServiceTests to all-tests
sgithens Nov 15, 2018
604b2a1
GPII-2966 Fixed termmap param name
sgithens Nov 17, 2018
74015c5
GPII-2966 Fixing error style for return payload
sgithens Nov 19, 2018
753b52f
GPII-2966 Minor doco typo
sgithens Nov 19, 2018
e0935e7
GPII-2966 More tests
sgithens Nov 21, 2018
fed8067
GPII-2966 Tests for already used login name
sgithens Nov 21, 2018
eac3195
GPII-2966 Filling in tests for invokers added to preferences service.
sgithens Nov 27, 2018
4a5aaae
GPII-2966 Changes from PR and more RESTful PrefsSafe Endpoints
sgithens Dec 14, 2018
ca60fb5
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Dec 14, 2018
a1167a5
Merge remote-tracking branch 'GPII/master' into GPII-2966
Jan 14, 2019
e6baad4
GPII-2966 Another round of PR updates. Doco, tests, minor idiom updates
sgithens Jan 21, 2019
b8c7645
GPII-2966 Removing unused findPrefsSafeByName view
sgithens Jan 21, 2019
7d3a1e9
GPII-2966 Adding tests for remaining dbstore methods.
sgithens Jan 21, 2019
ead61ff
GPII-2966 Adding tests for remaining dbstore methods.
sgithens Jan 21, 2019
e3073c0
GPII-2966 Changing findKeys to findRelatedDocs since we also return t…
sgithens Jan 21, 2019
e52e426
GPII-2966 Updates to doco from PR comments.
sgithens Jan 31, 2019
66ac6c2
GPII-2966 Added check for addGpiiKey to make sure prefsSafe exists.
sgithens Mar 12, 2019
8f3026d
GPII-2966 Removing old password prefsSafe field.
sgithens Mar 12, 2019
17d832e
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Mar 14, 2019
a1bf6aa
GPII-2966 Removing a few more occurances of `old` password field.
sgithens Mar 14, 2019
fcfcdb2
GPII-2966 Converts prefsSafes tests to couch testing.
sgithens Mar 14, 2019
82491ed
GPII-2966 Converts cloudSafeCred tests to couch testing.
sgithens Mar 14, 2019
f180848
GPII-2966 Convert leftover DbDataStore tests to couch testing.
sgithens Mar 14, 2019
34a1535
GPII-2966 Minor lint cleanup
sgithens Mar 14, 2019
00a2a26
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Mar 19, 2019
7d1becf
GPII-2966 Moving statusCode population to handler methods.
sgithens Mar 19, 2019
1dbdb28
GPII-2966 Moving error messages and codes to preferencesServerConst
sgithens Mar 20, 2019
82c1137
GPII-2966 Updating .nycrc with new source parts
sgithens Mar 20, 2019
52f15b4
GPII-2966 Adding error message and codes, linting, adding more tests …
sgithens Mar 26, 2019
0c56fe9
GPII-2966 Minimal validation for usernames and passwords.
sgithens Mar 26, 2019
c614c31
GPII-2966 Updated docs for adding credentials endpoint.
sgithens Mar 27, 2019
f2a2d15
GPII-2966 More cleanup for reject promise messages and errorCodes.
sgithens Mar 27, 2019
c98ea65
GPII-2966 Minor fix to tests to compensate for unpredictable array or…
sgithens Mar 27, 2019
2ff8f59
GPII-2966 Minor typo and comment updates based on PR.
sgithens Apr 10, 2019
d3f56f8
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Apr 10, 2019
bdac5f5
GPII-2966 Swapping out token terminology with key
sgithens Apr 10, 2019
2be8db1
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens May 21, 2019
db44149
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Jun 20, 2019
7db4a96
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Jun 27, 2019
8b2b97b
GPII-2966 Bumping dev release of gpii-express-user
sgithens Jun 27, 2019
f1c9207
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Oct 29, 2019
d0904d4
GPII-2966 Updating prefSafe and gpiiKey schema versions in test data
sgithens Dec 19, 2019
c9a9bbe
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Dec 19, 2019
b3eccba
GPII-2966 Minor updates to test data
sgithens Dec 19, 2019
e4956ff
GPII-2966 Moving existing work up to schemaVersion 0.3 before adding …
sgithens Dec 20, 2019
f4a1e68
GPII-2966 Migrations
sgithens Dec 27, 2019
1ee531f
GPII-2966 Bumping schemaVersion from 0.2 to 0.3
sgithens Dec 27, 2019
2f365c4
GPII-2966 Incrementing gpii.dbOperation.schemaVersion
sgithens Dec 27, 2019
ddd6cda
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Jan 23, 2020
2045391
GPII-2966 Eliminating separate userLookup.json views file and adding …
sgithens Jan 23, 2020
5400a69
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Mar 20, 2020
7e7fdf9
GPII-2966 Updating test payloads
sgithens Mar 20, 2020
bf6e5b3
GPII-2966 Breaking up promises into event firing transform.
sgithens Mar 30, 2020
331cfac
GPII-2966 minor typo
sgithens Mar 30, 2020
18ff970
GPII-2966 prefssafe -> prefsSafe
sgithens Mar 30, 2020
ad6d7a6
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Apr 6, 2020
2a6dbd5
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens May 26, 2020
9343166
GPII-2966 The lifecycle manager utils tests need to run in node.
sgithens May 26, 2020
04d6abe
Merge remote-tracking branch 'GPII/master' into GPII-2966
sgithens Jun 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions gpii/node_modules/gpii-db-operation/src/DbDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ fluid.defaults("gpii.dbOperation.dbDataStore", {
}
}
},
listPrefsSafesDataSource: {
type: "gpii.dbOperation.dbDataSource",
options: {
requestUrl: "/_design/views/_view/listPrefsSafes",
termMap: {
// gpiiKey: "%gpiiKey"
},
rules: {
readPayload: {
"": "rows"
}
}
}
},
listKeysForPrefsSafeDataSource: {
type: "gpii.dbOperation.dbDataSource",
options: {
requestUrl: "/_design/views/_view/listKeysForPrefsSafe?include_docs=true&key=%22%prefsSafeId%22",
termMap: {
prefsSafeId: "%prefsSafeId"
},
rules: {
readPayload: {
"": "rows"
}
}
}
},
findPrefsSafeByGpiiKeyDataSource: {
type: "gpii.dbOperation.dbDataSource",
options: {
Expand All @@ -111,6 +139,21 @@ fluid.defaults("gpii.dbOperation.dbDataStore", {
}
}
},
findPrefsSafeByNameDataSource: {
type: "gpii.dbOperation.dbDataSource",
options: {
requestUrl: "/_design/views/_view/findPrefsSafeByName?key=%22%name%22&include_docs=true",
termMap: {
name: "%name"
},
rules: {
// TODO: Blow up if there is more than one record
readPayload: {
"": "rows.0.doc"
}
}
}
},
findClientByOauth2ClientIdDataSource: {
type: "gpii.dbOperation.dbDataSource",
options: {
Expand Down
1 change: 1 addition & 0 deletions gpii/node_modules/preferencesServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ require("./src/preferencesPutHandler.js");
require("./src/preferencesService.js");
require("./src/preferencesServerConst.js");
require("./src/preferencesServer.js");
require("./src/prefsSafesHandlers.js");
26 changes: 26 additions & 0 deletions gpii/node_modules/preferencesServer/src/preferencesServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,32 @@ fluid.defaults("gpii.preferencesServer", {
route: "/preferences/:gpiiKey",
method: "put",
type: "gpii.preferencesServer.put.handler"
},
// GPII-2966
prefsSafeGet: {
route: "/prefssafe/:prefsSafeId",
Copy link
Member

Choose a reason for hiding this comment

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

"prefsSafe" for all these endpoints would be consistent with our usage everywhere else

Copy link
Member

Choose a reason for hiding this comment

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

Bump comment

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

method: "get",
type: "gpii.preferencesServer.prefsSafeGet.handler"
},
prefsSafeWithKeysGet: {
route: "/prefssafe-with-keys/:prefsSafeId",
method: "get",
type: "gpii.preferencesServer.prefsSafeWithKeysGet.handler"
},
prefsSafeSave: {
route: "/prefssafe/:prefsSafeId",
method: "put",
type: "gpii.preferencesServer.prefsSafePut.handler"
},
listPrefsSafes: {
route: "/prefssafes",
method: "get",
type: "gpii.preferencesServer.prefsSafeList.handler"
},
listKeysForPrefsSafe: {
route: "/prefssafe-keys/:prefsSafeId",
method: "get",
type: "gpii.preferencesServer.listKeysForPrefsSafe.handler"
}
},
invokers: {
Expand Down
129 changes: 129 additions & 0 deletions gpii/node_modules/preferencesServer/src/prefsSafesHandlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*!
GPII Preferences Server GET Handler
Copyright 2014 Raising the Floor - International
Copyright 2018 OCAD University
Licensed under the New BSD license. You may not use this file except in
compliance with this License.
The research leading to these results has received funding from the European Union's
Seventh Framework Programme (FP7/2007-2013) under grant agreement no. 289016.
You may obtain a copy of the License at
https://github.com/GPII/universal/blob/master/LICENSE.txt
*/

"use strict";

var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii");

fluid.defaults("gpii.preferencesServer.prefsSafeGet.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe",
args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"]
}
}
});

gpii.preferencesServer.prefsSafeGet.handler.getPrefsSafe = function (prefsService, preferencesServer, request, gpiiKey, view) {
var prefsPromise = prefsService.dataStore.findById(gpiiKey);
prefsPromise.then(request.events.onSuccess.fire, request.events.onError.fire);
};

fluid.defaults("gpii.preferencesServer.prefsSafeList.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList",
args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.query.view"]
}
}
});

gpii.preferencesServer.prefsSafeList.handler.getPrefsSafeList = function (prefsService, preferencesServer, request, view) {
var finalDirectModel = fluid.extend(true, {}, prefsService.dataStore.listPrefsSafesDataSource.options.directModel, {});
var prefsPromise = prefsService.dataStore.listPrefsSafesDataSource.get(finalDirectModel);
prefsPromise.then(function (data) {
var togo = [];
// TODO this should probably be done in a couchview for efficiency and eventual paging?
fluid.each(data, function(item) {
item.value.prefsSafeId = item.key;
togo.push(item.value);
});
request.events.onSuccess.fire(togo);
}, request.events.onError.fire);
};

fluid.defaults("gpii.preferencesServer.listKeysForPrefsSafe.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.preferencesServer.listKeysForPrefsSafe.handler.getKeysForPrefsSafe",
args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"]
}
}
});

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.

fluid.each(data, function (i) {
var next = i.doc;
gpii.dbOperation.dbDataStore.cleanUpDoc(next);
togo.push(next);
});
request.events.onSuccess.fire(togo);
}, request.events.onError.fire);
};

fluid.defaults("gpii.preferencesServer.prefsSafeWithKeysGet.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.preferencesServer.prefsSafeWithKeysGet.handler.get",
args: ["{gpii.preferencesServer.preferencesService}", "{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.query.view"]
}
}
});

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, {
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.

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.

prefsPromise.then(function (data) {
var togo = [];
fluid.each(data, function (i) {
var next = i.doc;
gpii.dbOperation.dbDataStore.cleanUpDoc(next);
togo.push(next);
});
var prefsSafePromise = prefsService.dataStore.findById(prefsSafeId);
prefsSafePromise.then(function (prefsSafeData) {
prefsSafeData.keys = togo;
request.events.onSuccess.fire(prefsSafeData);
}, request.events.onError.fire);
}, request.events.onError.fire);
};

fluid.defaults("gpii.preferencesServer.prefsSafePut.handler", {
gradeNames: ["kettle.request.http"],
invokers: {
handleRequest: {
funcName: "gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe",
args: ["{preferencesServer}", "{that}", "{that}.req.params.prefsSafeId", "{that}.req.body", "{that}.req.query.view",]
}
}
});

gpii.preferencesServer.prefsSafePut.handler.savePrefsSafe = function (preferencesServer, request, prefsSafeId, prefsSafe, view) {
var updatePrefsSafePromise = preferencesServer.dataStore.updatePrefsSafe(prefsSafeId, prefsSafeData);
updatePrefsSafePromise.then(request.events.onSuccess.fire, request.events.onError.fire);
};
9 changes: 9 additions & 0 deletions testData/dbData/views.json
Original file line number Diff line number Diff line change
Expand Up @@ -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".

},
"findPrefsSafeByName": {
"map": "function(doc) {if (doc.type === 'prefsSafe') emit(doc.name, null)}"
}
}
}
Expand Down