]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7980 apply feedback
authorStas Vilchik <vilchiks@gmail.com>
Fri, 9 Sep 2016 13:31:51 +0000 (15:31 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Fri, 9 Sep 2016 13:31:51 +0000 (15:31 +0200)
server/sonar-web/src/main/js/apps/settings/licenses/LicenseChangeForm.js
server/sonar-web/src/main/js/apps/settings/licenses/LicenseRow.js
server/sonar-web/src/main/js/apps/settings/licenses/LicenseStatus.js
server/sonar-web/src/main/js/apps/settings/licenses/LicenseValueView.hbs
server/sonar-web/src/main/js/apps/settings/licenses/licenseUtils.js [new file with mode: 0644]
server/sonar-web/src/main/js/apps/settings/store/licenses/actions.js
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 8976c35593ff4e9591355ca94860a7f2a328e48e..ce354ca12011fc9a13495c021fd3e3e47e9d9489 100644 (file)
@@ -42,7 +42,7 @@ export default class LicenseChangeForm extends React.Component {
 
   render () {
     return (
-        <button className="js-change" onClick={e => this.onClick(e)}>{translate('change_verb')}</button>
+        <button className="js-change" onClick={e => this.onClick(e)}>{translate('update_verb')}</button>
     );
   }
 }
index 2b095f0bec785b59bd41886569b632cc83e61673..afb705ae6c756e7d4508cd2647776e60398afadb 100644 (file)
@@ -50,9 +50,11 @@ export default class LicenseRow extends React.Component {
           </td>
           <td className="js-organization text-middle">{license.organization}</td>
           <td className="js-expiration text-middle">
-            <div className={license.invalidExpiration ? 'text-danger' : null}>
-              {moment(license.expiration).format('LL')}
-            </div>
+            {license.expiration != null && (
+                <div className={license.invalidExpiration ? 'text-danger' : null}>
+                  {moment(license.expiration).format('LL')}
+                </div>
+            )}
           </td>
           <td className="js-type text-middle">{license.type}</td>
           <td className="js-server-id text-middle">
index 657435686d7ed2fddcf6d250bb44fd43e20b617f..9f9abb4e302deec6e99e40bc38d3fbda198a251b 100644 (file)
@@ -18,6 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import React from 'react';
+import { isLicenseInvalid } from './licenseUtils';
 
 export default class LicenseStatus extends React.Component {
   static propTypes = {
@@ -31,7 +32,7 @@ export default class LicenseStatus extends React.Component {
       return null;
     }
 
-    const isInvalid = !!license.invalidProduct || !!license.invalidExpiration || !!license.invalidServerId;
+    const isInvalid = isLicenseInvalid(license);
     if (isInvalid) {
       return <i className="icon-alert-error"/>;
     }
index c472b282ddad65c3edaea3b2c4502247c24210cd..c4aab7ea6f7ca9bc7a050921ed68191b676c981b 100644 (file)
@@ -1,6 +1,6 @@
 <form>
   <div class="modal-head">
-    <h2>{{tp 'licenses.change_license_for_x' productName}}</h2>
+    <h2>{{tp 'licenses.update_license_for_x' productName}}</h2>
   </div>
   <div class="modal-body">
     <div class="js-modal-messages"></div>
diff --git a/server/sonar-web/src/main/js/apps/settings/licenses/licenseUtils.js b/server/sonar-web/src/main/js/apps/settings/licenses/licenseUtils.js
new file mode 100644 (file)
index 0000000..5b32668
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+export const isLicenseInvalid = license => (
+    !!license.invalidProduct || !!license.invalidExpiration || !!license.invalidServerId
+);
+
+export const isLicenseFromListInvalid = (licenses, key) => {
+  const license = licenses.find(license => license.key === key);
+  return license ? isLicenseInvalid(license) : false;
+};
index d94b51a5902474e0b7b56443b828ea7d6ba1d6bc..9071be540b5642ddffe95dd9df6f3a827d2d2f74 100644 (file)
@@ -21,6 +21,7 @@ import * as licenses from '../../../../api/licenses';
 import { parseError } from '../../../code/utils';
 import { addGlobalSuccessMessage, addGlobalErrorMessage } from '../../../../components/store/globalMessages';
 import { translate } from '../../../../helpers/l10n';
+import { isLicenseFromListInvalid, isLicenseInvalid } from '../../licenses/licenseUtils';
 
 export const RECEIVE_LICENSES = 'RECEIVE_LICENSES';
 
@@ -29,26 +30,37 @@ const receiveLicenses = licenses => ({
   licenses
 });
 
-export const fetchLicenses = () => dispatch =>
-    licenses.getLicenses()
-        .then(licenses => {
-          dispatch(receiveLicenses(licenses));
-        })
-        .catch(e => {
-          parseError(e).then(message => dispatch(addGlobalErrorMessage(key, message)));
-          return Promise.reject();
-        });
+const handleError = dispatch => error => {
+  parseError(error).then(message => dispatch(addGlobalErrorMessage(message)));
+  return Promise.reject();
+};
+
+export const fetchLicenses = () => dispatch => {
+  return licenses.getLicenses()
+      .then(licenses => {
+        dispatch(receiveLicenses(licenses));
+        /* eslint import/namespace: 0 */
+        const invalidLicenses = licenses.some(isLicenseInvalid);
+        if (invalidLicenses) {
+          dispatch(addGlobalErrorMessage(translate('licenses.there_are_invalid')));
+        }
+      })
+      .catch(handleError(dispatch));
+};
 
 export const setLicense = (key, value) => dispatch => {
   const request = value ? licenses.setLicense(key, value) : licenses.resetLicense(key);
 
   return request
       .then(() => {
-        dispatch(fetchLicenses());
-        dispatch(addGlobalSuccessMessage(translate('licenses.success_message')));
+        licenses.getLicenses().then(licenses => {
+          dispatch(receiveLicenses(licenses));
+          if (isLicenseFromListInvalid(licenses, key)) {
+            dispatch(addGlobalErrorMessage(translate('licenses.error_message')));
+          } else {
+            dispatch(addGlobalSuccessMessage(translate('licenses.success_message')));
+          }
+        });
       })
-      .catch(e => {
-        parseError(e).then(message => dispatch(addGlobalErrorMessage(message)));
-        return Promise.reject();
-      });
+      .catch(handleError(dispatch));
 };
index d41ef6ed74fa18becb3deda04ec598b7570e179e..275b964654ab5967f4684cd06d8fbdb132d875ad 100644 (file)
@@ -2077,10 +2077,12 @@ licenses.list.organization=Organization
 licenses.list.expiration=Expiration
 licenses.list.type=Type
 licenses.list.server=Server
-licenses.change_license_for_x=Change License for {0}
+licenses.update_license_for_x=Update License for {0}
 licenses.license_input_label=Insert the license text below:
 licenses.license_input_note=Keep empty if you want to unset this license.
 licenses.success_message=New license has been set.
+licenses.error_message=The license you have just set is invalid.
+licenses.there_are_invalid=There are licenses that are not valid. Please check details below.
 
 
 #------------------------------------------------------------------------------