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>
);
}
}
</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">
* 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 = {
return null;
}
- const isInvalid = !!license.invalidProduct || !!license.invalidExpiration || !!license.invalidServerId;
+ const isInvalid = isLicenseInvalid(license);
if (isInvalid) {
return <i className="icon-alert-error"/>;
}
<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>
--- /dev/null
+/*
+ * 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;
+};
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';
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));
};
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.
#------------------------------------------------------------------------------