Enable/disable buttons in action history based on user permission (#775)
* Fixed missing org.apache.logging.Log dependency in eclipse * Evaluate the user's permissions when rendering the action buttons * Added ConfimationDialog id * Fixed Sonar issues * Fixed review findings Signed-off-by: Markus Block <markus.block@bosch-si.com>
This commit is contained in:
committed by
Stefan Behl
parent
eada7cdd6f
commit
f918d32bc8
@@ -70,6 +70,11 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
@@ -139,7 +139,7 @@ public class DeploymentView extends AbstractNotificationView implements BrowserW
|
||||
|
||||
if (permChecker.hasTargetReadPermission()) {
|
||||
this.actionHistoryLayout = new ActionHistoryLayout(i18n, deploymentManagement, eventBus, uiNotification,
|
||||
managementUIState);
|
||||
managementUIState, permChecker);
|
||||
this.actionStatusLayout = new ActionStatusLayout(i18n, eventBus, managementUIState);
|
||||
this.actionStatusMsgLayout = new ActionStatusMsgLayout(i18n, eventBus, managementUIState);
|
||||
this.targetTagFilterLayout = new TargetTagFilterLayout(i18n, managementUIState,
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.eclipse.hawkbit.repository.exception.CancelActionNotAllowedException;
|
||||
import org.eclipse.hawkbit.repository.model.Action;
|
||||
import org.eclipse.hawkbit.repository.model.Action.ActionType;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.ui.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.common.ConfirmationDialog;
|
||||
import org.eclipse.hawkbit.ui.common.grid.AbstractGrid;
|
||||
import org.eclipse.hawkbit.ui.common.table.BaseEntityEventType;
|
||||
@@ -116,10 +117,12 @@ public class ActionHistoryGrid extends AbstractGrid<LazyQueryContainer> {
|
||||
* @param eventBus
|
||||
* @param notification
|
||||
* @param managementUIState
|
||||
* @param permissionChecker
|
||||
*/
|
||||
protected ActionHistoryGrid(final VaadinMessageSource i18n, final DeploymentManagement deploymentManagement,
|
||||
final UIEventBus eventBus, final UINotification notification, final ManagementUIState managementUIState) {
|
||||
super(i18n, eventBus, null);
|
||||
final UIEventBus eventBus, final UINotification notification, final ManagementUIState managementUIState,
|
||||
final SpPermissionChecker permissionChecker) {
|
||||
super(i18n, eventBus, permissionChecker);
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
this.notification = notification;
|
||||
this.managementUIState = managementUIState;
|
||||
@@ -239,19 +242,22 @@ public class ActionHistoryGrid extends AbstractGrid<LazyQueryContainer> {
|
||||
}
|
||||
|
||||
private StatusFontIcon createCancelButtonMetadata(final Action action) {
|
||||
final boolean isDisabled = !action.isActive() || action.isCancelingOrCanceled();
|
||||
final boolean isDisabled = !action.isActive() || action.isCancelingOrCanceled()
|
||||
|| !permissionChecker.hasUpdateTargetPermission();
|
||||
return new StatusFontIcon(FontAwesome.TIMES, STATUS_ICON_NEUTRAL, i18n.getMessage("message.cancel.action"),
|
||||
UIComponentIdProvider.ACTION_HISTORY_TABLE_CANCEL_ID, isDisabled);
|
||||
}
|
||||
|
||||
private StatusFontIcon createForceButtonMetadata(final Action action) {
|
||||
final boolean isDisabled = !action.isActive() || action.isForce() || action.isCancelingOrCanceled();
|
||||
final boolean isDisabled = !action.isActive() || action.isForce() || action.isCancelingOrCanceled()
|
||||
|| !permissionChecker.hasUpdateTargetPermission();
|
||||
return new StatusFontIcon(FontAwesome.BOLT, STATUS_ICON_NEUTRAL, i18n.getMessage("message.force.action"),
|
||||
UIComponentIdProvider.ACTION_HISTORY_TABLE_FORCE_ID, isDisabled);
|
||||
}
|
||||
|
||||
private StatusFontIcon createForceQuitButtonMetadata(final Action action) {
|
||||
final boolean isDisabled = !action.isActive() || !action.isCancelingOrCanceled();
|
||||
final boolean isDisabled = !action.isActive() || !action.isCancelingOrCanceled()
|
||||
|| !permissionChecker.hasUpdateTargetPermission();
|
||||
return new StatusFontIcon(FontAwesome.TIMES, STATUS_ICON_RED, i18n.getMessage("message.forcequit.action"),
|
||||
UIComponentIdProvider.ACTION_HISTORY_TABLE_FORCE_QUIT_ID, isDisabled);
|
||||
}
|
||||
@@ -313,7 +319,7 @@ public class ActionHistoryGrid extends AbstractGrid<LazyQueryContainer> {
|
||||
deploymentManagement.forceTargetAction(actionId);
|
||||
populateAndUpdateTargetDetails(selectedTarget);
|
||||
notification.displaySuccess(i18n.getMessage("message.force.action.success"));
|
||||
});
|
||||
}, UIComponentIdProvider.CONFIRMATION_POPUP_ID);
|
||||
UI.getCurrent().addWindow(confirmDialog.getWindow());
|
||||
|
||||
confirmDialog.getWindow().bringToFront();
|
||||
@@ -341,7 +347,7 @@ public class ActionHistoryGrid extends AbstractGrid<LazyQueryContainer> {
|
||||
} else {
|
||||
notification.displayValidationError(i18n.getMessage("message.forcequit.action.failed"));
|
||||
}
|
||||
}, FontAwesome.WARNING);
|
||||
}, FontAwesome.WARNING, UIComponentIdProvider.CONFIRMATION_POPUP_ID, null);
|
||||
UI.getCurrent().addWindow(confirmDialog.getWindow());
|
||||
|
||||
confirmDialog.getWindow().bringToFront();
|
||||
@@ -372,7 +378,7 @@ public class ActionHistoryGrid extends AbstractGrid<LazyQueryContainer> {
|
||||
} else {
|
||||
notification.displayValidationError(i18n.getMessage("message.cancel.action.failed"));
|
||||
}
|
||||
});
|
||||
}, UIComponentIdProvider.CONFIRMATION_POPUP_ID);
|
||||
UI.getCurrent().addWindow(confirmDialog.getWindow());
|
||||
confirmDialog.getWindow().bringToFront();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DeploymentManagement;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.ui.SpPermissionChecker;
|
||||
import org.eclipse.hawkbit.ui.common.grid.AbstractGrid;
|
||||
import org.eclipse.hawkbit.ui.common.grid.AbstractGridComponentLayout;
|
||||
import org.eclipse.hawkbit.ui.common.grid.DefaultGridHeader;
|
||||
@@ -47,6 +48,8 @@ public class ActionHistoryLayout extends AbstractGridComponentLayout {
|
||||
|
||||
private final String actionHistoryCaption;
|
||||
|
||||
private final SpPermissionChecker permChecker;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -55,13 +58,16 @@ public class ActionHistoryLayout extends AbstractGridComponentLayout {
|
||||
* @param eventBus
|
||||
* @param notification
|
||||
* @param managementUIState
|
||||
* @param permChecker
|
||||
*/
|
||||
public ActionHistoryLayout(final VaadinMessageSource i18n, final DeploymentManagement deploymentManagement,
|
||||
final UIEventBus eventBus, final UINotification notification, final ManagementUIState managementUIState) {
|
||||
final UIEventBus eventBus, final UINotification notification, final ManagementUIState managementUIState,
|
||||
final SpPermissionChecker permChecker) {
|
||||
super(i18n, eventBus);
|
||||
this.deploymentManagement = deploymentManagement;
|
||||
this.notification = notification;
|
||||
this.managementUIState = managementUIState;
|
||||
this.permChecker = permChecker;
|
||||
actionHistoryCaption = getActionHistoryCaption();
|
||||
init();
|
||||
}
|
||||
@@ -89,7 +95,8 @@ public class ActionHistoryLayout extends AbstractGridComponentLayout {
|
||||
|
||||
@Override
|
||||
public ActionHistoryGrid createGrid() {
|
||||
return new ActionHistoryGrid(getI18n(), deploymentManagement, getEventBus(), notification, managementUIState);
|
||||
return new ActionHistoryGrid(getI18n(), deploymentManagement, getEventBus(), notification, managementUIState,
|
||||
permChecker);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.UI)
|
||||
|
||||
Reference in New Issue
Block a user