dce-expresskit 4.1.0 → 4.2.1-beta-userid-match-checker.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/dataSigner.js +7 -5
- package/lib/helpers/dataSigner.js.map +1 -1
- package/lib/helpers/genRouteHandler.js +61 -20
- package/lib/helpers/genRouteHandler.js.map +1 -1
- package/lib/helpers/initExpressKitCollections.d.ts +33 -0
- package/lib/helpers/initExpressKitCollections.js +180 -0
- package/lib/helpers/initExpressKitCollections.js.map +1 -0
- package/lib/helpers/initServer.d.ts +0 -33
- package/lib/helpers/initServer.js +20 -63
- package/lib/helpers/initServer.js.map +1 -1
- package/lib/index.d.ts +2 -3
- package/lib/index.js +3 -5
- package/lib/index.js.map +1 -1
- package/lib/types/ExpressKitErrorCode.d.ts +3 -1
- package/lib/types/ExpressKitErrorCode.js +3 -1
- package/lib/types/ExpressKitErrorCode.js.map +1 -1
- package/lib/types/LogReviewerAdmin.d.ts +10 -0
- package/lib/types/LogReviewerAdmin.js +3 -0
- package/lib/types/LogReviewerAdmin.js.map +1 -0
- package/lib/types/SelectAdmin.d.ts +10 -0
- package/lib/types/SelectAdmin.js +3 -0
- package/lib/types/SelectAdmin.js.map +1 -0
- package/package.json +1 -1
- package/src/helpers/dataSigner.ts +2 -2
- package/src/helpers/genRouteHandler.ts +49 -4
- package/src/helpers/initExpressKitCollections.ts +144 -0
- package/src/helpers/initServer.ts +27 -67
- package/src/index.ts +2 -4
- package/src/types/ExpressKitErrorCode.ts +3 -1
- package/src/types/LogReviewerAdmin.ts +14 -0
- package/src/types/SelectAdmin.ts +14 -0
- package/src/helpers/initCrossServerCredentialCollection.ts +0 -19
- package/src/helpers/initLogCollection.ts +0 -30
|
@@ -50,7 +50,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.internalGetCrossServerCredentialCollection = exports.internalGetLogCollection = void 0;
|
|
54
53
|
// Import dce-reactkit
|
|
55
54
|
var dce_reactkit_1 = require("dce-reactkit");
|
|
56
55
|
// Import shared helpers
|
|
@@ -58,33 +57,8 @@ var genRouteHandler_1 = __importDefault(require("./genRouteHandler"));
|
|
|
58
57
|
var getLogReviewerLogs_1 = __importDefault(require("./getLogReviewerLogs"));
|
|
59
58
|
// Import shared types
|
|
60
59
|
var ExpressKitErrorCode_1 = __importDefault(require("../types/ExpressKitErrorCode"));
|
|
61
|
-
//
|
|
62
|
-
var
|
|
63
|
-
// Stored copy of dce-mango cross-server credential collection
|
|
64
|
-
var _crossServerCredentialCollection;
|
|
65
|
-
/*------------------------------------------------------------------------*/
|
|
66
|
-
/* Helpers */
|
|
67
|
-
/*------------------------------------------------------------------------*/
|
|
68
|
-
/**
|
|
69
|
-
* Get log collection
|
|
70
|
-
* @author Gabe Abrams
|
|
71
|
-
* @returns log collection if one was included during launch or null if we don't
|
|
72
|
-
* have a log collection (yet)
|
|
73
|
-
*/
|
|
74
|
-
var internalGetLogCollection = function () {
|
|
75
|
-
return _logCollection !== null && _logCollection !== void 0 ? _logCollection : null;
|
|
76
|
-
};
|
|
77
|
-
exports.internalGetLogCollection = internalGetLogCollection;
|
|
78
|
-
/**
|
|
79
|
-
* Get cross-server credential collection
|
|
80
|
-
* @author Gabe Abrams
|
|
81
|
-
* @return cross-server credential collection if one was included during launch or null
|
|
82
|
-
* if we don't have a cross-server credential collection (yet)
|
|
83
|
-
*/
|
|
84
|
-
var internalGetCrossServerCredentialCollection = function () {
|
|
85
|
-
return _crossServerCredentialCollection !== null && _crossServerCredentialCollection !== void 0 ? _crossServerCredentialCollection : null;
|
|
86
|
-
};
|
|
87
|
-
exports.internalGetCrossServerCredentialCollection = internalGetCrossServerCredentialCollection;
|
|
60
|
+
// Import shared helpers
|
|
61
|
+
var initExpressKitCollections_1 = require("./initExpressKitCollections");
|
|
88
62
|
/*------------------------------------------------------------------------*/
|
|
89
63
|
/* Main */
|
|
90
64
|
/*------------------------------------------------------------------------*/
|
|
@@ -94,23 +68,8 @@ exports.internalGetCrossServerCredentialCollection = internalGetCrossServerCrede
|
|
|
94
68
|
* @param opts object containing all arguments
|
|
95
69
|
* @param opts.app express app from inside of the postprocessor function that
|
|
96
70
|
* we will add routes to
|
|
97
|
-
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
98
|
-
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
99
|
-
* storing logs. If none is included, logs are written to the console
|
|
100
|
-
* @param [opts.logReviewAdmins=all] info on which admins can review
|
|
101
|
-
* logs from the client. If not included, all Canvas admins are allowed to
|
|
102
|
-
* review logs. If null, no Canvas admins are allowed to review logs.
|
|
103
|
-
* If an array of Canvas userIds (numbers), only Canvas admins with those
|
|
104
|
-
* userIds are allowed to review logs. If a dce-mango collection, only
|
|
105
|
-
* Canvas admins with entries in that collection ({ userId, ...}) are allowed
|
|
106
|
-
* to review logs
|
|
107
|
-
* @param [opts.crossServerCredentialCollection] mongo collection from dce-mango to use for
|
|
108
|
-
* storing cross-server credentials. If none is included, cross-server credentials
|
|
109
|
-
* are not supported
|
|
110
71
|
*/
|
|
111
72
|
var initServer = function (opts) {
|
|
112
|
-
_logCollection = opts.logCollection;
|
|
113
|
-
_crossServerCredentialCollection = opts.crossServerCredentialCollection;
|
|
114
73
|
/*----------------------------------------*/
|
|
115
74
|
/* Logging */
|
|
116
75
|
/*----------------------------------------*/
|
|
@@ -192,7 +151,7 @@ var initServer = function (opts) {
|
|
|
192
151
|
* @returns true if the user can review logs
|
|
193
152
|
*/
|
|
194
153
|
var canReviewLogs = function (userId, isAdmin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
195
|
-
var matches, err_1;
|
|
154
|
+
var logReviewerAdminCollection, matches, err_1;
|
|
196
155
|
return __generator(this, function (_a) {
|
|
197
156
|
switch (_a.label) {
|
|
198
157
|
case 0:
|
|
@@ -200,29 +159,22 @@ var initServer = function (opts) {
|
|
|
200
159
|
if (!isAdmin) {
|
|
201
160
|
return [2 /*return*/, false];
|
|
202
161
|
}
|
|
203
|
-
|
|
204
|
-
if (!opts.logReviewAdmins) {
|
|
205
|
-
return [2 /*return*/, true];
|
|
206
|
-
}
|
|
207
|
-
_a.label = 1;
|
|
162
|
+
return [4 /*yield*/, (0, initExpressKitCollections_1.internalGetLogReviewerAdminCollection)()];
|
|
208
163
|
case 1:
|
|
209
|
-
_a.
|
|
210
|
-
|
|
211
|
-
if (Array.isArray(opts.logReviewAdmins)) {
|
|
212
|
-
return [2 /*return*/, opts.logReviewAdmins.some(function (allowedId) {
|
|
213
|
-
return (userId === allowedId);
|
|
214
|
-
})];
|
|
215
|
-
}
|
|
216
|
-
return [4 /*yield*/, opts.logReviewAdmins.find({ userId: userId })];
|
|
164
|
+
logReviewerAdminCollection = _a.sent();
|
|
165
|
+
_a.label = 2;
|
|
217
166
|
case 2:
|
|
167
|
+
_a.trys.push([2, 4, , 5]);
|
|
168
|
+
return [4 /*yield*/, logReviewerAdminCollection.find({ id: userId })];
|
|
169
|
+
case 3:
|
|
218
170
|
matches = _a.sent();
|
|
219
171
|
// Make sure at least one entry matches
|
|
220
172
|
return [2 /*return*/, matches.length > 0];
|
|
221
|
-
case
|
|
173
|
+
case 4:
|
|
222
174
|
err_1 = _a.sent();
|
|
223
175
|
// If an error occurred, simply return false
|
|
224
176
|
return [2 /*return*/, false];
|
|
225
|
-
case
|
|
177
|
+
case 5: return [2 /*return*/];
|
|
226
178
|
}
|
|
227
179
|
});
|
|
228
180
|
}); };
|
|
@@ -242,6 +194,7 @@ var initServer = function (opts) {
|
|
|
242
194
|
return [4 /*yield*/, canReviewLogs(userId, isAdmin)];
|
|
243
195
|
case 1:
|
|
244
196
|
canReview = _c.sent();
|
|
197
|
+
// Return result
|
|
245
198
|
return [2 /*return*/, canReview];
|
|
246
199
|
}
|
|
247
200
|
});
|
|
@@ -249,7 +202,8 @@ var initServer = function (opts) {
|
|
|
249
202
|
}));
|
|
250
203
|
/**
|
|
251
204
|
* Get filtered logs based on provided filters
|
|
252
|
-
* @author Gabe Abrams
|
|
205
|
+
* @author Gabe Abrams
|
|
206
|
+
* @author Yuen Ler Chow
|
|
253
207
|
* @param pageNumber the page number to get
|
|
254
208
|
* @param filters the filters to apply to the logs
|
|
255
209
|
* @returns {Log[]} list of logs that match the filters
|
|
@@ -261,7 +215,7 @@ var initServer = function (opts) {
|
|
|
261
215
|
countDocuments: dce_reactkit_1.ParamType.Boolean,
|
|
262
216
|
},
|
|
263
217
|
handler: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
|
|
264
|
-
var pageNumber, userId, isAdmin, filters, countDocuments, canReview, response;
|
|
218
|
+
var pageNumber, userId, isAdmin, filters, countDocuments, canReview, logCollection, response;
|
|
265
219
|
var params = _b.params;
|
|
266
220
|
return __generator(this, function (_c) {
|
|
267
221
|
switch (_c.label) {
|
|
@@ -273,13 +227,16 @@ var initServer = function (opts) {
|
|
|
273
227
|
if (!canReview) {
|
|
274
228
|
throw new dce_reactkit_1.ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ExpressKitErrorCode_1.default.NotAllowedToReviewLogs);
|
|
275
229
|
}
|
|
230
|
+
return [4 /*yield*/, (0, initExpressKitCollections_1.internalGetLogCollection)()];
|
|
231
|
+
case 2:
|
|
232
|
+
logCollection = _c.sent();
|
|
276
233
|
return [4 /*yield*/, (0, getLogReviewerLogs_1.default)({
|
|
277
234
|
pageNumber: pageNumber,
|
|
278
235
|
filters: filters,
|
|
279
236
|
countDocuments: countDocuments,
|
|
280
|
-
logCollection:
|
|
237
|
+
logCollection: logCollection,
|
|
281
238
|
})];
|
|
282
|
-
case
|
|
239
|
+
case 3:
|
|
283
240
|
response = _c.sent();
|
|
284
241
|
// Return response
|
|
285
242
|
return [2 /*return*/, response];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initServer.js","sourceRoot":"","sources":["../../src/helpers/initServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"initServer.js","sourceRoot":"","sources":["../../src/helpers/initServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,sBAAsB;AACtB,6CAOsB;AAEtB,wBAAwB;AACxB,sEAAgD;AAChD,4EAAsD;AAEtD,sBAAsB;AACtB,qFAA+D;AAE/D,wBAAwB;AACxB,yEAGqC;AAErC,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAE5E;;;;;;GAMG;AACH,IAAM,UAAU,GAAG,UACjB,IAEC;IAED,4CAA4C;IAC5C,4CAA4C;IAC5C,4CAA4C;IAE5C;;;;;;;;;;;;;;;;;;OAkBG;IACH,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,6BAAc,EACd,IAAA,yBAAe,EAAC;QACd,UAAU,EAAE;YACV,OAAO,EAAE,wBAAS,CAAC,MAAM;YACzB,UAAU,EAAE,wBAAS,CAAC,MAAM;YAC5B,IAAI,EAAE,wBAAS,CAAC,IAAI;YACpB,KAAK,EAAE,wBAAS,CAAC,MAAM;YACvB,QAAQ,EAAE,wBAAS,CAAC,IAAI;YACxB,YAAY,EAAE,wBAAS,CAAC,cAAc;YACtC,SAAS,EAAE,wBAAS,CAAC,cAAc;YACnC,UAAU,EAAE,wBAAS,CAAC,cAAc;YACpC,MAAM,EAAE,wBAAS,CAAC,cAAc;YAChC,MAAM,EAAE,wBAAS,CAAC,cAAc;SACjC;QACD,OAAO,EAAE,UAAC,EAA0B;gBAAxB,MAAM,YAAA,EAAE,cAAc,oBAAA;YAChC,kBAAkB;YAClB,IAAM,OAAO,GAA+B,CAC1C,CAAC,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,UAAU,CAAC;gBAC5D,QAAQ;gBACR,CAAC,CAAC;oBACA,OAAO,EAAE,MAAM,CAAC,OAAO;oBACvB,UA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4BAAkB,EAAC;gCACxC,UAAU,YAAA;gCACV,OAAO,SAAA;gCACP,cAAc,gBAAA;gCACd,aAAa,eAAA;6BACd,CAAC,EAAA;;wBALI,QAAQ,GAAG,SAKf;wBAEF,kBAAkB;wBAClB,sBAAO,QAAQ,EAAC;;;aACjB;KACF,CAAC,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, getLocalTimeInfo, genCommaList, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, ErrorWithCode, ParamType } from 'dce-reactkit';
|
|
2
|
-
import initCrossServerCredentialCollection from './helpers/initCrossServerCredentialCollection';
|
|
3
|
-
import initLogCollection from './helpers/initLogCollection';
|
|
4
2
|
import initServer from './helpers/initServer';
|
|
5
3
|
import genRouteHandler from './helpers/genRouteHandler';
|
|
6
4
|
import handleError from './helpers/handleError';
|
|
7
5
|
import handleSuccess from './helpers/handleSuccess';
|
|
8
6
|
import addDBEditorEndpoints from './helpers/addDBEditorEndpoints';
|
|
9
7
|
import visitEndpointOnAnotherServer from './helpers/visitEndpointOnAnotherServer';
|
|
8
|
+
import initExpressKitCollections from './helpers/initExpressKitCollections';
|
|
10
9
|
import CrossServerCredential from './types/CrossServerCredential';
|
|
11
|
-
export { ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, genCommaList, getLocalTimeInfo, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initServer, genRouteHandler, handleError, handleSuccess,
|
|
10
|
+
export { ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, extractProp, compareArraysByProp, genCommaList, getLocalTimeInfo, prefixWithAOrAn, everyAsync, filterAsync, forEachAsync, mapAsync, someAsync, capitalize, shuffleArray, initServer, genRouteHandler, handleError, handleSuccess, initExpressKitCollections, addDBEditorEndpoints, visitEndpointOnAnotherServer, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, LogFunction, CrossServerCredential, ParamType, };
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ParamType = exports.LogBuiltInMetadata = exports.LogAction = exports.LogSource = exports.LogType = exports.DayOfWeek = exports.visitEndpointOnAnotherServer = exports.addDBEditorEndpoints = exports.
|
|
6
|
+
exports.ParamType = exports.LogBuiltInMetadata = exports.LogAction = exports.LogSource = exports.LogType = exports.DayOfWeek = exports.visitEndpointOnAnotherServer = exports.addDBEditorEndpoints = exports.initExpressKitCollections = exports.handleSuccess = exports.handleError = exports.genRouteHandler = exports.initServer = exports.shuffleArray = exports.capitalize = exports.someAsync = exports.mapAsync = exports.forEachAsync = exports.filterAsync = exports.everyAsync = exports.prefixWithAOrAn = exports.getLocalTimeInfo = exports.genCommaList = exports.compareArraysByProp = exports.extractProp = exports.genCSV = exports.getMonthName = exports.parallelLimit = exports.onlyKeepLetters = exports.stringsToHumanReadableList = exports.getPartOfDay = exports.getHumanReadableDate = exports.startMinWait = exports.getTimeInfoInET = exports.getOrdinal = exports.waitMs = exports.sum = exports.roundToNumDecimals = exports.padZerosLeft = exports.padDecimalZeros = exports.forceNumIntoBounds = exports.floorToNumDecimals = exports.ceilToNumDecimals = exports.avg = exports.abbreviate = exports.DAY_IN_MS = exports.HOUR_IN_MS = exports.MINUTE_IN_MS = exports.ErrorWithCode = void 0;
|
|
7
7
|
// Import dce-reactkit
|
|
8
8
|
var dce_reactkit_1 = require("dce-reactkit");
|
|
9
9
|
Object.defineProperty(exports, "abbreviate", { enumerable: true, get: function () { return dce_reactkit_1.abbreviate; } });
|
|
@@ -49,10 +49,6 @@ Object.defineProperty(exports, "DAY_IN_MS", { enumerable: true, get: function ()
|
|
|
49
49
|
Object.defineProperty(exports, "ErrorWithCode", { enumerable: true, get: function () { return dce_reactkit_1.ErrorWithCode; } });
|
|
50
50
|
Object.defineProperty(exports, "ParamType", { enumerable: true, get: function () { return dce_reactkit_1.ParamType; } });
|
|
51
51
|
// Import helpers
|
|
52
|
-
var initCrossServerCredentialCollection_1 = __importDefault(require("./helpers/initCrossServerCredentialCollection"));
|
|
53
|
-
exports.initCrossServerCredentialCollection = initCrossServerCredentialCollection_1.default;
|
|
54
|
-
var initLogCollection_1 = __importDefault(require("./helpers/initLogCollection"));
|
|
55
|
-
exports.initLogCollection = initLogCollection_1.default;
|
|
56
52
|
var initServer_1 = __importDefault(require("./helpers/initServer"));
|
|
57
53
|
exports.initServer = initServer_1.default;
|
|
58
54
|
var genRouteHandler_1 = __importDefault(require("./helpers/genRouteHandler"));
|
|
@@ -65,4 +61,6 @@ var addDBEditorEndpoints_1 = __importDefault(require("./helpers/addDBEditorEndpo
|
|
|
65
61
|
exports.addDBEditorEndpoints = addDBEditorEndpoints_1.default;
|
|
66
62
|
var visitEndpointOnAnotherServer_1 = __importDefault(require("./helpers/visitEndpointOnAnotherServer"));
|
|
67
63
|
exports.visitEndpointOnAnotherServer = visitEndpointOnAnotherServer_1.default;
|
|
64
|
+
var initExpressKitCollections_1 = __importDefault(require("./helpers/initExpressKitCollections"));
|
|
65
|
+
exports.initExpressKitCollections = initExpressKitCollections_1.default;
|
|
68
66
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sBAAsB;AACtB,6CA8CsB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sBAAsB;AACtB,6CA8CsB;AAuBpB,2FApEA,yBAAU,OAoEA;AACV,oFApEA,kBAAG,OAoEA;AACH,kGApEA,gCAAiB,OAoEA;AACjB,mGApEA,iCAAkB,OAoEA;AAClB,mGApEA,iCAAkB,OAoEA;AAClB,gGApEA,8BAAe,OAoEA;AACf,6FApEA,2BAAY,OAoEA;AACZ,mGApEA,iCAAkB,OAoEA;AAClB,oFApEA,kBAAG,OAoEA;AACH,uFApEA,qBAAM,OAoEA;AACN,2FApEA,yBAAU,OAoEA;AACV,gGApEA,8BAAe,OAoEA;AACf,6FApEA,2BAAY,OAoEA;AACZ,qGApEA,mCAAoB,OAoEA;AACpB,6FApEA,2BAAY,OAoEA;AACZ,2GApEA,yCAA0B,OAoEA;AAC1B,gGApEA,8BAAe,OAoEA;AACf,8FApEA,4BAAa,OAoEA;AACb,6FApEA,2BAAY,OAoEA;AACZ,uFApEA,qBAAM,OAoEA;AACN,4FApEA,0BAAW,OAoEA;AACX,oGApEA,kCAAmB,OAoEA;AAEnB,iGArEA,+BAAgB,OAqEA;AADhB,6FAnEA,2BAAY,OAmEA;AAEZ,gGApEA,8BAAe,OAoEA;AACf,2FApEA,yBAAU,OAoEA;AACV,4FApEA,0BAAW,OAoEA;AACX,6FApEA,2BAAY,OAoEA;AACZ,yFApEA,uBAAQ,OAoEA;AACR,0FApEA,wBAAS,OAoEA;AACT,2FApEA,yBAAU,OAoEA;AACV,6FApEA,2BAAY,OAoEA;AAUZ,0FA7EA,wBAAS,OA6EA;AAET,wFA7EA,sBAAO,OA6EA;AACP,0FA7EA,wBAAS,OA6EA;AACT,0FA7EA,wBAAS,OA6EA;AACT,mGA7EA,iCAAkB,OA6EA;AAlDlB,6FAxBA,2BAAY,OAwBA;AACZ,2FAxBA,yBAAU,OAwBA;AACV,0FAxBA,wBAAS,OAwBA;AAJT,8FAnBA,4BAAa,OAmBA;AAyDb,0FA3EA,wBAAS,OA2EA;AAxEX,iBAAiB;AACjB,oEAA8C;AAqD5C,qBArDK,oBAAU,CAqDL;AApDZ,8EAAwD;AAqDtD,0BArDK,yBAAe,CAqDL;AApDjB,sEAAgD;AAqD9C,sBArDK,qBAAW,CAqDL;AApDb,0EAAoD;AAqDlD,wBArDK,uBAAa,CAqDL;AApDf,wFAAkE;AAsDhE,+BAtDK,8BAAoB,CAsDL;AArDtB,wGAAkF;AAsDhF,uCAtDK,sCAA4B,CAsDL;AArD9B,kGAA4E;AAmD1E,oCAnDK,mCAAyB,CAmDL"}
|
|
@@ -10,6 +10,7 @@ declare enum ExpressKitErrorCode {
|
|
|
10
10
|
ThemeCheckedBeforeReactKitReady = "DEK12",
|
|
11
11
|
InvalidParameter = "DEK5",
|
|
12
12
|
MissingParameter = "DEK4",
|
|
13
|
+
StudentIdMismatch = "DEK36",
|
|
13
14
|
NotConnected = "DEK14",
|
|
14
15
|
SelfSigned = "DEK15",
|
|
15
16
|
ResponseParseError = "DEK16",
|
|
@@ -26,6 +27,7 @@ declare enum ExpressKitErrorCode {
|
|
|
26
27
|
NoOauthLib = "DEK31",
|
|
27
28
|
NoCryptoLib = "DEK32",
|
|
28
29
|
InvalidCrossServerCredentialsFormat = "DEK33",
|
|
29
|
-
UnknownCrossServerError = "DEK34"
|
|
30
|
+
UnknownCrossServerError = "DEK34",
|
|
31
|
+
NotSelectAdmin = "DEK35"
|
|
30
32
|
}
|
|
31
33
|
export default ExpressKitErrorCode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Highest error code =
|
|
2
|
+
// Highest error code = DEK36
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
/**
|
|
5
5
|
* List of error codes built into the express kit
|
|
@@ -15,6 +15,7 @@ var ExpressKitErrorCode;
|
|
|
15
15
|
ExpressKitErrorCode["ThemeCheckedBeforeReactKitReady"] = "DEK12";
|
|
16
16
|
ExpressKitErrorCode["InvalidParameter"] = "DEK5";
|
|
17
17
|
ExpressKitErrorCode["MissingParameter"] = "DEK4";
|
|
18
|
+
ExpressKitErrorCode["StudentIdMismatch"] = "DEK36";
|
|
18
19
|
// Server-to-server requests
|
|
19
20
|
ExpressKitErrorCode["NotConnected"] = "DEK14";
|
|
20
21
|
ExpressKitErrorCode["SelfSigned"] = "DEK15";
|
|
@@ -33,6 +34,7 @@ var ExpressKitErrorCode;
|
|
|
33
34
|
ExpressKitErrorCode["NoCryptoLib"] = "DEK32";
|
|
34
35
|
ExpressKitErrorCode["InvalidCrossServerCredentialsFormat"] = "DEK33";
|
|
35
36
|
ExpressKitErrorCode["UnknownCrossServerError"] = "DEK34";
|
|
37
|
+
ExpressKitErrorCode["NotSelectAdmin"] = "DEK35";
|
|
36
38
|
})(ExpressKitErrorCode || (ExpressKitErrorCode = {}));
|
|
37
39
|
exports.default = ExpressKitErrorCode;
|
|
38
40
|
//# sourceMappingURL=ExpressKitErrorCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ExpressKitErrorCode.ts"],"names":[],"mappings":";AAAA,6BAA6B;;AAE7B;;;GAGG;AACH,IAAK,
|
|
1
|
+
{"version":3,"file":"ExpressKitErrorCode.js","sourceRoot":"","sources":["../../src/types/ExpressKitErrorCode.ts"],"names":[],"mappings":";AAAA,6BAA6B;;AAE7B;;;GAGG;AACH,IAAK,mBA8BJ;AA9BD,WAAK,mBAAmB;IACtB,iBAAiB;IACjB,2CAAoB,CAAA;IACpB,sCAAe,CAAA;IACf,yCAAkB,CAAA;IAClB,uDAAgC,CAAA;IAChC,gEAAyC,CAAA;IACzC,gDAAyB,CAAA;IACzB,gDAAyB,CAAA;IACzB,kDAA2B,CAAA;IAE3B,4BAA4B;IAC5B,6CAAsB,CAAA;IACtB,2CAAoB,CAAA;IACpB,mDAA4B,CAAA;IAC5B,yDAAkC,CAAA;IAClC,+DAAwC,CAAA;IACxC,+DAAwC,CAAA;IACxC,0DAAmC,CAAA;IACnC,8DAAuC,CAAA;IACvC,8DAAuC,CAAA;IACvC,yDAAkC,CAAA;IAClC,mEAA4C,CAAA;IAC5C,oEAA6C,CAAA;IAC7C,oEAA6C,CAAA;IAC7C,2CAAoB,CAAA;IACpB,4CAAqB,CAAA;IACrB,oEAA6C,CAAA;IAC7C,wDAAiC,CAAA;IACjC,+CAAwB,CAAA;AAC1B,CAAC,EA9BI,mBAAmB,KAAnB,mBAAmB,QA8BvB;AAED,kBAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogReviewerAdmin.js","sourceRoot":"","sources":["../../src/types/LogReviewerAdmin.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectAdmin.js","sourceRoot":"","sources":["../../src/types/SelectAdmin.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@ import oauth from 'oauth-signature';
|
|
|
11
11
|
import crypto from 'crypto';
|
|
12
12
|
|
|
13
13
|
// Import shared helpers
|
|
14
|
-
import { internalGetCrossServerCredentialCollection } from './
|
|
14
|
+
import { internalGetCrossServerCredentialCollection } from './initExpressKitCollections';
|
|
15
15
|
|
|
16
16
|
// Import shared types
|
|
17
17
|
import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
@@ -240,7 +240,7 @@ export const validateSignedRequest = async (
|
|
|
240
240
|
/* ------- Look Up Credential ------- */
|
|
241
241
|
|
|
242
242
|
// Get the cross-server credential collection
|
|
243
|
-
const crossServerCredentialCollection = internalGetCrossServerCredentialCollection();
|
|
243
|
+
const crossServerCredentialCollection = await internalGetCrossServerCredentialCollection();
|
|
244
244
|
if (!crossServerCredentialCollection) {
|
|
245
245
|
throw new ErrorWithCode(
|
|
246
246
|
'Could not validate a cross-server request because the cross-server credential collection was not ready in time.',
|
|
@@ -19,9 +19,7 @@ import {
|
|
|
19
19
|
import { getLaunchInfo } from 'caccl/server';
|
|
20
20
|
|
|
21
21
|
// Import caccl functions
|
|
22
|
-
import {
|
|
23
|
-
internalGetLogCollection,
|
|
24
|
-
} from './initServer';
|
|
22
|
+
import initExpressKitCollections, { internalGetLogCollection, internalGetSelectAdminCollection } from './initExpressKitCollections';
|
|
25
23
|
|
|
26
24
|
// Import shared types
|
|
27
25
|
import ExpressKitErrorCode from '../types/ExpressKitErrorCode';
|
|
@@ -390,6 +388,27 @@ const genRouteHandler = (
|
|
|
390
388
|
);
|
|
391
389
|
}
|
|
392
390
|
|
|
391
|
+
// Make sure students don't try to get/change data for other students
|
|
392
|
+
if (
|
|
393
|
+
// launchInfo is defined
|
|
394
|
+
launchInfo
|
|
395
|
+
// launched is true
|
|
396
|
+
&& launched
|
|
397
|
+
// user is a student
|
|
398
|
+
&& launchInfo.isLearner
|
|
399
|
+
// launchInfo.userId not equal to output.userId
|
|
400
|
+
&& (launchInfo.userId !== output.userId)
|
|
401
|
+
) {
|
|
402
|
+
return handleError(
|
|
403
|
+
res,
|
|
404
|
+
{
|
|
405
|
+
message: 'We encountered a student ID mismatch and cannot proceed with that action. Please start over and try again.',
|
|
406
|
+
code: ExpressKitErrorCode.StudentIdMismatch,
|
|
407
|
+
status: 401,
|
|
408
|
+
},
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
393
412
|
// Error if user info cannot be found
|
|
394
413
|
if (
|
|
395
414
|
// User information is incomplete
|
|
@@ -563,6 +582,32 @@ const genRouteHandler = (
|
|
|
563
582
|
);
|
|
564
583
|
}
|
|
565
584
|
|
|
585
|
+
// Add Select Admin endpoint security
|
|
586
|
+
if (
|
|
587
|
+
// This is a select admin endpoint
|
|
588
|
+
req.path.startsWith('/api/admin/select')
|
|
589
|
+
) {
|
|
590
|
+
// Get select admin collection
|
|
591
|
+
const selectAdminCollection = await internalGetSelectAdminCollection();
|
|
592
|
+
const id = output.userId;
|
|
593
|
+
|
|
594
|
+
// Find match if exists in select admin collection
|
|
595
|
+
const [match] = await selectAdminCollection.find({ id });
|
|
596
|
+
|
|
597
|
+
// Check that user exists in select admin collection
|
|
598
|
+
if (!match) {
|
|
599
|
+
// User does not have access
|
|
600
|
+
return handleError(
|
|
601
|
+
res,
|
|
602
|
+
{
|
|
603
|
+
message: 'This action is only allowed for select Canvas admins. Please go back to Canvas, log in as a select admin, and try again.',
|
|
604
|
+
code: ExpressKitErrorCode.NotSelectAdmin,
|
|
605
|
+
status: 401,
|
|
606
|
+
},
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
566
611
|
/*----------------------------------------*/
|
|
567
612
|
/* ------------- Log Handler ------------ */
|
|
568
613
|
/*----------------------------------------*/
|
|
@@ -675,7 +720,7 @@ const genRouteHandler = (
|
|
|
675
720
|
};
|
|
676
721
|
|
|
677
722
|
// Either print to console or save to db
|
|
678
|
-
const logCollection = internalGetLogCollection();
|
|
723
|
+
const logCollection = await internalGetLogCollection();
|
|
679
724
|
if (logCollection) {
|
|
680
725
|
// Store to the log collection
|
|
681
726
|
await logCollection.insert(log);
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Import dce-mango
|
|
2
|
+
import { Collection as MangoCollection } from 'dce-mango';
|
|
3
|
+
|
|
4
|
+
// Import dce-reactkit
|
|
5
|
+
import { Log } from 'dce-reactkit';
|
|
6
|
+
|
|
7
|
+
// Import shared types
|
|
8
|
+
import CrossServerCredential from '../types/CrossServerCredential';
|
|
9
|
+
import SelectAdmin from '../types/SelectAdmin';
|
|
10
|
+
import LogReviewerAdmin from '../types/LogReviewerAdmin';
|
|
11
|
+
|
|
12
|
+
/*------------------------------------------------------------------------*/
|
|
13
|
+
/* ------------------------- Collection Storage ------------------------- */
|
|
14
|
+
/*------------------------------------------------------------------------*/
|
|
15
|
+
|
|
16
|
+
// Variables to store collections
|
|
17
|
+
let logCollection: MangoCollection<Log>;
|
|
18
|
+
let crossServerCredentialCollection: MangoCollection<CrossServerCredential>;
|
|
19
|
+
let selectAdminCollection: MangoCollection<SelectAdmin>;
|
|
20
|
+
let logReviewerAdminCollection: MangoCollection<LogReviewerAdmin>;
|
|
21
|
+
|
|
22
|
+
// Promise that resolves when all collections are initialized
|
|
23
|
+
let collectionsInitializedResolve: (v?: unknown) => void;
|
|
24
|
+
let collectionsInitializedReject: (error: Error) => void;
|
|
25
|
+
const collectionsInitialized = new Promise((resolve, reject) => {
|
|
26
|
+
collectionsInitializedResolve = resolve;
|
|
27
|
+
collectionsInitializedReject = reject;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/*------------------------------------------------------------------------*/
|
|
31
|
+
/* ------------------------- Collection Getters ------------------------- */
|
|
32
|
+
/*------------------------------------------------------------------------*/
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the log collection after initialization
|
|
36
|
+
* @author Gardenia Liu
|
|
37
|
+
*/
|
|
38
|
+
export const internalGetLogCollection = async () => {
|
|
39
|
+
// Wait for collections to be initialized
|
|
40
|
+
await collectionsInitialized;
|
|
41
|
+
|
|
42
|
+
// Return the log collection
|
|
43
|
+
return logCollection;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get the cross server credential collection after initialization
|
|
48
|
+
* @author Gardenia Liu
|
|
49
|
+
*/
|
|
50
|
+
export const internalGetCrossServerCredentialCollection = async () => {
|
|
51
|
+
// Wait for collections to be initialized
|
|
52
|
+
await collectionsInitialized;
|
|
53
|
+
|
|
54
|
+
// Return the cross server credential collection
|
|
55
|
+
return crossServerCredentialCollection;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the select admin collection after initialization
|
|
60
|
+
* @author Gardenia Liu
|
|
61
|
+
*/
|
|
62
|
+
export const internalGetSelectAdminCollection = async () => {
|
|
63
|
+
// Wait for collections to be initialized
|
|
64
|
+
await collectionsInitialized;
|
|
65
|
+
|
|
66
|
+
// Return the cross server credential collection
|
|
67
|
+
return selectAdminCollection;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the log reviewer admin collection after initialization
|
|
72
|
+
* @author Yuen Ler Chow
|
|
73
|
+
*/
|
|
74
|
+
export const internalGetLogReviewerAdminCollection = async () => {
|
|
75
|
+
// Wait for collections to be initialized
|
|
76
|
+
await collectionsInitialized;
|
|
77
|
+
|
|
78
|
+
// Return the log reviewer admin collection
|
|
79
|
+
return logReviewerAdminCollection;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/*------------------------------------------------------------------------*/
|
|
83
|
+
/* -------------------------------- Main -------------------------------- */
|
|
84
|
+
/*------------------------------------------------------------------------*/
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Initialize all collections required for expresskit
|
|
88
|
+
* @author Gardenia Liu
|
|
89
|
+
* @author Gabe Abrams
|
|
90
|
+
* @param Collection the Collection class from dce-mango
|
|
91
|
+
*/
|
|
92
|
+
const initExpressKitCollections = (Collection: typeof MangoCollection) => {
|
|
93
|
+
try {
|
|
94
|
+
// Create and store log collection
|
|
95
|
+
logCollection = new Collection<Log>(
|
|
96
|
+
'Log',
|
|
97
|
+
{
|
|
98
|
+
uniqueIndexKey: 'id',
|
|
99
|
+
indexKeys: [
|
|
100
|
+
'courseId',
|
|
101
|
+
'context',
|
|
102
|
+
'subcontext',
|
|
103
|
+
'tags',
|
|
104
|
+
'year',
|
|
105
|
+
'month',
|
|
106
|
+
'day',
|
|
107
|
+
'hour',
|
|
108
|
+
'type',
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Create and store cross server credential collection
|
|
114
|
+
crossServerCredentialCollection = new Collection<CrossServerCredential>(
|
|
115
|
+
'CrossServerCredential',
|
|
116
|
+
{
|
|
117
|
+
uniqueIndexKey: 'key',
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Create and store select admin collection
|
|
122
|
+
selectAdminCollection = new Collection<SelectAdmin>(
|
|
123
|
+
'SelectAdmin',
|
|
124
|
+
{
|
|
125
|
+
uniqueIndexKey: 'id',
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Create and store log reviewer admin collection
|
|
130
|
+
logReviewerAdminCollection = new Collection<LogReviewerAdmin>(
|
|
131
|
+
'LogReviewerAdmin',
|
|
132
|
+
{
|
|
133
|
+
uniqueIndexKey: 'id',
|
|
134
|
+
},
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Finished! Resolve the promise
|
|
138
|
+
collectionsInitializedResolve();
|
|
139
|
+
} catch (err) {
|
|
140
|
+
return collectionsInitializedReject(err as Error);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export default initExpressKitCollections;
|