Skip to content

Commit

Permalink
Fixes for PageHistory:
Browse files Browse the repository at this point in the history
1. Fix for object history displaying.
2. Fix for redirection.
3. Fix for authorization in services and organization history.
  • Loading branch information
tchrapovic committed Aug 15, 2022
1 parent 06e29a3 commit a28e7d1
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5471,9 +5471,9 @@ public static IModel<String> createMappingDescription(IModel<PrismContainerValue
}

//TODO
public static <T extends ObjectType> Panel createPanel(Class<? extends Panel> panelClass, String markupId, ObjectDetailsModels<T> objectDetailsModels, ContainerPanelConfigurationType panelConfig) {
public static <T extends ObjectType> Component createPanel(Class<? extends Panel> panelClass, String markupId, ObjectDetailsModels<T> objectDetailsModels, ContainerPanelConfigurationType panelConfig) {
if (panelClass == null) {
return null;
return new WebMarkupContainer(markupId);
}

if (AbstractAssignmentTypePanel.class.isAssignableFrom(panelClass)) {
Expand All @@ -5494,7 +5494,7 @@ public static <T extends ObjectType> Panel createPanel(Class<? extends Panel> pa
e.printStackTrace();
LOGGER.trace("No constructor found for (String, LoadableModel, ContainerPanelConfigurationType). Continue with lookup.", e);
}
return null;
return new WebMarkupContainer(markupId);
}

public static PrismObject<ResourceType> findResource(PrismPropertyWrapper itemWrapper, PrismPropertyPanelContext panelCtx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,12 @@ private void initMainPanel(ContainerPanelConfigurationType panelConfig, Midpoint

getSessionStorage().setObjectDetailsStorage("details" + getType().getSimpleName(), panelConfig);
String panelType = panelConfig.getPanelType();
if (panelType == null) {
addErrorPanel(false, form, MessagePanel.MessagePanelType.ERROR,"AbstractPageObjectDetails.panelTypeUndefined", panelConfig.getIdentifier());
return;
if (panelType == null && LOGGER.isDebugEnabled()) {
LOGGER.debug("AbstractPageObjectDetails.panelTypeUndefined {}", panelConfig.getIdentifier());
}

Class<? extends Panel> panelClass = findObjectPanel(panelType);
Panel panel = WebComponentUtil.createPanel(panelClass, ID_MAIN_PANEL, objectDetailsModels, panelConfig);
Component panel = WebComponentUtil.createPanel(panelClass, ID_MAIN_PANEL, objectDetailsModels, panelConfig);
panel.add(AttributeAppender.append("class", () -> {
List panels = getPanelConfigurations().getObject();
if (panels == null || panels.size() <= 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import java.util.Collection;
import java.util.List;

import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto;

import org.apache.wicket.model.LoadableDetachableModel;
import org.jetbrains.annotations.NotNull;

Expand All @@ -37,6 +35,7 @@
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand All @@ -50,8 +49,19 @@ public class FocusDetailsModels<F extends FocusType> extends AssignmentHolderDet
private LoadableDetachableModel<List<ShadowWrapper>> projectionModel;
private final LoadableModel<ExecuteChangeOptionsDto> executeOptionsModel;
private boolean isSelfProfile = false;
private boolean history;

private static final String PANEL_TYPE_BASIC = "basic";
private static final String PANEL_TYPE_ASSIGNMENTS = "assignments";
private static final String PANEL_TYPE_ACTIVATION = "activation";
private static final String PANEL_TYPE_PASSWORD = "password";
private static final String PANEL_TYPE_DELEGATED_TO_ME = "delegatedToMe";

public FocusDetailsModels(LoadableDetachableModel<PrismObject<F>> prismObjectModel, PageBase serviceLocator) {
this(prismObjectModel, false, serviceLocator);
}

public FocusDetailsModels(LoadableDetachableModel<PrismObject<F>> prismObjectModel, boolean history, PageBase serviceLocator) {
super(prismObjectModel, serviceLocator);

projectionModel = new LoadableDetachableModel<>() {
Expand All @@ -71,6 +81,51 @@ protected ExecuteChangeOptionsDto load() {
return ExecuteChangeOptionsDto.createFromSystemConfiguration();
}
};
this.history = history;
}

@Override
protected GuiObjectDetailsPageType loadDetailsPageConfiguration() {
if (history) {
GuiObjectDetailsPageType guiObjectDetailsPageType = super.loadDetailsPageConfiguration().clone();
List<ContainerPanelConfigurationType> containerPanelConfigurationTypeList = guiObjectDetailsPageType.getPanel();
hiddeSpecificPanel(containerPanelConfigurationTypeList, visiblePanelIdentifierList());

return guiObjectDetailsPageType;
}

return super.loadDetailsPageConfiguration();
}

private void hiddeSpecificPanel(List<ContainerPanelConfigurationType> item, List<String> visiblePanelIdentifierList) {
for (ContainerPanelConfigurationType containerPanelConfigurationType : item) {
String identifier = containerPanelConfigurationType
.getIdentifier();

if (identifier == null) {
continue;
}

if (!visiblePanelIdentifierList.contains(identifier)) {
containerPanelConfigurationType.setVisibility(UserInterfaceElementVisibilityType.HIDDEN);
}
}
}

@Override
protected boolean isReadonly() {
return history;
}

private List<String> visiblePanelIdentifierList() {
ArrayList<String> visiblePanelIdentifier = new ArrayList<>();
visiblePanelIdentifier.add(PANEL_TYPE_BASIC);
visiblePanelIdentifier.add(PANEL_TYPE_DELEGATED_TO_ME);
visiblePanelIdentifier.add(PANEL_TYPE_PASSWORD);
visiblePanelIdentifier.add(PANEL_TYPE_ACTIVATION);
visiblePanelIdentifier.add(PANEL_TYPE_ASSIGNMENTS);

return visiblePanelIdentifier;
}

private List<ShadowWrapper> loadShadowWrappers() {
Expand Down Expand Up @@ -363,6 +418,6 @@ protected List<ObjectDelta<? extends ObjectType>> getAdditionalModifyDeltas(Oper
}

public LoadableModel<ExecuteChangeOptionsDto> getExecuteOptionsModel() {
return executeOptionsModel;
return this.executeOptionsModel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
*/
package com.evolveum.midpoint.gui.impl.page.admin.focus.component;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
Expand All @@ -15,7 +27,6 @@
import com.evolveum.midpoint.gui.impl.page.admin.role.PageRoleHistory;
import com.evolveum.midpoint.gui.impl.page.admin.service.PageServiceHistory;
import com.evolveum.midpoint.gui.impl.page.admin.user.PageUserHistory;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand All @@ -39,18 +50,6 @@
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventStageType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import java.util.List;

/**
* Created by honchar.
*/
Expand All @@ -66,6 +65,11 @@ public class FocusHistoryPanel<F extends FocusType> extends AbstractObjectMainPa
private static final String DOT_CLASS = FocusHistoryPanel.class.getName() + ".";
private static final String OPERATION_RESTRUCT_OBJECT = DOT_CLASS + "restructObject";

private static final String OID_PARAMETER_LABEL = "oid";
private static final String EID_PARAMETER_LABEL = "eventIdentifier";
private static final String DATE_PARAMETER_LABEL = "date";
private static final String CLASS_TYPE_PARAMETER_LABEL = "classType";

public FocusHistoryPanel(String id, FocusDetailsModels<F> focusModel, ContainerPanelConfigurationType config) {
super(id, focusModel, config);
}
Expand Down Expand Up @@ -106,8 +110,9 @@ protected Component createButton(int index, String componentId, IModel<Selectabl
createStringResource("ObjectHistoryTabPanel.viewHistoricalObjectDataTitle"),
new Model<>("btn btn-sm " + DoubleButtonColumn.ButtonColorClass.INFO),
target ->
currentStateButtonClicked(target, getReconstructedObject(getObjectWrapper().getOid(),
unwrapModel(model).getEventIdentifier(), getObjectWrapper().getCompileTimeClass()),
currentStateButtonClicked(getObjectWrapper().getOid(),
unwrapModel(model).getEventIdentifier(),
getObjectWrapper().getCompileTimeClass(),
WebComponentUtil.getLocalizedDate(unwrapModel(model).getTimestamp(), DateLabelComponent.SHORT_NOTIME_STYLE)));
break;
case 1:
Expand Down Expand Up @@ -163,63 +168,53 @@ protected boolean isObjectHistoryPanel() {
add(panel);
}

protected void currentStateButtonClicked(AjaxRequestTarget target, PrismObject<F> object, String date) {
Class<F> objectClass = object.getCompileTimeClass();
protected void currentStateButtonClicked(String oid, String eventIdentifier, Class<F> type, String date) {
PrismObject<F> object = getReconstructedObject(oid, eventIdentifier, type);

//TODO fix sessionStorage
getPageBase().getSessionStorage().setObjectDetailsStorage("details" + type.getSimpleName(),null);

PageParameters pageParameters = new PageParameters();
pageParameters.add(OID_PARAMETER_LABEL, oid);
pageParameters.add(EID_PARAMETER_LABEL, eventIdentifier);
pageParameters.add(DATE_PARAMETER_LABEL, date);

Class<F> objectClass = null;
if (object != null) {
objectClass = object.getCompileTimeClass();
}
if (UserType.class.equals(objectClass)) {
getPageBase().navigateToNext(new PageUserHistory((PrismObject<UserType>) object, date));
getPageBase().navigateToNext(PageUserHistory.class, pageParameters);
} else if (RoleType.class.equals(objectClass)) {
getPageBase().navigateToNext(new PageRoleHistory((PrismObject<RoleType>) object, date));
getPageBase().navigateToNext(PageRoleHistory.class,pageParameters);
} else if (OrgType.class.equals(objectClass)) {
getPageBase().navigateToNext(new PageOrgHistory((PrismObject<OrgType>) object, date));
getPageBase().navigateToNext(PageOrgHistory.class,pageParameters);
} else if (ServiceType.class.equals(objectClass)) {
getPageBase().navigateToNext(new PageServiceHistory((PrismObject<ServiceType>) object, date));
getPageBase().navigateToNext(PageServiceHistory.class,pageParameters);
}
}

private PrismObject<F> getReconstructedObject(String oid, String eventIdentifier,
Class type) {
Class<F> type) {
OperationResult result = new OperationResult(OPERATION_RESTRUCT_OBJECT);
try {
Task task = getPageBase().createSimpleTask(OPERATION_RESTRUCT_OBJECT);
PrismObject<F> object = WebModelServiceUtils.reconstructObject(type, oid, eventIdentifier, task, result);
return object;
return WebModelServiceUtils.reconstructObject(type, oid, eventIdentifier, task, result);
} catch (Exception ex) {
result.recordFatalError(getPageBase().createStringResource("ObjectHistoryTabPanel.message.getReconstructedObject.fatalError").getString(), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't restruct object", ex);
}
return null;
}

private void viewObjectXmlButtonClicked(String oid, String eventIdentifier, Class type, String date) {
PrismObject<F> object = getReconstructedObject(oid, eventIdentifier, type);
String name = WebComponentUtil.getName(object);

getPageBase().navigateToNext(new PageXmlDataReview(getPageBase().createStringResource("PageXmlDataReview.aceEditorPanelTitle", name, date),
new IModel<String>() {
private static final long serialVersionUID = 1L;
private void viewObjectXmlButtonClicked(String oid, String eventIdentifier, Class<F> type, String date) {
PageParameters pageParameters = new PageParameters();
pageParameters.add(OID_PARAMETER_LABEL, oid);
pageParameters.add(EID_PARAMETER_LABEL, eventIdentifier);
pageParameters.add(DATE_PARAMETER_LABEL, date);
pageParameters.add(CLASS_TYPE_PARAMETER_LABEL, type.getName());

@Override
public String getObject() {
PrismContext context = getPageBase().getPrismContext();
String xml = "";
try {
xml = context.xmlSerializer().serialize(object);
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't serialize object", ex);
}
return xml;
}

@Override
public void setObject(String s) {

}

@Override
public void detach() {

}
}));
getPageBase().navigateToNext(PageXmlDataReview.class, pageParameters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

import com.evolveum.midpoint.gui.impl.page.admin.assignmentholder.FocusDetailsModels;

import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.LoggingUtils;

import org.apache.wicket.model.IModel;

import com.evolveum.midpoint.authentication.api.authorization.AuthorizationAction;
Expand All @@ -21,12 +25,14 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType;

import org.apache.wicket.request.mapper.parameter.PageParameters;

/**
* Created by honchar.
*/
@PageDescriptor(
urls = {
@Url(mountUrl = "/admin/orgHistory", matchUrlForSecurity = "/admin/orgUnitHistory")
@Url(mountUrl = "/admin/orgHistory", matchUrlForSecurity = "/admin/orgHistory")
},
action = {
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_ORG_ALL_URL,
Expand All @@ -40,28 +46,25 @@ public class PageOrgHistory extends PageOrg {

private static final String DOT_CLASS = PageOrgHistory.class.getName() + ".";
private static final Trace LOGGER = TraceManager.getTrace(PageOrgHistory.class);
private String date = "";

public PageOrgHistory(final PrismObject<OrgType> org, String date) {
super(org);
this.date = date;

private static final String OPERATION_RESTRUCT_OBJECT = DOT_CLASS + "restructObject";
private static final String OID_PARAMETER_LABEL = "oid";
private static final String EID_PARAMETER_LABEL = "eventIdentifier";
private static final String DATE_PARAMETER_LABEL = "date";

public PageOrgHistory(PageParameters pageParameters) {
super(pageParameters);
}

@Override
protected FocusDetailsModels<OrgType> createObjectDetailsModels(PrismObject<OrgType> object) {
return new FocusDetailsModels<OrgType>(createPrismObjectModel(object), this) {
private static final long serialVersionUID = 1L;

@Override
protected boolean isReadonly() {
return true;
}
};
return new FocusDetailsModels<>(createPrismObjectModel(getReconstructedObject()), true, this);
}

@Override
protected IModel<String> createPageTitleModel() {
return new LoadableModel<String>() {
return new LoadableModel<>() {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -70,9 +73,35 @@ protected String load() {
if (getModelObjectType() != null) {
name = WebComponentUtil.getName(getModelObjectType());
}
return createStringResource("PageUserHistory.title", name, date).getObject();
return createStringResource("PageUserHistory.title", name, getDate()).getObject();
}
};
}

private PrismObject<OrgType> getReconstructedObject() {
OperationResult result = new OperationResult(OPERATION_RESTRUCT_OBJECT);
try {
Task task = createSimpleTask(OPERATION_RESTRUCT_OBJECT);
return getModelAuditService().reconstructObject(OrgType.class, getObjectId(), getEventIdentifier(), task, result);
} catch (Exception ex) {
result.recordFatalError(
createStringResource("ObjectHistoryTabPanel.message.getReconstructedObject.fatalError")
.getString(), ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't restruct object", ex);
}
return null;
}

public String getDate() {
return String.valueOf(getPageParameters().get(DATE_PARAMETER_LABEL));
}

public String getObjectId() {
return String.valueOf(getPageParameters().get(OID_PARAMETER_LABEL));
}

public String getEventIdentifier() {
return String.valueOf(getPageParameters().get(EID_PARAMETER_LABEL));
}

}

0 comments on commit a28e7d1

Please sign in to comment.