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

Merge pull request #2946 from weseek/feat/gw-4201-show-message-and-fixed-form-in-gcs-settings

Feat/gw 4201 show message and fixed form in gcs settings
Yuki Takei 5 лет назад
Родитель
Сommit
72eaa47f30

+ 2 - 1
resource/locales/en_US/admin/admin.json

@@ -59,7 +59,8 @@
     "load_plugins": "Load_plugins",
     "load_plugins": "Load_plugins",
     "enable": "Enable",
     "enable": "Enable",
     "disable": "Disable",
     "disable": "Disable",
-    "use_env_var_if_empty": "If the value in the database is empty, the value of the environment variable <cod>{{variable}}</code> is used."
+    "use_env_var_if_empty": "If the value in the database is empty, the value of the environment variable <cod>{{variable}}</code> is used.",
+    "note_for_the_only_env_option": "The GCS Settings is limited by the value of environment variable.<br>To change this setting, please change to false or delete the value of the environment variable <code>{{env}}</code> ."
   },
   },
   "markdown_setting": {
   "markdown_setting": {
     "lineBreak_header": "Line break setting",
     "lineBreak_header": "Line break setting",

+ 1 - 1
resource/locales/en_US/translation.json

@@ -535,7 +535,7 @@
     "missing mandatory configs": "The following mandatory items are not set in either database nor environment variables.",
     "missing mandatory configs": "The following mandatory items are not set in either database nor environment variables.",
     "Local": {
     "Local": {
       "name": "ID/Password",
       "name": "ID/Password",
-      "note for the only env option": "The LOCAL authentication is limited by the value of environment variable.<br>To change this setting, please change to false or delete the value of the environment variable <code>{{env}}/code> .",
+      "note for the only env option": "The LOCAL authentication is limited by the value of environment variable.<br>To change this setting, please change to false or delete the value of the environment variable <code>{{env}}</code> .",
       "enable_local": "Enable ID/Password"
       "enable_local": "Enable ID/Password"
     },
     },
     "ldap": {
     "ldap": {

+ 2 - 1
resource/locales/ja_JP/admin/admin.json

@@ -59,7 +59,8 @@
     "load_plugins": "プラグインを読み込む",
     "load_plugins": "プラグインを読み込む",
     "enable": "有効",
     "enable": "有効",
     "disable": "無効",
     "disable": "無効",
-    "use_env_var_if_empty": "データベース側の値が空の場合、環境変数 <code>{{variable}}</code> の値を利用します"
+    "use_env_var_if_empty": "データベース側の値が空の場合、環境変数 <code>{{variable}}</code> の値を利用します",
+    "note_for_the_only_env_option": "現在GCS設定は環境変数の値によって制限されています<br>この設定を変更する場合は環境変数 <code>{{env}}</code> の値をfalseに変更もしくは削除してください"
   },
   },
   "markdown_setting": {
   "markdown_setting": {
     "lineBreak_header": "Line Break設定",
     "lineBreak_header": "Line Break設定",

+ 3 - 2
resource/locales/zh_CN/admin/admin.json

@@ -60,8 +60,9 @@
 		"load_plugins": "加载插件",
 		"load_plugins": "加载插件",
 		"enable": "启用",
 		"enable": "启用",
 		"disable": "停用",
 		"disable": "停用",
-		"use_env_var_if_empty": "如果数据库中的值为空,则环境变量的值 <cod>{{variable}}</code> 启用。"
-	},
+		"use_env_var_if_empty": "如果数据库中的值为空,则环境变量的值 <cod>{{variable}}</code> 启用。",
+    "note_for_the_only_env_option": "The GCS settings is limited by the value of environment variable.<br>To change this setting, please change to false or delete the value of the environment variable <code>{{env}}</code> ."
+  },
 	"markdown_setting": {
 	"markdown_setting": {
 		"lineBreak_header": "换行设置",
 		"lineBreak_header": "换行设置",
 		"lineBreak_desc": "您可以更改换行设置。",
 		"lineBreak_desc": "您可以更改换行设置。",

+ 1 - 1
resource/locales/zh_CN/translation.json

@@ -522,7 +522,7 @@
 		"missing mandatory configs": "The following mandatory items are not set in either database nor environment variables.",
 		"missing mandatory configs": "The following mandatory items are not set in either database nor environment variables.",
 		"Local": {
 		"Local": {
 			"name": "ID/Password",
 			"name": "ID/Password",
-			"note for the only env option": "The LOCAL authentication is limited by the value of environment variable.<br>To change this setting, please change to false or delete the value of the environment variable <code>{{env}}/code> .",
+			"note for the only env option": "The LOCAL authentication is limited by the value of environment variable.<br>To change this setting, please change to false or delete the value of the environment variable <code>{{env}}</code> .",
 			"enable_local": "Enable ID/Password"
 			"enable_local": "Enable ID/Password"
 		},
 		},
 		"ldap": {
 		"ldap": {

+ 85 - 87
src/client/js/components/Admin/App/GcsSettings.jsx

@@ -11,95 +11,93 @@ import AdminAppContainer from '../../../services/AdminAppContainer';
 
 
 function GcsSetting(props) {
 function GcsSetting(props) {
   const { t, adminAppContainer } = props;
   const { t, adminAppContainer } = props;
+  const { gcsUseOnlyEnvVars } = adminAppContainer.state;
 
 
   return (
   return (
-    <table className="table settings-table">
-      <colgroup>
-        <col className="item-name" />
-        <col className="from-db" />
-        <col className="from-env-vars" />
-      </colgroup>
-      <thead>
-        <tr><th></th><th>Database</th><th>Environment variables</th></tr>
-      </thead>
-      <tbody>
-        <tr>
-          <th>Api Key Json Path</th>
-          <td>
-            <input
-              className="form-control"
-              type="text"
-              name="gcsApiKeyJsonPath"
-              defaultValue={adminAppContainer.state.gcsApiKeyJsonPath}
-              onChange={e => adminAppContainer.changeGcsApiKeyJsonPath(e.target.value)}
-            />
-          </td>
-          <td>
-            <input
-              className="form-control"
-              type="text"
-              value={adminAppContainer.state.envGcsApiKeyJsonPath || ''}
-              readOnly
-              tabIndex="-1"
-            />
-            <p className="form-text text-muted">
-              {/* eslint-disable-next-line react/no-danger */}
-              <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_API_KEY_JSON_PATH' }) }} />
-            </p>
-          </td>
-        </tr>
-        <tr>
-          <th>{t('admin:app_setting.bucket_name')}</th>
-          <td>
-            <input
-              className="form-control"
-              type="text"
-              name="gcsBucket"
-              defaultValue={adminAppContainer.state.gcsBucket}
-              onChange={e => adminAppContainer.changeGcsBucket(e.target.value)}
-            />
-          </td>
-          <td>
-            <input
-              className="form-control"
-              type="text"
-              value={adminAppContainer.state.envGcsBucket || ''}
-              readOnly
-              tabIndex="-1"
-            />
-            <p className="form-text text-muted">
-              {/* eslint-disable-next-line react/no-danger */}
-              <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_BUCKET' }) }} />
-            </p>
-          </td>
-        </tr>
-        <tr>
-          <th>Name Space</th>
-          <td>
-            <input
-              className="form-control"
-              type="text"
-              name="gcsUploadNamespace"
-              defaultValue={adminAppContainer.state.gcsUploadNamespace}
-              onChange={e => adminAppContainer.changeGcsUploadNamespace(e.target.value)}
-            />
-          </td>
-          <td>
-            <input
-              className="form-control"
-              type="text"
-              value={adminAppContainer.state.envGcsUploadNamespace || ''}
-              readOnly
-              tabIndex="-1"
-            />
-            <p className="form-text text-muted">
-              {/* eslint-disable-next-line react/no-danger */}
-              <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_UPLOAD_NAMESPACE' }) }} />
-            </p>
-          </td>
-        </tr>
-      </tbody>
-    </table>
+    <>
+      {gcsUseOnlyEnvVars && (
+        <p
+          className="alert alert-info"
+          dangerouslySetInnerHTML={{ __html: t('admin:app_setting.note_for_the_only_env_option', { env: 'IS_GCS_ENV_PRIORITIZED' }) }}
+        />
+      )}
+      <table className={`table settings-table ${gcsUseOnlyEnvVars && 'use-only-env-vars'}`}>
+        <colgroup>
+          <col className="item-name" />
+          <col className="from-db" />
+          <col className="from-env-vars" />
+        </colgroup>
+        <thead>
+          <tr>
+            <th></th>
+            <th>Database</th>
+            <th>Environment variables</th>
+          </tr>
+        </thead>
+        <tbody>
+          <tr>
+            <th>Api Key Json Path</th>
+            <td>
+              <input
+                className="form-control"
+                type="text"
+                name="gcsApiKeyJsonPath"
+                readOnly={gcsUseOnlyEnvVars}
+                defaultValue={adminAppContainer.state.gcsApiKeyJsonPath}
+                onChange={e => adminAppContainer.changeGcsApiKeyJsonPath(e.target.value)}
+              />
+            </td>
+            <td>
+              <input className="form-control" type="text" value={adminAppContainer.state.envGcsApiKeyJsonPath || ''} readOnly tabIndex="-1" />
+              <p className="form-text text-muted">
+                {/* eslint-disable-next-line react/no-danger */}
+                <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_API_KEY_JSON_PATH' }) }} />
+              </p>
+            </td>
+          </tr>
+          <tr>
+            <th>{t('admin:app_setting.bucket_name')}</th>
+            <td>
+              <input
+                className="form-control"
+                type="text"
+                name="gcsBucket"
+                readOnly={gcsUseOnlyEnvVars}
+                defaultValue={adminAppContainer.state.gcsBucket}
+                onChange={e => adminAppContainer.changeGcsBucket(e.target.value)}
+              />
+            </td>
+            <td>
+              <input className="form-control" type="text" value={adminAppContainer.state.envGcsBucket || ''} readOnly tabIndex="-1" />
+              <p className="form-text text-muted">
+                {/* eslint-disable-next-line react/no-danger */}
+                <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_BUCKET' }) }} />
+              </p>
+            </td>
+          </tr>
+          <tr>
+            <th>Name Space</th>
+            <td>
+              <input
+                className="form-control"
+                type="text"
+                name="gcsUploadNamespace"
+                readOnly={gcsUseOnlyEnvVars}
+                defaultValue={adminAppContainer.state.gcsUploadNamespace}
+                onChange={e => adminAppContainer.changeGcsUploadNamespace(e.target.value)}
+              />
+            </td>
+            <td>
+              <input className="form-control" type="text" value={adminAppContainer.state.envGcsUploadNamespace || ''} readOnly tabIndex="-1" />
+              <p className="form-text text-muted">
+                {/* eslint-disable-next-line react/no-danger */}
+                <small dangerouslySetInnerHTML={{ __html: t('admin:app_setting.use_env_var_if_empty', { variable: 'GCS_UPLOAD_NAMESPACE' }) }} />
+              </p>
+            </td>
+          </tr>
+        </tbody>
+      </table>
+    </>
   );
   );
 
 
 }
 }

+ 2 - 0
src/client/js/services/AdminAppContainer.js

@@ -39,6 +39,7 @@ export default class AdminAppContainer extends Container {
       envFileUploadType: '',
       envFileUploadType: '',
       isFixedFileUploadByEnvVar: false,
       isFixedFileUploadByEnvVar: false,
 
 
+      gcsUseOnlyEnvVars: false,
       gcsApiKeyJsonPath: '',
       gcsApiKeyJsonPath: '',
       envGcsApiKeyJsonPath: '',
       envGcsApiKeyJsonPath: '',
       gcsBucket: '',
       gcsBucket: '',
@@ -97,6 +98,7 @@ export default class AdminAppContainer extends Container {
       s3Bucket: appSettingsParams.s3Bucket,
       s3Bucket: appSettingsParams.s3Bucket,
       s3AccessKeyId: appSettingsParams.s3AccessKeyId,
       s3AccessKeyId: appSettingsParams.s3AccessKeyId,
       s3SecretAccessKey: appSettingsParams.s3SecretAccessKey,
       s3SecretAccessKey: appSettingsParams.s3SecretAccessKey,
+      gcsUseOnlyEnvVars: appSettingsParams.gcsUseOnlyEnvVars,
       gcsApiKeyJsonPath: appSettingsParams.gcsApiKeyJsonPath,
       gcsApiKeyJsonPath: appSettingsParams.gcsApiKeyJsonPath,
       gcsBucket: appSettingsParams.gcsBucket,
       gcsBucket: appSettingsParams.gcsBucket,
       gcsUploadNamespace: appSettingsParams.gcsUploadNamespace,
       gcsUploadNamespace: appSettingsParams.gcsUploadNamespace,

+ 1 - 0
src/server/routes/apiv3/app-settings.js

@@ -232,6 +232,7 @@ module.exports = (crowi) => {
       s3Bucket: crowi.configManager.getConfig('crowi', 'aws:s3Bucket'),
       s3Bucket: crowi.configManager.getConfig('crowi', 'aws:s3Bucket'),
       s3AccessKeyId: crowi.configManager.getConfig('crowi', 'aws:s3AccessKeyId'),
       s3AccessKeyId: crowi.configManager.getConfig('crowi', 'aws:s3AccessKeyId'),
       s3SecretAccessKey: crowi.configManager.getConfig('crowi', 'aws:s3SecretAccessKey'),
       s3SecretAccessKey: crowi.configManager.getConfig('crowi', 'aws:s3SecretAccessKey'),
+      gcsUseOnlyEnvVars: crowi.configManager.getConfig('crowi', 'gcs:isGcsEnvPrioritizes'),
       gcsApiKeyJsonPath: crowi.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath'),
       gcsApiKeyJsonPath: crowi.configManager.getConfig('crowi', 'gcs:apiKeyJsonPath'),
       gcsBucket: crowi.configManager.getConfig('crowi', 'gcs:bucket'),
       gcsBucket: crowi.configManager.getConfig('crowi', 'gcs:bucket'),
       gcsUploadNamespace: crowi.configManager.getConfig('crowi', 'gcs:uploadNamespace'),
       gcsUploadNamespace: crowi.configManager.getConfig('crowi', 'gcs:uploadNamespace'),