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

+ 5 - 5
apps/app/src/pages/admin/index.page.tsx

@@ -25,12 +25,12 @@ const ForbiddenPage = dynamic(() => import('~/client/components/Admin/ForbiddenP
 
 
 type Props = CommonProps & {
-  growiCloudUri: string,
-  growiAppIdForGrowiCloud: number,
+  growiCloudUri?: string,
+  growiAppIdForGrowiCloud?: number,
 };
 
 
-const AdminHomepage: NextPage<Props> = (props) => {
+const AdminHomepage: NextPage<Props> = (props: Props) => {
   useCurrentUser(props.currentUser ?? null);
   useGrowiCloudUri(props.growiCloudUri);
   useGrowiAppIdForGrowiCloud(props.growiAppIdForGrowiCloud);
@@ -71,8 +71,8 @@ const injectServerConfigurations = async(context: GetServerSidePropsContext, pro
   const req: CrowiRequest = context.req as CrowiRequest;
   const { crowi } = req;
 
-  props.growiCloudUri = await crowi.configManager.getConfig('crowi', 'app:growiCloudUri');
-  props.growiAppIdForGrowiCloud = await crowi.configManager.getConfig('crowi', 'app:growiAppIdForCloud');
+  props.growiCloudUri = crowi.configManager.getConfig('crowi', 'app:growiCloudUri');
+  props.growiAppIdForGrowiCloud = crowi.configManager.getConfig('crowi', 'app:growiAppIdForCloud');
 };
 
 

+ 1 - 1
apps/app/src/pages/login/index.page.tsx

@@ -114,7 +114,7 @@ async function injectServerConfigurations(context: GetServerSidePropsContext, pr
     passportService,
   } = crowi;
 
-  props.isPasswordResetEnabled = crowi.configManager.getConfig('crowi', 'security:passport-local:isPasswordResetEnabled');
+  props.isPasswordResetEnabled = configManager.getConfig('crowi', 'security:passport-local:isPasswordResetEnabled');
   props.isMailerSetup = mailService.isMailerSetup;
   props.isLocalStrategySetup = passportService.isLocalStrategySetup;
   props.isLdapStrategySetup = passportService.isLdapStrategySetup;

+ 8 - 6
apps/app/src/server/routes/apiv3/slack-integration.js

@@ -9,6 +9,7 @@ import { parseSlashCommand } from '@growi/slack/dist/utils/slash-command-parser'
 import createError from 'http-errors';
 
 import { SlackCommandHandlerError } from '~/server/models/vo/slack-command-handler-error';
+import { configManager } from '~/server/service/config-manager';
 import loggerFactory from '~/utils/logger';
 
 
@@ -23,9 +24,10 @@ const SlackAppIntegration = mongoose.model('SlackAppIntegration');
 const { handleError } = require('../../service/slack-command-handler/error-handler');
 const { checkPermission } = require('../../util/slack-integration');
 
+/** @param {import('~/server/crowi').default} crowi Crowi instance */
 module.exports = (crowi) => {
 
-  const { configManager, slackIntegrationService } = crowi;
+  const { slackIntegrationService } = crowi;
 
   // Check if the access token is correct
   async function verifyAccessTokenFromProxy(req, res, next) {
@@ -210,7 +212,7 @@ module.exports = (crowi) => {
   };
 
   function getRespondUtil(responseUrl) {
-    const proxyUri = crowi.slackIntegrationService.proxyUriForCurrentType; // can be null
+    const proxyUri = slackIntegrationService.proxyUriForCurrentType ?? null; // can be null
 
     const appSiteUrl = crowi.appService.getSiteUrl();
     if (appSiteUrl == null || appSiteUrl === '') {
@@ -280,7 +282,7 @@ module.exports = (crowi) => {
     }
 
     try {
-      await crowi.slackIntegrationService.handleCommandRequest(growiCommand, client, body, respondUtil);
+      await slackIntegrationService.handleCommandRequest(growiCommand, client, body, respondUtil);
     }
     catch (err) {
       return handleError(err, responseUrl);
@@ -352,10 +354,10 @@ module.exports = (crowi) => {
       const respondUtil = getRespondUtil(responseUrl);
       switch (type) {
         case 'block_actions':
-          await crowi.slackIntegrationService.handleBlockActionsRequest(client, interactionPayload, interactionPayloadAccessor, respondUtil);
+          await slackIntegrationService.handleBlockActionsRequest(client, interactionPayload, interactionPayloadAccessor, respondUtil);
           break;
         case 'view_submission':
-          await crowi.slackIntegrationService.handleViewSubmissionRequest(client, interactionPayload, interactionPayloadAccessor, respondUtil);
+          await slackIntegrationService.handleViewSubmissionRequest(client, interactionPayload, interactionPayloadAccessor, respondUtil);
           break;
         default:
           break;
@@ -431,7 +433,7 @@ module.exports = (crowi) => {
       const client = await slackIntegrationService.generateClientBySlackAppIntegration(slackAppIntegration);
       const { permissionsForSlackEventActions } = slackAppIntegration;
 
-      await crowi.slackIntegrationService.handleEventsRequest(client, growiBotEvent, permissionsForSlackEventActions, data);
+      await slackIntegrationService.handleEventsRequest(client, growiBotEvent, permissionsForSlackEventActions, data);
 
       return res.apiv3({});
     }

+ 6 - 1
apps/app/src/server/routes/ogp.ts

@@ -61,8 +61,12 @@ module.exports = function(crowi) {
 
   const renderOgp = async(req: Request, res: Response) => {
 
-    const User = mongoose.model<IUser>('User');
     const ogpUri = configManager.getConfig('crowi', 'app:ogpUri');
+
+    if (ogpUri == null) {
+      return res.status(501).send('OGP_URI for growi-unique-ogp has not been setup');
+    }
+
     const page: PageDocument = req.body.page; // asserted by ogpValidator
 
     const title = (new DevidedPagePath(page.path)).latter;
@@ -73,6 +77,7 @@ module.exports = function(crowi) {
 
     try {
       if (page.creator != null) {
+        const User = mongoose.model<IUser>('User');
         user = await User.findById(getIdStringForRef(page.creator));
 
         if (user != null) {

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

@@ -5,6 +5,7 @@ import type OpenAI from 'openai';
 import { ActionGroupSize } from '~/interfaces/activity';
 import { AttachmentMethodType } from '~/interfaces/attachment';
 import type { IPageDeleteConfigValue, IPageDeleteConfigValueToProcessValidation } from '~/interfaces/page-delete-config';
+import type { RegistrationMode } from '~/interfaces/registration-mode';
 import { RehypeSanitizeType } from '~/interfaces/services/rehype-sanitize';
 import { GrowiServiceType } from '~/interfaces/system';
 
@@ -425,7 +426,7 @@ export const CONFIG_DEFINITIONS = {
     envVarName: 'GROWI_CLOUD_URI',
     defaultValue: undefined,
   }),
-  'app:growiAppIdForCloud': defineConfig<string | undefined>({
+  'app:growiAppIdForCloud': defineConfig<number | undefined>({
     envVarName: 'GROWI_APP_ID_FOR_GROWI_CLOUD',
     defaultValue: undefined,
   }),
@@ -602,7 +603,7 @@ export const CONFIG_DEFINITIONS = {
   'security:restrictGuestMode': defineConfig<string>({
     defaultValue: 'Deny',
   }),
-  'security:registrationMode': defineConfig<string>({
+  'security:registrationMode': defineConfig<RegistrationMode>({
     defaultValue: 'Open',
   }),
   'security:registrationWhitelist': defineConfig<string[]>({

+ 10 - 8
apps/app/src/server/service/search-delegator/elasticsearch.ts

@@ -69,7 +69,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
 
   indexName: string;
 
-  esUri: string;
+  esUri: string | undefined;
 
   constructor(socketIoService) {
     this.name = SearchDelegatorName.DEFAULT;
@@ -142,14 +142,16 @@ class ElasticsearchDelegator implements SearchDelegator<Data, ESTermsKey, ESQuer
 
     const elasticsearchUri = configManager.getConfig('crowi', 'app:elasticsearchUri');
 
-    const url = new URL(elasticsearchUri);
-    if (url.pathname !== '/') {
-      host = `${url.protocol}//${url.host}`;
-      indexName = url.pathname.substring(1); // omit heading slash
+    if (elasticsearchUri != null) {
+      const url = new URL(elasticsearchUri);
+      if (url.pathname !== '/') {
+        host = `${url.protocol}//${url.host}`;
+        indexName = url.pathname.substring(1); // omit heading slash
 
-      if (url.username != null && url.password != null) {
-        const { username, password } = url;
-        auth = { username, password };
+        if (url.username != null && url.password != null) {
+          const { username, password } = url;
+          auth = { username, password };
+        }
       }
     }
 

+ 5 - 4
apps/app/src/server/service/slack-integration.ts

@@ -2,10 +2,11 @@ import {
   SlackbotType, type GrowiCommand, type GrowiBotEvent,
 } from '@growi/slack';
 import { markdownSectionBlock } from '@growi/slack/dist/utils/block-kit-builder';
-import { InteractionPayloadAccessor } from '@growi/slack/dist/utils/interaction-payload-accessor';
+import type { InteractionPayloadAccessor } from '@growi/slack/dist/utils/interaction-payload-accessor';
 import type { RespondUtil } from '@growi/slack/dist/utils/respond-util-factory';
 import { generateWebClient } from '@growi/slack/dist/utils/webclient-factory';
-import { type ChatPostMessageArguments, WebClient } from '@slack/web-api';
+import type { WebClient } from '@slack/web-api';
+import { type ChatPostMessageArguments } from '@slack/web-api';
 import type { IncomingWebhookSendArguments } from '@slack/webhook';
 import mongoose from 'mongoose';
 
@@ -118,12 +119,12 @@ export class SlackIntegrationService implements S2sMessageHandlable {
     return true;
   }
 
-  get proxyUriForCurrentType(): string {
+  get proxyUriForCurrentType(): string | undefined {
     const currentBotType = this.configManager.getConfig('crowi', 'slackbot:currentBotType');
 
     // TODO assert currentBotType is not null and CUSTOM_WITHOUT_PROXY
 
-    let proxyUri: string;
+    let proxyUri: string | undefined;
 
     switch (currentBotType) {
       case SlackbotType.OFFICIAL: