Yuki Takei 1 год назад
Родитель
Сommit
d2a801dd95

+ 7 - 7
apps/app/src/features/questionnaire/server/models/schema/growi-info.ts

@@ -9,7 +9,7 @@ import { IExternalAuthProviderType } from '~/interfaces/external-auth-provider';
 
 // legacy properties (extracted from additionalInfo for growi-questionnaire)
 // see: https://gitlab.weseek.co.jp/tech/growi/growi-questionnaire
-type IGrowiInfoLegacy = IGrowiInfo<IGrowiAppAdditionalInfo> & IGrowiAppAdditionalInfo;
+export type IGrowiInfoLegacy = Omit<IGrowiInfo<IGrowiAppAdditionalInfo>, 'additionalInfo'> & IGrowiAppAdditionalInfo;
 
 const growiAdditionalInfoSchema = new Schema<IGrowiAppAdditionalInfo>({
   installedAt: { type: Date, required: true },
@@ -20,7 +20,7 @@ const growiAdditionalInfoSchema = new Schema<IGrowiAppAdditionalInfo>({
   activeExternalAccountTypes: [{ type: String, enum: Object.values(IExternalAuthProviderType) }],
 });
 
-export const growiInfoSchema = new Schema<IGrowiInfoLegacy>({
+export const growiInfoSchema = new Schema<IGrowiInfo<IGrowiAppAdditionalInfo> & IGrowiAppAdditionalInfo>({
   version: { type: String, required: true },
   appSiteUrl: { type: String },
   appSiteUrlHashed: { type: String, required: true },
@@ -37,10 +37,10 @@ export const growiInfoSchema = new Schema<IGrowiInfoLegacy>({
 
   // legacy properties (extracted from additionalInfo for growi-questionnaire)
   // see: https://gitlab.weseek.co.jp/tech/growi/growi-questionnaire
-  installedAt: { type: Date, required: true },
-  installedAtByOldestUser: { type: Date, required: true },
-  currentUsersCount: { type: Number, required: true },
-  currentActiveUsersCount: { type: Number, required: true },
-  attachmentType: { type: String, required: true, enum: Object.values(AttachmentMethodType) },
+  installedAt: { type: Date },
+  installedAtByOldestUser: { type: Date },
+  currentUsersCount: { type: Number },
+  currentActiveUsersCount: { type: Number },
+  attachmentType: { type: String, enum: Object.values(AttachmentMethodType) },
   activeExternalAccountTypes: [{ type: String, enum: Object.values(IExternalAuthProviderType) }],
 });

+ 8 - 17
apps/app/src/features/questionnaire/server/service/questionnaire.ts

@@ -3,13 +3,11 @@ import * as os from 'node:os';
 
 
 import type { IUserHasId } from '@growi/core';
-import { GrowiDeploymentType, GrowiServiceType } from '@growi/core/dist/consts';
 import type { IGrowiInfo, IUser } from '@growi/core/dist/interfaces';
 import { GrowiWikiType } from '@growi/core/dist/interfaces';
 import type { Model } from 'mongoose';
 import mongoose from 'mongoose';
 
-import { AttachmentMethodType } from '~/interfaces/attachment';
 import { IExternalAuthProviderType } from '~/interfaces/external-auth-provider';
 import type Crowi from '~/server/crowi';
 import type { ObjectIdLike } from '~/server/interfaces/mongoose-utils';
@@ -72,15 +70,6 @@ class QuestionnaireService {
       return configManager.getConfig(`security:passport-${type}:isEnabled`);
     });
 
-    const typeStr = configManager.getConfig('app:serviceType');
-    const type = Object.values(GrowiServiceType).includes(typeStr) ? typeStr : null;
-
-    const attachmentTypeStr = configManager.getConfig('app:fileUploadType');
-    const attachmentType = Object.values(AttachmentMethodType).includes(attachmentTypeStr) ? attachmentTypeStr : null;
-
-    const deploymentTypeStr = configManager.getConfig('app:deploymentType');
-    const deploymentType = Object.values(GrowiDeploymentType).includes(deploymentTypeStr) ? deploymentTypeStr : null;
-
     return {
       version: this.crowi.version,
       osInfo: {
@@ -89,18 +78,18 @@ class QuestionnaireService {
         arch: os.arch(),
         totalmem: os.totalmem(),
       },
-      appSiteUrl: configManager.getConfig('questionnaire:isAppSiteUrlHashed') ? null : appSiteUrl,
+      appSiteUrl: configManager.getConfig('questionnaire:isAppSiteUrlHashed') ? undefined : appSiteUrl,
       appSiteUrlHashed,
-      type,
+      type: configManager.getConfig('app:serviceType'),
       wikiType,
-      attachmentType,
-      activeExternalAccountTypes,
-      deploymentType,
+      deploymentType: configManager.getConfig('app:deploymentType'),
       additionalInfo: {
         installedAt,
         installedAtByOldestUser,
         currentUsersCount,
         currentActiveUsersCount,
+        attachmentType: configManager.getConfig('app:fileUploadType'),
+        activeExternalAccountTypes,
       },
     };
   }
@@ -120,7 +109,9 @@ class QuestionnaireService {
     return { type: UserType.guest };
   }
 
-  async getQuestionnaireOrdersToShow(userInfo: IUserInfo, growiInfo: IGrowiInfo, userId: ObjectIdLike | null): Promise<QuestionnaireOrderDocument[]> {
+  async getQuestionnaireOrdersToShow(
+      userInfo: IUserInfo, growiInfo: IGrowiInfo<IGrowiAppAdditionalInfo>, userId: ObjectIdLike | null,
+  ): Promise<QuestionnaireOrderDocument[]> {
     const currentDate = new Date();
 
     let questionnaireOrders = await QuestionnaireOrder.find({

+ 9 - 6
apps/app/src/features/questionnaire/server/util/condition.ts

@@ -1,7 +1,10 @@
-import { ICondition } from '../../interfaces/condition';
-import { IGrowiInfo } from '../../interfaces/growi-info';
-import { IQuestionnaireOrder } from '../../interfaces/questionnaire-order';
-import { IUserInfo, UserType } from '../../interfaces/user-info';
+import type { IGrowiInfo } from '@growi/core/dist/interfaces';
+
+import type { ICondition } from '../../interfaces/condition';
+import type { IGrowiAppAdditionalInfo } from '../../interfaces/growi-app-additional-info';
+import type { IQuestionnaireOrder } from '../../interfaces/questionnaire-order';
+import type { IUserInfo } from '../../interfaces/user-info';
+import { UserType } from '../../interfaces/user-info';
 
 
 const checkUserInfo = (condition: ICondition, userInfo: IUserInfo): boolean => {
@@ -39,7 +42,7 @@ const checkUserInfo = (condition: ICondition, userInfo: IUserInfo): boolean => {
   return true;
 };
 
-const checkGrowiInfo = (condition: ICondition, growiInfo: IGrowiInfo): boolean => {
+const checkGrowiInfo = (condition: ICondition, growiInfo: IGrowiInfo<IGrowiAppAdditionalInfo>): boolean => {
   const { growi: { types, versionRegExps } } = condition;
 
   if (!types.includes(growiInfo.type)) {
@@ -53,7 +56,7 @@ const checkGrowiInfo = (condition: ICondition, growiInfo: IGrowiInfo): boolean =
   return true;
 };
 
-export const isShowableCondition = (order: IQuestionnaireOrder, userInfo: IUserInfo, growiInfo: IGrowiInfo): boolean => {
+export const isShowableCondition = (order: IQuestionnaireOrder, userInfo: IUserInfo, growiInfo: IGrowiInfo<IGrowiAppAdditionalInfo>): boolean => {
   const { condition } = order;
 
   if (!checkUserInfo(condition, userInfo)) {

+ 3 - 3
apps/app/src/server/service/config-manager/config-definition.ts

@@ -1,4 +1,4 @@
-import { GrowiServiceType } from '@growi/core/dist/consts';
+import { GrowiDeploymentType, GrowiServiceType } from '@growi/core/dist/consts';
 import type { ConfigDefinition, Lang } from '@growi/core/dist/interfaces';
 import { defineConfig } from '@growi/core/dist/interfaces';
 import type OpenAI from 'openai';
@@ -478,9 +478,9 @@ export const CONFIG_DEFINITIONS = {
     envVarName: 'SERVICE_TYPE',
     defaultValue: GrowiServiceType.onPremise,
   }),
-  'app:deploymentType': defineConfig<string | undefined>({
+  'app:deploymentType': defineConfig<GrowiDeploymentType>({
     envVarName: 'DEPLOYMENT_TYPE',
-    defaultValue: undefined,
+    defaultValue: GrowiDeploymentType.others,
   }),
   'app:ssrMaxRevisionBodyLength': defineConfig<number>({
     envVarName: 'SSR_MAX_REVISION_BODY_LENGTH',

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

@@ -21,11 +21,11 @@ export interface IGrowiAdditionalInfo {
 
 export interface IGrowiInfo<A extends IGrowiAdditionalInfo> {
   version: string
-  appSiteUrl?: string
+  appSiteUrl: string | undefined
   appSiteUrlHashed: string
   type: GrowiServiceType
   wikiType: GrowiWikiType
+  deploymentType: GrowiDeploymentType
   osInfo?: IGrowiOSInfo
-  deploymentType?: GrowiDeploymentType
   additionalInfo?: A
 }