yusuketk 6 лет назад
Родитель
Сommit
da31a2d263

+ 1 - 1
src/client/js/components/Admin/App/AppSetting.jsx

@@ -31,7 +31,7 @@ class AppSetting extends React.Component {
 
 
   async componentDidMount() {
   async componentDidMount() {
     try {
     try {
-      const response = await this.props.appContainer.apiv3.get('/app-settings/app-setting');
+      const response = await this.props.appContainer.apiv3.get('/app-settings/');
       const appSettingParams = response.data.appSettingParams;
       const appSettingParams = response.data.appSettingParams;
 
 
       this.setState({
       this.setState({

+ 12 - 6
src/client/js/components/Admin/App/SiteUrlSetting.jsx

@@ -20,12 +20,13 @@ class SiteUrlSetting extends React.Component {
       envSiteUrl: '',
       envSiteUrl: '',
     };
     };
 
 
+    this.submitHandler = this.submitHandler.bind(this);
     this.inputSiteUrlChangeHandler = this.inputSiteUrlChangeHandler.bind(this);
     this.inputSiteUrlChangeHandler = this.inputSiteUrlChangeHandler.bind(this);
   }
   }
 
 
   async componentDidMount() {
   async componentDidMount() {
     try {
     try {
-      const response = await this.props.appContainer.apiv3.get('/app-settings/site-url-setting');
+      const response = await this.props.appContainer.apiv3.get('/app-settings/');
       const appSettingParams = response.data.appSettingParams;
       const appSettingParams = response.data.appSettingParams;
 
 
       this.setState({
       this.setState({
@@ -48,7 +49,7 @@ class SiteUrlSetting extends React.Component {
 
 
     try {
     try {
       await this.props.appContainer.apiv3.put('/app-settings/site-url-setting', params);
       await this.props.appContainer.apiv3.put('/app-settings/site-url-setting', params);
-      toastSuccess(t('Updated_site_url'));
+      toastSuccess(t('app_setting.updated_site_url'));
     }
     }
     catch (err) {
     catch (err) {
       toastError(err);
       toastError(err);
@@ -60,14 +61,20 @@ class SiteUrlSetting extends React.Component {
     this.setState({ siteUrl: event.target.value });
     this.setState({ siteUrl: event.target.value });
   }
   }
 
 
+  renderWarningMessage() {
+    const { t } = this.props;
+
+    if (this.state.siteUrl) {
+      return (<p className="alert alert-danger"><i className="icon-exclamation"></i> {t('app_setting.Site URL warn')}</p>);
+    }
+  }
+
   render() {
   render() {
     const { t } = this.props;
     const { t } = this.props;
 
 
     return (
     return (
       <React.Fragment>
       <React.Fragment>
         <p className="well">{t('app_setting.Site URL desc')}</p>
         <p className="well">{t('app_setting.Site URL desc')}</p>
-        {this.state.siteUrl === '' && (<p className="alert alert-danger"><i className="icon-exclamation"></i> { t('app_setting.Site URL warn') }</p>)}
-
         <div className="row">
         <div className="row">
           <div className="col-md-12">
           <div className="col-md-12">
             <div className="col-xs-offset-3">
             <div className="col-xs-offset-3">
@@ -116,8 +123,7 @@ class SiteUrlSetting extends React.Component {
           <div className="col-md-12">
           <div className="col-md-12">
             <div className="form-group">
             <div className="form-group">
               <div className="col-xs-offset-3 col-xs-6">
               <div className="col-xs-offset-3 col-xs-6">
-                <input type="hidden" name="_csrf" value="{{ csrf() }}" />
-                <button type="submit" className="btn btn-primary">
+                <button type="submit" className="btn btn-primary" onClick={this.submitHandler}>
                   {t('app_setting.Update')}
                   {t('app_setting.Update')}
                 </button>
                 </button>
               </div>
               </div>

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

@@ -17,6 +17,9 @@ const validator = {
     body('globalLang').isIn(['en-US', 'ja']),
     body('globalLang').isIn(['en-US', 'ja']),
     body('fileUpload').isBoolean(),
     body('fileUpload').isBoolean(),
   ],
   ],
+  siteUrlSetting: [
+    body('siteUrl').trim(),
+  ],
 };
 };
 
 
 
 
@@ -46,6 +49,12 @@ const validator = {
  *          fileUpload:
  *          fileUpload:
  *            type: boolean
  *            type: boolean
  *            description: enable upload file except image file
  *            description: enable upload file except image file
+ *          siteUrl:
+ *            type: String
+ *            description: Site URL. e.g. https://example.com, https://example.com:8080
+ *          envSiteUrl:
+ *            type: String
+ *            description: environment variable 'APP_SITE_URL'
  */
  */
 
 
 module.exports = (crowi) => {
 module.exports = (crowi) => {
@@ -60,7 +69,7 @@ module.exports = (crowi) => {
   /**
   /**
    * @swagger
    * @swagger
    *
    *
-   *    /app-settings/app-setting:
+   *    /app-settings/:
    *      get:
    *      get:
    *        tags: [AppSettings]
    *        tags: [AppSettings]
    *        description: get app setting params
    *        description: get app setting params
@@ -83,13 +92,21 @@ module.exports = (crowi) => {
    *                    fileUpload:
    *                    fileUpload:
    *                      type: boolean
    *                      type: boolean
    *                      description: enable upload file except image file
    *                      description: enable upload file except image file
+   *                    siteUrl:
+   *                      type: String
+   *                      description: Site URL. e.g. https://example.com, https://example.com:8080
+   *                    envSiteUrl:
+   *                      type: String
+   *                      description: environment variable 'APP_SITE_URL'
    */
    */
-  router.get('/app-setting', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
+  router.get('/', accessTokenParser, loginRequired, adminRequired, async(req, res) => {
     const appSettingParams = {
     const appSettingParams = {
       title: crowi.configManager.getConfig('crowi', 'app:title'),
       title: crowi.configManager.getConfig('crowi', 'app:title'),
       confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
       confidential: crowi.configManager.getConfig('crowi', 'app:confidential'),
       globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
       globalLang: crowi.configManager.getConfig('crowi', 'app:globalLang'),
       fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
       fileUpload: crowi.configManager.getConfig('crowi', 'app:fileUpload'),
+      siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
+      envSiteUrl: crowi.configManager.getConfigFromEnvVars('crowi', 'app:siteUrl'),
     };
     };
     return res.apiv3({ appSettingParams });
     return res.apiv3({ appSettingParams });
 
 
@@ -159,6 +176,54 @@ module.exports = (crowi) => {
 
 
   });
   });
 
 
+  /**
+ * @swagger
+ *
+ *    /app-settings/site-url-setting:
+ *      put:
+ *        tags: [AppSettings]
+ *        description: Update site url setting
+ *        requestBody:
+ *          required: true
+ *          content:
+ *            application/json:
+ *              schema:
+ *                type: object
+ *                properties:
+ *                  siteUrl:
+ *                    type: String
+ *                    description: Site URL. e.g. https://example.com, https://example.com:8080
+ *        responses:
+ *          200:
+ *            description: Succeeded to update site url setting
+ *            content:
+ *              application/json:
+ *                schema:
+ *                  properties:
+ *                    status:
+ *                      $ref: '#/components/schemas/appSettingParams'
+ */
+  router.put('/site-url-setting', loginRequiredStrictly, adminRequired, csrf, validator.siteUrlSetting, ApiV3FormValidator, async(req, res) => {
+
+    const requestSiteUrlSettingParams = {
+      'app:siteUrl': req.body.siteUrl,
+    };
+
+    try {
+      await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestSiteUrlSettingParams);
+      const appSettingParams = {
+        siteUrl: crowi.configManager.getConfig('crowi', 'app:siteUrl'),
+      };
+      return res.apiv3({ appSettingParams });
+    }
+    catch (err) {
+      const msg = 'Error occurred in updating site url setting';
+      logger.error('Error', err);
+      return res.apiv3Err(new ErrorV3(msg, 'update-siteUrlSetting-failed'));
+    }
+
+  });
+
 
 
   return router;
   return router;
 };
 };