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

Merge branch 'feat/ldap-group-sync' into feat/123277-125405-external-user-group-index-ui

Futa Arai 2 лет назад
Родитель
Сommit
9a39056829

+ 0 - 7
apps/app/src/features/external-user-group/server/models/external-user-group-relation.ts

@@ -16,13 +16,6 @@ const schema = new Schema<ExternalUserGroupRelationDocument, ExternalUserGroupRe
   timestamps: { createdAt: true, updatedAt: false },
 });
 
-schema.statics.findOrCreateRelation = function(userGroup, user) {
-  return this.updateOne({
-    relatedGroup: { $eq: userGroup.id },
-    relatedUser: { $eq: user.id },
-  }, {}, { upsert: true });
-};
-
 schema.statics.createRelations = async function(userGroupIds, user) {
   const documentsToInsert = userGroupIds.map((groupId) => {
     return {

+ 2 - 6
apps/app/src/server/crowi/index.js

@@ -26,7 +26,7 @@ import { aclService as aclServiceSingletonInstance } from '../service/acl';
 import AppService from '../service/app';
 import AttachmentService from '../service/attachment';
 import { configManager as configManagerSingletonInstance } from '../service/config-manager';
-import { instanciate as instanciateExternalAccountService, externalAccountService } from '../service/external-account';
+import { instanciate as instanciateExternalAccountService } from '../service/external-account';
 import { G2GTransferPusherService, G2GTransferReceiverService } from '../service/g2g-transfer';
 import { InstallerService } from '../service/installer';
 import PageService from '../service/page';
@@ -88,7 +88,6 @@ function Crowi() {
   this.xss = new Xss();
   this.questionnaireService = null;
   this.questionnaireCronService = null;
-  this.externalAccountService = null;
 
   this.tokens = null;
 
@@ -785,10 +784,7 @@ Crowi.prototype.setupG2GTransferService = async function() {
 
 // execute after setupPassport
 Crowi.prototype.setupExternalAccountService = function() {
-  if (this.externalAccountService == null) {
-    instanciateExternalAccountService(this.passportService);
-    this.externalAccountService = externalAccountService;
-  }
+  instanciateExternalAccountService(this.passportService);
 };
 
 export default Crowi;

+ 7 - 8
apps/app/src/server/routes/login-passport.js

@@ -3,19 +3,18 @@ import { ErrorV3 } from '@growi/core';
 import next from 'next';
 
 import { SupportedAction } from '~/interfaces/activity';
-import { LoginErrorCode } from '~/interfaces/errors/login-error';
 import { ExternalAccountLoginError } from '~/models/vo/external-account-login-error';
-import { NullUsernameToBeRegisteredError } from '~/server/models/errors';
 import { createRedirectToForUnauthenticated } from '~/server/util/createRedirectToForUnauthenticated';
 import loggerFactory from '~/utils/logger';
 
+import { externalAccountService } from '../service/external-account';
+
 /* eslint-disable no-use-before-define */
 
 module.exports = function(crowi, app) {
   const debug = require('debug')('growi:routes:login-passport');
   const logger = loggerFactory('growi:routes:login-passport');
   const passport = require('passport');
-  const ExternalAccount = crowi.model('ExternalAccount');
   const passportService = crowi.passportService;
 
   const activityEvent = crowi.event('activity');
@@ -214,7 +213,7 @@ module.exports = function(crowi, app) {
 
     let externalAccount;
     try {
-      externalAccount = await crowi.externalAccountService.getOrCreateUser(userInfo, providerId);
+      externalAccount = await externalAccountService.getOrCreateUser(userInfo, providerId);
     }
     catch (error) {
       return next(error);
@@ -388,7 +387,7 @@ module.exports = function(crowi, app) {
       userInfo.username = userInfo.email.slice(0, userInfo.email.indexOf('@'));
     }
 
-    const externalAccount = await crowi.externalAccountService.getOrCreateUser(userInfo, providerId);
+    const externalAccount = await externalAccountService.getOrCreateUser(userInfo, providerId);
     if (!externalAccount) {
       return next(new ExternalAccountLoginError('message.sign_in_failure'));
     }
@@ -431,7 +430,7 @@ module.exports = function(crowi, app) {
       name: response.displayName,
     };
 
-    const externalAccount = await crowi.externalAccountService.getOrCreateUser(userInfo, providerId);
+    const externalAccount = await externalAccountService.getOrCreateUser(userInfo, providerId);
     if (!externalAccount) {
       return next(new ExternalAccountLoginError('message.sign_in_failure'));
     }
@@ -481,7 +480,7 @@ module.exports = function(crowi, app) {
     };
     debug('mapping response to userInfo', userInfo, response, attrMapId, attrMapUserName, attrMapMail);
 
-    const externalAccount = await crowi.externalAccountService.getOrCreateUser(userInfo, providerId);
+    const externalAccount = await externalAccountService.getOrCreateUser(userInfo, providerId);
     if (!externalAccount) {
       return new ExternalAccountLoginError('message.sign_in_failure');
     }
@@ -540,7 +539,7 @@ module.exports = function(crowi, app) {
       return next(new ExternalAccountLoginError('Sign in failure due to insufficient privileges.'));
     }
 
-    const externalAccount = await crowi.externalAccountService.getOrCreateUser(userInfo, providerId);
+    const externalAccount = await externalAccountService.getOrCreateUser(userInfo, providerId);
     if (!externalAccount) {
       return next(new ExternalAccountLoginError('message.sign_in_failure'));
     }