dce-reactkit 3.2.2-beta.3 → 3.2.2-beta.4
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/dist/cjs/index.js +73 -65
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/server/initServer.d.ts +1 -1
- package/dist/esm/index.js +73 -65
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/server/initServer.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/LOG_REVIEW_STATUS_ROUTE.ts +1 -1
- package/src/server/initServer.ts +86 -73
|
@@ -25,7 +25,7 @@ export declare const internalGetLogCollection: () => any;
|
|
|
25
25
|
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
26
26
|
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
27
27
|
* storing logs. If none is included, logs are written to the console
|
|
28
|
-
* @param [opts.logReviewAdmins=all
|
|
28
|
+
* @param [opts.logReviewAdmins=all] info on which admins can review
|
|
29
29
|
* logs from the client. If not included, all Canvas admins are allowed to
|
|
30
30
|
* review logs. If null, no Canvas admins are allowed to review logs.
|
|
31
31
|
* If an array of Canvas userIds (numbers), only Canvas admins with those
|
package/dist/esm/index.js
CHANGED
|
@@ -3884,7 +3884,7 @@ const padZerosLeft = (num, numDigits) => {
|
|
|
3884
3884
|
* access to log review
|
|
3885
3885
|
* @author Gabe Abrams
|
|
3886
3886
|
*/
|
|
3887
|
-
const LOG_REVIEW_STATUS_ROUTE =
|
|
3887
|
+
const LOG_REVIEW_STATUS_ROUTE = `${ROUTE_PATH_PREFIX}/logs/access_allowed`;
|
|
3888
3888
|
|
|
3889
3889
|
// Stored copy of caccl functions
|
|
3890
3890
|
let _cacclGetLaunchInfo;
|
|
@@ -3926,7 +3926,7 @@ const internalGetLogCollection = () => {
|
|
|
3926
3926
|
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
3927
3927
|
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
3928
3928
|
* storing logs. If none is included, logs are written to the console
|
|
3929
|
-
* @param [opts.logReviewAdmins=all
|
|
3929
|
+
* @param [opts.logReviewAdmins=all] info on which admins can review
|
|
3930
3930
|
* logs from the client. If not included, all Canvas admins are allowed to
|
|
3931
3931
|
* review logs. If null, no Canvas admins are allowed to review logs.
|
|
3932
3932
|
* If an array of Canvas userIds (numbers), only Canvas admins with those
|
|
@@ -4009,71 +4009,79 @@ const initServer = (opts) => {
|
|
|
4009
4009
|
/*----------------------------------------*/
|
|
4010
4010
|
/* Log Reviewer */
|
|
4011
4011
|
/*----------------------------------------*/
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4012
|
+
/**
|
|
4013
|
+
* Check if a given user is allowed to review logs
|
|
4014
|
+
* @author Gabe Abrams
|
|
4015
|
+
* @param userId the id of the user
|
|
4016
|
+
* @param isAdmin if true, the user is an admin
|
|
4017
|
+
* @returns true if the user can review logs
|
|
4018
|
+
*/
|
|
4019
|
+
const canReviewLogs = (userId, isAdmin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4020
|
+
// Immediately deny access if user is not an admin
|
|
4021
|
+
if (!isAdmin) {
|
|
4022
|
+
return false;
|
|
4023
|
+
}
|
|
4024
|
+
// If all admins are allowed, we're done
|
|
4025
|
+
if (!opts.logReviewAdmins) {
|
|
4026
|
+
return true;
|
|
4027
|
+
}
|
|
4028
|
+
// Do a dynamic check
|
|
4029
|
+
try {
|
|
4030
|
+
// Array of userIds
|
|
4031
|
+
if (Array.isArray(opts.logReviewAdmins)) {
|
|
4032
|
+
return opts.logReviewAdmins.some((allowedId) => {
|
|
4033
|
+
return (userId === allowedId);
|
|
4034
|
+
});
|
|
4031
4035
|
}
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4036
|
+
// Must be a collection
|
|
4037
|
+
const matches = yield opts.logReviewAdmins.find({ userId });
|
|
4038
|
+
// Make sure at least one entry matches
|
|
4039
|
+
return matches.length > 0;
|
|
4040
|
+
}
|
|
4041
|
+
catch (err) {
|
|
4042
|
+
// If an error occurred, simply return false
|
|
4043
|
+
return false;
|
|
4044
|
+
}
|
|
4045
|
+
});
|
|
4046
|
+
/**
|
|
4047
|
+
* Check if the current user has access to logs
|
|
4048
|
+
* @author Gabe Abrams
|
|
4049
|
+
* @returns {boolean} true if user has access
|
|
4050
|
+
*/
|
|
4051
|
+
opts.app.get(LOG_REVIEW_STATUS_ROUTE, genRouteHandler({
|
|
4052
|
+
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4053
|
+
const { userId, isAdmin } = params;
|
|
4054
|
+
const canReview = yield canReviewLogs(userId, isAdmin);
|
|
4055
|
+
return canReview;
|
|
4056
|
+
}),
|
|
4057
|
+
}));
|
|
4058
|
+
/**
|
|
4059
|
+
* Get all logs for a certain month
|
|
4060
|
+
* @author Gabe Abrams
|
|
4061
|
+
* @param {number} year the year to query (e.g. 2022)
|
|
4062
|
+
* @param {number} month the month to query (e.g. 1 = January)
|
|
4063
|
+
* @returns {Log[]} list of logs from the given month
|
|
4064
|
+
*/
|
|
4065
|
+
opts.app.post(`${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/:year/months/:month`, genRouteHandler({
|
|
4066
|
+
paramTypes: {
|
|
4067
|
+
year: ParamType$1.Int,
|
|
4068
|
+
month: ParamType$1.Int,
|
|
4069
|
+
},
|
|
4070
|
+
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4071
|
+
// Get user info
|
|
4072
|
+
const { userId, isAdmin } = params;
|
|
4073
|
+
// Validate user
|
|
4074
|
+
// isAdmin is already checked because path starts with '/admin'
|
|
4075
|
+
const canReview = yield canReviewLogs(userId, isAdmin);
|
|
4076
|
+
if (!canReview) {
|
|
4077
|
+
throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
|
|
4035
4078
|
}
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
opts.app.get(LOG_REVIEW_STATUS_ROUTE, genRouteHandler({
|
|
4043
|
-
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4044
|
-
const { userId } = params;
|
|
4045
|
-
const canReview = yield canReviewLogs(userId);
|
|
4046
|
-
return canReview;
|
|
4047
|
-
}),
|
|
4048
|
-
}));
|
|
4049
|
-
/**
|
|
4050
|
-
* Get all logs for a certain month
|
|
4051
|
-
* @author Gabe Abrams
|
|
4052
|
-
* @param {number} year the year to query (e.g. 2022)
|
|
4053
|
-
* @param {number} month the month to query (e.g. 1 = January)
|
|
4054
|
-
* @returns {Log[]} list of logs from the given month
|
|
4055
|
-
*/
|
|
4056
|
-
opts.app.post(`${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/:year/months/:month`, genRouteHandler({
|
|
4057
|
-
paramTypes: {
|
|
4058
|
-
year: ParamType$1.Int,
|
|
4059
|
-
month: ParamType$1.Int,
|
|
4060
|
-
},
|
|
4061
|
-
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4062
|
-
// Get user info
|
|
4063
|
-
const { userId } = params;
|
|
4064
|
-
// Validate user
|
|
4065
|
-
// isAdmin is already checked because path starts with '/admin'
|
|
4066
|
-
const canReview = yield canReviewLogs(userId);
|
|
4067
|
-
if (!canReview) {
|
|
4068
|
-
throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
|
|
4069
|
-
}
|
|
4070
|
-
// Query for logs
|
|
4071
|
-
const logs = yield _logCollection.find({ userId });
|
|
4072
|
-
// Return logs
|
|
4073
|
-
return logs;
|
|
4074
|
-
}),
|
|
4075
|
-
}));
|
|
4076
|
-
}
|
|
4079
|
+
// Query for logs
|
|
4080
|
+
const logs = yield _logCollection.find({ userId });
|
|
4081
|
+
// Return logs
|
|
4082
|
+
return logs;
|
|
4083
|
+
}),
|
|
4084
|
+
}));
|
|
4077
4085
|
};
|
|
4078
4086
|
|
|
4079
4087
|
// Import shared types
|