[New] Added enabled flag to notifications

This commit is contained in:
Robert von Burg 2024-04-23 08:19:52 +02:00
parent 1080096549
commit baa7a0af4e
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
4 changed files with 12 additions and 1 deletions

View File

@ -28,7 +28,8 @@ public class DefaultNotificationsPolicy extends NotificationsPolicy {
protected boolean isForUser(Resource notification) {
if (!isActive(notification))
return false;
return isForAll(notification) || isForRole(notification) || isForGroup(notification);
return isEnabled(notification) && (
isForAll(notification) || isForRole(notification) || isForGroup(notification));
}
protected boolean isActive(Resource notification) {
@ -38,6 +39,10 @@ public class DefaultNotificationsPolicy extends NotificationsPolicy {
.contains(ZonedDateTime.now());
}
protected boolean isEnabled(Resource notification) {
return notification.getBoolean(BAG_VISIBILITY, PARAM_ENABLED);
}
protected boolean isForAll(Resource notification) {
return notification.getBoolean(BAG_VISIBILITY, PARAM_FOR_ALL);
}

View File

@ -104,6 +104,7 @@ public class StrolchModelConstants {
public static final String PARAM_START_DATE = "startDate";
public static final String PARAM_MODE = "mode";
public static final String PARAM_GROUP = "group";
public static final String PARAM_ENABLED = "enabled";
public static final String PARAM_VISIBLE_FROM = "visibleFrom";
public static final String PARAM_VISIBLE_TO = "visibleTo";
public static final String PARAM_TITLE = "title";

View File

@ -58,6 +58,8 @@ public class CreateNotificationService extends AbstractService<JsonServiceArgume
JsonObject visibilityJ = jsonObject.get(BAG_VISIBILITY).getAsJsonObject();
ParameterBag visibility = notification.getParameterBag(BAG_VISIBILITY);
visibility.setBoolean(PARAM_ENABLED,
visibilityJ.has(PARAM_ENABLED) && visibilityJ.get(PARAM_ENABLED).getAsBoolean());
visibility.setBoolean(PARAM_FOR_ALL,
visibilityJ.has(PARAM_FOR_ALL) && visibilityJ.get(PARAM_FOR_ALL).getAsBoolean());
if (visibilityJ.has(PARAM_VISIBLE_FROM))
@ -111,6 +113,8 @@ public class CreateNotificationService extends AbstractService<JsonServiceArgume
.bag(BAG_VISIBILITY, TYPE_VISIBILITY)
.booleanB(PARAM_ENABLED).end()
.date(PARAM_VISIBLE_FROM).end()
.date(PARAM_VISIBLE_TO).end()

View File

@ -163,6 +163,7 @@ public class NotificationResource {
ISO8601.toString(notification.getDate(BAG_VISIBILITY, PARAM_VISIBLE_FROM)));
notificationJ.addProperty(PARAM_VISIBLE_TO,
ISO8601.toString(notification.getDate(BAG_VISIBILITY, PARAM_VISIBLE_TO)));
notificationJ.addProperty(PARAM_ENABLED, notification.getBoolean(BAG_VISIBILITY, PARAM_ENABLED));
return notificationJ;
};