Explorar el Código

refs 123795: use new configService and add comment

Futa Arai hace 2 años
padre
commit
9ae20d5be4

+ 0 - 7
apps/app/src/server/crowi/index.js

@@ -28,7 +28,6 @@ import AttachmentService from '../service/attachment';
 import { configManager as configManagerSingletonInstance } from '../service/config-manager';
 import { G2GTransferPusherService, G2GTransferReceiverService } from '../service/g2g-transfer';
 import { InstallerService } from '../service/installer';
-import LdapService from '../service/ldap';
 import PageService from '../service/page';
 import PageGrantService from '../service/page-grant';
 import PageOperationService from '../service/page-operation';
@@ -87,7 +86,6 @@ function Crowi() {
   this.xss = new Xss();
   this.questionnaireService = null;
   this.questionnaireCronService = null;
-  this.ldapService = null;
 
   this.tokens = null;
 
@@ -151,7 +149,6 @@ Crowi.prototype.init = async function() {
     this.setupCommentService(),
     this.setupSyncPageStatusService(),
     this.setupQuestionnaireService(),
-    this.setupLdapService(),
     this.setUpCustomize(), // depends on pluginService
   ]);
 
@@ -323,10 +320,6 @@ Crowi.prototype.setupQuestionnaireService = function() {
   this.questionnaireService = new QuestionnaireService(this);
 };
 
-Crowi.prototype.setupLdapService = function() {
-  this.ldapService = new LdapService(this);
-};
-
 Crowi.prototype.scanRuntimeVersions = async function() {
   const self = this;
 

+ 17 - 12
apps/app/src/server/routes/apiv3/external-user-group.ts

@@ -3,12 +3,15 @@ import { body, validationResult } from 'express-validator';
 
 import Crowi from '~/server/crowi';
 import { ApiV3Response } from '~/server/routes/apiv3/interfaces/apiv3-response';
+import LdapService from '~/server/service/ldap';
 import loggerFactory from '~/utils/logger';
 
 const logger = loggerFactory('growi:routes:apiv3:external-user-group');
 
 const router = Router();
 
+const ldapService = new LdapService();
+
 interface AuthorizedRequest extends Request {
   user?: any
 }
@@ -81,18 +84,20 @@ module.exports = (crowi: Crowi): Router => {
   router.put('/ldap/sync', loginRequiredStrictly, adminRequired, async(req: AuthorizedRequest, res: ApiV3Response) => {
     try {
       const isUserBind = crowi.configManager?.getConfig('crowi', 'security:passport-ldap:isUserBind');
-      if (isUserBind) {
-        const username = req.user.name;
-        const password = req.body.password;
-        const groups = await crowi.ldapService?.searchGroup(username, password);
-        console.log('ldap groups');
-        console.log(groups);
-      }
-      else {
-        const groups = await crowi.ldapService?.searchGroup();
-        console.log('ldap groups');
-        console.log(groups);
-      }
+      const groups = async() => {
+        if (isUserBind) {
+          const username = req.user.name;
+          const password = req.body.password;
+          return ldapService.searchGroup(username, password);
+        }
+        return ldapService.searchGroup();
+      };
+
+      // Print searched groups for now
+      // TODO: implement LDAP group sync
+      // see: https://redmine.weseek.co.jp/issues/120030
+      console.log('ldap groups');
+      console.log(await groups);
     }
     catch (e) {
       res.apiv3Err(e, 500);

+ 2 - 10
apps/app/src/server/service/ldap.ts

@@ -4,6 +4,8 @@ import ldap from 'ldapjs';
 
 import loggerFactory from '~/utils/logger';
 
+import { configManager } from './config-manager';
+
 
 const logger = loggerFactory('growi:service:ldap-service');
 
@@ -13,13 +15,6 @@ const logger = loggerFactory('growi:service:ldap-service');
 */
 class LdapService {
 
-  crowi: any;
-
-  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-  constructor(crowi) {
-    this.crowi = crowi;
-  }
-
   /**
    * Execute search on LDAP server and return result
    * @param {string} username Necessary when bind type is user bind
@@ -28,7 +23,6 @@ class LdapService {
    * @param {string} base Base DN to execute search on
    */
   search(username?: string, password?: string, filter?: string, base?: string): Promise<ldap.SearchEntry[]> {
-    const { configManager } = this.crowi;
     const isLdapEnabled = configManager?.getConfig('crowi', 'security:passport-ldap:isEnabled');
 
     if (!isLdapEnabled) {
@@ -98,8 +92,6 @@ class LdapService {
   }
 
   searchGroup(username?: string, password?: string): Promise<ldap.SearchEntry[]> {
-    const { configManager } = this.crowi;
-
     const groupSearchBase = configManager?.getConfig('crowi', 'external-user-group:ldap:groupSearchBase')
     || configManager?.getConfig('crowi', 'security:passport-ldap:groupSearchBase');