Browse Source

Merge pull request #7358 from arafubeatbox/imprv/114331-114885-get-actual-vals-for-growi-info

Imprv/114331 114885 get actual vals for growi info
Ryoji Shimizu 3 years ago
parent
commit
6c384f5afd

+ 1 - 3
packages/app/src/components/Questionnaire/QuestionnaireModal.tsx

@@ -1,9 +1,7 @@
 import { useCallback } from 'react';
 
 import { useTranslation } from 'next-i18next';
-import {
-  Modal, ModalHeader, ModalBody, ModalFooter,
-} from 'reactstrap';
+import { Modal, ModalBody } from 'reactstrap';
 
 import { apiv3Put } from '~/client/util/apiv3-client';
 import { toastSuccess, toastError } from '~/client/util/toastr';

+ 10 - 2
packages/app/src/interfaces/questionnaire/growi-info.ts

@@ -6,7 +6,7 @@ export const GrowiServiceType = {
   onPremise: 'on-premise',
   others: 'others',
 } as const;
-const GrowiWikiType = { open: 'open', closed: 'closed' } as const;
+export const GrowiWikiType = { open: 'open', closed: 'closed' } as const;
 const GrowiAttachmentType = {
   aws: 'aws',
   gcs: 'gcs',
@@ -23,11 +23,19 @@ const GrowiDeploymentType = {
   node: 'node',
   others: 'others',
 } as const;
+export const GrowiExternalAuthProviderType = {
+  ldap: 'ldap',
+  saml: 'saml',
+  oicd: 'oidc',
+  google: 'google',
+  github: 'github',
+} as const;
 
 export type GrowiServiceType = typeof GrowiServiceType[keyof typeof GrowiServiceType]
 type GrowiWikiType = typeof GrowiWikiType[keyof typeof GrowiWikiType]
 type GrowiAttachmentType = typeof GrowiAttachmentType[keyof typeof GrowiAttachmentType]
 type GrowiDeploymentType = typeof GrowiDeploymentType[keyof typeof GrowiDeploymentType]
+export type GrowiExternalAuthProviderType = typeof GrowiExternalAuthProviderType[keyof typeof GrowiExternalAuthProviderType]
 
 interface IGrowiOSInfo {
   type?: ReturnType<typeof os.type>
@@ -45,7 +53,7 @@ export interface IGrowiInfo {
   currentActiveUsersCount: number
   wikiType: GrowiWikiType
   attachmentType: GrowiAttachmentType
-  activeExternalAccountTypes?: string
+  activeExternalAccountTypes?: GrowiExternalAuthProviderType[]
   osInfo?: IGrowiOSInfo
   deploymentType?: GrowiDeploymentType
 }

+ 13 - 1
packages/app/src/server/service/config-loader.ts

@@ -1,7 +1,7 @@
 import { envUtils } from '@growi/core';
 import { parseISO } from 'date-fns';
 
-
+import { GrowiServiceType } from '~/interfaces/questionnaire/growi-info';
 import loggerFactory from '~/utils/logger';
 
 import ConfigModel, {
@@ -670,6 +670,18 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type: ValueType.BOOLEAN,
     default: true,
   },
+  SERVICE_TYPE: {
+    ns: 'crowi',
+    key: 'app:serviceType',
+    type: ValueType.STRING,
+    default: GrowiServiceType.onPremise,
+  },
+  DEPLOYMENT_TYPE: {
+    ns: 'crowi',
+    key: 'app:deploymentType',
+    type: ValueType.STRING,
+    default: null,
+  },
 };
 
 

+ 14 - 8
packages/app/src/server/service/questionnaire.ts

@@ -1,7 +1,7 @@
 import crypto from 'crypto';
 import * as os from 'node:os';
 
-import { IGrowiInfo } from '~/interfaces/questionnaire/growi-info';
+import { GrowiWikiType, GrowiExternalAuthProviderType, IGrowiInfo } from '~/interfaces/questionnaire/growi-info';
 import { StatusType } from '~/interfaces/questionnaire/questionnaire-answer-status';
 import { IUserInfo, UserType } from '~/interfaces/questionnaire/user-info';
 import { IUserHasId } from '~/interfaces/user';
@@ -30,7 +30,13 @@ class QuestionnaireService {
 
     const currentUsersCount = await User.countDocuments();
     const currentActiveUsersCount = await User.countActiveUsers();
-    const attachmentType = this.crowi.configManager.getConfig('crowi', 'app:fileUploadType');
+
+    const wikiMode = this.crowi.configManager.getConfig('crowi', 'security:wikiMode');
+    const wikiType = wikiMode === 'private' ? GrowiWikiType.closed : GrowiWikiType.open;
+
+    const activeExternalAccountTypes: GrowiExternalAuthProviderType[] = Object.values(GrowiExternalAuthProviderType).filter((type) => {
+      return this.crowi.configManager.getConfig('crowi', `security:passport-${type}:isEnabled`);
+    });
 
     return {
       version: this.crowi.version,
@@ -40,15 +46,15 @@ class QuestionnaireService {
         arch: os.arch(),
         totalmem: os.totalmem(),
       },
-      appSiteUrl, // TODO: set only if allowed (see: https://dev.growi.org/6385911e1632aa30f4dae6a4#mdcont-%E5%8C%BF%E5%90%8D%E5%8C%96%E3%81%8C%E5%BF%85%E8%A6%81%E3%81%AA%E3%83%97%E3%83%AD%E3%83%91%E3%83%86%E3%82%A3)
+      appSiteUrl: this.crowi.configManager.getConfig('crowi', 'questionnaire:isAppSiteUrlHashed') ? null : appSiteUrl,
       appSiteUrlHashed,
-      type: 'cloud', // TODO: set actual value
+      type: this.crowi.configManager.getConfig('crowi', 'app:serviceType'),
       currentUsersCount,
       currentActiveUsersCount,
-      wikiType: 'open', // TODO: set actual value
-      attachmentType,
-      activeExternalAccountTypes: undefined, // TODO: set actual value
-      deploymentType: undefined, // TODO: set actual value
+      wikiType,
+      attachmentType: this.crowi.configManager.getConfig('crowi', 'app:fileUploadType'),
+      activeExternalAccountTypes,
+      deploymentType: this.crowi.configManager.getConfig('crowi', 'app:deploymentType'),
     };
   }