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

+ 2 - 2
packages/app/src/interfaces/activity.ts

@@ -86,8 +86,8 @@ export type ISnapshot = Partial<Pick<IUser, 'username'>>
 
 
 export type IActivity = {
 export type IActivity = {
   user?: IUser
   user?: IUser
-  ip: string
-  path: string
+  ip?: string
+  endpoint?: string
   targetModel?: SupportedTargetModelType
   targetModel?: SupportedTargetModelType
   target?: string
   target?: string
   action: SupportedActionType
   action: SupportedActionType

+ 4 - 8
packages/app/src/server/middlewares/add-activity.ts

@@ -12,17 +12,13 @@ interface AuthorizedRequest extends Request {
 }
 }
 
 
 export const generateAddActivityMiddleware = crowi => async(req: AuthorizedRequest, res: Response, next: NextFunction): Promise<void> => {
 export const generateAddActivityMiddleware = crowi => async(req: AuthorizedRequest, res: Response, next: NextFunction): Promise<void> => {
-  const ip = req.headers['x-forwarded-for'];
-  const path = req.originalUrl;
-  const user = req.user;
-
   const parameter = {
   const parameter = {
-    ip,
-    path,
+    ip:  req.ip,
+    endpoint: req.originalUrl,
     action: SUPPORTED_ACTION_TYPE.ACTION_UNSETTLED,
     action: SUPPORTED_ACTION_TYPE.ACTION_UNSETTLED,
-    user: user?._id,
+    user: req.user?._id,
     snapshot: {
     snapshot: {
-      username: user?.username,
+      username: req.user?.username,
     },
     },
   };
   };
 
 

+ 2 - 4
packages/app/src/server/models/activity.ts

@@ -19,7 +19,7 @@ export interface ActivityDocument extends Document {
   _id: Types.ObjectId
   _id: Types.ObjectId
   user: Types.ObjectId | any
   user: Types.ObjectId | any
   ip: string
   ip: string
-  path: string
+  endpoint: string
   targetModel: string
   targetModel: string
   target: Types.ObjectId
   target: Types.ObjectId
   action: SupportedActionType
   action: SupportedActionType
@@ -46,11 +46,9 @@ const activitySchema = new Schema<ActivityDocument, ActivityModel>({
   },
   },
   ip: {
   ip: {
     type: String,
     type: String,
-    required: true,
   },
   },
-  path: {
+  endpoint: {
     type: String,
     type: String,
-    required: true,
   },
   },
   targetModel: {
   targetModel: {
     type: String,
     type: String,