reiji-h 1 год назад
Родитель
Сommit
b22d0ea9a8

+ 42 - 40
apps/app/src/server/routes/apiv3/users.js

@@ -1033,28 +1033,29 @@ module.exports = (crowi) => {
    *          200:
    *            description: success send new password email
    */
-  router.put('/reset-password-email', accessTokenParser([SCOPE.WRITE.ADMIN.USER_MANAGEMENT]), loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
-    const { id } = req.body;
+  router.put('/reset-password-email', accessTokenParser([SCOPE.WRITE.ADMIN.USER_MANAGEMENT]), loginRequiredStrictly, adminRequired, addActivity,
+    async(req, res) => {
+      const { id } = req.body;
 
-    try {
-      const user = await User.findById(id);
-      if (user == null) {
-        throw new Error('User not found');
-      }
-      const userInfo = {
-        email: user.email,
-        password: req.body.newPassword,
-      };
+      try {
+        const user = await User.findById(id);
+        if (user == null) {
+          throw new Error('User not found');
+        }
+        const userInfo = {
+          email: user.email,
+          password: req.body.newPassword,
+        };
 
-      await sendEmailByUser(userInfo);
-      return res.apiv3();
-    }
-    catch (err) {
-      const msg = err.message;
-      logger.error('Error', err);
-      return res.apiv3Err(new ErrorV3(msg));
-    }
-  });
+        await sendEmailByUser(userInfo);
+        return res.apiv3();
+      }
+      catch (err) {
+        const msg = err.message;
+        logger.error('Error', err);
+        return res.apiv3Err(new ErrorV3(msg));
+      }
+    });
 
   /**
    * @swagger
@@ -1085,29 +1086,30 @@ module.exports = (crowi) => {
    *                      type: object
    *                      description: email and reasons for email sending failure
    */
-  router.put('/send-invitation-email', accessTokenParser([SCOPE.WRITE.ADMIN.USER_MANAGEMENT]), loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
-    const { id } = req.body;
+  router.put('/send-invitation-email', accessTokenParser([SCOPE.WRITE.ADMIN.USER_MANAGEMENT]), loginRequiredStrictly, adminRequired, addActivity,
+    async(req, res) => {
+      const { id } = req.body;
 
-    try {
-      const user = await User.findById(id);
-      const newPassword = await User.resetPasswordByRandomString(id);
-      const userList = [{
-        email: user.email,
-        password: newPassword,
-        user: { id },
-      }];
-      const sendEmail = await sendEmailByUserList(userList);
-      // return null if absent
+      try {
+        const user = await User.findById(id);
+        const newPassword = await User.resetPasswordByRandomString(id);
+        const userList = [{
+          email: user.email,
+          password: newPassword,
+          user: { id },
+        }];
+        const sendEmail = await sendEmailByUserList(userList);
+        // return null if absent
 
-      activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_ADMIN_USERS_SEND_INVITATION_EMAIL });
+        activityEvent.emit('update', res.locals.activity._id, { action: SupportedAction.ACTION_ADMIN_USERS_SEND_INVITATION_EMAIL });
 
-      return res.apiv3({ failedToSendEmail: sendEmail.failedToSendEmailList[0] });
-    }
-    catch (err) {
-      logger.error('Error', err);
-      return res.apiv3Err(new ErrorV3(err));
-    }
-  });
+        return res.apiv3({ failedToSendEmail: sendEmail.failedToSendEmailList[0] });
+      }
+      catch (err) {
+        logger.error('Error', err);
+        return res.apiv3Err(new ErrorV3(err));
+      }
+    });
 
   /**
    * @swagger

+ 2 - 2
apps/app/src/server/routes/attachment/get-brand-logo.ts

@@ -4,6 +4,8 @@ import type {
 } from 'express';
 
 import type { CrowiRequest } from '~/interfaces/crowi-request';
+import { SCOPE } from '~/interfaces/scope';
+import { accessTokenParser } from '~/server/middlewares/access-token-parser';
 import loggerFactory from '~/utils/logger';
 
 import type Crowi from '../../crowi';
@@ -11,8 +13,6 @@ import { AttachmentType } from '../../interfaces/attachment';
 import { generateCertifyBrandLogoMiddleware } from '../../middlewares/certify-brand-logo';
 import { Attachment } from '../../models/attachment';
 import ApiResponse from '../../util/apiResponse';
-import { accessTokenParser } from '~/server/middlewares/access-token-parser';
-import {SCOPE} from '~/interfaces/scope';
 
 import { getActionFactory } from './get';