Skip to content

Commit

Permalink
RHBPMS-5008: [Security management] Disabled assets can be edited (apa…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovmr authored and manstis committed Oct 17, 2017
1 parent 89a2f9f commit e151cad
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ protected void makeMenuBar() {
if (canUpdateProject()) {
fileMenuBuilder
.addCopy(versionRecordManager.getCurrentPath(),
fileNameValidator)
assetUpdateValidator)
.addRename(versionRecordManager.getPathToLatest(),
fileNameValidator)
.addDelete(versionRecordManager.getPathToLatest());
assetUpdateValidator)
.addDelete(versionRecordManager.getPathToLatest(),
assetUpdateValidator);
}

fileMenuBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.kie.workbench.common.widgets.client.menu.FileMenuBuilderImpl;
import org.kie.workbench.common.widgets.client.popups.validation.ValidationPopup;
import org.kie.workbench.common.widgets.metadata.client.KieEditorWrapperView;
import org.kie.workbench.common.widgets.metadata.client.validation.AssetUpdateValidator;
import org.kie.workbench.common.widgets.metadata.client.widget.OverviewWidgetPresenter;
import org.mockito.InjectMocks;
import org.mockito.Mock;
Expand All @@ -50,7 +51,6 @@
import org.uberfire.backend.vfs.Path;
import org.uberfire.ext.editor.commons.client.history.VersionRecordManager;
import org.uberfire.ext.editor.commons.client.menu.BasicFileMenuBuilder;
import org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator;
import org.uberfire.ext.widgets.common.client.common.BusyIndicatorView;
import org.uberfire.ext.widgets.common.client.common.ConcurrentChangePopup;
import org.uberfire.mocks.EventSourceMock;
Expand Down Expand Up @@ -219,10 +219,11 @@ public void testMakeMenuBar() {
presenter.makeMenuBar();

verify(fileMenuBuilder).addCopy(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder).addRename(any(Path.class),
any(DefaultFileNameValidator.class));
verify(fileMenuBuilder).addDelete(any(Path.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder).addDelete(any(Path.class),
any(AssetUpdateValidator.class));
}

@Test
Expand All @@ -234,12 +235,13 @@ public void testMakeMenuBarWithoutUpdateProjectPermission() {

verify(fileMenuBuilder,
never()).addCopy(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder,
never()).addRename(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder,
never()).addDelete(any(Path.class));
never()).addDelete(any(Path.class),
any(AssetUpdateValidator.class));
}

private class ServiceMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ public void onStartup(final ObservablePath path,
protected void makeMenuBar() {
if (canUpdateProject()) {
fileMenuBuilder
.addSave(versionRecordManager.newSaveMenuItem(this::onSave))
.addSave(versionRecordManager.newSaveMenuItem(this::saveAction))
.addCopy(versionRecordManager.getCurrentPath(),
fileNameValidator)
assetUpdateValidator)
.addRename(versionRecordManager.getPathToLatest(),
fileNameValidator)
assetUpdateValidator)
.addDelete(this::onDelete);
}

Expand Down Expand Up @@ -206,12 +206,13 @@ protected void onDelete() {
}

private void showDeletePopup(final Path path) {
deletePopUpPresenter.show(comment -> {
view.showBusyIndicator(CommonConstants.INSTANCE.Deleting());
globalsEditorService.call(getDeleteSuccessCallback(),
new HasBusyIndicatorDefaultErrorCallback(view)).delete(path,
"delete");
});
deletePopUpPresenter.show(assetUpdateValidator,
comment -> {
view.showBusyIndicator(CommonConstants.INSTANCE.Deleting());
globalsEditorService.call(getDeleteSuccessCallback(),
new HasBusyIndicatorDefaultErrorCallback(view)).delete(path,
"delete");
});
}

private RemoteCallback<Path> getDeleteSuccessCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.kie.workbench.common.widgets.client.menu.FileMenuBuilderImpl;
import org.kie.workbench.common.widgets.client.popups.validation.ValidationPopup;
import org.kie.workbench.common.widgets.metadata.client.KieEditorWrapperView;
import org.kie.workbench.common.widgets.metadata.client.validation.AssetUpdateValidator;
import org.kie.workbench.common.widgets.metadata.client.widget.OverviewWidgetPresenter;
import org.mockito.InjectMocks;
import org.mockito.Mock;
Expand All @@ -47,7 +48,6 @@
import org.uberfire.ext.editor.commons.client.file.popups.SavePopUpPresenter;
import org.uberfire.ext.editor.commons.client.history.VersionRecordManager;
import org.uberfire.ext.editor.commons.client.menu.BasicFileMenuBuilder;
import org.uberfire.ext.editor.commons.client.validation.DefaultFileNameValidator;
import org.uberfire.mocks.CallerMock;
import org.uberfire.mvp.Command;
import org.uberfire.mvp.ParameterizedCommand;
Expand Down Expand Up @@ -99,6 +99,9 @@ public class GlobalsEditorPresenterTest {
@Mock
private ProjectContext workbenchContext;

@Mock
private AssetUpdateValidator assetUpdateValidator;

private GlobalsEditorPresenter presenter;

@Before
Expand All @@ -117,6 +120,7 @@ public void setUp() {
projectController = GlobalsEditorPresenterTest.this.projectController;
workbenchContext = GlobalsEditorPresenterTest.this.workbenchContext;
versionRecordManager = GlobalsEditorPresenterTest.this.versionRecordManager;
assetUpdateValidator = GlobalsEditorPresenterTest.this.assetUpdateValidator;
}
};
}
Expand Down Expand Up @@ -190,7 +194,8 @@ public void deleteNoValidationErrors() {
verify(validationService,
times(1)).validateForDelete(any(Path.class));
verify(deletePopUpPresenter,
times(1)).show(any(ParameterizedCommand.class));
times(1)).show(eq(assetUpdateValidator),
any(ParameterizedCommand.class));
}

