Skip to content

Commit

Permalink
fixed metadata permissions for entity details header metadata icons, …
Browse files Browse the repository at this point in the history
…details metadata grid, metadata window header, grid and input fields (#1035)

Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch.io>
  • Loading branch information
bogdan-bondar committed Oct 22, 2020
1 parent c75b481 commit ac2d482
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
*/
package org.eclipse.hawkbit.ui.artifacts.smtable;

import java.util.function.BooleanSupplier;

import org.eclipse.hawkbit.ui.common.detailslayout.MetaDataAddUpdateWindowLayout;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;

import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.VerticalLayout;

/**
* Class for sm metadata add/update window layout.
Expand All @@ -24,23 +26,28 @@ public class SmMetaDataAddUpdateWindowLayout extends MetaDataAddUpdateWindowLayo
* Constructor for AbstractTagWindowLayout
*
* @param i18n
* I18N
* VaadinMessageSource
* @param hasMetadataChangePermission
* checks the permission allowing to change metadata entities
*/
public SmMetaDataAddUpdateWindowLayout(final VaadinMessageSource i18n) {
super(i18n);
public SmMetaDataAddUpdateWindowLayout(final VaadinMessageSource i18n,
final BooleanSupplier hasMetadataChangePermission) {
super(i18n, hasMetadataChangePermission);

this.isVisibleForTarget = metaDataComponentBuilder.createVisibleForTargetsField(binder);
}

/**
* @return form layout checkbox container for software module
*/
@Override
public ComponentContainer getRootComponent() {
final ComponentContainer formLayout = super.getRootComponent();
protected VerticalLayout getMetadataAddUpdateLayout() {
final VerticalLayout addUpdateLayout = super.getMetadataAddUpdateLayout();
addUpdateLayout.addComponent(isVisibleForTarget);

formLayout.addComponent(isVisibleForTarget);
return addUpdateLayout;
}

return formLayout;
@Override
protected void disableMetadataInputComponents() {
super.disableMetadataInputComponents();
isVisibleForTarget.setEnabled(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public SmMetaDataWindowLayout(final VaadinMessageSource i18n, final UIEventBus e
this.entityFactory = entityFactory;

this.smMetaDataWindowGrid = new MetaDataWindowGrid<>(i18n, eventBus, permChecker, uiNotification,
new SmMetaDataDataProvider(smManagement), this::deleteMetaData);
new SmMetaDataDataProvider(smManagement), this::hasMetadataChangePermission, this::deleteMetaData);

this.smMetaDataAddUpdateWindowLayout = new SmMetaDataAddUpdateWindowLayout(i18n);
this.smMetaDataAddUpdateWindowLayout = new SmMetaDataAddUpdateWindowLayout(i18n,
this::hasMetadataChangePermission);
this.addSmMetaDataWindowController = new AddMetaDataWindowController(i18n, uiNotification,
smMetaDataAddUpdateWindowLayout, this::createMetaData, this::isDuplicate);
this.updateSmMetaDataWindowController = new UpdateMetaDataWindowController(i18n, uiNotification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public abstract class AbstractMetaDataWindowLayout<F> extends HorizontalLayout {
protected final VaadinMessageSource i18n;
protected final transient UIEventBus eventBus;
protected final UINotification uiNotification;
protected final SpPermissionChecker permChecker;

private final MetadataWindowGridHeader metadataWindowGridHeader;

Expand All @@ -62,9 +63,23 @@ public AbstractMetaDataWindowLayout(final VaadinMessageSource i18n, final UIEven
this.i18n = i18n;
this.eventBus = eventBus;
this.uiNotification = uiNotification;
this.permChecker = permChecker;

this.metadataWindowGridHeader = new MetadataWindowGridHeader(i18n, permChecker, eventBus,
this::showAddMetaDataLayout);
this::hasMetadataChangePermission, this::showAddMetaDataLayout);
}

// can be overriden in child classes for entity-specific permission
protected boolean hasMetadataChangePermission() {
return permChecker.hasUpdateRepositoryPermission();
}

private void showAddMetaDataLayout() {
getMetaDataWindowGrid().deselectAll();
getAddMetaDataWindowController().populateWithData(null);
saveCallback.accept(getAddMetaDataWindowController().getSaveDialogCloseListener());

resetSaveButton();
}

protected MetaData createMetaData(final ProxyMetaData entity) {
Expand Down Expand Up @@ -129,14 +144,6 @@ protected boolean deleteMetaData(final Collection<ProxyMetaData> metaDataToDelet

protected abstract void doDeleteMetaDataByKey(final String metaDataKey);

private void showAddMetaDataLayout() {
getMetaDataWindowGrid().deselectAll();
getAddMetaDataWindowController().populateWithData(null);
saveCallback.accept(getAddMetaDataWindowController().getSaveDialogCloseListener());

resetSaveButton();
}

/**
* @return add meta data window controller
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public class DistributionSetDetailsHeader extends AbstractDetailsHeader<ProxyDis
* Constructor for DistributionSetDetailsHeader
*
* @param i18n
* VaadinMessageSource
* VaadinMessageSource
* @param permChecker
* SpPermissionChecker
* SpPermissionChecker
* @param eventBus
* UIEventBus
* UIEventBus
* @param uiNotification
* UINotification
* UINotification
* @param dsWindowBuilder
* DsWindowBuilder
* DsWindowBuilder
* @param dsMetaDataWindowBuilder
* DsMetaDataWindowBuilder
* DsMetaDataWindowBuilder
*/
public DistributionSetDetailsHeader(final VaadinMessageSource i18n, final SpPermissionChecker permChecker,
final UIEventBus eventBus, final UINotification uiNotification, final DsWindowBuilder dsWindowBuilder,
Expand Down Expand Up @@ -72,11 +72,6 @@ protected String getMasterEntityName(final ProxyDistributionSet masterEntity) {
return masterEntity.getNameVersion();
}

@Override
protected boolean hasEditPermission() {
return permChecker.hasUpdateRepositoryPermission();
}

@Override
protected String getEditIconId() {
return UIComponentIdProvider.DS_EDIT_BUTTON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.ui.common.detailslayout;

import java.util.function.BooleanSupplier;

import org.eclipse.hawkbit.ui.common.AbstractEntityWindowLayout;
import org.eclipse.hawkbit.ui.common.data.proxies.ProxyMetaData;
import org.eclipse.hawkbit.ui.utils.VaadinMessageSource;
Expand All @@ -21,6 +23,7 @@
* Class for metadata add/update window layout.
*/
public class MetaDataAddUpdateWindowLayout extends AbstractEntityWindowLayout<ProxyMetaData> {
private final BooleanSupplier hasMetadataChangePermission;
protected final MetaDataAddUpdateWindowLayoutComponentBuilder metaDataComponentBuilder;

private final TextField metadataKey;
Expand All @@ -30,11 +33,15 @@ public class MetaDataAddUpdateWindowLayout extends AbstractEntityWindowLayout<Pr
* Constructor for AbstractTagWindowLayout
*
* @param i18n
* I18N
* VaadinMessageSource
* @param hasMetadataChangePermission
* checks the permission allowing to change metadata entities
*/
public MetaDataAddUpdateWindowLayout(final VaadinMessageSource i18n) {
public MetaDataAddUpdateWindowLayout(final VaadinMessageSource i18n,
final BooleanSupplier hasMetadataChangePermission) {
super();

this.hasMetadataChangePermission = hasMetadataChangePermission;
this.metaDataComponentBuilder = new MetaDataAddUpdateWindowLayoutComponentBuilder(i18n);

this.metadataKey = metaDataComponentBuilder.createKeyField(binder);
Expand All @@ -43,6 +50,16 @@ public MetaDataAddUpdateWindowLayout(final VaadinMessageSource i18n) {

@Override
public ComponentContainer getRootComponent() {
final VerticalLayout addUpdateLayout = getMetadataAddUpdateLayout();

if (!hasMetadataChangePermission.getAsBoolean()) {
disableMetadataInputComponents();
}

return addUpdateLayout;
}

protected VerticalLayout getMetadataAddUpdateLayout() {
final VerticalLayout addUpdateLayout = new VerticalLayout();
addUpdateLayout.setSpacing(true);
addUpdateLayout.setMargin(false);
Expand All @@ -57,11 +74,18 @@ public ComponentContainer getRootComponent() {
return addUpdateLayout;
}

protected void disableMetadataInputComponents() {
metadataKey.setEnabled(false);
metadataValue.setEnabled(false);
}

/**
* Enable meta data key
*/
public void enableMetadataKey() {
metadataKey.setEnabled(true);
if (hasMetadataChangePermission.getAsBoolean()) {
metadataKey.setEnabled(true);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package org.eclipse.hawkbit.ui.common.detailslayout;

import java.util.Collection;
import java.util.function.BooleanSupplier;
import java.util.function.Predicate;

import org.eclipse.hawkbit.ui.SpPermissionChecker;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class MetaDataWindowGrid<F> extends AbstractGrid<ProxyMetaData, F> implem
public static final String META_DATA_VALUE_ID = "metaDataValue";
public static final String META_DATA_DELETE_BUTTON_ID = "metaDataDeleteButton";

private final transient BooleanSupplier hasMetadataChangePermission;
private final transient DeleteSupport<ProxyMetaData> metaDataDeleteSupport;

/**
Expand All @@ -52,17 +54,20 @@ public class MetaDataWindowGrid<F> extends AbstractGrid<ProxyMetaData, F> implem
* @param notification
* UINotification
* @param dataProvider
* AbstractMetaDataDataProvider for filter support
* provides entity-specific metadata entities
* @param hasMetadataChangePermission
* checks the permission allowing to change metadata entities
* @param itemsDeletionCallback
* Grid item deletion Call back for event listener
* callback method to delete metadata entities
*
*/
public MetaDataWindowGrid(final VaadinMessageSource i18n, final UIEventBus eventBus,
final SpPermissionChecker permissionChecker, final UINotification notification,
final AbstractMetaDataDataProvider<?, F> dataProvider,
final AbstractMetaDataDataProvider<?, F> dataProvider, final BooleanSupplier hasMetadataChangePermission,
final Predicate<Collection<ProxyMetaData>> itemsDeletionCallback) {
super(i18n, eventBus, permissionChecker);

this.hasMetadataChangePermission = hasMetadataChangePermission;
this.metaDataDeleteSupport = new DeleteSupport<>(this, i18n, notification, "caption.metadata",
"caption.metadata.plur", ProxyMetaData::getKey, itemsDeletionCallback,
UIComponentIdProvider.METADATA_DELETE_CONFIRMATION_DIALOG);
Expand All @@ -79,7 +84,7 @@ public MetaDataWindowGrid(final VaadinMessageSource i18n, final UIEventBus event

@Override
public String getGridId() {
return UIComponentIdProvider.METDATA_WINDOW_TABLE_ID;
return UIComponentIdProvider.METADATA_WINDOW_TABLE_ID;
}

@Override
Expand All @@ -91,7 +96,7 @@ public void addColumns() {
.setCaption(i18n.getMessage("header.value")).setHidden(true).setHidable(true);

GridComponentBuilder.addDeleteColumn(this, i18n, META_DATA_DELETE_BUTTON_ID, metaDataDeleteSupport,
UIComponentIdProvider.META_DATA_DELET_ICON, e -> permissionChecker.hasDeleteRepositoryPermission());
UIComponentIdProvider.META_DATA_DELET_ICON, e -> hasMetadataChangePermission.getAsBoolean());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void init() {

@Override
public String getGridId() {
return typePrefix + "." + UIComponentIdProvider.METDATA_DETAILS_TABLE_ID;
return typePrefix + "." + UIComponentIdProvider.METADATA_DETAILS_TABLE_ID;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
*/
package org.eclipse.hawkbit.ui.common.detailslayout;

import java.util.function.BooleanSupplier;

import org.eclipse.hawkbit.ui.SpPermissionChecker;
import org.eclipse.hawkbit.ui.common.grid.header.AbstractGridHeader;
import org.eclipse.hawkbit.ui.common.grid.header.support.AddHeaderSupport;
Expand Down Expand Up @@ -35,15 +37,18 @@ public class MetadataWindowGridHeader extends AbstractGridHeader {
* SpPermissionChecker
* @param eventBus
* UIEventBus
* @param hasMetadataChangePermission
* checks the permission allowing to change metadata entities
* @param addNewItemCallback
* Runnable
* callback method to add new metadata entities
*/
public MetadataWindowGridHeader(final VaadinMessageSource i18n, final SpPermissionChecker permChecker,
final UIEventBus eventBus, final Runnable addNewItemCallback) {
final UIEventBus eventBus, final BooleanSupplier hasMetadataChangePermission,
final Runnable addNewItemCallback) {
super(i18n, permChecker, eventBus);

if (permChecker.hasCreateRepositoryPermission()) {
this.addHeaderSupport = new AddHeaderSupport(i18n, UIComponentIdProvider.METADTA_ADD_ICON_ID,
if (hasMetadataChangePermission.getAsBoolean()) {
this.addHeaderSupport = new AddHeaderSupport(i18n, UIComponentIdProvider.METADATA_ADD_ICON_ID,
addNewItemCallback, () -> false);
} else {
this.addHeaderSupport = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ public void masterEntityChanged(final ProxySoftwareModule entity) {
}
}

@Override
protected boolean hasEditPermission() {
return permChecker.hasUpdateRepositoryPermission();
}

@Override
protected String getEditIconId() {
return UIComponentIdProvider.UPLOAD_SW_MODULE_EDIT_BUTTON;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Header for entity details with edit and metadata support.
*
* @param <T>
* Generic type
* Generic type
*/
public abstract class AbstractDetailsHeader<T> extends AbstractMasterAwareGridHeader<T> {
private static final long serialVersionUID = 1L;
Expand All @@ -37,13 +37,13 @@ public abstract class AbstractDetailsHeader<T> extends AbstractMasterAwareGridHe
* Constructor for AbstractDetailsHeader
*
* @param i18n
* VaadinMessageSource
* VaadinMessageSource
* @param permChecker
* SpPermissionChecker
* SpPermissionChecker
* @param eventBus
* UIEventBus
* UIEventBus
* @param uiNotification
* UINotification
* UINotification
*/
public AbstractDetailsHeader(final VaadinMessageSource i18n, final SpPermissionChecker permChecker,
final UIEventBus eventBus, final UINotification uiNotification) {
Expand All @@ -53,17 +53,29 @@ public AbstractDetailsHeader(final VaadinMessageSource i18n, final SpPermissionC

if (hasEditPermission()) {
this.editDetailsHeaderSupport = new EditDetailsHeaderSupport(i18n, getEditIconId(), this::onEdit);
} else {
this.editDetailsHeaderSupport = null;
}

if (hasMetadataReadPermission()) {
this.metaDataDetailsHeaderSupport = new MetaDataDetailsHeaderSupport(i18n, getMetaDataIconId(),
this::showMetaData);
} else {
this.editDetailsHeaderSupport = null;
this.metaDataDetailsHeaderSupport = null;
}

addHeaderSupports(Arrays.asList(editDetailsHeaderSupport, metaDataDetailsHeaderSupport));
}

protected abstract boolean hasEditPermission();
// can be overriden in child classes for entity-specific permission
protected boolean hasEditPermission() {
return permChecker.hasUpdateRepositoryPermission();
}

// can be overriden in child classes for entity-specific permission
protected boolean hasMetadataReadPermission() {
return permChecker.hasReadRepositoryPermission();
}

protected abstract String getEditIconId();

Expand Down
Loading

0 comments on commit ac2d482

Please sign in to comment.