Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send ecrf notifications only for subjects accessible by account #321

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Hallo #if($notification.password.user.identity)Benutzer $password_user_name#{else}Angehörige/r der Site $password_user_department#end,
Hallo #if($notification.password.inheriteduser.identity)Benutzer $password_inheriteduser_name#{else}Angehörige/r der Site $password_inheriteduser_department#end,

dies ist die Benachrichtigung für folgendes Ereignis:

$type

• Benutzername: $password_user_name
• Benutzer Site: $password_user_department
• Benutzername: $password_inheriteduser_name
• Benutzer Site: $password_inheriteduser_department

• Passwort Ablauf: $password_expiration

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Dear #if($notification.password.user.identity)user $password_user_name#{else}member of site $password_user_department#end,
Dear #if($notification.password.inheriteduser.identity)user $password_inheriteduser_name#{else}member of site $password_inheriteduser_department#end,

this is a notification for the following event:

$type

• Username: $password_user_name
• User site: $password_user_department
• Username: $password_inheriteduser_name
• User site: $password_inheriteduser_department

• Password expiration: $password_expiration

Expand Down
Loading
Loading