Skip to content

Commit

Permalink
Add function to display system wide warning message to users
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Oct 12, 2023
1 parent b5d56b9 commit 945545e
Show file tree
Hide file tree
Showing 14 changed files with 470 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--
-- (c) Kitodo. Key to digital objects e. V. <[email protected]>
--
-- This file is part of the Kitodo project.
--
-- It is licensed under GNU General Public License version 3 or later.
--
-- For the full copyright and license information, please read the
-- GPL3-License.txt file that was distributed with this source code.
--

-- Insert authority to broadcast messages

INSERT IGNORE INTO authority (title) VALUES ('broadcastMessage_globalAssignable');

INSERT IGNORE INTO role_x_authority (role_id, authority_id)
SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'broadcastMessage_globalAssignable';
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.production.channel;

import java.util.HashMap;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;
import javax.faces.push.Push;
import javax.faces.push.PushContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.kitodo.data.database.beans.User;
import org.kitodo.production.security.SecuritySession;
import org.kitodo.production.services.ServiceManager;

@Named("SystemMessageChannel")
@ApplicationScoped
public class SystemMessageChannel {

@Inject
@Push
PushContext messageChannel;

private static final String SHOW_MESSAGE = "showMessage";
private static final String UPDATE_USER_TABLE = "updateUserTable";

private String userName = "";
private String message = "";
private HashMap<String, Boolean> currentUsers;

private String staticSystemMessage = "";
private Boolean showSystemMessage = false;

/**
* Inform connected websocket clients to show message.
*/
public void showMessage() {
messageChannel.send(SHOW_MESSAGE);
}

/**
* Inform connected websocket clients to update user table.
*/
public void updateUserTable() {
messageChannel.send(UPDATE_USER_TABLE);
}

/**
* Set message String.
*
* @param messageText message String
*/
public void setMessage(String messageText) {
this.message = messageText;
}

/**
* Get message String.
*
* @return message String
*/
public String getMessage() {
return this.message;
}

/**
* Acknowledge system message.
*
* @param user User that acknowledges system message
*/
public void acknowledge(User user) {
this.currentUsers.put(user.getLogin(), true);
this.updateUserTable();
}

/**
* Load list of current users.
*/
public void loadCurrentUsers() {
this.currentUsers = new HashMap<>();
for (SecuritySession session : ServiceManager.getSessionService().getActiveSessions()) {
this.currentUsers.put(session.getUserName(), null);
}
}

/**
* Reset status of current users.
*/
public void resetCurrentUsersStatus() {
this.currentUsers.replaceAll((n, v) -> false);
}

/**
* Get list of current users.
*
* @return list of current users
*/
public Set<String> getCurrentUsers() {
return this.currentUsers.keySet();
}

/**
* Return whether User with user name 'userName' acknowledged system message or not.
*
* @param userName user name of user to check
* @return whether user acknowledged system message or not
*/
public Boolean acknowledged(String userName) {
return this.currentUsers.get(userName);
}

/**
* Get user name of broadcaster.
*
* @return user name
*/
public String getUserName() {
return this.userName;
}

/**
* Set user name of broadcaster.
*
* @param name user name
*/
public void setUserName(String name) {
this.userName = name;
}

/**
* Send message String to connected clients.
*/
public void sendMessage() {
this.resetCurrentUsersStatus();
this.showMessage();
}

/**
* Get staticSystemMessage.
*
* @return value of staticSystemMessage
*/
public String getStaticSystemMessage() {
return staticSystemMessage;
}

/**
* Set staticSystemMessage.
*
* @param staticSystemMessage as java.lang.String
*/
public void setStaticSystemMessage(String staticSystemMessage) {
this.staticSystemMessage = staticSystemMessage;
}

/**
* Get showSystemMessage.
*
* @return value of showSystemMessage
*/
public boolean isShowSystemMessage() {
return showSystemMessage;
}

/**
* Set showSystemMessage.
*
* @param showSystemMessage as boolean
*/
public void setShowSystemMessage(boolean showSystemMessage) {
this.showSystemMessage = showSystemMessage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ public boolean hasAuthorityToViewSystemPage() {
return securityAccessService.hasAuthorityToViewIndexPage()
|| securityAccessService.hasAuthorityToViewTaskManagerPage()
|| securityAccessService.hasAuthorityToViewTermsPage()
|| securityAccessService.hasAuthorityToViewMigrationPage();
|| securityAccessService.hasAuthorityToViewMigrationPage()
|| securityAccessService.hasAuthorityToViewMessagePage();
}

/**
Expand Down Expand Up @@ -753,6 +754,15 @@ public boolean hasAuthorityToViewMigrationPage() {
return securityAccessService.hasAuthorityToViewMigrationPage();
}

/**
* Check if current user has authority to view message tab of system page.
*
* @return true if user has authority to view message tab of system page
*/
public boolean hasAuthorityToViewMessagePage() {
return securityAccessService.hasAuthorityToViewMessagePage();
}

/**
* Check if current user has authority to view task page. It returns true if
* user has "viewAllTasks" authority for client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,15 @@ public boolean hasAuthorityToViewMigrationPage() {
return hasAnyAuthorityGlobal("viewMigration");
}

/**
* Check if the current user has the authority to view the message tab of the system page.
*
* @return true if the current user has the authority to view the message tab of the system page
*/
public boolean hasAuthorityToViewMessagePage() {
return hasAnyAuthorityGlobal("broadcastMessage");
}


private boolean hasAuthorityForTask(int taskId) throws DataException {
Integer processId = ServiceManager.getTaskService().findById(taskId).getProcess().getId();
Expand Down
6 changes: 6 additions & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ emptyTask=Beispiel f\u00FCr eine lang laufende Aufgabe
mapping=ElasticSearch Mapping
NOT=Enth\u00E4lt nicht
NoCataloguePluginForCatalogue=Keines der verf\u00fcgbaren OPAC-Plugins unterst\u00fctzt diesen Katalog.
acknowledged=Best\u00E4tigt
active=Aktiv
ACTIVE=Aktiv
activeUsers=Aktive Benutzer
Expand Down Expand Up @@ -683,6 +684,7 @@ locked=Gesperrt
location=Standort
loggedIn=Angemeldet
logical=Logische
loggedInUsers=Angemeldete Benutzer
login=Login
loginNoteText=Kitodo.Production ist das Workflowmanagementmodul der Kitodo-Suite. Es unterst\u00FCtzt den Digitalisierungsprozess verschiedener Materialarten wie z.B. Drucken, Periodika, Handschriften, Noten und Musikalien, Einblattmedien und Dokumentennachl\u00E4ssen.
logout=Logout
Expand Down Expand Up @@ -997,6 +999,7 @@ selectProject=Bitte Projekt ausw\u00E4hlen
selectTemplate=Bitte Produktionsvorlage ausw\u00E4hlen
selectWorkflow=Bitte Workflow ausw\u00E4hlen
selfAssignTask=Die Bearbeitung dieser Aufgabe \u00FCbernehmen
send=Absenden
sendSolutionMessageNextTask=Meldung \u00FCber Probleml\u00F6sung an nachfolgende Station senden
sendSolutionMessage=Meldung \u00FCber Probleml\u00F6sung senden
sendSolutionMessageForAll=Meldung \u00FCber Probleml\u00F6sung f\u00FCr alle Schritte senden
Expand Down Expand Up @@ -1074,6 +1077,9 @@ systemErrorInformAdminMessage=Bitte informieren Sie einen Administrator!
systemErrorMessage=Es ist ein Fehler im System aufgetreten.
systemMaintenanceHeader=Systemwartung
systemMaintenanceMessage=Das System wird derzeit gewartet.
systemMessage=Systemnachricht
systemMessage.broadcast=Broadcast
systemMessage.static=Statische Systemnachricht
table=Tabelle
tableSize=Tabellengr\u00F6\u00DFe
task=Aufgabe
Expand Down
6 changes: 6 additions & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ emptyTask=Example of a long-running task
mapping=ElasticSearch mapping
NOT=does not contain
NoCataloguePluginForCatalogue=None of the OPAC plugins available is capable of reading this catalogue.
acknowledged=Acknowledged
active=Active
ACTIVE=Active
activeUsers=Current users
Expand Down Expand Up @@ -684,6 +685,7 @@ locked=Locked
location=Location
loggedIn=Logged in
logical=Logical
loggedInUsers=Logged in users
login=Login
loginNoteText=Kitodo.Production is the workflow management module in the Kitodo suite. It supports the process of digitising a range of material types, such as books, periodicals, manuscripts, printed music, single-sheet media, and document collections.
logout=Log out
Expand Down Expand Up @@ -998,6 +1000,7 @@ selectProject=Please select a project
selectTemplate=Please select a template
selectWorkflow=Please select a workflow
selfAssignTask=Accept editing of this task
send=Send
sendSolutionMessageNextTask=Send message about problem solution to following task
sendSolutionMessage=Send message about problem solution
sendSolutionMessageForAll=send troubleshooting message to all steps
Expand Down Expand Up @@ -1075,6 +1078,9 @@ systemErrorInformAdminMessage=Please inform an administrator!
systemErrorMessage=A system error occurred.
systemMaintenanceHeader=System maintenance
systemMaintenanceMessage=The system is currently under maintenance.
systemMessage=System message
systemMessage.broadcast=Broadcast
systemMessage.static=Static system message
table=Table
tableSize=Table size
task=Task
Expand Down
53 changes: 53 additions & 0 deletions Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css
Original file line number Diff line number Diff line change
Expand Up @@ -3492,6 +3492,59 @@ kbd {
padding: 0 var(--default-half-size);
}

/*----------------------------------------------------------------------
System page
----------------------------------------------------------------------*/

#systemTabView .messageWrapper {
border: 1px solid var(--carbon-blue);
border-radius: var(--default-border-radius);
margin: auto;
padding: var(--default-double-size);
width: 50%;
}

#systemTabView\:systemWarningForm\:warningText {
height: 100px;
}

#systemTabView\:systemWarningForm\:sendWarningButton {
margin-top: var(--default-half-size);
}

#acknowledgeSystemWarningForm\:okButton {
margin-right: var(--default-double-size);
}

#acknowledgeSystemWarningForm\:systemMessageLabel {
font-style: italic;
font-weight: bold;
}

#acknowledgeSystemWarningForm\:messageWrapper {
padding: 0 var(--default-double-size);
}

#systemMessagePanel {
background-color: white;
border: 3px solid red;
color: red;
height: 70px;
left: calc(50% - 320px);
opacity: 80%;
padding: var(--default-full-size);
pointer-events: none;
position: absolute;
text-align: center;
top: 10px;
width: 640px;
z-index: 9999;
}

#systemTabView\:messagePanel.ui-accordion .ui-accordion-content {
padding: 0;
}

/*----------------------------------------------------------------------
Workflow Editor
----------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,15 @@ Popup dialogs
padding: 0;
}

/* Helper classes for colors */
.red {
color: var(--focused-orange);
}

.green {
color: var(--focused-green);
}

/* Messages */
.ui-messages-error.ui-corner-all,
.ui-messages-warn.ui-corner-all,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
$(document).ready(function() {
$('#loadingScreen').hide();
});

Loading

0 comments on commit 945545e

Please sign in to comment.