@Test
Expand All @@ -216,9 +221,9 @@ public void testMakeMenuBar() {

verify(fileMenuBuilder).addSave(any(MenuItem.class));
verify(fileMenuBuilder).addCopy(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder).addRename(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder).addDelete(any(Command.class));
}

Expand All @@ -233,10 +238,10 @@ public void testMakeMenuBarWithoutUpdateProjectPermission() {
never()).addSave(any(MenuItem.class));
verify(fileMenuBuilder,
never()).addCopy(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder,
never()).addRename(any(Path.class),
any(DefaultFileNameValidator.class));
any(AssetUpdateValidator.class));
verify(fileMenuBuilder,
never()).addDelete(any(Command.class));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.kie.workbench.common.widgets.metadata.client.KieMultipleDocumentEditor;
import org.kie.workbench.common.widgets.metadata.client.KieMultipleDocumentEditorWrapperView;
import org.kie.workbench.common.widgets.metadata.client.menu.RegisteredDocumentsMenuBuilder;
import org.kie.workbench.common.widgets.metadata.client.validation.AssetUpdateValidator;
import org.kie.workbench.common.widgets.metadata.client.widget.OverviewWidgetPresenter;
import org.uberfire.backend.vfs.ObservablePath;
import org.uberfire.client.mvp.PlaceManager;
Expand Down Expand Up @@ -78,7 +79,6 @@ public interface View extends RequiresResize,

protected View view;
protected Caller<GuidedDecisionTableEditorService> service;
protected Event<NotificationEvent> notification;
protected Event<DecisionTableSelectedEvent> decisionTableSelectedEvent;
protected ValidationPopup validationPopup;
protected ClientResourceType resourceType;
Expand Down Expand Up @@ -200,6 +200,12 @@ protected void setFileNameValidator(final DefaultFileNameValidator fileNameValid
super.setFileNameValidator(fileNameValidator);
}

@Override
//Delegated to expose package-protected setter for Unit Tests
protected void setAssetUpdateValidator(final AssetUpdateValidator assetUpdateValidator) {
super.setAssetUpdateValidator(assetUpdateValidator);
}

protected void init() {
viewMenuBuilder.setModeller(modeller);
insertMenuBuilder.setModeller(modeller);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ public void makeMenuBar() {
fileMenuBuilder
.addSave(getSaveMenuItem())
.addCopy(() -> getActiveDocument().getCurrentPath(),
fileNameValidator)
assetUpdateValidator)
.addRename(() -> getActiveDocument().getLatestPath(),
fileNameValidator)
.addDelete(() -> getActiveDocument().getLatestPath());
assetUpdateValidator)
.addDelete(() -> getActiveDocument().getLatestPath(),
assetUpdateValidator);
}

this.menus = fileMenuBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.enterprise.context.Dependent;
import javax.enterprise.event.Event;
Expand All @@ -37,8 +36,8 @@
import org.drools.workbench.screens.guided.dtable.client.editor.menu.ViewMenuBuilder;
import org.drools.workbench.screens.guided.dtable.client.type.GuidedDTableGraphResourceType;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableModellerView;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter.Access;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter.Access;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView;
import org.drools.workbench.screens.guided.dtable.client.widget.table.events.cdi.DecisionTableSelectedEvent;
import org.drools.workbench.screens.guided.dtable.client.wizard.NewGuidedDecisionTableWizardHelper;
Expand Down Expand Up @@ -367,10 +366,11 @@ public void makeMenuBar() {
fileMenuBuilder
.addSave(getSaveMenuItem())
.addCopy(versionRecordManager::getCurrentPath,
fileNameValidator)
assetUpdateValidator)
.addRename(versionRecordManager::getPathToLatest,
fileNameValidator)
.addDelete(versionRecordManager::getPathToLatest);
assetUpdateValidator)
.addDelete(versionRecordManager::getPathToLatest,
assetUpdateValidator);
}

