Skip to content

Commit b314253

Browse files
authored
Merge pull request #11915 from IQSS/11773-incorrect-roles-listed-in-assignrole-notifications
Limit notifications role assignment list
2 parents f5049ac + ad99401 commit b314253

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This release changes the text in assign role notifications to list only the role being assigned that generated the specific notification.
2+
The previous implementation listed all the roles associated with the dataset in each notification.
3+
4+
See also [the guides](https://dataverse-guide--11664.org.readthedocs.build/en/11664/user/account.html#notifications) and #11773.

src/main/java/edu/harvard/iq/dataverse/ManagePermissionsPage.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private void revokeRole(RoleAssignment ra) {
202202
commandEngine.submit(new RevokeRoleCommand(ra, dvRequestService.getDataverseRequest()));
203203
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("permission.roleWasRemoved", Arrays.asList(ra.getRole().getName(), roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier()).getDisplayInfo().getTitle())));
204204
RoleAssignee assignee = roleAssigneeService.getRoleAssignee(ra.getAssigneeIdentifier());
205-
notifyRoleChange(assignee, UserNotification.Type.REVOKEROLE);
205+
notifyRoleChange(assignee, UserNotification.Type.REVOKEROLE, ra.getRole());
206206
} catch (PermissionException ex) {
207207
JH.addMessage(FacesMessage.SEVERITY_ERROR, BundleUtil.getStringFromBundle("permission.roleNotAbleToBeRemoved"), BundleUtil.getStringFromBundle("permission.permissionsMissing", Arrays.asList(ex.getRequiredPermissions().toString())));
208208
} catch (CommandException ex) {
@@ -525,17 +525,21 @@ public void assignRole(ActionEvent evt) {
525525
* Will notify all members of a group.
526526
* @param ra The {@code RoleAssignee} to be notified.
527527
* @param type The type of notification.
528+
* @param r The {@code DataverseRole} associated with the change
528529
*/
529-
private void notifyRoleChange(RoleAssignee ra, UserNotification.Type type) {
530+
private void notifyRoleChange(RoleAssignee ra, UserNotification.Type type, DataverseRole r) {
531+
String additionalInfo = r != null ? String.format("{ roleId: %d, roleName: %s }", r.getId(), r.getName()) : null;
530532
if (ra instanceof AuthenticatedUser) {
531-
userNotificationService.sendNotification((AuthenticatedUser) ra, new Timestamp(new Date().getTime()), type, dvObject.getId());
533+
userNotificationService.sendNotification((AuthenticatedUser) ra, new Timestamp(new Date().getTime()), type,
534+
dvObject.getId(), null, null, false, additionalInfo);
532535
} else if (ra instanceof ExplicitGroup) {
533536
ExplicitGroup eg = (ExplicitGroup) ra;
534537
Set<String> explicitGroupMembers = eg.getContainedRoleAssgineeIdentifiers();
535538
for (String id : explicitGroupMembers) {
536539
RoleAssignee explicitGroupMember = roleAssigneeService.getRoleAssignee(id);
537540
if (explicitGroupMember instanceof AuthenticatedUser) {
538-
userNotificationService.sendNotification((AuthenticatedUser) explicitGroupMember, new Timestamp(new Date().getTime()), type, dvObject.getId());
541+
userNotificationService.sendNotification((AuthenticatedUser) explicitGroupMember, new Timestamp(new Date().getTime()), type,
542+
dvObject.getId(), null, null, false, additionalInfo);
539543
}
540544
}
541545
}
@@ -553,7 +557,7 @@ private void assignRole(RoleAssignee ra, DataverseRole r) {
553557
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("permission.roleAssignedToFor", args));
554558
// don't notify if role = file downloader and object is not released
555559
if (!(r.getAlias().equals(DataverseRole.FILE_DOWNLOADER) && !dvObject.isReleased()) ){
556-
notifyRoleChange(ra, UserNotification.Type.ASSIGNROLE);
560+
notifyRoleChange(ra, UserNotification.Type.ASSIGNROLE, r);
557561
}
558562

559563
} catch (PermissionException ex) {

src/main/java/edu/harvard/iq/dataverse/authorization/providers/builtin/DataverseUserPage.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.OrcidOAuth2AP;
7070
import java.io.IOException;
7171
import org.apache.commons.lang3.StringUtils;
72+
import org.json.JSONObject;
7273
import org.primefaces.event.TabChangeEvent;
7374

7475
/**
@@ -453,8 +454,13 @@ public void onTabChange(TabChangeEvent event) {
453454
}
454455

455456

456-
private String getRoleStringFromUser(AuthenticatedUser au, DvObject dvObj) {
457+
private String getRoleStringFromUser(AuthenticatedUser au, DvObject dvObj, String additionalInfo) {
457458
// Find user's role(s) for given dataverse/dataset
459+
if (additionalInfo != null && additionalInfo.contains("roleName:")) {
460+
JSONObject jsonObject = new JSONObject(additionalInfo);
461+
return jsonObject.getString("roleName");
462+
}
463+
458464
Set<RoleAssignment> roles = permissionService.assignmentsFor(au, dvObj);
459465
List<String> roleNames = new ArrayList<>();
460466

@@ -481,16 +487,16 @@ public void displayNotification() {
481487
// Can either be a dataverse or dataset, so search both
482488
Dataverse dataverse = dataverseService.find(userNotification.getObjectId());
483489
if (dataverse != null) {
484-
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), dataverse ));
490+
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), dataverse, userNotification.getAdditionalInfo()));
485491
userNotification.setTheObject(dataverse);
486492
} else {
487493
Dataset dataset = datasetService.find(userNotification.getObjectId());
488494
if (dataset != null){
489-
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), dataset ));
495+
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), dataset, userNotification.getAdditionalInfo()));
490496
userNotification.setTheObject(dataset);
491497
} else {
492498
DataFile datafile = fileService.find(userNotification.getObjectId());
493-
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), datafile ));
499+
userNotification.setRoleString(this.getRoleStringFromUser(this.getCurrentUser(), datafile, userNotification.getAdditionalInfo()));
494500
userNotification.setTheObject(datafile);
495501
}
496502
}

0 commit comments

Comments
 (0)