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

Merge branch 'feat/auditlog' of https://github.com/weseek/growi into feat/96535-create-activity-when-a-page-is-viewed

Shun Miyazawa 3 лет назад
Родитель
Сommit
8ee10d3b71

+ 4 - 0
packages/app/src/interfaces/activity.ts

@@ -7,6 +7,7 @@ const MODEL_COMMENT = 'Comment';
 
 // Action
 const ACTION_UNSETTLED = 'UNSETTLED';
+const ACTION_REGISTRATION_SUCCESS = 'REGISTRATION_SUCCESS';
 const ACTION_LOGIN_SUCCESS = 'LOGIN_SUCCESS';
 const ACTION_LOGIN_FAILURE = 'LOGIN_FAILURE';
 const ACTION_LOGOUT = 'LOGOUT';
@@ -24,6 +25,7 @@ const ACTION_PAGE_DELETE_COMPLETELY = 'PAGE_DELETE_COMPLETELY';
 const ACTION_PAGE_REVERT = 'PAGE_REVERT';
 const ACTION_COMMENT_CREATE = 'COMMENT_CREATE';
 const ACTION_COMMENT_UPDATE = 'COMMENT_UPDATE';
+const ACTION_COMMENT_REMOVE = 'COMMENT_REMOVE';
 
 
 export const SUPPORTED_TARGET_MODEL_TYPE = {
@@ -36,6 +38,7 @@ export const SUPPORTED_EVENT_MODEL_TYPE = {
 
 export const SUPPORTED_ACTION_TYPE = {
   ACTION_UNSETTLED,
+  ACTION_REGISTRATION_SUCCESS,
   ACTION_LOGIN_SUCCESS,
   ACTION_LOGIN_FAILURE,
   ACTION_LOGOUT,
@@ -53,6 +56,7 @@ export const SUPPORTED_ACTION_TYPE = {
   ACTION_PAGE_REVERT,
   ACTION_COMMENT_CREATE,
   ACTION_COMMENT_UPDATE,
+  ACTION_COMMENT_REMOVE,
 } as const;
 
 export const SUPPORTED_ACTION_TO_NOTIFIED_TYPE = {

+ 6 - 2
packages/app/src/server/routes/comment.js

@@ -1,3 +1,4 @@
+
 import { SUPPORTED_ACTION_TYPE, SUPPORTED_TARGET_MODEL_TYPE, SUPPORTED_EVENT_MODEL_TYPE } from '~/interfaces/activity';
 import loggerFactory from '~/utils/logger';
 
@@ -54,6 +55,8 @@ module.exports = function(crowi, app) {
   const GlobalNotificationSetting = crowi.model('GlobalNotificationSetting');
   const ApiResponse = require('../util/apiResponse');
 
+  const activityEvent = crowi.event('activity');
+
   const globalNotificationService = crowi.getGlobalNotificationService();
   const userNotificationService = crowi.getUserNotificationService();
 
@@ -61,8 +64,6 @@ module.exports = function(crowi, app) {
   const mongoose = require('mongoose');
   const ObjectId = mongoose.Types.ObjectId;
 
-  const activityEvent = crowi.event('activity');
-
   const actions = {};
   const api = {};
 
@@ -479,6 +480,9 @@ module.exports = function(crowi, app) {
       return res.json(ApiResponse.error(err));
     }
 
+    const parameters = { action: SUPPORTED_ACTION_TYPE.ACTION_COMMENT_REMOVE };
+    activityEvent.emit('update', res.locals.activity._id, parameters);
+
     return res.json(ApiResponse.success({}));
   };
 

+ 3 - 2
packages/app/src/server/routes/index.js

@@ -81,7 +81,7 @@ module.exports = function(crowi, app) {
   app.post('/login/activateInvited'   , apiLimiter , applicationInstalled, loginFormValidator.inviteRules(), loginFormValidator.inviteValidation, csrf, login.invited);
   app.post('/login'                   , apiLimiter , applicationInstalled, loginFormValidator.loginRules(), loginFormValidator.loginValidation, csrf, addActivity, loginPassport.loginWithLocal, loginPassport.loginWithLdap, loginPassport.loginFailure);
 
-  app.post('/register'                , apiLimiter , applicationInstalled, registerFormValidator.registerRules(), registerFormValidator.registerValidation, csrf, login.register);
+  app.post('/register'                , apiLimiter , applicationInstalled, registerFormValidator.registerRules(), registerFormValidator.registerValidation, csrf, addActivity, login.register);
   app.get('/register'                 , applicationInstalled, login.preLogin, login.register);
 
   app.get('/admin'                    , applicationInstalled, loginRequiredStrictly , adminRequired , admin.index);
@@ -188,7 +188,8 @@ module.exports = function(crowi, app) {
   apiV1Router.get('/comments.get'        , accessTokenParser , loginRequired , comment.api.get);
   apiV1Router.post('/comments.add'       , comment.api.validators.add(), accessTokenParser , loginRequiredStrictly , csrf, addActivity, comment.api.add);
   apiV1Router.post('/comments.update'    , comment.api.validators.add(), accessTokenParser , loginRequiredStrictly , csrf, addActivity, comment.api.update);
-  apiV1Router.post('/comments.remove'    , accessTokenParser , loginRequiredStrictly , csrf, comment.api.remove);
+  apiV1Router.post('/comments.remove'    , accessTokenParser , loginRequiredStrictly , csrf, addActivity, comment.api.remove);
+
   apiV1Router.post('/attachments.add'                  , uploads.single('file'), autoReap, accessTokenParser, loginRequiredStrictly ,csrf, attachment.api.add);
   apiV1Router.post('/attachments.uploadProfileImage'   , uploads.single('file'), autoReap, accessTokenParser, loginRequiredStrictly ,csrf, attachment.api.uploadProfileImage);
   apiV1Router.post('/attachments.remove'               , accessTokenParser , loginRequiredStrictly , csrf, attachment.api.remove);

+ 6 - 1
packages/app/src/server/routes/login.js

@@ -1,5 +1,5 @@
+import { SUPPORTED_ACTION_TYPE } from '~/interfaces/activity';
 import loggerFactory from '~/utils/logger';
-
 // disable all of linting
 // because this file is a deprecated legacy of Crowi
 
@@ -11,6 +11,7 @@ module.exports = function(crowi, app) {
   const {
     configManager, appService, aclService, mailService,
   } = crowi;
+  const activityEvent = crowi.event('activity');
 
   const actions = {};
 
@@ -38,6 +39,10 @@ module.exports = function(crowi, app) {
       const { redirectTo } = req.session;
       // remove session.redirectTo
       delete req.session.redirectTo;
+
+      const parameters = { action: SUPPORTED_ACTION_TYPE.ACTION_REGISTRATION_SUCCESS };
+      activityEvent.emit('update', res.locals.activity._id, parameters);
+
       return res.safeRedirect(redirectTo);
     });
   };

+ 2 - 2
packages/app/src/server/service/comment.ts

@@ -55,12 +55,12 @@ class CommentService {
     });
 
     // remove
-    this.commentEvent.on('delete', async(comment) => {
+    this.commentEvent.on('delete', async(removedComment) => {
       this.commentEvent.onDelete();
 
       try {
         const Page = getModelSafely('Page') || require('../models/page')(this.crowi);
-        await Page.updateCommentCount(comment.page);
+        await Page.updateCommentCount(removedComment.page);
       }
       catch (err) {
         logger.error('Error occurred while updating the comment count:\n', err);