this.menus = fileMenuBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.kie.workbench.common.widgets.configresource.client.widget.bound.ImportsWidgetPresenter;
import org.kie.workbench.common.widgets.metadata.client.KieMultipleDocumentEditorWrapperView;
import org.kie.workbench.common.widgets.metadata.client.menu.RegisteredDocumentsMenuBuilder;
import org.kie.workbench.common.widgets.metadata.client.validation.AssetUpdateValidator;
import org.kie.workbench.common.widgets.metadata.client.widget.OverviewWidgetPresenter;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
Expand Down Expand Up @@ -208,6 +209,9 @@ public void fire(final DecisionTableSelectedEvent event) {
@Mock
protected DefaultFileNameValidator fileNameValidator;

@Mock
protected AssetUpdateValidator assetUpdateValidator;

@Mock
protected SyncBeanManager beanManager;

Expand Down Expand Up @@ -243,6 +247,7 @@ public void setup() {
wrapped.setRegisteredDocumentsMenuBuilder(registeredDocumentsMenuBuilder);
wrapped.setFileMenuBuilder(fileMenuBuilder);
wrapped.setFileNameValidator(fileNameValidator);
wrapped.setAssetUpdateValidator(assetUpdateValidator);

this.presenter = spy(wrapped);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ public void testSetupMenuBar() {
times(1)).addSave(any(MenuItem.class));
verify(fileMenuBuilder,
times(1)).addCopy(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
times(1)).addRename(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
times(1)).addDelete(any(BasicFileMenuBuilder.PathProvider.class));
times(1)).addDelete(any(BasicFileMenuBuilder.PathProvider.class),
eq(assetUpdateValidator));
verify(fileMenuBuilder,
times(1)).addValidate(any(Command.class));
verify(fileMenuBuilder,
Expand All @@ -103,12 +104,13 @@ public void testMakeMenuBarWithoutUpdateProjectPermission() {
never()).addSave(any(MenuItem.class));
verify(fileMenuBuilder,
never()).addCopy(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
never()).addRename(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
never()).addDelete(any(BasicFileMenuBuilder.PathProvider.class));
never()).addDelete(any(BasicFileMenuBuilder.PathProvider.class),
eq(assetUpdateValidator));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import javax.enterprise.event.Event;

import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwtmockito.GwtMockitoTestRunner;
import org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52;
import org.drools.workbench.screens.guided.dtable.client.type.GuidedDTableGraphResourceType;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter.Access.LockedBy;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTablePresenter.Access.LockedBy;
import org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView;
import org.drools.workbench.screens.guided.dtable.client.widget.table.events.cdi.DecisionTableSelectedEvent;
import org.drools.workbench.screens.guided.dtable.client.wizard.NewGuidedDecisionTableWizardHelper;
import org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorContent;
import org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphContent;
import org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel.GuidedDecisionTableGraphEntry;
import org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel;
import org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorGraphModel.GuidedDecisionTableGraphEntry;
import org.drools.workbench.screens.guided.dtable.service.GuidedDecisionTableGraphEditorService;
import org.guvnor.common.services.project.model.Project;
import org.guvnor.common.services.shared.metadata.model.Metadata;
Expand All @@ -56,8 +55,8 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.uberfire.backend.vfs.ObservablePath.OnConcurrentUpdateEvent;
import org.uberfire.backend.vfs.ObservablePath;
import org.uberfire.backend.vfs.ObservablePath.OnConcurrentUpdateEvent;
import org.uberfire.backend.vfs.Path;
import org.uberfire.backend.vfs.PathFactory;
import org.uberfire.backend.vfs.impl.ObservablePathImpl;
Expand Down Expand Up @@ -308,12 +307,13 @@ public void testSetupMenuBar() {
times(1)).addSave(any(MenuItem.class));
verify(fileMenuBuilder,
times(1)).addCopy(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
times(1)).addRename(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
times(1)).addDelete(any(BasicFileMenuBuilder.PathProvider.class));
times(1)).addDelete(any(BasicFileMenuBuilder.PathProvider.class),
eq(assetUpdateValidator));
verify(fileMenuBuilder,
times(1)).addValidate(any(Command.class));
verify(fileMenuBuilder,
Expand Down Expand Up @@ -342,12 +342,13 @@ public void testMakeMenuBarWithoutUpdateProjectPermission() {
never()).addSave(any(MenuItem.class));
verify(fileMenuBuilder,
never()).addCopy(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
never()).addRename(any(BasicFileMenuBuilder.PathProvider.class),
eq(fileNameValidator));
eq(assetUpdateValidator));
verify(fileMenuBuilder,
never()).addDelete(any(BasicFileMenuBuilder.PathProvider.class));
never()).addDelete(any(BasicFileMenuBuilder.PathProvider.class),
eq(assetUpdateValidator));
}

@Test
Expand Down
Loading

0 comments on commit e151cad

Please sign in to comment.