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
package/dist/cjs/index.js
CHANGED
|
@@ -3892,7 +3892,7 @@ const padZerosLeft = (num, numDigits) => {
|
|
|
3892
3892
|
* access to log review
|
|
3893
3893
|
* @author Gabe Abrams
|
|
3894
3894
|
*/
|
|
3895
|
-
const LOG_REVIEW_STATUS_ROUTE =
|
|
3895
|
+
const LOG_REVIEW_STATUS_ROUTE = `${ROUTE_PATH_PREFIX}/logs/access_allowed`;
|
|
3896
3896
|
|
|
3897
3897
|
// Stored copy of caccl functions
|
|
3898
3898
|
let _cacclGetLaunchInfo;
|
|
@@ -3934,7 +3934,7 @@ const internalGetLogCollection = () => {
|
|
|
3934
3934
|
* @param opts.getLaunchInfo CACCL LTI's get launch info function
|
|
3935
3935
|
* @param [opts.logCollection] mongo collection from dce-mango to use for
|
|
3936
3936
|
* storing logs. If none is included, logs are written to the console
|
|
3937
|
-
* @param [opts.logReviewAdmins=all
|
|
3937
|
+
* @param [opts.logReviewAdmins=all] info on which admins can review
|
|
3938
3938
|
* logs from the client. If not included, all Canvas admins are allowed to
|
|
3939
3939
|
* review logs. If null, no Canvas admins are allowed to review logs.
|
|
3940
3940
|
* If an array of Canvas userIds (numbers), only Canvas admins with those
|
|
@@ -4017,71 +4017,79 @@ const initServer = (opts) => {
|
|
|
4017
4017
|
/*----------------------------------------*/
|
|
4018
4018
|
/* Log Reviewer */
|
|
4019
4019
|
/*----------------------------------------*/
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4020
|
+
/**
|
|
4021
|
+
* Check if a given user is allowed to review logs
|
|
4022
|
+
* @author Gabe Abrams
|
|
4023
|
+
* @param userId the id of the user
|
|
4024
|
+
* @param isAdmin if true, the user is an admin
|
|
4025
|
+
* @returns true if the user can review logs
|
|
4026
|
+
*/
|
|
4027
|
+
const canReviewLogs = (userId, isAdmin) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4028
|
+
// Immediately deny access if user is not an admin
|
|
4029
|
+
if (!isAdmin) {
|
|
4030
|
+
return false;
|
|
4031
|
+
}
|
|
4032
|
+
// If all admins are allowed, we're done
|
|
4033
|
+
if (!opts.logReviewAdmins) {
|
|
4034
|
+
return true;
|
|
4035
|
+
}
|
|
4036
|
+
// Do a dynamic check
|
|
4037
|
+
try {
|
|
4038
|
+
// Array of userIds
|
|
4039
|
+
if (Array.isArray(opts.logReviewAdmins)) {
|
|
4040
|
+
return opts.logReviewAdmins.some((allowedId) => {
|
|
4041
|
+
return (userId === allowedId);
|
|
4042
|
+
});
|
|
4039
4043
|
}
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4044
|
+
// Must be a collection
|
|
4045
|
+
const matches = yield opts.logReviewAdmins.find({ userId });
|
|
4046
|
+
// Make sure at least one entry matches
|
|
4047
|
+
return matches.length > 0;
|
|
4048
|
+
}
|
|
4049
|
+
catch (err) {
|
|
4050
|
+
// If an error occurred, simply return false
|
|
4051
|
+
return false;
|
|
4052
|
+
}
|
|
4053
|
+
});
|
|
4054
|
+
/**
|
|
4055
|
+
* Check if the current user has access to logs
|
|
4056
|
+
* @author Gabe Abrams
|
|
4057
|
+
* @returns {boolean} true if user has access
|
|
4058
|
+
*/
|
|
4059
|
+
opts.app.get(LOG_REVIEW_STATUS_ROUTE, genRouteHandler({
|
|
4060
|
+
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4061
|
+
const { userId, isAdmin } = params;
|
|
4062
|
+
const canReview = yield canReviewLogs(userId, isAdmin);
|
|
4063
|
+
return canReview;
|
|
4064
|
+
}),
|
|
4065
|
+
}));
|
|
4066
|
+
/**
|
|
4067
|
+
* Get all logs for a certain month
|
|
4068
|
+
* @author Gabe Abrams
|
|
4069
|
+
* @param {number} year the year to query (e.g. 2022)
|
|
4070
|
+
* @param {number} month the month to query (e.g. 1 = January)
|
|
4071
|
+
* @returns {Log[]} list of logs from the given month
|
|
4072
|
+
*/
|
|
4073
|
+
opts.app.post(`${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/:year/months/:month`, genRouteHandler({
|
|
4074
|
+
paramTypes: {
|
|
4075
|
+
year: ParamType$1.Int,
|
|
4076
|
+
month: ParamType$1.Int,
|
|
4077
|
+
},
|
|
4078
|
+
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4079
|
+
// Get user info
|
|
4080
|
+
const { userId, isAdmin } = params;
|
|
4081
|
+
// Validate user
|
|
4082
|
+
// isAdmin is already checked because path starts with '/admin'
|
|
4083
|
+
const canReview = yield canReviewLogs(userId, isAdmin);
|
|
4084
|
+
if (!canReview) {
|
|
4085
|
+
throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
|
|
4043
4086
|
}
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
opts.app.get(LOG_REVIEW_STATUS_ROUTE, genRouteHandler({
|
|
4051
|
-
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4052
|
-
const { userId } = params;
|
|
4053
|
-
const canReview = yield canReviewLogs(userId);
|
|
4054
|
-
return canReview;
|
|
4055
|
-
}),
|
|
4056
|
-
}));
|
|
4057
|
-
/**
|
|
4058
|
-
* Get all logs for a certain month
|
|
4059
|
-
* @author Gabe Abrams
|
|
4060
|
-
* @param {number} year the year to query (e.g. 2022)
|
|
4061
|
-
* @param {number} month the month to query (e.g. 1 = January)
|
|
4062
|
-
* @returns {Log[]} list of logs from the given month
|
|
4063
|
-
*/
|
|
4064
|
-
opts.app.post(`${LOG_REVIEW_ROUTE_PATH_PREFIX}/years/:year/months/:month`, genRouteHandler({
|
|
4065
|
-
paramTypes: {
|
|
4066
|
-
year: ParamType$1.Int,
|
|
4067
|
-
month: ParamType$1.Int,
|
|
4068
|
-
},
|
|
4069
|
-
handler: ({ params }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4070
|
-
// Get user info
|
|
4071
|
-
const { userId } = params;
|
|
4072
|
-
// Validate user
|
|
4073
|
-
// isAdmin is already checked because path starts with '/admin'
|
|
4074
|
-
const canReview = yield canReviewLogs(userId);
|
|
4075
|
-
if (!canReview) {
|
|
4076
|
-
throw new ErrorWithCode('You cannot access this resource because you do not have the appropriate permissions.', ReactKitErrorCode$1.NotAllowedToReviewLogs);
|
|
4077
|
-
}
|
|
4078
|
-
// Query for logs
|
|
4079
|
-
const logs = yield _logCollection.find({ userId });
|
|
4080
|
-
// Return logs
|
|
4081
|
-
return logs;
|
|
4082
|
-
}),
|
|
4083
|
-
}));
|
|
4084
|
-
}
|
|
4087
|
+
// Query for logs
|
|
4088
|
+
const logs = yield _logCollection.find({ userId });
|
|
4089
|
+
// Return logs
|
|
4090
|
+
return logs;
|
|
4091
|
+
}),
|
|
4092
|
+
}));
|
|
4085
4093
|
};
|
|
4086
4094
|
|
|
4087
4095
|
// Import shared types
|