Skip to content

Commit 45b7571

Browse files
committed
fix notification user dataset original owner instead of new owner to check permissions
1 parent e785c0b commit 45b7571

2 files changed

Lines changed: 19 additions & 15 deletions

File tree

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/MoveDatasetCommand.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
148148
}
149149

150150
// OK, move
151+
Dataverse originalOwner = moved.getOwner();
151152
moved.setOwner(destination);
152153
ctxt.em().merge(moved);
153-
sendNotification(moved, ctxt);
154+
sendNotification(moved, originalOwner, ctxt);
154155

155156
boolean doNormalSolrDocCleanUp = true;
156157
ctxt.index().asyncIndexDataset(moved, doNormalSolrDocCleanUp);
@@ -160,14 +161,15 @@ public void executeImpl(CommandContext ctxt) throws CommandException {
160161
* Sends notifications to those able to publish the dataset upon the successful move of a dataset.
161162
* <p>
162163
* This method checks if dataset move notifications are enabled. If so, it
163-
* notifies all users with {@code Permission.PublishDataset} on the dataset.
164+
* notifies all users with {@code Permission.PublishDataset} on the original owning Dataverse.
164165
* The user who initiated the action can be included or excluded from this
165166
* notification based on the allowSelfNotification flag.
166167
*
167168
* @param dataset The moved {@code Dataset}.
169+
* @param originalOwner The original owning {@code Dataverse}.
168170
* @param ctxt The {@code CommandContext} providing access to application services.
169171
*/
170-
protected void sendNotification(Dataset dataset, CommandContext ctxt) {
172+
protected void sendNotification(Dataset dataset, Dataverse originalOwner, CommandContext ctxt) {
171173
// 1. Exit early if the SendNotificationOnDatasetMove setting is disabled.
172174
if (!ctxt.settings().isTrueForKey(SettingsServiceBean.Key.SendNotificationOnDatasetMove, false)) {
173175
return;
@@ -177,8 +179,9 @@ protected void sendNotification(Dataset dataset, CommandContext ctxt) {
177179
final User user = getUser();
178180
final AuthenticatedUser requestor = user.isAuthenticated() ? (AuthenticatedUser) user : null;
179181

180-
// 3. Get all users with publish permission and notify them.
181-
Map<String, AuthenticatedUser> recipients = ctxt.permissions().getDistinctUsersWithPermissionOn(Permission.PublishDataset, dataset);
182+
// 3. Get all users with publish permission on the dataset's original owner (dataverse) and notify them.
183+
Map<String, AuthenticatedUser> recipients = ctxt.permissions().getDistinctUsersWithPermissionOn(Permission.PublishDataset, originalOwner);
184+
// make sure the requestor is in the recipient list in case they don't match the permission
182185
if (requestor != null) {
183186
recipients.put(requestor.getIdentifier(), requestor);
184187
}

src/test/java/edu/harvard/iq/dataverse/api/MoveIT.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public void testMoveDataset() {
159159
@Test
160160
public void testMoveDatasetNotification() {
161161
sendNotificationOnDatasetMoveSetting(true);
162-
// Create the first user/dataverse/dataset
162+
// Create the first user/dataverse (superuser)
163163
Response createUser1 = UtilIT.createRandomUser();
164164
createUser1.prettyPrint();
165165
createUser1.then().assertThat()
@@ -174,12 +174,6 @@ public void testMoveDatasetNotification() {
174174
.statusCode(CREATED.getStatusCode());
175175
String dataverseAlias1 = UtilIT.getAliasFromResponse(createDataverse1);
176176

177-
Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias1, user1ApiToken);
178-
createDataset.prettyPrint();
179-
createDataset.then().assertThat()
180-
.statusCode(CREATED.getStatusCode());
181-
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset);
182-
183177
// Create the second user/dataverse
184178
Response createUser2 = UtilIT.createRandomUser();
185179
createUser2.prettyPrint();
@@ -194,12 +188,19 @@ public void testMoveDatasetNotification() {
194188
.statusCode(CREATED.getStatusCode());
195189
String dataverseAlias2 = UtilIT.getAliasFromResponse(createDataverse2);
196190

197-
// clear existing notifications
191+
// User2 creates dataset in DV2
192+
Response createDataset = UtilIT.createRandomDatasetViaNativeApi(dataverseAlias2, user2ApiToken);
193+
createDataset.prettyPrint();
194+
createDataset.then().assertThat()
195+
.statusCode(CREATED.getStatusCode());
196+
Integer datasetId = UtilIT.getDatasetIdFromResponse(createDataset);
197+
198+
// clear existing notifications (so the DATASETMOVED notification will be the only one)
198199
clearNotifications(user1ApiToken);
199200
clearNotifications(user2ApiToken);
200201

201-
// Move the dataset from dataverse1 to dataverse2
202-
Response moveDataset = UtilIT.moveDataset(datasetId.toString(), dataverseAlias2, user1ApiToken);
202+
// User1(superuser) moves the dataset from dataverse2 to dataverse1
203+
Response moveDataset = UtilIT.moveDataset(datasetId.toString(), dataverseAlias1, user1ApiToken);
203204
moveDataset.prettyPrint();
204205
moveDataset.then().assertThat()
205206
.statusCode(OK.getStatusCode())

0 commit comments

Comments
 (0)