]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17096 Improve announcement order and description
authorMathieu Suen <mathieu.suen@sonarsource.com>
Fri, 23 Sep 2022 13:01:32 +0000 (15:01 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 28 Sep 2022 20:04:08 +0000 (20:04 +0000)
server/sonar-web/src/main/js/app/components/SystemAnnouncement.tsx
server/sonar-web/src/main/js/app/components/__tests__/SystemAnnouncement-test.tsx
server/sonar-web/src/main/js/types/features.ts
server/sonar-web/src/main/js/types/settings.ts
sonar-core/src/main/java/org/sonar/core/config/CorePropertyDefinitions.java
sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java

index dd0abf833ea68d8b21bfb90366e5127bbc337353..89e23b08ce6bbd539816b0e3fd083f714646cd78 100644 (file)
@@ -22,7 +22,11 @@ import { isEmpty, keyBy } from 'lodash';
 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 {
@@ -30,29 +34,33 @@ 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) ||
         ''
     });
   };
@@ -82,3 +90,5 @@ export default class SystemAnnouncement extends React.PureComponent<{}, State> {
     );
   }
 }
+
+export default withAvailableFeatures(SystemAnnouncement);
index cc837ef72d01f3ae04b68973dd4564492b5285bc..1b44b1a34bb8b2d1867251fe3b7e838e9a35452a 100644 (file)
@@ -21,6 +21,8 @@ import { fireEvent, screen } from '@testing-library/dom';
 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', () => ({
@@ -31,41 +33,41 @@ it('should display system announcement', async () => {
   (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'
       }
     ]);
@@ -85,5 +87,9 @@ it('should display system announcement', async () => {
 });
 
 function renderSystemAnnouncement() {
-  return renderComponent(<SystemAnnouncement />);
+  return renderComponent(
+    <AvailableFeaturesContext.Provider value={[Feature.Announcement]}>
+      <SystemAnnouncement />
+    </AvailableFeaturesContext.Provider>
+  );
 }
index 768e51e41ca62f68bd32fca6b08f4e7158330e7b..10efdac37de27bac248af102f1dace088fdd46f4 100644 (file)
@@ -22,5 +22,6 @@ export enum Feature {
   MonoRepositoryPullRequestDecoration = 'monorepo',
   RegulatoryReport = 'regulatory-reports',
   ProjectImport = 'project-import',
-  MultipleAlm = 'multiple-alm'
+  MultipleAlm = 'multiple-alm',
+  Announcement = 'announcement'
 }
index 079c23e8b6cc619b3e787b85e18ae74532a3644b..9e9a3946ef6d921da0ad5a8a4f93a14afe684b1b 100644 (file)
@@ -37,8 +37,8 @@ export enum GlobalSettingKeys {
   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 = {
index 397314d3c17c36c60c13b93740796c1d16ad1720..5756ba63d6da26a8eb9787c908e820962e41db45 100644 (file)
@@ -42,10 +42,6 @@ public class CorePropertyDefinitions {
 
   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() {
@@ -92,22 +88,6 @@ public class 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.")
index ed3f949f5632be04c3b3c6fe39bd1d79e884ca96..00d1068c7a325c60c8ac6389f83ba7b3aa7d1680 100644 (file)
@@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest {
   @Test
   public void all() {
     List<PropertyDefinition> defs = CorePropertyDefinitions.all();
-    assertThat(defs).hasSize(54);
+    assertThat(defs).hasSize(52);
   }
 
   @Test