import * as React from 'react';
import { getValues } from '../../api/settings';
import { Alert } from '../../components/ui/Alert';
+import { Feature } from '../../types/features';
import { GlobalSettingKeys, SettingValue } from '../../types/settings';
+import withAvailableFeatures, {
+ WithAvailableFeaturesProps
+} from './available-features/withAvailableFeatures';
import './SystemAnnouncement.css';
interface State {
message: string;
}
-export default class SystemAnnouncement extends React.PureComponent<{}, State> {
+export class SystemAnnouncement extends React.PureComponent<WithAvailableFeaturesProps, State> {
state: State = { displayMessage: false, message: '' };
componentDidMount() {
- this.getSettings();
- document.addEventListener('visibilitychange', this.handleVisibilityChange);
+ if (this.props.hasFeature(Feature.Announcement)) {
+ this.getSettings();
+ document.addEventListener('visibilitychange', this.handleVisibilityChange);
+ }
}
componentWillUnmount() {
- document.removeEventListener('visibilitychange', this.handleVisibilityChange);
+ if (this.props.hasFeature(Feature.Announcement)) {
+ document.removeEventListener('visibilitychange', this.handleVisibilityChange);
+ }
}
getSettings = async () => {
const values: SettingValue[] = await getValues({
- keys: [GlobalSettingKeys.DisplaySystemMessage, GlobalSettingKeys.SystemMessage]
+ keys: [GlobalSettingKeys.DisplayAnnouncementMessage, GlobalSettingKeys.AnnouncementMessage]
});
const settings = keyBy(values, 'key');
this.setState({
- displayMessage: settings[GlobalSettingKeys.DisplaySystemMessage].value === 'true',
+ displayMessage: settings[GlobalSettingKeys.DisplayAnnouncementMessage].value === 'true',
message:
- (settings[GlobalSettingKeys.SystemMessage] &&
- settings[GlobalSettingKeys.SystemMessage].value) ||
+ (settings[GlobalSettingKeys.AnnouncementMessage] &&
+ settings[GlobalSettingKeys.AnnouncementMessage].value) ||
''
});
};
);
}
}
+
+export default withAvailableFeatures(SystemAnnouncement);
import * as React from 'react';
import { getValues } from '../../../api/settings';
import { renderComponent } from '../../../helpers/testReactTestingUtils';
+import { Feature } from '../../../types/features';
+import { AvailableFeaturesContext } from '../available-features/AvailableFeaturesContext';
import SystemAnnouncement from '../SystemAnnouncement';
jest.mock('../../../api/settings', () => ({
(getValues as jest.Mock)
.mockResolvedValueOnce([
{
- key: 'sonar.systemAnnouncement.displayMessage',
+ key: 'sonar.announcement.displayMessage',
value: 'false',
inherited: true
}
])
.mockResolvedValueOnce([
{
- key: 'sonar.systemAnnouncement.displayMessage',
+ key: 'sonar.announcement.displayMessage',
value: 'false',
inherited: true
}
])
.mockResolvedValueOnce([
{
- key: 'sonar.systemAnnouncement.displayMessage',
+ key: 'sonar.announcement.displayMessage',
value: 'true'
}
])
.mockResolvedValueOnce([
{
- key: 'sonar.systemAnnouncement.displayMessage',
+ key: 'sonar.announcement.displayMessage',
value: 'true'
},
{
- key: 'sonar.systemAnnouncement.message',
+ key: 'sonar.announcement.message',
value: ''
}
])
.mockResolvedValueOnce([
{
- key: 'sonar.systemAnnouncement.displayMessage',
+ key: 'sonar.announcement.displayMessage',
value: 'true'
},
{
- key: 'sonar.systemAnnouncement.message',
+ key: 'sonar.announcement.message',
value: 'Foo'
}
]);
});
function renderSystemAnnouncement() {
- return renderComponent(<SystemAnnouncement />);
+ return renderComponent(
+ <AvailableFeaturesContext.Provider value={[Feature.Announcement]}>
+ <SystemAnnouncement />
+ </AvailableFeaturesContext.Provider>
+ );
}
MonoRepositoryPullRequestDecoration = 'monorepo',
RegulatoryReport = 'regulatory-reports',
ProjectImport = 'project-import',
- MultipleAlm = 'multiple-alm'
+ MultipleAlm = 'multiple-alm',
+ Announcement = 'announcement'
}
RatingGrid = 'sonar.technicalDebt.ratingGrid',
DeveloperAggregatedInfoDisabled = 'sonar.developerAggregatedInfo.disabled',
UpdatecenterActivated = 'sonar.updatecenter.activate',
- DisplaySystemMessage = 'sonar.systemAnnouncement.displayMessage',
- SystemMessage = 'sonar.systemAnnouncement.message'
+ DisplayAnnouncementMessage = 'sonar.announcement.displayMessage',
+ AnnouncementMessage = 'sonar.announcement.message'
}
export type SettingDefinitionAndValue = {
public static final String DISABLE_NOTIFICATION_ON_BUILT_IN_QPROFILES = "sonar.builtInQualityProfiles.disableNotificationOnUpdate";
- public static final String SUB_SYSTEM_ANNOUNCEMENT = "announcement";
- public static final String SYSTEM_ANNOUNCEMENT_MESSAGE = "sonar.systemAnnouncement.message";
- public static final String SYSTEM_ANNOUNCEMENT_DISPLAY_MESSAGE = "sonar.systemAnnouncement.displayMessage";
-
public static final String PLUGINS_RISK_CONSENT = "sonar.plugins.risk.consent";
private CorePropertyDefinitions() {
.defaultValue(String.valueOf(false))
.hidden()
.build(),
- PropertyDefinition.builder(SYSTEM_ANNOUNCEMENT_MESSAGE)
- .name("System announcement message")
- .description("If \"Display system announcement message\" is set to True, this message will be displayed in a warning banner to all SonarQube users."
- +" If this field is empty, no message will be displayed, even if \"Display system announcement message\" is set to True.")
- .category(CoreProperties.CATEGORY_GENERAL)
- .subCategory(SUB_SYSTEM_ANNOUNCEMENT)
- .type(TEXT)
- .build(),
- PropertyDefinition.builder(SYSTEM_ANNOUNCEMENT_DISPLAY_MESSAGE)
- .name("Display system announcement message")
- .description("If set to True, the \"System announcement message\" will be displayed in a warning banner to all SonarQube users.")
- .defaultValue(Boolean.toString(false))
- .subCategory(SUB_SYSTEM_ANNOUNCEMENT)
- .category(CoreProperties.CATEGORY_GENERAL)
- .type(BOOLEAN)
- .build(),
PropertyDefinition.builder(DISABLE_NOTIFICATION_ON_BUILT_IN_QPROFILES)
.name("Avoid quality profiles notification")
.description("Avoid sending email notification on each update of built-in quality profiles to quality profile administrators.")
@Test
public void all() {
List<PropertyDefinition> defs = CorePropertyDefinitions.all();
- assertThat(defs).hasSize(54);
+ assertThat(defs).hasSize(52);
}
@Test