Skip to content

Commit

Permalink
Fix notification settings creation
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Lamparelli <[email protected]>
  • Loading branch information
lampajr committed Feb 25, 2025
1 parent 216c835 commit d437b36
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
@Startup
public class NotificationServiceImpl implements NotificationService {
private static final Logger log = Logger.getLogger(NotificationServiceImpl.class);
//@formatter:off
private static final String GET_NOTIFICATIONS = """
//@formatter:off
private static final String GET_NOTIFICATIONS = """
WITH ens AS (
SELECT ns.*, watch_id FROM notificationsettings ns
JOIN watch_users wu ON NOT ns.isteam AND ns.name = wu.users
Expand All @@ -60,7 +60,7 @@ WITH ens AS (
WHERE testid = ?
AND name NOT IN (SELECT optout FROM watch_optout WHERE ens.watch_id = watch_optout.watch_id)
""";
//@formatter:on
//@formatter:on
public final Map<String, NotificationPlugin> plugins = new HashMap<>();

@Inject
Expand Down Expand Up @@ -147,6 +147,7 @@ public List<NotificationSettings> settings(String name, boolean team) {
@RolesAllowed({ Roles.VIEWER, Roles.TESTER, Roles.ADMIN })
@Transactional
@Override
// remove and re-create the settings for the user
public void updateSettings(String name, boolean team, NotificationSettings[] settings) {
NotificationSettingsDAO.delete("name = ?1 AND isTeam = ?2", name, team);
Arrays.stream(settings).map(NotificationSettingsMapper::to).forEach(ns -> {
Expand All @@ -158,9 +159,11 @@ public void updateSettings(String name, boolean team, NotificationSettings[] set
}
throw ServiceException.badRequest("Invalid method " + ns.method);
}
// reset the id
ns.id = null;
ns.name = name;
ns.isTeam = team;
em.merge(ns);
ns.persist();
});
}

Expand Down

0 comments on commit d437b36

Please sign in to comment.