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

feat: salck ID to growi user conversion

https://youtrack.weseek.co.jp/issue/GW-7697
- Update create page method
- Update slack ID conversion to Growi user
- Implement userChannelId in create page and preview method
- Adjust  page creator name and updated by
mudana 4 лет назад
Родитель
Сommit
430606f118

+ 2 - 2
packages/app/src/server/service/slack-command-handler/create-page-service.js

@@ -11,7 +11,7 @@ class CreatePageService {
     this.crowi = crowi;
   }
 
-  async createPageInGrowi(interactionPayloadAccessor, path, contentsBody, respondUtil) {
+  async createPageInGrowi(interactionPayloadAccessor, path, contentsBody, respondUtil, userChannelId) {
     const Page = this.crowi.model('Page');
     const reshapedContentsBody = reshapeContentsBody(contentsBody);
 
@@ -20,7 +20,7 @@ class CreatePageService {
     const normalizedPath = pathUtils.normalizePath(sanitizedPath);
 
     // generate a dummy id because Operation to create a page needs ObjectId
-    const dummyObjectIdOfUser = new mongoose.Types.ObjectId();
+    const dummyObjectIdOfUser = userChannelId || new mongoose.Types.ObjectId();
     const page = await Page.create(normalizedPath, reshapedContentsBody, dummyObjectIdOfUser, {});
 
     // Send a message when page creation is complete

+ 10 - 2
packages/app/src/server/service/slack-command-handler/keep.js

@@ -33,8 +33,9 @@ module.exports = (crowi) => {
   handler.createPage = async function(client, payload, interactionPayloadAccessor, respondUtil) {
     let result = [];
     const channelId = payload.channel.id; // this must exist since the type is always block_actions
-    const userChannelId = payload.user.id;
+    const user = await User.findUserBySlackId(payload.user.id);
 
+    const userChannelId = user ? user._id : null;
     // validate form
     const { path, oldest, newest } = await this.keepValidateForm(client, payload, interactionPayloadAccessor);
     // get messages
@@ -138,12 +139,19 @@ module.exports = (crowi) => {
     return result;
   };
 
+  /**
+   * Convert slack ID to growi user if slack ID is found in messages
+   * @param {*} messages
+   */
   handler.messagesWithGrowiUser = async function(messages) {
     await Promise.all(messages.map(async(message) => {
       const growiUser = await User.findUserBySlackId(message.user);
       if (growiUser) {
         message.user = `${growiUser.name} (@${growiUser.username})`;
       }
+      else {
+        message.user = `This slack ID is not registered (${message.user})`;
+      }
     }));
   };
 
@@ -176,7 +184,7 @@ module.exports = (crowi) => {
   };
 
   handler.keepCreatePageAndSendPreview = async function(client, interactionPayloadAccessor, path, userChannelId, contentsBody, respondUtil) {
-    await createPageService.createPageInGrowi(interactionPayloadAccessor, path, contentsBody, respondUtil);
+    await createPageService.createPageInGrowi(interactionPayloadAccessor, path, contentsBody, respondUtil, userChannelId);
 
     // TODO: contentsBody text characters must be less than 3001
     // send preview to dm