dce-reactkit 3.2.2-beta.2 → 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 +99 -65
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/types/server/initServer.d.ts +1 -1
- package/dist/esm/index.js +99 -66
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/types/server/initServer.d.ts +1 -1
- package/dist/index.d.ts +9 -2
- package/package.json +1 -1
- package/src/constants/LOG_REVIEW_STATUS_ROUTE.ts +1 -1
- package/src/index.ts +2 -0
- package/src/server/initServer.ts +86 -73
|
@@ -48,6 +48,7 @@ import logClientEvent from './helpers/logClientEvent';
|
|
|
48
48
|
import initLogCollection from './server/initLogCollection';
|
|
49
49
|
import getMonthName from './helpers/getMonthName';
|
|
50
50
|
import genCSV from './helpers/genCSV';
|
|
51
|
+
import canReviewLogs from './helpers/canReviewLogs';
|
|
51
52
|
import ModalButtonType from './types/ModalButtonType';
|
|
52
53
|
import ModalSize from './types/ModalSize';
|
|
53
54
|
import ModalType from './types/ModalType';
|
|
@@ -63,4 +64,4 @@ import LogBuiltInMetadata from './types/LogBuiltInMetadata';
|
|
|
63
64
|
import LogMetadataType from './types/LogMetadataType';
|
|
64
65
|
import IntelliTableColumn from './types/IntelliTableColumn';
|
|
65
66
|
import PickableItem from './components/ItemPicker/types/PickableItem';
|
|
66
|
-
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, visitServerEndpoint, logClientEvent, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, ParamType, };
|
|
67
|
+
export { AppWrapper, LoadingSpinner, ErrorBox, Modal, TabBox, RadioButton, CheckboxButton, ButtonInputGroup, SimpleDateChooser, Drawer, PopSuccessMark, PopFailureMark, PopPendingMark, CopiableBox, ItemPicker, LogReviewer, IntelliTable, CSVDownloadButton, alert, confirm, showFatalError, ErrorWithCode, MINUTE_IN_MS, HOUR_IN_MS, DAY_IN_MS, abbreviate, avg, ceilToNumDecimals, floorToNumDecimals, forceNumIntoBounds, padDecimalZeros, padZerosLeft, roundToNumDecimals, sum, waitMs, getOrdinal, getTimeInfoInET, stubServerEndpoint, startMinWait, getHumanReadableDate, getPartOfDay, stringsToHumanReadableList, onlyKeepLetters, parallelLimit, getMonthName, genCSV, canReviewLogs, visitServerEndpoint, logClientEvent, initServer, genRouteHandler, handleError, handleSuccess, initLogCollection, ModalButtonType, ModalSize, ModalType, ReactKitErrorCode, Variant, DayOfWeek, Log, LogType, LogSource, LogAction, LogBuiltInMetadata, LogMetadataType, IntelliTableColumn, PickableItem, ParamType, };
|
|
@@ -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
|
|
@@ -5124,6 +5132,31 @@ const initLogCollection = (Collection) => {
|
|
|
5124
5132
|
});
|
|
5125
5133
|
};
|
|
5126
5134
|
|
|
5135
|
+
// Cache user's ability
|
|
5136
|
+
let canReview = undefined;
|
|
5137
|
+
/**
|
|
5138
|
+
* Check if the current user can review logs
|
|
5139
|
+
* @author Gabe Abrams
|
|
5140
|
+
* @returns true if current user can review logs
|
|
5141
|
+
*/
|
|
5142
|
+
const canReviewLogs = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
5143
|
+
// If cached, use that value
|
|
5144
|
+
if (canReview !== undefined) {
|
|
5145
|
+
return canReview;
|
|
5146
|
+
}
|
|
5147
|
+
// Ask on server
|
|
5148
|
+
try {
|
|
5149
|
+
canReview = !!(yield visitServerEndpoint({
|
|
5150
|
+
path: LOG_REVIEW_STATUS_ROUTE,
|
|
5151
|
+
method: 'GET',
|
|
5152
|
+
}));
|
|
5153
|
+
}
|
|
5154
|
+
catch (err) {
|
|
5155
|
+
canReview = false;
|
|
5156
|
+
}
|
|
5157
|
+
return canReview;
|
|
5158
|
+
});
|
|
5159
|
+
|
|
5127
5160
|
/**
|
|
5128
5161
|
* Days of the week
|
|
5129
5162
|
* @author Gabe Abrams
|
|
@@ -5140,5 +5173,5 @@ var DayOfWeek;
|
|
|
5140
5173
|
})(DayOfWeek || (DayOfWeek = {}));
|
|
5141
5174
|
var DayOfWeek$1 = DayOfWeek;
|
|
5142
5175
|
|
|
5143
|
-
export { AppWrapper, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek$1 as DayOfWeek, Drawer, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, Variant$1 as Variant, abbreviate, alert$1 as alert, avg, ceilToNumDecimals, confirm, floorToNumDecimals, forceNumIntoBounds, genCSV, genRouteHandler, getHumanReadableDate, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, initLogCollection, initServer, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
|
5176
|
+
export { AppWrapper, ButtonInputGroup, CSVDownloadButton, CheckboxButton, CopiableBox, DAY_IN_MS, DayOfWeek$1 as DayOfWeek, Drawer, ErrorBox, ErrorWithCode, HOUR_IN_MS, IntelliTable, ItemPicker, LoadingSpinner, LogAction$1 as LogAction, LogBuiltInMetadata, LogReviewer, LogSource$1 as LogSource, LogType$1 as LogType, MINUTE_IN_MS, Modal, ModalButtonType$1 as ModalButtonType, ModalSize$1 as ModalSize, ModalType$1 as ModalType, ParamType$1 as ParamType, PopFailureMark, PopPendingMark, PopSuccessMark, RadioButton, ReactKitErrorCode$1 as ReactKitErrorCode, SimpleDateChooser, TabBox, Variant$1 as Variant, abbreviate, alert$1 as alert, avg, canReviewLogs, ceilToNumDecimals, confirm, floorToNumDecimals, forceNumIntoBounds, genCSV, genRouteHandler, getHumanReadableDate, getMonthName, getOrdinal, getPartOfDay, getTimeInfoInET, handleError, handleSuccess, initLogCollection, initServer, logClientEvent, onlyKeepLetters, padDecimalZeros, padZerosLeft, parallelLimit, roundToNumDecimals, showFatalError, startMinWait, stringsToHumanReadableList, stubServerEndpoint, sum, visitServerEndpoint, waitMs };
|
|
5144
5177
|
//# sourceMappingURL=index.js.map
|