2019-07-22 14:51:27 +02:00
|
|
|
package org.gcube.portlets.user.workspace.client.view.sharing;
|
2014-03-17 14:43:06 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
2014-03-18 12:50:53 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.event.UpdatedVREPermissionEvent;
|
2014-03-17 14:43:06 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
|
|
|
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
2019-07-22 14:51:27 +02:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplay;
|
|
|
|
import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert;
|
2019-07-22 14:51:27 +02:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.PanelTogglePermission;
|
2019-02-22 12:18:03 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
2019-04-04 17:46:26 +02:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
|
2014-03-17 14:43:06 +01:00
|
|
|
|
|
|
|
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
|
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
|
|
|
import com.extjs.gxt.ui.client.Style.VerticalAlignment;
|
|
|
|
import com.extjs.gxt.ui.client.event.ButtonEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.SelectionListener;
|
|
|
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
|
|
|
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
|
|
|
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
|
|
|
|
import com.google.gwt.core.shared.GWT;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Label;
|
|
|
|
|
|
|
|
/**
|
2019-02-22 14:40:20 +01:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
2014-03-17 14:43:06 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class DialogPermission extends Dialog {
|
|
|
|
|
|
|
|
private int widthDialog = 400;
|
|
|
|
private FileModel parentFolder = null;
|
|
|
|
|
|
|
|
private PanelTogglePermission permission;
|
|
|
|
private HorizontalPanel hpPermission = new HorizontalPanel();
|
|
|
|
private FileModel folder;
|
|
|
|
|
|
|
|
private DialogPermission INSTANCE = this;
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
public FileModel getParentFolder() {
|
|
|
|
return parentFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initLayout(String folderParentName) {
|
|
|
|
FormLayout layout = new FormLayout();
|
|
|
|
layout.setLabelWidth(90);
|
|
|
|
layout.setDefaultWidth(380);
|
|
|
|
setLayout(layout);
|
|
|
|
setModal(true);
|
|
|
|
setScrollMode(Scroll.AUTOY);
|
|
|
|
setBodyStyle("padding: 9px; background: none");
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setHeight(140);
|
|
|
|
setResizable(true);
|
|
|
|
setButtonAlign(HorizontalAlignment.CENTER);
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
|
|
|
enableFormDialog(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use to set permission to VRE Folder
|
2019-02-22 12:37:09 +01:00
|
|
|
*
|
|
|
|
* @param folder
|
|
|
|
* folder
|
2014-03-17 14:43:06 +01:00
|
|
|
*/
|
|
|
|
public DialogPermission(FileModel folder) {
|
|
|
|
|
|
|
|
this.folder = folder;
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
Label labelProperty = new Label("Permissions");
|
|
|
|
|
|
|
|
hpPermission.add(labelProperty);
|
|
|
|
hpPermission.setVerticalAlign(VerticalAlignment.MIDDLE);
|
|
|
|
hpPermission.mask("Checking authorization");
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
AsyncCallback<List<InfoContactModel>> callback = new AsyncCallback<List<InfoContactModel>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2019-02-22 12:37:09 +01:00
|
|
|
new MessageBoxAlert("Alert", "Sorry, an error occurred on recovering ACLs", null);
|
2014-03-17 14:43:06 +01:00
|
|
|
hpPermission.unmask();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> listManagers) {
|
2019-02-22 12:37:09 +01:00
|
|
|
permissionControl(listManagers, true);
|
|
|
|
hpPermission.unmask();
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
|
|
|
};
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
getUsersManagers(folder.getIdentifier(), callback);
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
// TODO GET ACL FOR USER
|
2019-02-22 12:18:03 +01:00
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
|
2014-03-17 14:43:06 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<WorkspaceACL> result) {
|
|
|
|
permission = new PanelTogglePermission(result);
|
|
|
|
hpPermission.add(permission);
|
|
|
|
hpPermission.layout();
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2019-02-22 12:37:09 +01:00
|
|
|
new MessageBoxAlert("Alert", "Sorry, an error occurred on recovering ACLs", null);
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
initLayout(folder.getName());
|
|
|
|
this.setIcon(Resources.getIconVREFolder());
|
|
|
|
setHeading("Change permissions to folder: " + folder.getName());
|
|
|
|
|
|
|
|
setWidth(widthDialog);
|
|
|
|
setButtons(Dialog.OKCANCEL);
|
|
|
|
|
|
|
|
add(hpPermission);
|
|
|
|
addListners();
|
|
|
|
getButtonById(Dialog.OK).setEnabled(false);
|
|
|
|
enableFormDialog(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addListners() {
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
this.getButtonById(Dialog.CANCEL).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
2014-03-17 14:43:06 +01:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
hide();
|
|
|
|
}
|
2014-03-17 14:43:06 +01:00
|
|
|
});
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
this.getButtonById(Dialog.OK).addSelectionListener(new SelectionListener<ButtonEvent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void componentSelected(ButtonEvent ce) {
|
|
|
|
|
|
|
|
INSTANCE.mask("Changing permissions");
|
|
|
|
if (folder != null && getSelectedACL().getId() != null) {
|
|
|
|
|
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.updateACLForVREbyGroupName(folder.getIdentifier(),
|
|
|
|
getSelectedACL().getId(), new AsyncCallback<Void>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
INSTANCE.hide();
|
|
|
|
new MessageBoxAlert("Error", caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Void result) {
|
|
|
|
INSTANCE.unmask();
|
|
|
|
INSTANCE.hide();
|
|
|
|
new InfoDisplay("Permission updated",
|
|
|
|
"The permissions have been changed correctly");
|
|
|
|
|
|
|
|
AppControllerExplorer.getEventBus()
|
|
|
|
.fireEvent(new UpdatedVREPermissionEvent(folder.getIdentifier()));
|
|
|
|
}
|
|
|
|
});
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
}
|
2014-03-17 14:43:06 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
|
|
|
|
private void permissionControl(List<InfoContactModel> listManagers, boolean showAlert) {
|
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
boolean permissionsOk = false;
|
|
|
|
for (InfoContactModel infoContactModel : listManagers) {
|
2019-02-22 12:37:09 +01:00
|
|
|
|
|
|
|
GWT.log("DialogPermission control compare between : " + infoContactModel.getLogin() + " and my login: "
|
|
|
|
+ AppControllerExplorer.myLogin);
|
|
|
|
if (AppControllerExplorer.myLogin.compareToIgnoreCase(infoContactModel.getLogin()) == 0) {
|
2014-03-17 14:43:06 +01:00
|
|
|
permissionsOk = true;
|
|
|
|
break;
|
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
|
|
|
|
if (permissionsOk) {
|
2014-03-17 14:43:06 +01:00
|
|
|
enableFormDialog(true);
|
2019-02-22 12:37:09 +01:00
|
|
|
} else {
|
2014-03-17 14:43:06 +01:00
|
|
|
enableFormDialog(false);
|
2019-02-22 12:37:09 +01:00
|
|
|
if (showAlert)
|
|
|
|
new MessageBoxAlert("Permission denied",
|
|
|
|
"You have no permissions to change sharing. You are not manager of \"" + folder.getName()
|
|
|
|
+ "\"",
|
|
|
|
null);
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
|
|
|
|
private void enableFormDialog(boolean bool) {
|
|
|
|
getButtonById(Dialog.OK).setEnabled(bool);
|
|
|
|
|
|
|
|
if (permission != null)
|
|
|
|
permission.setEnabled(bool);
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
public void getUsersManagers(final String sharedFolderId, final AsyncCallback<List<InfoContactModel>> callback) {
|
2014-03-17 14:43:06 +01:00
|
|
|
|
2019-02-22 12:37:09 +01:00
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getAdministratorsByFolderId(sharedFolderId,
|
|
|
|
new AsyncCallback<List<InfoContactModel>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable arg0) {
|
|
|
|
GWT.log("an error occured in getting user managers by Id " + sharedFolderId + " "
|
|
|
|
+ arg0.getMessage());
|
|
|
|
new MessageBoxAlert("Alert",
|
|
|
|
"Sorry, an error occurred on getting users managers, try again later", null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> listManagers) {
|
|
|
|
callback.onSuccess(listManagers);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2014-03-17 14:43:06 +01:00
|
|
|
}
|
2019-02-22 12:37:09 +01:00
|
|
|
|
|
|
|
public WorkspaceACL getSelectedACL() {
|
|
|
|
if (permission != null)
|
2014-03-17 14:43:06 +01:00
|
|
|
return permission.getSelectedACL();
|
2019-02-22 12:37:09 +01:00
|
|
|
|
2014-03-17 14:43:06 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|