Просмотр исходного кода

Merge branch 'master' into imprv/reactify-admin

itizawa 6 лет назад
Родитель
Сommit
846f68ab89

+ 2 - 1
CHANGES.md

@@ -2,7 +2,8 @@
 
 
 ## 3.5.17-RC
 ## 3.5.17-RC
 
 
-* 
+* Fix: Use HTTP PlantUML URL in default
+    * Introduced by 3.5.12
 
 
 ## 3.5.16
 ## 3.5.16
 
 

+ 2 - 1
src/client/js/util/markdown-it/plantuml.js

@@ -7,7 +7,8 @@ export default class PlantUMLConfigurer {
     this.crowi = crowi;
     this.crowi = crowi;
     const config = crowi.getConfig();
     const config = crowi.getConfig();
 
 
-    this.serverUrl = config.env.PLANTUML_URI || 'https://plantuml.com/plantuml';
+    // Do NOT use HTTPS URL because plantuml.com refuse request except from members
+    this.serverUrl = config.env.PLANTUML_URI || 'http://plantuml.com/plantuml';
 
 
     this.generateSource = this.generateSource.bind(this);
     this.generateSource = this.generateSource.bind(this);
   }
   }

+ 2 - 0
src/server/routes/apiv3/index.js

@@ -27,5 +27,7 @@ module.exports = (crowi) => {
 
 
   router.use('/import', require('./import')(crowi));
   router.use('/import', require('./import')(crowi));
 
 
+  router.use('/statistics', require('./statistics')(crowi));
+
   return router;
   return router;
 };
 };

+ 93 - 0
src/server/routes/apiv3/statistics.js

@@ -0,0 +1,93 @@
+const loggerFactory = require('@alias/logger');
+
+const logger = loggerFactory('growi:routes:apiv3:healthcheck'); // eslint-disable-line no-unused-vars
+
+const express = require('express');
+
+const router = express.Router();
+
+const helmet = require('helmet');
+
+const util = require('util');
+
+const USER_STATUS_MASTER = {
+  1: 'registered',
+  2: 'active',
+  3: 'suspended',
+  4: 'deleted',
+  5: 'invited',
+};
+
+
+/**
+ * @swagger
+ *  tags:
+ *    name: Statistics
+ */
+module.exports = (crowi) => {
+
+  const models = crowi.models;
+  const User = models.User;
+
+  /**
+   * @swagger
+   *
+   *  /statistics/user:
+   *    get:
+   *      tags: [Statistics]
+   *      description: Get statistics for user
+   *      responses:
+   *        200:
+   *          description: Statistics for user
+   *          content:
+   *            application/json:
+   *              schema:
+   *                properties:
+   *                  data:
+   *                    type: object
+   *                    description: Statistics for all user
+   */
+  router.get('/user', helmet.noCache(), async(req, res) => {
+    const userCountGroupByStatus = await User.aggregate().group({
+      _id: '$status',
+      totalCount: { $sum: 1 },
+    });
+
+    // Initialize userCountResults with 0
+    const userCountResults = {};
+    Object.values(USER_STATUS_MASTER).forEach((status) => {
+      userCountResults[status] = 0;
+    });
+
+    userCountGroupByStatus.forEach((userCount) => {
+      const key = USER_STATUS_MASTER[userCount._id];
+      userCountResults[key] = userCount.totalCount;
+    });
+    const activeUserCount = userCountResults.active;
+
+    // Use userCountResults for inactive users, so delete unnecessary active
+    delete userCountResults.active;
+
+    // Calculate the total number of inactive users
+    const inactiveUserTotal = userCountResults.invited + userCountResults.deleted + userCountResults.suspended + userCountResults.registered;
+
+    // Get admin users
+    const findAdmins = util.promisify(User.findAdmins).bind(User);
+    const adminUsers = await findAdmins();
+
+    const data = {
+      total: activeUserCount + userCountResults.total,
+      active: {
+        total: activeUserCount,
+        admin: adminUsers.length,
+      },
+      inactive: {
+        total: inactiveUserTotal,
+        ...userCountResults,
+      },
+    };
+    res.status(200).send({ data });
+  });
+
+  return router;
+};

+ 2 - 1
src/server/routes/attachment.js

@@ -203,7 +203,8 @@ module.exports = function(crowi, app) {
    * @apiGroup Attachment
    * @apiGroup Attachment
    */
    */
   api.limit = async function(req, res) {
   api.limit = async function(req, res) {
-    return res.json(ApiResponse.success(await fileUploader.checkLimit(req.query.fileSize)));
+    const fileSize = Number(req.query.fileSize);
+    return res.json(ApiResponse.success(await fileUploader.checkLimit(fileSize)));
   };
   };
 
 
   /**
   /**