use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.
the class RepositoryLockControllerTest method testBlockLock.
@Test
public void testBlockLock() throws Exception {
RepositoryLockController repositoryLockController = new RepositoryLockController();
List<UIRepositoryObject> selectedRepoObjects = new ArrayList<>();
UIEETransformation lockObject = Mockito.mock(UIEETransformation.class);
selectedRepoObjects.add(lockObject);
Mockito.when(lockObject.isLocked()).thenReturn(true);
ObjectId objectId = Mockito.mock(ObjectId.class);
Mockito.when(lockObject.getObjectId()).thenReturn(objectId);
XulMenuitem lockFileMenuItem = Mockito.mock(XulMenuitem.class);
Field lockFileMenuItemField = repositoryLockController.getClass().getDeclaredField("lockFileMenuItem");
lockFileMenuItemField.setAccessible(true);
lockFileMenuItemField.set(repositoryLockController, lockFileMenuItem);
XulMenuitem deleteFileMenuItem = Mockito.mock(XulMenuitem.class);
Field deleteFileMenuItemField = repositoryLockController.getClass().getDeclaredField("deleteFileMenuItem");
deleteFileMenuItemField.setAccessible(true);
deleteFileMenuItemField.set(repositoryLockController, deleteFileMenuItem);
XulMenuitem renameFileMenuItem = Mockito.mock(XulMenuitem.class);
Field renameFileMenuItemField = repositoryLockController.getClass().getDeclaredField("renameFileMenuItem");
renameFileMenuItemField.setAccessible(true);
renameFileMenuItemField.set(repositoryLockController, renameFileMenuItem);
Repository repository = Mockito.mock(Repository.class);
PurRepositoryMeta repositoryMeta = Mockito.mock(PurRepositoryMeta.class);
Mockito.when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
Field repositoryField = repositoryLockController.getClass().getDeclaredField("repository");
repositoryField.setAccessible(true);
repositoryField.set(repositoryLockController, repository);
ILockService service = Mockito.mock(ILockService.class);
Mockito.when(service.canUnlockFileById(objectId)).thenReturn(true);
Field serviceField = repositoryLockController.getClass().getDeclaredField("service");
serviceField.setAccessible(true);
serviceField.set(repositoryLockController, service);
repositoryLockController.setMenuItemEnabledState(selectedRepoObjects);
Assert.assertFalse(lockFileMenuItem.isDisabled());
Mockito.verify(lockFileMenuItem).setDisabled(false);
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.
the class PermissionsController method createBindings.
protected void createBindings() {
super.createBindings();
// $NON-NLS-1$
fileFolderLabel = (XulLabel) document.getElementById("file-folder-name");
// $NON-NLS-1$
aclDeck = (XulDeck) document.getElementById("acl-deck");
// $NON-NLS-1$
inheritParentPermissionCheckbox = (XulCheckbox) document.getElementById("inherit-from-parent-permission-checkbox");
bf.setBindingType(Binding.Type.ONE_WAY);
BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>> securityBindingConverter = new BindingConvertor<List<UIRepositoryObject>, List<UIRepositoryObjectAcl>>() {
@Override
public List<UIRepositoryObjectAcl> sourceToTarget(List<UIRepositoryObject> ro) {
if (ro == null) {
return null;
}
if (ro.size() <= 0) {
return null;
}
setSelectedRepositoryObject(ro);
if (!hasManageAclAccess()) {
// disable everything
applyAclButton.setDisabled(true);
addAclButton.setDisabled(true);
removeAclButton.setDisabled(true);
inheritParentPermissionCheckbox.setDisabled(true);
manageAclCheckbox.setDisabled(true);
deleteCheckbox.setDisabled(true);
writeCheckbox.setDisabled(true);
readCheckbox.setDisabled(true);
viewAclsModel.setHasManageAclAccess(false);
} else {
applyAclButton.setDisabled(false);
inheritParentPermissionCheckbox.setDisabled(false);
viewAclsModel.setHasManageAclAccess(true);
}
viewAclsModel.setRemoveEnabled(false);
List<UIRepositoryObjectAcl> selectedAclList = Collections.emptyList();
// we've moved to a new file/folder; need to clear out what the model thinks is selected
viewAclsModel.setSelectedAclList(selectedAclList);
permissionsCheckboxHandler.updateCheckboxes(EnumSet.noneOf(RepositoryFilePermission.class));
UIRepositoryObject repoObject = ro.get(0);
try {
if (repoObject instanceof IAclObject) {
((IAclObject) repoObject).getAcls(viewAclsModel);
} else {
// $NON-NLS-1$
throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
}
fileFolderLabel.setValue(// $NON-NLS-1$
BaseMessages.getString(PKG, "AclTab.UserRolePermission", repoObject.getName()));
bf.setBindingType(Binding.Type.ONE_WAY);
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(viewAclsModel, "acls", userRoleList, "elements");
updateInheritFromParentPermission();
} catch (AccessDeniedException ade) {
if (mainController == null || !mainController.handleLostRepository(ade)) {
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
ade.getLocalizedMessage()));
messageBox.open();
}
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", repoObject.getName(), // $NON-NLS-1$
e.getLocalizedMessage()));
messageBox.open();
}
}
aclDeck.setSelectedIndex(ACL);
return viewAclsModel.getAcls();
}
@Override
public List<UIRepositoryObject> targetToSource(List<UIRepositoryObjectAcl> elements) {
return null;
}
};
// Binding between the selected repository objects and the user role list for acls
securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(browseController, "repositoryObjects", userRoleList, "elements", securityBindingConverter);
securityBinding = // $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(browseController, "repositoryDirectories", userRoleList, "elements", securityBindingConverter);
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
// Binding Add Remove button to the inherit check box. If the checkbox is checked that disable add remove
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(viewAclsModel, "entriesInheriting", inheritParentPermissionCheckbox, "checked");
// Setting the default Deck to show no permission
aclDeck.setSelectedIndex(NO_ACL);
try {
if (securityBinding != null) {
securityBinding.fireSourceChanged();
}
} catch (Exception e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.
the class PermissionsController method updateInheritFromParentPermission.
/*
* public void closeApplyAclConfirmationDialog() { applyAclConfirmationDialog.hide(); }
*/
/*
* If the user check or unchecks the inherit from parent checkbox, this method is called.
*/
public void updateInheritFromParentPermission() throws AccessDeniedException {
viewAclsModel.setEntriesInheriting(inheritParentPermissionCheckbox.isChecked());
if (inheritParentPermissionCheckbox.isChecked()) {
addAclButton.setDisabled(true);
UIRepositoryObject ro = repoObject.get(0);
if (ro instanceof IAclObject) {
// force inherit to true to get effective ACLs before apply...
((IAclObject) ro).clearAcl();
((IAclObject) ro).getAcls(viewAclsModel, true);
}
permissionsCheckboxHandler.updateCheckboxes(EnumSet.noneOf(RepositoryFilePermission.class));
} else {
addAclButton.setDisabled(!hasManageAclAccess());
permissionsCheckboxHandler.processCheckboxes();
}
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.
the class RepositoryLockController method viewLockNote.
public void viewLockNote() throws Exception {
List<UIRepositoryObject> selectedRepoObjects = browseController.getSelectedFileItems();
if (selectedRepoObjects.size() > 0 && selectedRepoObjects.get(0) instanceof UIRepositoryContent) {
final UIRepositoryContent contentToLock = (UIRepositoryContent) selectedRepoObjects.get(0);
// $NON-NLS-1$
XulMessageBox msgBox = (XulMessageBox) document.createElement("messagebox");
// $NON-NLS-1$
msgBox.setTitle(BaseMessages.getString(PKG, "PurRepository.LockNote.Title"));
msgBox.setMessage(((ILockObject) contentToLock).getLockMessage());
msgBox.open();
}
}
use of org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject in project pentaho-kettle by pentaho.
the class RepositoryLockController method onDragFromLocalTable.
// Object being dragged from the file listing table
public void onDragFromLocalTable(DropEvent event) {
try {
Collection<Object> selectedRepoObjects = fileTable.getSelectedItems();
if (selectedRepoObjects.size() > 0) {
for (Object ro : selectedRepoObjects) {
if (ro instanceof UIRepositoryObject && ro instanceof ILockObject) {
final UIRepositoryContent contentToLock = (UIRepositoryContent) ro;
if (((ILockObject) contentToLock).isLocked()) {
// Content is locked, not allowed to move
event.setAccepted(false);
// $NON-NLS-1$
messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
// $NON-NLS-1$
messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
// $NON-NLS-1$
messageBox.setMessage(BaseMessages.getString(PKG, "BrowseController.MoveNotAllowed"));
messageBox.open();
break;
} else {
// Content is not locked, check default permissions
browseController.onDragFromLocalTable(event);
}
} else if (ro instanceof UIRepositoryDirectory && repositoryDirectoryHasLockedObject(event, (UIRepositoryDirectory) ro)) {
// locked content nested in this directory. move not allowed.
event.setAccepted(false);
break;
}
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations