Skip to content

Commit

Permalink
SAK-43953 PA System: Banner Dismissal Resets Upon Any Form of Update (#…
Browse files Browse the repository at this point in the history
…11977)

(cherry picked from commit 9ca81e5)
  • Loading branch information
kunaljaykam authored and ern committed Oct 31, 2023
1 parent 6e1403b commit 097e81f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface Banners extends Acknowledger {
/**
* Forget all acknowledgements for the current user.
*/
public void clearTemporaryDismissedForUser(String userId);
public void clearAcknowledgementForUser(String userId);

public Optional<Banner> getForId(String uuid);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ public Void call(DBConnection db) throws SQLException {
}

/**
* Forget all temporary acknowledgements created by a user.
* Forget all acknowledgements created by a user.
*/
public void clearTemporaryDismissedForUser(String userId) {
public void clearAcknowledgementForUser(String userId) {
DB.transaction
("Delete all temporarily dismissed banners for a user",
("Delete all acknowledgement for a user",
new DBAction<Void>() {
@Override
public Void call(DBConnection db) throws SQLException {
db.run("DELETE FROM " + tableName + " WHERE state = ? AND user_id = ?")
.param(AcknowledgementType.TEMPORARY.dbValue())
db.run("DELETE FROM " + tableName + " WHERE user_id = ?")
.param(userId)
.executeUpdate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private AcknowledgementType calculateAcknowledgementType(String uuid) {
}

@Override
public void clearTemporaryDismissedForUser(String userId) {
new AcknowledgementStorage(AcknowledgementStorage.NotificationType.BANNER).clearTemporaryDismissedForUser(userId);
public void clearAcknowledgementForUser(String userId) {
new AcknowledgementStorage(AcknowledgementStorage.NotificationType.BANNER).clearAcknowledgementForUser(userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public String clearBannerAcknowledgements(EntityView view, Map<String, Object> p
return result.toJSONString();
}

paSystem.getBanners().clearTemporaryDismissedForUser(userId);
paSystem.getBanners().clearAcknowledgementForUser(userId);
result.put("status", "SUCCESS");

return result.toJSONString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import org.sakaiproject.time.api.Time;
import org.sakaiproject.time.cover.TimeService;
import org.sakaiproject.tool.api.Session;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.user.cover.PreferencesService;

Expand All @@ -75,12 +75,14 @@ public class PASystemServlet extends HttpServlet {

private PASystem paSystem;
private ClusterService clusterService;
private SessionManager sessionManager;

public void init(ServletConfig config) throws ServletException {
super.init(config);

paSystem = ComponentManager.get(PASystem.class);
clusterService = ComponentManager.get(ClusterService.class);
sessionManager = ComponentManager.get(SessionManager.class);
}

private Handler handlerForRequest(HttpServletRequest request) {
Expand All @@ -93,7 +95,7 @@ private Handler handlerForRequest(HttpServletRequest request) {
if (path.contains("/popups/")) {
return new PopupsHandler(paSystem);
} else if (path.contains("/banners/")) {
return new BannersHandler(paSystem, clusterService);
return new BannersHandler(paSystem, clusterService, sessionManager);
} else {
return new IndexHandler(paSystem);
}
Expand Down Expand Up @@ -149,18 +151,18 @@ private void checkAccessControl() {
String siteId = ToolManager.getCurrentPlacement().getContext();

if (!SecurityService.unlock("pasystem.manage", "/site/" + siteId)) {
log.error("Access denied to PA System management tool for user " + SessionManager.getCurrentSessionUserId());
log.error("Access denied to PA System management tool for user " + sessionManager.getCurrentSessionUserId());
throw new PASystemException("Access denied");
}
}

private void storeFlashMessages(Map<String, List<String>> messages) {
Session session = SessionManager.getCurrentSession();
Session session = sessionManager.getCurrentSession();
session.setAttribute(FLASH_MESSAGE_KEY, messages);
}

private Map<String, List<String>> loadFlashMessages() {
Session session = SessionManager.getCurrentSession();
Session session = sessionManager.getCurrentSession();

if (session.getAttribute(FLASH_MESSAGE_KEY) != null) {
Map<String, List<String>> flashErrors = (Map<String, List<String>>) session.getAttribute(FLASH_MESSAGE_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.sakaiproject.pasystem.api.Banner;
import org.sakaiproject.pasystem.api.PASystem;
import org.sakaiproject.pasystem.tool.forms.BannerForm;
import org.sakaiproject.tool.api.SessionManager;

/**
* A handler for creating and updating banners in the PA System administration tool.
Expand All @@ -45,11 +46,13 @@
public class BannersHandler extends CrudHandler {

private final PASystem paSystem;
private final ClusterService clusterService;
private final ClusterService clusterService;
private final SessionManager sessionManager;

public BannersHandler(PASystem pasystem, ClusterService clusterService) {
public BannersHandler(PASystem pasystem, ClusterService clusterService, SessionManager sessionManager) {
this.paSystem = pasystem;
this.clusterService = clusterService;
this.sessionManager = sessionManager;
}

@Override
Expand Down Expand Up @@ -89,6 +92,12 @@ protected void handleCreateOrUpdate(HttpServletRequest request, Map<String, Obje
String uuid = extractId(request);
BannerForm bannerForm = BannerForm.fromRequest(uuid, request);

String userId = sessionManager.getCurrentSessionUserId();
if (userId == null) {
log.warn("No user ID found for current session");
return;
}

this.addErrors(bannerForm.validate());

if (hasErrors()) {
Expand All @@ -101,6 +110,7 @@ protected void handleCreateOrUpdate(HttpServletRequest request, Map<String, Obje
flash("info", "banner_created");
} else {
paSystem.getBanners().updateBanner(bannerForm.toBanner());
paSystem.getBanners().clearAcknowledgementForUser(userId);
flash("info", "banner_updated");
}

Expand Down

0 comments on commit 097e81f

Please sign in to comment.