Skip to content

Commit

Permalink
Merge pull request Sage-Bionetworks#5536 from Sage-Bionetworks/releas…
Browse files Browse the repository at this point in the history
…e-515

Merge release 515 to develop (Revert "SWC-6776 - Show ACL editor after successful upload" (Sage-Bionetworks#5535))
  • Loading branch information
jay-hodgson authored Sep 30, 2024
2 parents 26fe34d + f25c2d4 commit ddb4ea3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.sagebionetworks.web.client.events;

public interface UploadSuccessHandler {
/**
* Called when one or more files have been successfully uploaded.
* @param benefactorId the benefactor ID of all uploaded files. May be null if request to get benefactor fails
*/
void onSuccessfulUpload(String benefactorId);
void onSuccessfulUpload();
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,20 @@ public interface Callback {
public boolean open;
public Callback onUpdateSuccess;
public Callback onClose;
public boolean isAfterUpload;

@JsOverlay
public static EntityAclEditorModalProps create(
String entityId,
boolean open,
Callback onUpdateSuccess,
Callback onClose,
boolean isAfterUpload
Callback onClose
) {
EntityAclEditorModalProps props = new EntityAclEditorModalProps();

props.entityId = entityId;
props.open = open;
props.onUpdateSuccess = onUpdateSuccess;
props.onClose = onClose;
props.isAfterUpload = isAfterUpload;
return props;
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
package org.sagebionetworks.web.client.widget.entity.download;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.web.client.events.EntityUpdatedEvent;
import org.sagebionetworks.web.client.utils.CallbackP;
import org.sagebionetworks.web.client.widget.SynapseWidgetPresenter;
import org.sagebionetworks.web.client.widget.sharing.EntityAccessControlListModalWidget;

public class UploadDialogWidget
implements UploadDialogWidgetView.Presenter, SynapseWidgetPresenter {

private UploadDialogWidgetView view;
private Uploader uploader;
private final EventBus eventBus;
private final EntityAccessControlListModalWidget entityAclEditor;

@Inject
public UploadDialogWidget(
UploadDialogWidgetView view,
Uploader uploader,
EventBus eventBus,
EntityAccessControlListModalWidget entityAccessControlListModalWidget
) {
public UploadDialogWidget(UploadDialogWidgetView view, Uploader uploader) {
this.view = view;
this.uploader = uploader;
this.eventBus = eventBus;
this.entityAclEditor = entityAccessControlListModalWidget;
view.setPresenter(this);
}

Expand All @@ -52,16 +40,8 @@ public void configure(
view.configureDialog(title, body);

// add handlers for closing the window
uploader.setSuccessHandler(benefactorId -> {
uploader.setSuccessHandler(() -> {
view.hideDialog();
if (benefactorId != null) {
entityAclEditor.configure(
benefactorId,
() -> eventBus.fireEvent(new EntityUpdatedEvent(benefactorId)),
true
);
entityAclEditor.setOpen(true);
}
});

uploader.setCancelHandler(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import java.util.List;
import org.sagebionetworks.repo.model.AccessControlList;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.Folder;
import org.sagebionetworks.repo.model.attachment.UploadResult;
Expand Down Expand Up @@ -791,22 +790,7 @@ public void onSuccess(Entity result) {
entity = result;
view.showInfo(DisplayConstants.TEXT_LINK_SUCCESS);
if (successHandler != null) {
synapseClient.getEntityBenefactorAcl(
result.getId(),
new AsyncCallback<AccessControlList>() {
@Override
public void onSuccess(AccessControlList benefactorAcl) {
successHandler.onSuccessfulUpload(benefactorAcl.getId());
}

@Override
public void onFailure(Throwable caught) {
view.showErrorMessage(caught.getMessage());
// Upload was still a success, benefactor ID is not required to continue
successHandler.onSuccessfulUpload(null);
}
}
);
successHandler.onSuccessfulUpload();
}

entityUpdated();
Expand Down Expand Up @@ -1025,22 +1009,7 @@ private void uploadSuccess() {
view.resetToInitialState();
resetUploadProgress();
if (successHandler != null) {
synapseClient.getEntityBenefactorAcl(
parentEntityId,
new AsyncCallback<AccessControlList>() {
@Override
public void onSuccess(AccessControlList benefactorAcl) {
successHandler.onSuccessfulUpload(benefactorAcl.getId());
}

@Override
public void onFailure(Throwable caught) {
view.showErrorMessage(caught.getMessage());
// Upload was still a success, benefactor ID is not required to continue.
successHandler.onSuccessfulUpload(null);
}
}
);
successHandler.onSuccessfulUpload();
}
entityUpdated();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@ void configure(
EntityAclEditorModalProps.Callback onUpdateSuccess
);

void configure(
String entityId,
EntityAclEditorModalProps.Callback onUpdateSuccess,
boolean isAfterUpload
);

void setOpen(boolean open);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,13 @@ public class EntityAccessControlListModalWidgetImpl
public void configure(
String entityId,
EntityAclEditorModalProps.Callback onUpdateSuccess
) {
configure(entityId, onUpdateSuccess, false);
}

@Override
public void configure(
String entityId,
EntityAclEditorModalProps.Callback onUpdateSuccess,
boolean isAfterUpload
) {
componentProps =
EntityAclEditorModalProps.create(
entityId,
false,
onUpdateSuccess,
() -> setOpen(false),
isAfterUpload
() -> setOpen(false)
);
renderComponent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.Widget;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.web.client.events.CancelHandler;
import org.sagebionetworks.web.client.events.UploadSuccessHandler;
import org.sagebionetworks.web.client.jsinterop.EntityAclEditorModalProps;
import org.sagebionetworks.web.client.utils.CallbackP;
import org.sagebionetworks.web.client.widget.entity.download.UploadDialogWidget;
import org.sagebionetworks.web.client.widget.entity.download.UploadDialogWidgetView;
import org.sagebionetworks.web.client.widget.entity.download.Uploader;
import org.sagebionetworks.web.client.widget.sharing.EntityAccessControlListModalWidget;

@RunWith(MockitoJUnitRunner.Silent.class)
public class UploadDialogTest {
Expand All @@ -32,31 +28,11 @@ public class UploadDialogTest {
@Mock
Uploader mockUploader;

@Mock
EventBus mockEventBus;

@Mock
EntityAccessControlListModalWidget mockEntityAccessControlListModalWidget;

@Captor
ArgumentCaptor<UploadSuccessHandler> uploadSuccessCaptor;

@Captor
ArgumentCaptor<
EntityAclEditorModalProps.Callback
> updateAclSuccessCallbackCaptor;

UploadDialogWidget widget;

@Before
public void before() throws Exception {
widget =
new UploadDialogWidget(
view,
mockUploader,
mockEventBus,
mockEntityAccessControlListModalWidget
);
widget = new UploadDialogWidget(view, mockUploader);
}

@Test
Expand All @@ -78,24 +54,8 @@ public void testConfigure() {
.configure(entity, parentEntityId, fileHandleIdCallback, isEntity);
verify(view).configureDialog(eq(title), any());

verify(mockUploader).setSuccessHandler(uploadSuccessCaptor.capture());
verify(mockUploader).setSuccessHandler(any(UploadSuccessHandler.class));
verify(mockUploader).setCancelHandler(any(CancelHandler.class));

// simulate a successful upload
String benefactorId = "syn123";
uploadSuccessCaptor.getValue().onSuccessfulUpload(benefactorId);
verify(view).hideDialog();
verify(mockEntityAccessControlListModalWidget)
.configure(
eq(benefactorId),
updateAclSuccessCallbackCaptor.capture(),
eq(true)
);
verify(mockEntityAccessControlListModalWidget).setOpen(true);

// Simulate a successful ACL save
updateAclSuccessCallbackCaptor.getValue().run();
verify(mockEventBus).fireEvent(any());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doAnswer;
Expand All @@ -29,13 +30,13 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.sagebionetworks.repo.model.AccessControlList;
import org.sagebionetworks.repo.model.Entity;
import org.sagebionetworks.repo.model.FileEntity;
import org.sagebionetworks.repo.model.Folder;
Expand Down Expand Up @@ -165,7 +166,6 @@ public class UploaderTest {
private final Long defaultSynapseStorageId = 1L;

public static final String SUCCESS_FILE_HANDLE = "99999";
public static final String UPLOAD_BENEFACTOR_ID = "syn12345";

@Before
public void before() throws Exception {
Expand Down Expand Up @@ -291,11 +291,6 @@ public void testSetNewExternalPath() throws Exception {
// this is the full success test
// if entity is null, it should call synapseClient.createExternalFile() to create the FileEntity and
// associate the path.
AsyncMockStubber
.callSuccessWith(new AccessControlList().setId(UPLOAD_BENEFACTOR_ID))
.when(mockSynapseClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));

uploader.setExternalFilePath(
"http://fakepath.url/blah.xml",
"",
Expand All @@ -312,10 +307,8 @@ public void testSetNewExternalPath() throws Exception {
eq(storageLocationId),
any()
);
verify(mockSynapseClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));
verify(mockView).showInfo(anyString());
verify(mockUploadSuccessHandler).onSuccessfulUpload(UPLOAD_BENEFACTOR_ID);
verify(mockUploadSuccessHandler).onSuccessfulUpload();
}

@Test
Expand Down Expand Up @@ -418,25 +411,19 @@ public void testDirectUploadHappyCase() throws Exception {
.callSuccessWith(testEntity)
.when(mockSynapseJavascriptClient)
.getEntity(anyString(), any(OBJECT_TYPE.class), any(AsyncCallback.class));
AsyncMockStubber
.callSuccessWith(new AccessControlList().setId(UPLOAD_BENEFACTOR_ID))
.when(mockSynapseClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));
uploader.handleUploads();
verify(mockGlobalApplicationState).clearDropZoneHandler(); // SWC-5161 (cleared on handleUploads)
verify(mockView).disableSelectionDuringUpload();
verify(mockSynapseClient)
.setFileEntityFileHandle(any(), any(), any(), any());
verify(mockSynapseClient)
.getEntityBenefactorAcl(anyString(), any(AsyncCallback.class));
verify(mockView).hideLoading();
assertEquals(UploadType.S3, uploader.getCurrentUploadType());
// verify upload success

verify(mockView).showSingleFileUploaded("entityID");
verify(mockView).clear();
verify(mockView, times(2)).resetToInitialState();
verify(mockUploadSuccessHandler).onSuccessfulUpload(UPLOAD_BENEFACTOR_ID);
verify(mockUploadSuccessHandler).onSuccessfulUpload();
verify(mockEventBus).fireEvent(any(EntityUpdatedEvent.class));
}

Expand Down

0 comments on commit ddb4ea3

Please sign in to comment.