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
  • Loading branch information
kunaljaykam committed Oct 13, 2023
1 parent 6ec64fd commit bbf2288
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 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 @@ -37,6 +37,8 @@
import org.sakaiproject.pasystem.api.Banner;
import org.sakaiproject.pasystem.api.PASystem;
import org.sakaiproject.pasystem.tool.forms.BannerForm;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.cover.UserDirectoryService;

/**
* A handler for creating and updating banners in the PA System administration tool.
Expand Down Expand Up @@ -89,6 +91,12 @@ protected void handleCreateOrUpdate(HttpServletRequest request, Map<String, Obje
String uuid = extractId(request);
BannerForm bannerForm = BannerForm.fromRequest(uuid, request);

User currentUser = UserDirectoryService.getCurrentUser();
if (currentUser == null) {
return;
}
String userId = currentUser.getId();

this.addErrors(bannerForm.validate());

if (hasErrors()) {
Expand All @@ -101,6 +109,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 bbf2288

Please sign in to comment.