diff --git a/README.md b/README.md index d879fce..12550f9 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ One or more system messages can be shown between the header and the breadcrumb b things related to the instance, e.g. a planned update of Jenkins, a downtime due to hardware replacement or an ongoing incident. You can include html (sanitized with owasp) in the message to apply some simple styling or include a link with more details.
-System messages can have an expiration time to automatically remove them. They can be dismissed on a per-user basis. +System messages can have an expiration time to automatically remove them. They can be dismissed on a per-user basis (can be disabled). ![System Message](/docs/pics/system-message.png)
@@ -61,12 +61,13 @@ To be able to later delete a system message, pass an id parameter in the call. I Parameters: -| Parameter |required| description | -|------------|--------|--------------------------------------------------------------| -| message | true | The message, can contain html | -| level | true | Message level, one of `info`, `success`, `warning`, `danger` | -| expireDate | false | Expiration date for the message, format: `yyyy-M-d H:m` | -| uid | false | An optional unique id | +| Parameter | required | description | +|--------------|----------|--------------------------------------------------------------| +| message | true | The message, can contain html | +| level | true | Message level, one of `info`, `success`, `warning`, `danger` | +| expireDate | false | Expiration date for the message, format: `yyyy-M-d H:m` | +| uid | false | An optional unique id | +| dismissible | false | Message can be dismissed by users, defaults to `true` | To delete a system message do a post request to `/customizable-header/deleteSystemMessage?id=` diff --git a/src/main/java/io/jenkins/plugins/customizable_header/HeaderRootAction.java b/src/main/java/io/jenkins/plugins/customizable_header/HeaderRootAction.java index cf0ad2b..d7fc4e0 100644 --- a/src/main/java/io/jenkins/plugins/customizable_header/HeaderRootAction.java +++ b/src/main/java/io/jenkins/plugins/customizable_header/HeaderRootAction.java @@ -65,7 +65,7 @@ public boolean hasLinks() { @POST public HttpResponse doAddSystemMessage(@QueryParameter(fixEmpty = true) String message, @QueryParameter(fixEmpty = true) String level, - @QueryParameter String expireDate, @QueryParameter(fixEmpty = true) String id) throws IOException { + @QueryParameter String expireDate, @QueryParameter(fixEmpty = true) String id, @QueryParameter(fixEmpty = true) Boolean dismissible) throws IOException { Jenkins.get().checkPermission(Jenkins.ADMINISTER); if (message == null || level == null) { throw HttpResponses.error(HttpServletResponse.SC_BAD_REQUEST, "Missing parameters: message and level are mandatory"); @@ -74,6 +74,7 @@ public HttpResponse doAddSystemMessage(@QueryParameter(fixEmpty = true) String m SystemMessage.SystemMessageColor lvl = SystemMessage.SystemMessageColor.valueOf(level); SystemMessage msg = new SystemMessage(message, lvl, id); msg.setExpireDate(expireDate); + msg.setDismissible(dismissible); CustomHeaderConfiguration config = CustomHeaderConfiguration.get(); config.addSystemMessage(msg); return HttpResponses.text(msg.getUid()); diff --git a/src/main/java/io/jenkins/plugins/customizable_header/SystemMessage.java b/src/main/java/io/jenkins/plugins/customizable_header/SystemMessage.java index 5c87e98..9553364 100644 --- a/src/main/java/io/jenkins/plugins/customizable_header/SystemMessage.java +++ b/src/main/java/io/jenkins/plugins/customizable_header/SystemMessage.java @@ -28,6 +28,8 @@ public class SystemMessage extends AbstractDescribableImpl { private LocalDateTime expireDate; private String uid; + private Boolean dismissible = true; + @DataBoundConstructor public SystemMessage(String message, SystemMessageColor level, String uid) { this.message = Util.fixEmptyAndTrim(message); @@ -38,6 +40,17 @@ public SystemMessage(String message, SystemMessageColor level, String uid) { this.uid = uid; } + public Boolean getDismissible() { + return dismissible; + } + + @DataBoundSetter + public void setDismissible(Boolean dismissible) { + if (dismissible != null) { + this.dismissible = dismissible; + } + } + @DataBoundSetter public void setExpireDate(String expireDate) { if (Util.fixEmptyAndTrim(expireDate) != null) { @@ -58,7 +71,7 @@ public String getExpireDate() { public boolean isDismissed() { User user = User.current(); - if (user != null) { + if (user != null && dismissible) { UserHeader userHeader = user.getProperty(UserHeader.class); if (userHeader != null) { return userHeader.getDismissedMessages().contains(uid); @@ -101,6 +114,9 @@ public void setColor(String color) { public Object readResolve() { setColor(color); color = null; + if (dismissible == null) { + dismissible = true; + } return this; } diff --git a/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/config.jelly b/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/config.jelly index 2d8e7a5..bc5f359 100644 --- a/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/config.jelly +++ b/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/config.jelly @@ -3,6 +3,9 @@ + + + ${it.toString()} diff --git a/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/help-dismissible.html b/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/help-dismissible.html new file mode 100644 index 0000000..912ead9 --- /dev/null +++ b/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/help-dismissible.html @@ -0,0 +1,3 @@ +
+ When not checked, users are not able to dismiss the message. +
\ No newline at end of file diff --git a/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/index.jelly b/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/index.jelly index a397817..9adba8c 100644 --- a/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/index.jelly +++ b/src/main/resources/io/jenkins/plugins/customizable_header/SystemMessage/index.jelly @@ -3,7 +3,7 @@
- + diff --git a/yarn.lock b/yarn.lock index 0ab93d5..58d19b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1823,7 +1823,7 @@ fs.realpath@^1.0.0: fsevents@~2.3.2: version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== gensync@^1.0.0-beta.2: