Skip to content

Commit

Permalink
SAK-44623 Bullhorn no notification is thrown when an assignment's ope…
Browse files Browse the repository at this point in the history
…ning date is in the future (sakaiproject#10732)
  • Loading branch information
jkjanetschek authored Aug 4, 2022
1 parent ab17af4 commit a612504
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static org.sakaiproject.assignment.api.AssignmentConstants.EVENT_ADD_ASSIGNMENT;
import static org.sakaiproject.assignment.api.AssignmentConstants.EVENT_UPDATE_ASSIGNMENT_ACCESS;
import static org.sakaiproject.assignment.api.AssignmentServiceConstants.SECURE_ACCESS_ASSIGNMENT;
import static org.sakaiproject.assignment.api.AssignmentConstants.EVENT_AVAILABLE_ASSIGNMENT;

import org.sakaiproject.assignment.api.model.Assignment;
import org.sakaiproject.authz.api.AuthzGroupService;
Expand Down Expand Up @@ -86,6 +87,7 @@ public Optional<List<BullhornData>> handleEvent(Event e) {
Assignment assignment = assignmentService.getAssignment(assignmentId);
switch (e.getEvent()) {
case EVENT_ADD_ASSIGNMENT:
case EVENT_AVAILABLE_ASSIGNMENT:
return bhAlreadyExists(ref) ? Optional.empty() : Optional.of(handleAdd(from, siteId, assignmentId, assignment));
case EVENT_UPDATE_ASSIGNMENT_ACCESS:
return Optional.of(handleUpdateAccess(from, ref, siteId, assignmentId, assignment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public final class AssignmentConstants {
*/
public static final String EVENT_ADD_ASSIGNMENT = "asn.new.assignment";


/**
* Event for delayed assignment
*/
public static final String EVENT_AVAILABLE_ASSIGNMENT = "asn.available.assignment";

/**********************************************************************************************************************************************************************************************************************************************************
* EVENT STRINGS
*********************************************************************************************************************************************************************************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8647,6 +8647,18 @@ private void post_save_assignment(RunData data, String postOrSave) {
}
}


if (oldOpenTime != null && !oldOpenTime.equals(a.getOpenDate())) {
//cancel not fired event
eventTrackingService.cancelDelays(assignmentReference, AssignmentConstants.EVENT_AVAILABLE_ASSIGNMENT);
// open time change
eventTrackingService.post(eventTrackingService.newEvent(AssignmentConstants.EVENT_UPDATE_ASSIGNMENT_OPENDATE, assignmentId, true));
if (a.getOpenDate().isAfter(Instant.now())) {
eventTrackingService.delay(eventTrackingService.newEvent(AssignmentConstants.EVENT_AVAILABLE_ASSIGNMENT, assignmentReference,
true), openTime);
}
}

if (oldOpenTime != null && !oldOpenTime.equals(a.getOpenDate())) {
// open time change
eventTrackingService.post(eventTrackingService.newEvent(AssignmentConstants.EVENT_UPDATE_ASSIGNMENT_OPENDATE, assignmentReference, true));
Expand All @@ -8664,10 +8676,27 @@ private void post_save_assignment(RunData data, String postOrSave) {
}
}
}
//SAK-45967
if (newAssignment || !a.getDraft()) {
// post new assignment event since it is fully initialized by now
eventTrackingService.post(eventTrackingService.newEvent(AssignmentConstants.EVENT_ADD_ASSIGNMENT, assignmentReference, true));

if ((newAssignment && !a.getDraft()) || (!a.getDraft() && !newAssignment)) {

Collection aGroups = a.getGroups();
if (aGroups.size() != 0) {
// If already open
if (openTime.isBefore(Instant.now())) {
eventTrackingService.post(eventTrackingService.newEvent(AssignmentConstants.EVENT_UPDATE_ASSIGNMENT_ACCESS, assignmentReference, true));
} else {
// Not open yet, delay the event
eventTrackingService.delay(eventTrackingService.newEvent(AssignmentConstants.EVENT_AVAILABLE_ASSIGNMENT, assignmentReference,
true), openTime);
}
} else {
if (openTime.isBefore(Instant.now())) {
// post new assignment event since it is fully initialized by now
eventTrackingService.post(eventTrackingService.newEvent(AssignmentConstants.EVENT_ADD_ASSIGNMENT, assignmentReference, true));
} else {
eventTrackingService.delay(eventTrackingService.newEvent(AssignmentConstants.EVENT_AVAILABLE_ASSIGNMENT, assignmentReference, true), openTime);
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions content/content-impl-providers/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<groupId>org.sakaiproject.scheduler</groupId>
<artifactId>scheduler-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import lombok.extern.slf4j.Slf4j;

import org.sakaiproject.api.app.scheduler.ScheduledInvocationCommand;
Expand Down Expand Up @@ -308,12 +308,23 @@ public void execute(String opaqueContext)

securityService.pushAdvisor(new SecurityAdvisor() {
public SecurityAdvice isAllowed(String userId, String function, String reference) {
if (securityService.unlock(event.getUserId(), function, reference)) {
return SecurityAdvice.ALLOWED;
}
return SecurityAdvice.PASS;
}
});
//SAK-44623: bullhorn notification execution of delayed "asn.available.assignment" event would build wrong DeepLink for users with no "asn.new" permission.
if (StringUtils.isNotEmpty(userId)) {
if (event.getUserId().equals(userId)) {
if (securityService.unlock(event.getUserId(), function, reference)) {
return SecurityAdvice.ALLOWED;
}
return SecurityAdvice.PASS;
}
return SecurityAdvice.PASS;
} else {
if (securityService.unlock(event.getUserId(), function, reference)) {
return SecurityAdvice.ALLOWED;
}
return SecurityAdvice.PASS;
}
}
});

eventService.post(event, user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@

bunch.alerts.forEach(alert => {

if ("asn.new.assignment" === alert.event || "asn.revise.access" === alert.event) {
if ("asn.new.assignment" === alert.event || "asn.revise.access" === alert.event || "asn.available.assignment" === alert.event) {
messageTemplate = i18n.assignmentCreated;
} else if ("asn.grade.submission" === alert.event) {
messageTemplate = i18n.assignmentSubmissionGraded;
Expand Down

0 comments on commit a612504

Please sign in to comment.