|
@@ -11,30 +11,32 @@ const logger = loggerFactory('growi:middleware:exclude-read-only-user');
|
|
|
export const excludeReadOnlyUser = (
|
|
export const excludeReadOnlyUser = (
|
|
|
req: Request,
|
|
req: Request,
|
|
|
res: Response & { apiv3Err },
|
|
res: Response & { apiv3Err },
|
|
|
- next: () => NextFunction,
|
|
|
|
|
-): NextFunction => {
|
|
|
|
|
|
|
+ next: NextFunction,
|
|
|
|
|
+): void => {
|
|
|
const user = req.user;
|
|
const user = req.user;
|
|
|
|
|
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
logger.warn('req.user is null');
|
|
logger.warn('req.user is null');
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (user.readOnly) {
|
|
if (user.readOnly) {
|
|
|
const message = 'This user is read only user';
|
|
const message = 'This user is read only user';
|
|
|
logger.warn(message);
|
|
logger.warn(message);
|
|
|
|
|
|
|
|
- return res.apiv3Err(new ErrorV3(message, 'validation_failed'));
|
|
|
|
|
|
|
+ res.apiv3Err(new ErrorV3(message, 'validation_failed'));
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export const excludeReadOnlyUserIfCommentNotAllowed = (
|
|
export const excludeReadOnlyUserIfCommentNotAllowed = (
|
|
|
req: Request,
|
|
req: Request,
|
|
|
res: Response & { apiv3Err },
|
|
res: Response & { apiv3Err },
|
|
|
- next: () => NextFunction,
|
|
|
|
|
-): NextFunction => {
|
|
|
|
|
|
|
+ next: NextFunction,
|
|
|
|
|
+): void => {
|
|
|
const user = req.user;
|
|
const user = req.user;
|
|
|
|
|
|
|
|
const isRomUserAllowedToComment = configManager.getConfig(
|
|
const isRomUserAllowedToComment = configManager.getConfig(
|
|
@@ -43,15 +45,17 @@ export const excludeReadOnlyUserIfCommentNotAllowed = (
|
|
|
|
|
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
|
logger.warn('req.user is null');
|
|
logger.warn('req.user is null');
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (user.readOnly && !isRomUserAllowedToComment) {
|
|
if (user.readOnly && !isRomUserAllowedToComment) {
|
|
|
const message = 'This user is read only user and comment is not allowed';
|
|
const message = 'This user is read only user and comment is not allowed';
|
|
|
logger.warn(message);
|
|
logger.warn(message);
|
|
|
|
|
|
|
|
- return res.apiv3Err(new ErrorV3(message, 'validation_failed'));
|
|
|
|
|
|
|
+ res.apiv3Err(new ErrorV3(message, 'validation_failed'));
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return next();
|
|
|
|
|
|
|
+ next();
|
|
|
};
|
|
};
|