Kaynağa Gözat

Merge branch 'master' into imprv/149280-156770-display-tooltip-hover-toolicon

reiji-h 1 yıl önce
ebeveyn
işleme
0650ca4a69

+ 2 - 2
apps/app/src/server/routes/apiv3/app-settings.js

@@ -4,8 +4,8 @@ import { body } from 'express-validator';
 import { i18n } from '^/config/next-i18next.config';
 import { i18n } from '^/config/next-i18next.config';
 
 
 import { SupportedAction } from '~/interfaces/activity';
 import { SupportedAction } from '~/interfaces/activity';
-import { getTranslation } from '~/server/service/i18next';
 import { accessTokenParser } from '~/server/middlewares/access-token-parser';
 import { accessTokenParser } from '~/server/middlewares/access-token-parser';
+import { getTranslation } from '~/server/service/i18next';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
 import { generateAddActivityMiddleware } from '../../middlewares/add-activity';
 import { generateAddActivityMiddleware } from '../../middlewares/add-activity';
@@ -569,7 +569,7 @@ module.exports = (crowi) => {
    *            description: Succeeded to send test mail for smtp
    *            description: Succeeded to send test mail for smtp
    */
    */
   router.post('/smtp-test', loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
   router.post('/smtp-test', loginRequiredStrictly, adminRequired, addActivity, async(req, res) => {
-    const { t } = await getTranslation();
+    const { t } = await getTranslation(req.user.lang);
 
 
     try {
     try {
       await sendTestEmail(req.user.email);
       await sendTestEmail(req.user.email);

+ 1 - 1
apps/app/src/server/routes/apiv3/page/create-page.ts

@@ -1,7 +1,7 @@
 import { allOrigin } from '@growi/core';
 import { allOrigin } from '@growi/core';
 import type {
 import type {
   IPage, IUser, IUserHasId,
   IPage, IUser, IUserHasId,
-} from '@growi/core';
+} from '@growi/core/dist/interfaces';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { ErrorV3 } from '@growi/core/dist/models';
 import { isCreatablePage, isUserPage, isUsersHomepage } from '@growi/core/dist/utils/page-path-utils';
 import { isCreatablePage, isUserPage, isUsersHomepage } from '@growi/core/dist/utils/page-path-utils';
 import { attachTitleHeader, normalizePath } from '@growi/core/dist/utils/path-utils';
 import { attachTitleHeader, normalizePath } from '@growi/core/dist/utils/path-utils';

+ 4 - 3
apps/app/src/server/routes/apiv3/page/index.ts

@@ -125,6 +125,7 @@ module.exports = (crowi) => {
       query('path').optional().isString(),
       query('path').optional().isString(),
       query('findAll').optional().isBoolean(),
       query('findAll').optional().isBoolean(),
       query('shareLinkId').optional().isMongoId(),
       query('shareLinkId').optional().isMongoId(),
+      query('includeEmpty').optional().isBoolean(),
     ],
     ],
     likes: [
     likes: [
       body('pageId').isString(),
       body('pageId').isString(),
@@ -209,7 +210,7 @@ module.exports = (crowi) => {
   router.get('/', certifySharedPage, accessTokenParser, loginRequired, validator.getPage, apiV3FormValidator, async(req, res) => {
   router.get('/', certifySharedPage, accessTokenParser, loginRequired, validator.getPage, apiV3FormValidator, async(req, res) => {
     const { user, isSharedPage } = req;
     const { user, isSharedPage } = req;
     const {
     const {
-      pageId, path, findAll, revisionId, shareLinkId,
+      pageId, path, findAll, revisionId, shareLinkId, includeEmpty,
     } = req.query;
     } = req.query;
 
 
     const isValid = (shareLinkId != null && pageId != null && path == null) || (shareLinkId == null && (pageId != null || path != null));
     const isValid = (shareLinkId != null && pageId != null && path == null) || (shareLinkId == null && (pageId != null || path != null));
@@ -231,10 +232,10 @@ module.exports = (crowi) => {
         page = await Page.findByIdAndViewer(pageId, user);
         page = await Page.findByIdAndViewer(pageId, user);
       }
       }
       else if (!findAll) {
       else if (!findAll) {
-        page = await Page.findByPathAndViewer(path, user, null, true);
+        page = await Page.findByPathAndViewer(path, user, null, true, false);
       }
       }
       else {
       else {
-        pages = await Page.findByPathAndViewer(path, user, null, false);
+        pages = await Page.findByPathAndViewer(path, user, null, false, includeEmpty);
       }
       }
     }
     }
     catch (err) {
     catch (err) {

+ 4 - 4
apps/app/src/server/routes/apiv3/security-settings/index.js

@@ -932,7 +932,7 @@ module.exports = (crowi) => {
    *                  $ref: '#/components/schemas/SamlAuthSetting'
    *                  $ref: '#/components/schemas/SamlAuthSetting'
    */
    */
   router.put('/saml', loginRequiredStrictly, adminRequired, addActivity, validator.samlAuth, apiV3FormValidator, async(req, res) => {
   router.put('/saml', loginRequiredStrictly, adminRequired, addActivity, validator.samlAuth, apiV3FormValidator, async(req, res) => {
-    const { t } = await getTranslation();
+    const { t } = await getTranslation(req.user.lang);
 
 
     //  For the value of each mandatory items,
     //  For the value of each mandatory items,
     //  check whether it from the environment variables is empty and form value to update it is empty
     //  check whether it from the environment variables is empty and form value to update it is empty
@@ -943,11 +943,11 @@ module.exports = (crowi) => {
       const formValue = req.body[key];
       const formValue = req.body[key];
       if (configManager.getConfigFromEnvVars('crowi', configKey) === null && formValue == null) {
       if (configManager.getConfigFromEnvVars('crowi', configKey) === null && formValue == null) {
         const formItemName = t(`security_setting.form_item_name.${key}`);
         const formItemName = t(`security_setting.form_item_name.${key}`);
-        invalidValues.push(t('form_validation.required', formItemName));
+        invalidValues.push(t('input_validation.message.required', formItemName));
       }
       }
     }
     }
     if (invalidValues.length !== 0) {
     if (invalidValues.length !== 0) {
-      return res.apiv3Err(t('form_validation.error_message'), 400, invalidValues);
+      return res.apiv3Err(t('input_validation.message.error_message'), 400, invalidValues);
     }
     }
 
 
     const rule = req.body.ABLCRule;
     const rule = req.body.ABLCRule;
@@ -958,7 +958,7 @@ module.exports = (crowi) => {
         crowi.passportService.parseABLCRule(rule);
         crowi.passportService.parseABLCRule(rule);
       }
       }
       catch (err) {
       catch (err) {
-        return res.apiv3Err(t('form_validation.invalid_syntax', t('security_settings.form_item_name.ABLCRule')), 400);
+        return res.apiv3Err(t('input_validation.message.invalid_syntax', t('security_settings.form_item_name.ABLCRule')), 400);
       }
       }
     }
     }
 
 

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

@@ -241,7 +241,7 @@ module.exports = function(crowi, app) {
    * @param {*} res
    * @param {*} res
    */
    */
   const testLdapCredentials = async(req, res) => {
   const testLdapCredentials = async(req, res) => {
-    const { t } = await getTranslation();
+    const { t } = await getTranslation(req.user.lang);
 
 
     if (!passportService.isLdapStrategySetup) {
     if (!passportService.isLdapStrategySetup) {
       logger.debug('LdapStrategy has not been set up');
       logger.debug('LdapStrategy has not been set up');

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

@@ -14,7 +14,7 @@ import { configManager } from './config-manager';
 
 
 const relativePathToLocalesRoot = path.relative(__dirname, resolveFromRoot('public/static/locales'));
 const relativePathToLocalesRoot = path.relative(__dirname, resolveFromRoot('public/static/locales'));
 
 
-const initI18next = async(lang: Lang = defaultLang) => {
+const initI18next = async(fallbackLng: Lang[] = [defaultLang]) => {
   const i18nInstance = createInstance();
   const i18nInstance = createInstance();
   await i18nInstance
   await i18nInstance
     .use(
     .use(
@@ -26,7 +26,7 @@ const initI18next = async(lang: Lang = defaultLang) => {
     )
     )
     .init({
     .init({
       ...initOptions,
       ...initOptions,
-      lng: lang,
+      fallbackLng,
     });
     });
   return i18nInstance;
   return i18nInstance;
 };
 };
@@ -38,10 +38,11 @@ type Translation = {
 
 
 export async function getTranslation(lang?: Lang): Promise<Translation> {
 export async function getTranslation(lang?: Lang): Promise<Translation> {
   const globalLang = configManager.getConfig('crowi', 'app:globalLang') as Lang;
   const globalLang = configManager.getConfig('crowi', 'app:globalLang') as Lang;
-  const i18nextInstance = await initI18next(globalLang);
+  const fixedLang = lang ?? globalLang;
+  const i18nextInstance = await initI18next([fixedLang, defaultLang]);
 
 
   return {
   return {
-    t: i18nextInstance.getFixedT(lang ?? globalLang),
+    t: i18nextInstance.getFixedT(fixedLang),
     i18n: i18nextInstance,
     i18n: i18nextInstance,
   };
   };
 }
 }

+ 3 - 2
apps/app/src/stores/page-listing.tsx

@@ -22,9 +22,10 @@ import type {
 
 
 export const useSWRxPagesByPath = (path?: Nullable<string>): SWRResponse<IPageHasId[], Error> => {
 export const useSWRxPagesByPath = (path?: Nullable<string>): SWRResponse<IPageHasId[], Error> => {
   const findAll = true;
   const findAll = true;
+  const includeEmpty = true;
   return useSWR(
   return useSWR(
-    path != null ? ['/page', path, findAll] : null,
-    ([endpoint, path, findAll]) => apiv3Get(endpoint, { path, findAll }).then(result => result.data.pages),
+    path != null ? ['/page', path, findAll, includeEmpty] : null,
+    ([endpoint, path, findAll, includeEmpty]) => apiv3Get(endpoint, { path, findAll, includeEmpty }).then(result => result.data.pages),
   );
   );
 };
 };