Skip to content

Commit

Permalink
send ecrf notifications only for subjects accessible by account
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrenn committed Jul 19, 2024
1 parent 7336d3c commit d5630e0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,12 @@ private ArrayList<Staff> addSuperVisorsRecipients(Notification newNotification,
return result;
}

private HashSet<Staff> addTrialTeamMemberOtherRecipients(Notification newNotification, Trial trial, boolean create) throws Exception {
return addTrialTeamMemberRecipients(newNotification, trial, false, true, false, false, false, false, create);
private HashSet<Staff> addTrialTeamMemberOtherRecipients(Notification newNotification, Trial trial, Department department, boolean create) throws Exception {
return addTrialTeamMemberRecipients(newNotification, trial, department, false, true, false, false, false, false, create);
}

private HashSet<Staff> addTrialTeamMemberRecipients(Notification newNotification, Trial trial, boolean filterTimelineEventRecipients, boolean filterOtherRecipients,
private HashSet<Staff> addTrialTeamMemberRecipients(Notification newNotification, Trial trial, Department department, boolean filterTimelineEventRecipients,
boolean filterOtherRecipients,
boolean filterEcrfValidatedStatusRecipients, boolean filterEcrfReviewStatusRecipients, boolean filterEcrfVerifiedStatusRecipients,
boolean filterEcrfFieldStatusRecipients, boolean create) throws Exception {
HashSet<Staff> result = new HashSet<Staff>();
Expand All @@ -218,8 +219,11 @@ private HashSet<Staff> addTrialTeamMemberRecipients(Notification newNotification
&& (!filterEcrfVerifiedStatusRecipients || teamMember.isNotifyEcrfVerifiedStatus())
&& (!filterEcrfFieldStatusRecipients || teamMember.isNotifyEcrfFieldStatus())) {
Staff teamMemberStaff = teamMember.getStaff();
if (result.add(teamMemberStaff) && create) {
createNotificationRecipient(newNotification, teamMemberStaff);
if (department == null || department.equals(teamMemberStaff.getDepartment())
|| ServiceUtil.hasProbandAllDepartmentsAccount(teamMemberStaff, this.getUserPermissionProfileDao())) {
if (result.add(teamMemberStaff) && create) {
createNotificationRecipient(newNotification, teamMemberStaff);
}
}
}
}
Expand Down Expand Up @@ -413,7 +417,7 @@ private String getSubject(Notification notification, Map messageParameters) {
});
case EXPIRING_PASSWORD:
return L10nUtil.getNotificationSubject(Locales.NOTIFICATION, type.getSubjectL10nKey(), new Object[] {
messageParameters.get("password_user_name"),
messageParameters.get("password_inheriteduser_name"),
messageParameters.get(NotificationMessageTemplateParameters.PASSWORD_EXPIRATION_DAYS_LEFT)
});
case TRIAL_STATUS_UPDATED:
Expand Down Expand Up @@ -611,7 +615,7 @@ protected Notification handleAddNotification(DutyRosterTurn dutyRosterTurn, Staf
if (setRemainingFields(notification, today, notificationType, messageParameters)) {
notification = this.create(notification);
if (addSuperVisorsRecipients(notification, dutyRosterTurn.getStaff(), true).size() == 0
&& addTrialTeamMemberOtherRecipients(notification, dutyRosterTurn.getTrial(), true).size() == 0) {
&& addTrialTeamMemberOtherRecipients(notification, dutyRosterTurn.getTrial(), null, true).size() == 0) {
createNotificationRecipient(notification, dutyRosterTurn.getStaff());
}
return notification;
Expand Down Expand Up @@ -660,7 +664,8 @@ protected Notification handleAddNotification(ECRFFieldStatusEntry ecrfFieldStatu
Notification notification = Notification.Factory.newInstance();
Department department = null;
Trial trial = ecrfFieldStatusEntry.getListEntry().getTrial();
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, false, false, false, false, false, true, false);
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, ecrfFieldStatusEntry.getListEntry().getProband().getDepartment(), false, false, false,
false, false, true, false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand Down Expand Up @@ -688,8 +693,10 @@ protected Notification handleAddNotification(ECRFStatusEntry ecrfStatusEntry, Da
Notification notification = Notification.Factory.newInstance();
Department department = null;
Trial trial = ecrfStatusEntry.getListEntry().getTrial();
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, false, false, ecrfStatusEntry.getStatus().isValidated(), ecrfStatusEntry.getStatus()
.isReview(), ecrfStatusEntry.getStatus().isVerified(), false, false);
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, ecrfStatusEntry.getListEntry().getProband().getDepartment(), false, false,
ecrfStatusEntry.getStatus().isValidated(), ecrfStatusEntry.getStatus()
.isReview(),
ecrfStatusEntry.getStatus().isVerified(), false, false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand Down Expand Up @@ -861,7 +868,7 @@ protected Notification handleAddNotification(TimelineEvent timelineEvent, Date t
Notification notification = Notification.Factory.newInstance();
Trial trial = timelineEvent.getTrial();
Department department = null;
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, true, false, false, false, false, false, false);
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, null, true, false, false, false, false, false, false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand All @@ -884,7 +891,7 @@ protected Notification handleAddNotification(Trial trial, Date today, Map messag
ServiceUtil.cancelNotifications(trial.getNotifications(), this, notificationType);
Notification notification = Notification.Factory.newInstance();
Department department = null;
HashSet<Staff> trialMembers = addTrialTeamMemberOtherRecipients(notification, trial, false);
HashSet<Staff> trialMembers = addTrialTeamMemberOtherRecipients(notification, trial, null, false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand Down Expand Up @@ -916,7 +923,7 @@ protected Notification handleAddNotification(Trial trial, TrialTag trialTag, Dat
ServiceUtil.cancelNotifications(trialTagNotifications, this, notificationType);
Notification notification = Notification.Factory.newInstance();
Department department = null;
HashSet<Staff> trialMembers = addTrialTeamMemberOtherRecipients(notification, trial, false);
HashSet<Staff> trialMembers = addTrialTeamMemberOtherRecipients(notification, trial, null, false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand Down Expand Up @@ -961,7 +968,7 @@ protected Notification handleAddNotification(VisitScheduleItem visitScheduleItem
Notification notification = Notification.Factory.newInstance();
Trial trial = visitScheduleItem.getTrial();
Department department = null;
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, true, false, false, false, false, false, false);
HashSet<Staff> trialMembers = addTrialTeamMemberRecipients(notification, trial, proband.getDepartment(), true, false, false, false, false, false, false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand Down Expand Up @@ -1016,7 +1023,7 @@ protected Notification handleAddNotification(
Notification notification = Notification.Factory.newInstance();
Trial trial = visitScheduleItem.getTrial();
Department department = null;
HashSet<Staff> trialMembers = addTrialTeamMemberOtherRecipients(notification, trial, false);
HashSet<Staff> trialMembers = addTrialTeamMemberOtherRecipients(notification, trial, proband.getDepartment(), false);
if (trialMembers.size() == 0) {
department = trial.getDepartment();
notification.setDepartment(department);
Expand Down Expand Up @@ -1057,7 +1064,7 @@ protected Notification handleAddNotification(VisitScheduleItem visitScheduleItem
if (setRemainingFields(notification, today, notificationType, messageParameters)) {
notification = this.create(notification);
if (addSuperVisorsRecipients(notification, staff, true).size() == 0
&& addTrialTeamMemberOtherRecipients(notification, visitScheduleItem.getTrial(), true).size() == 0) {
&& addTrialTeamMemberOtherRecipients(notification, visitScheduleItem.getTrial(), null, true).size() == 0) {
createNotificationRecipient(notification, staff);
}
return notification;
Expand Down
18 changes: 18 additions & 0 deletions core/src/main/java/org/phoenixctms/ctsms/util/ServiceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3346,6 +3346,24 @@ public static Collection<PermissionProfileVO> getPermissionProfiles(PermissionPr
return result;
}

public static boolean hasProbandAllDepartmentsAccount(Staff staff, UserPermissionProfileDao userPermissionProfileDao) {
HashMap<Long, HashSet<PermissionProfileGroup>> inheritPermissionProfileGroupMap = new HashMap<Long, HashSet<PermissionProfileGroup>>();
Iterator<User> accountsIt = staff.getAccounts().iterator();
while (accountsIt.hasNext()) {
Iterator<UserPermissionProfile> userPermissionProfilesIt = ServiceUtil.getInheritedUserPermissionProfiles(accountsIt.next(), PermissionProfileGroup.PROBAND,
true, inheritPermissionProfileGroupMap, userPermissionProfileDao).iterator();
while (userPermissionProfilesIt.hasNext()) {
UserPermissionProfile permissionProfile = userPermissionProfilesIt.next();
if (PermissionProfile.PROBAND_MASTER_ALL_DEPARTMENTS.equals(permissionProfile.getProfile())
|| PermissionProfile.PROBAND_DETAIL_ALL_DEPARTMENTS.equals(permissionProfile.getProfile())
|| PermissionProfile.PROBAND_VIEW_ALL_DEPARTMENTS.equals(permissionProfile.getProfile())) {
return true;
}
}
}
return false;
}

public static Collection<UserPermissionProfile> getInheritedUserPermissionProfiles(User user, PermissionProfileGroup profileGroup, Boolean active,
HashMap<Long, HashSet<PermissionProfileGroup>> inheritPermissionProfileGroupMap, UserPermissionProfileDao userPermissionProfileDao) {
if (isPermissionProfileGroupInherited(user, profileGroup, inheritPermissionProfileGroupMap)) {
Expand Down

0 comments on commit d5630e0

Please sign in to comment.