summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Draebing <thomas.draebing@sap.com>2020-01-27 11:20:28 +0100
committerThomas Draebing <thomas.draebing@sap.com>2020-01-31 10:14:23 +0100
commitc77032cc74b2d766cb8eb69b65a205dd0d8a5887 (patch)
tree4cfceafd7b8e27873a5ae7525661f7ad7a5e8a0b
parent720d0af16dfc334cd5d2a660a4ab2f728888c3b2 (diff)
Add MessageOfTheDay-entries to ServerInfo
The message of the day functionality was lost in the new PolyGerrit-UI, since the original implementation relied on the server side addition of the messages to the host page. This change adds the messages registered to the MessageOfTheDay- extension point to the ServerInfo, which can be fetched via Rest API. This allows accessing this information from the new UI. The UI elements that consume this information will be added in a followup change. Change-Id: I1deff5afbd812a1efaf6ad11e871544b36a5d88d
-rw-r--r--Documentation/rest-api-config.txt19
-rw-r--r--java/com/google/gerrit/extensions/common/MessageOfTheDayInfo.java27
-rw-r--r--java/com/google/gerrit/extensions/common/ServerInfo.java2
-rw-r--r--java/com/google/gerrit/server/restapi/config/GetServerInfo.java24
4 files changed, 71 insertions, 1 deletions
diff --git a/Documentation/rest-api-config.txt b/Documentation/rest-api-config.txt
index 7be8c324b4..0e4cac28f1 100644
--- a/Documentation/rest-api-config.txt
+++ b/Documentation/rest-api-config.txt
@@ -1905,6 +1905,21 @@ The maximal memory size. The value is returned with a unit abbreviation
The number of open files.
|============================
+[[message-of-the-day-info]]
+=== MessageOfTheDayInfo
+The `MessageOfTheDayInfo` entity contains information about a message
+that was registered with the `MessageOfTheDay`-extension by plugins.
+
+[options="header",cols="1,^1,5"]
+|===========================
+|Field Name ||Description
+|`id` ||ID of the message.
+|`redisplay` ||
+Date and Time, when the message should be displayed again after it was dismissed
+by the user.
+|`html` ||Message in HTML-format.
+|===========================
+
[[plugin-config-info]]
=== PluginConfigInfo
The `PluginConfigInfo` entity contains information about Gerrit
@@ -1958,6 +1973,10 @@ information about Gerrit
Information about the configuration from the
link:config-gerrit.html#gerrit[gerrit] section as link:#gerrit-info[
GerritInfo] entity.
+|`messages` ||
+List of messages registered with the `MessageOfTheDay`-
+extension containing link:#message-of-the-day-info[
+MessageOfTheDayInfo] entities.
|`note_db_enabled` |not set if `false`|
Whether the NoteDb storage backend is fully enabled.
|`plugin` ||
diff --git a/java/com/google/gerrit/extensions/common/MessageOfTheDayInfo.java b/java/com/google/gerrit/extensions/common/MessageOfTheDayInfo.java
new file mode 100644
index 0000000000..f752f86a64
--- /dev/null
+++ b/java/com/google/gerrit/extensions/common/MessageOfTheDayInfo.java
@@ -0,0 +1,27 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.extensions.common;
+
+import java.util.Date;
+
+/** REST API representation of a "message of the day". */
+public class MessageOfTheDayInfo {
+ /** The ID of the message. */
+ public String id;
+ /** The date and time the message will be displayed again after being dismissed by the user. */
+ public Date redisplay;
+ /** The message in HTML-format. */
+ public String html;
+}
diff --git a/java/com/google/gerrit/extensions/common/ServerInfo.java b/java/com/google/gerrit/extensions/common/ServerInfo.java
index 8904f0a03b..27cf529a24 100644
--- a/java/com/google/gerrit/extensions/common/ServerInfo.java
+++ b/java/com/google/gerrit/extensions/common/ServerInfo.java
@@ -14,6 +14,7 @@
package com.google.gerrit.extensions.common;
+import java.util.List;
import java.util.Map;
public class ServerInfo {
@@ -22,6 +23,7 @@ public class ServerInfo {
public ChangeConfigInfo change;
public DownloadInfo download;
public GerritInfo gerrit;
+ public List<MessageOfTheDayInfo> messages;
public Boolean noteDbEnabled;
public PluginConfigInfo plugin;
public SshdInfo sshd;
diff --git a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
index eca26c34a5..04f4f8a824 100644
--- a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
+++ b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
@@ -27,6 +27,7 @@ import com.google.gerrit.extensions.common.ChangeConfigInfo;
import com.google.gerrit.extensions.common.DownloadInfo;
import com.google.gerrit.extensions.common.DownloadSchemeInfo;
import com.google.gerrit.extensions.common.GerritInfo;
+import com.google.gerrit.extensions.common.MessageOfTheDayInfo;
import com.google.gerrit.extensions.common.PluginConfigInfo;
import com.google.gerrit.extensions.common.ReceiveInfo;
import com.google.gerrit.extensions.common.ServerInfo;
@@ -36,7 +37,9 @@ import com.google.gerrit.extensions.common.UserConfigInfo;
import com.google.gerrit.extensions.config.CloneCommand;
import com.google.gerrit.extensions.config.DownloadCommand;
import com.google.gerrit.extensions.config.DownloadScheme;
+import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.restapi.RestReadView;
+import com.google.gerrit.extensions.systemstatus.MessageOfTheDay;
import com.google.gerrit.extensions.webui.WebUiPlugin;
import com.google.gerrit.server.EnableSignedPush;
import com.google.gerrit.server.account.AccountVisibilityProvider;
@@ -69,6 +72,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@@ -100,6 +104,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
private final GerritOptions gerritOptions;
private final ChangeIndexCollection indexes;
private final SitePaths sitePaths;
+ private final DynamicSet<MessageOfTheDay> messages;
@Inject
public GetServerInfo(
@@ -123,7 +128,8 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
AgreementJson agreementJson,
GerritOptions gerritOptions,
ChangeIndexCollection indexes,
- SitePaths sitePaths) {
+ SitePaths sitePaths,
+ DynamicSet<MessageOfTheDay> motd) {
this.config = config;
this.accountVisibilityProvider = accountVisibilityProvider;
this.authConfig = authConfig;
@@ -145,6 +151,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
this.gerritOptions = gerritOptions;
this.indexes = indexes;
this.sitePaths = sitePaths;
+ this.messages = motd;
}
@Override
@@ -155,6 +162,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
info.change = getChangeInfo();
info.download = getDownloadInfo();
info.gerrit = getGerritInfo();
+ info.messages = getMessages();
info.noteDbEnabled = toBoolean(isNoteDbEnabled());
info.plugin = getPluginInfo();
info.defaultTheme = getDefaultTheme();
@@ -325,6 +333,20 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
return CharMatcher.is('/').trimTrailingFrom(docUrl) + '/';
}
+ private List<MessageOfTheDayInfo> getMessages() {
+ return this.messages.stream()
+ .filter(motd -> !Strings.isNullOrEmpty(motd.getHtmlMessage()))
+ .map(
+ motd -> {
+ MessageOfTheDayInfo m = new MessageOfTheDayInfo();
+ m.id = motd.getMessageId();
+ m.redisplay = motd.getRedisplay();
+ m.html = motd.getHtmlMessage();
+ return m;
+ })
+ .collect(toList());
+ }
+
private boolean isNoteDbEnabled() {
return migration.readChanges();
}