Explorar el Código

Merge pull request #749 from weseek/imprv/update-saml-configs-by-new-api

Imprv/update saml configs by new api
Haru hace 7 años
padre
commit
e54d410b38
Se han modificado 2 ficheros con 14 adiciones y 18 borrados
  1. 2 3
      src/server/routes/admin.js
  2. 12 15
      src/server/service/config-manager.js

+ 2 - 3
src/server/routes/admin.js

@@ -1073,13 +1073,12 @@ module.exports = function(crowi, app) {
     }
 
     debug('form content', form);
-    await saveSettingAsync(form);
-    const config = await crowi.getConfig();
+    await crowi.configManager.updateConfigsInTheSameNamespace('crowi', form);
 
     // reset strategy
     await crowi.passportService.resetSamlStrategy();
     // setup strategy
-    if (Config.isEnabledPassportSaml(config)) {
+    if (crowi.configManager.getConfig('security:passport-saml:isEnabled')) {
       try {
         await crowi.passportService.setupSamlStrategy(true);
       }

+ 12 - 15
src/server/service/config-manager.js

@@ -69,30 +69,27 @@ class ConfigManager {
   }
 
   /**
-   * update configs by a iterable object consisting of several objects with ns, key, value fields
+   * update configs in the same namespace
    *
    * For example:
    * ```
-   *  updateConfigs(
-   *   [{
-   *     ns:    'some namespace 1',
-   *     key:   'some key 1',
-   *     value: 'some value 1'
-   *   }, {
-   *     ns:    'some namespace 2',
-   *     key:   'some key 2',
-   *     value: 'some value 2'
-   *   }]
+   *  updateConfigsInTheSameNamespace(
+   *   'some namespace',
+   *   {
+   *    'some key 1': 'value 1',
+   *    'some key 2': 'value 2',
+   *    ...
+   *   }
    *  );
    * ```
    */
-  async updateConfigs(configs) {
+  async updateConfigsInTheSameNamespace(namespace, configs) {
     const results = [];
-    for (const config of configs) {
+    for (const key of Object.keys(configs)) {
       results.push(
         this.configModel.findOneAndUpdate(
-          { ns: config.ns, key: config.key },
-          { ns: config.ns, key: config.key, value: JSON.stringify(config.value) },
+          { ns: namespace, key: key },
+          { ns: namespace, key: key, value: JSON.stringify(configs[key]) },
           { upsert: true, }
         ).exec()
       );