To ensure users are presented with a Dialog box to acknowledge it before logging into Jira, we have implemented using Script Runner. We are aware of the KB article Customize Jira login page | Jira | Atlassian Documentation and Atlassian has recorded a Suggestion for their development team https://jira.atlassian.com/browse/JSDSERVER-14682
We wanted more of a Dialog box, where users explicitly acknowledges the message and once acknowledged, it should never show-up.
Script Runner REST End point
import javax.servlet.http.HttpServletRequest
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import com.atlassian.sal.api.user.UserManager
import com.atlassian.jira.user.preferences.UserPreferencesManager
import com.atlassian.core.user.preferences.Preferences
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
setUserProperties(
httpMethod: "GET"
) { queryParams, body, HttpServletRequest request ->
def userManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserManager)
def userProfile = userManager.getRemoteUser(request)
if (userProfile) {
log.warn(userProfile.username + " set properties")
def user = ComponentAccessor.userManager.getUserByName(userProfile.username)
String newInfoTag = "Jira Outage Message1" //Setting this value to match with that of Fragment Panel newInfoTag. If this does not match, then the dialog box pops-up for every Jira call
def userPreferencesManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserPreferencesManager.class);
userPreferencesManager.getExtendedPreferences(user).setString("Dialog Box", newInfoTag) //Setting the value of the Key to newInfoTag so that, the message box only shows once per user.
}
return Response.ok(new JsonBuilder().toString()).build()
}
Script Runner Fragment Web Panel
Condition
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.module.propertyset.PropertySet
import com.atlassian.jira.user.preferences.UserPreferencesManager
import com.atlassian.core.user.preferences.Preferences
String newInfoTag = "Jira Outage Message1" //Setting the initial value
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def userPreferencesManager = ComponentAccessor.getOSGiComponentInstanceOfType(UserPreferencesManager.class);
def userPreference = userPreferencesManager.getExtendedPreferences(user)?.getString("Dialog Box"); // Setting the Key value of Dialog Box to Null
if (userPreference != newInfoTag) {
// this will be True for the first time, as newInfoTag will not be equal to UserPreference for the first time. Subsequently in the provider/class script, the REST End point makes it equal and will return false on subsequent Jira calls
return true
}
return false
Provider class/script
writer.write("""
<body onload="showWelcome()">
<section id="demo-dialog" class="aui-dialog2 aui-dialog2-small aui-layer" data-aui-modal="true" role="dialog" aria-hidden="true">
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-main">Enterprise Jira Outage Notification</h2>
</header>
<div class="aui-dialog2-content">
<p>
<div style="background-color: linen; border: 3px solid darkred; margin: 4px; padding: 2px; text-align: left;">
Enterprise Jira will be down on <strong>10/12/2023 starting at 12:00 p.m. (ET) until 10/16/2023 at approximately 12:00p.m. (ET) </strong>
<br>
<br>
Please do not login during these times. By clicking the Okay button, you acknowledge that you have read this message.
<br>
<br>
For information regarding the outage and offline activity guidance, please click
<a style="color:blue;"href="https://google.com>here</a>
<br>
</p>
</div>
<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<button id="dialog-submit-button" class="aui-button aui-button-primary">Okay</button>
</div>
</footer>
</section>
</div>
<script>
var ci = document.getElementById("dialog-submit-button");
if (ci.addEventListener) ci.addEventListener("click", dialogClose, true);
function showWelcome() {
AJS.dialog2("#demo-dialog").show();
}
function dialogClose() {
var url = "/rest/scriptrunner/latest/custom/setUserProperties";
fetch(url)
AJS.dialog2("#demo-dialog").hide();
}
</script>
""")
The problem we are facing is, every time there is a new message that needs to be acknowledged (for example new outage), we have to change the Key so that the new message is acknowledged. Are there any better solutions available? or any fine-tuning of current solution?