Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 2, 2019
2 parents f052877 + 0689373 commit f15a905
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 100 deletions.
Expand Up @@ -29,6 +29,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.xml.ns._public.common.common_3.CaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFactory;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType;

Expand All @@ -55,6 +56,7 @@ public class OpResult implements Serializable, Visitable {
private static final Trace LOGGER = TraceManager.getTrace(OpResult.class);

private static final String OPERATION_CHECK_TASK_VISIBILITY = OpResult.class.getName() + ".checkTaskVisibility";
private static final String OPERATION_CHECK_CASE_VISIBILITY = OpResult.class.getName() + ".checkCaseVisibility";

private OperationResultStatus status;
private String operation;
Expand All @@ -72,7 +74,10 @@ public class OpResult implements Serializable, Visitable {
// we assume there is at most one background task created (TODO revisit this assumption)
private String backgroundTaskOid;
private Boolean backgroundTaskVisible; // available on root opResult only


private String caseOid;
private Boolean caseVisible;

private boolean showMore;
private boolean showError;

Expand Down Expand Up @@ -163,6 +168,11 @@ public static OpResult getOpResult(PageBase page, OperationResult result) {
if (result.getBackgroundTaskOid() != null) {
opResult.backgroundTaskOid = result.getBackgroundTaskOid();
}

String caseOid = OperationResult.referenceToCaseOid(result.findAsynchronousOperationReference());
if(caseOid != null) {
opResult.caseOid = caseOid;
}

try {
OperationResultType resultType = result.createOperationResultType();
Expand All @@ -179,7 +189,12 @@ public static OpResult getOpResult(PageBase page, OperationResult result) {

// This method should be called along with getOpResult for root operationResult. However, it might take some time,
// and there might be situations in which it is not required -- so we opted for calling it explicitly.
public void determineBackgroundTaskVisibility(PageBase pageBase) {
public void determineObjectsVisibility(PageBase pageBase) {
determineBackgroundTaskVisibility(pageBase);
determineCaseVisibility(pageBase);
}

private void determineBackgroundTaskVisibility(PageBase pageBase) {
if (backgroundTaskOid == null) {
return;
}
Expand All @@ -203,6 +218,36 @@ public void determineBackgroundTaskVisibility(PageBase pageBase) {
backgroundTaskVisible = false;
}
}

private void determineCaseVisibility(PageBase pageBase) {
if(getStatus().equals(OperationResultStatus.FATAL_ERROR)) {
caseVisible = false;
return;
}

if (caseOid == null) {
return;
}
try {
if (pageBase.isAuthorized(AuthorizationConstants.AUTZ_ALL_URL)) {
caseVisible = true;
return;
}
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException e) {
caseVisible = false;
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't determine case visibility", e);
return;
}

Task task = pageBase.createSimpleTask(OPERATION_CHECK_CASE_VISIBILITY);
try {
pageBase.getModelService().getObject(CaseType.class, caseOid, null, task, task.getResult());
caseVisible = true;
} catch (ObjectNotFoundException|SchemaException|SecurityViolationException|CommunicationException|ConfigurationException|ExpressionEvaluationException e) {
LOGGER.debug("Case {} is not visible by the current user: {}: {}", caseOid, e.getClass(), e.getMessage());
caseVisible = false;
}
}

public boolean isShowMore() {
return showMore;
Expand Down Expand Up @@ -282,6 +327,20 @@ public boolean isBackgroundTaskVisible() {
}
return true; // at least as for now
}

public String getCaseOid() {
return caseOid;
}

public boolean isCaseVisible() {
if (caseVisible != null) {
return caseVisible;
}
if (parent != null) {
return parent.isCaseVisible();
}
return true; // at least as for now
}

@Override
public void accept(Visitor visitor) {
Expand Down
Expand Up @@ -24,6 +24,9 @@
</a>
<a class="box-title" wicket:id="backgroundTask">
<wicket:message key="OperationResultPanel.showTask"/>
</a>
<a class="box-title" wicket:id="case">
<wicket:message key="OperationResultPanel.showCase"/>
</a>
<div class="box-tools pull-right">
<a wicket:id="showAll" class="btn btn-box-tool">
Expand Down
Expand Up @@ -69,6 +69,7 @@ public class OperationResultPanel extends BasePanel<OpResult> implements Popupab
private static final String ID_MESSAGE_LABEL = "messageLabel";
private static final String ID_PARAMS = "params";
private static final String ID_BACKGROUND_TASK = "backgroundTask";
private static final String ID_CASE = "case";
private static final String ID_SHOW_ALL = "showAll";
private static final String ID_HIDE_ALL = "hideAll";
private static final String ID_ERROR_STACK_TRACE = "errorStackTrace";
Expand Down Expand Up @@ -173,6 +174,31 @@ public boolean isVisible() {
}
});
box.add(backgroundTask);

AjaxLink<String> aCase = new AjaxLink<String>(ID_CASE) {
private static final long serialVersionUID = 1L;

@Override
public void onClick(AjaxRequestTarget target) {
final OpResult opResult = OperationResultPanel.this.getModelObject();
String oid = opResult.getCaseOid();
if (oid == null || !opResult.isCaseVisible()) {
return; // just for safety
}
ObjectReferenceType ref = ObjectTypeUtil.createObjectRef(oid, ObjectTypes.CASE);
WebComponentUtil.dispatchToObjectDetailsPage(ref, getPageBase(), false);
}
};
aCase.add(new VisibleEnableBehaviour() {
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return getModelObject().getCaseOid() != null
&& getModelObject().isCaseVisible();
}
});
box.add(aCase);

AjaxLink<String> showAll = new AjaxLink<String>(ID_SHOW_ALL) {
private static final long serialVersionUID = 1L;
Expand Down
Expand Up @@ -1329,6 +1329,14 @@ public static StringResourceModel createStringResourceStatic(Component component
return new StringResourceModel(resourceKey, component).setModel(new Model<String>())
.setDefaultValue(resourceKey).setParameters(objects);
}

public StringResourceModel createStringResourceDefault(String defaultKey, PolyStringType polystringKey, Object... objects) {
if (polystringKey == null) {
return createStringResource(defaultKey);
} else {
return createStringResource(polystringKey, objects);
}
}

public OpResult showResult(OperationResult result, String errorMessageKey) {
return showResult(result, errorMessageKey, true);
Expand Down Expand Up @@ -1374,7 +1382,7 @@ public OpResult showResult(OperationResult result, String errorMessageKey, boole
result = scriptResult;

OpResult opResult = OpResult.getOpResult((PageBase) getPage(), result);
opResult.determineBackgroundTaskVisibility(this);
opResult.determineObjectsVisibility(this);
switch (opResult.getStatus()) {
case FATAL_ERROR:
case PARTIAL_ERROR:
Expand Down Expand Up @@ -2288,17 +2296,14 @@ private void addCollectionsMenuItems(List<MenuItem> menu, QName type, Class<? ex
if (objectViews == null) {
return;
}
objectViews.sort(Comparator.comparing(o -> (o.getDisplay() != null && PolyStringUtils.isNotEmpty(o.getDisplay().getPluralLabel())
? createStringResource(o.getDisplay().getPluralLabel()).getString()
: createStringResource("MenuItem.noName").getString() )));
objectViews.sort(Comparator.comparingInt(o -> (ObjectUtils.defaultIfNull(o.getDisplayOrder(), Integer.MAX_VALUE))));
List<MenuItem> collectionMenuItems = new ArrayList<>(objectViews.size());
objectViews.forEach(objectView -> {
CollectionRefSpecificationType collection = objectView.getCollection();
if (collection == null) {
CollectionRefSpecificationType collectionRefSpec = objectView.getCollection();
if (collectionRefSpec == null) {
return;
}

ObjectReferenceType collectionRef = collection.getCollectionRef();
ObjectReferenceType collectionRef = collectionRefSpec.getCollectionRef();
if (collectionRef == null) {
return;
}
Expand All @@ -2319,10 +2324,9 @@ private void addCollectionsMenuItems(List<MenuItem> menu, QName type, Class<? ex
PageParameters pageParameters = new PageParameters();
pageParameters.add(PARAMETER_OBJECT_COLLECTION_NAME, objectView.getViewIdentifier());

MenuItem userViewMenu = new MenuItem(viewDisplayType != null && PolyStringUtils.isNotEmpty(viewDisplayType.getPluralLabel())
? createStringResource(viewDisplayType.getPluralLabel())
: createStringResource("MenuItem.noName"),
WebComponentUtil.getIconCssClass(viewDisplayType), redirectToPage, pageParameters, null){
MenuItem userViewMenu = new MenuItem(
createStringResourceDefault("MenuItem.noName", WebComponentUtil.getCollectionLabel(viewDisplayType, collectionRefSpec, objectType)),
WebComponentUtil.getIconCssClass(viewDisplayType), redirectToPage, pageParameters, null) {
private static final long serialVersionUID = 1L;

@Override
Expand All @@ -2337,9 +2341,17 @@ public boolean isMenuActive(WebPage page) {
return false;
}
};
menu.add(userViewMenu);

userViewMenu.setDisplayOrder(objectView.getDisplayOrder());
collectionMenuItems.add(userViewMenu);
});

// We need to sort after we get all the collections. Only then we have correct collection labels.
// We do not want to determine the labels twice.

// TODO: can this be combined in a single sort?
collectionMenuItems.sort(Comparator.comparing(o -> o.getNameModel().getObject()));
collectionMenuItems.sort(Comparator.comparingInt(o -> ObjectUtils.defaultIfNull(o.getDisplayOrder(), Integer.MAX_VALUE)));
menu.addAll(collectionMenuItems);
}

public PrismObject<UserType> loadUserSelf() {
Expand Down
Expand Up @@ -2499,6 +2499,32 @@ public static DisplayType getNewObjectDisplayTypeFromCollectionView(CompiledObje
}
return view != null ? view.getDisplay() : null;
}

/**
* Returns name of the collection suitable to be displayed in the menu or other labels.
* E.g. "All tasks", "Active employees".
*/
public static PolyStringType getCollectionLabel(DisplayType viewDisplayType, CollectionRefSpecificationType collectionRefSpec ,ObjectType collectionRefTarget) {
if (viewDisplayType != null) {
PolyStringType viewPluralLabel = viewDisplayType.getPluralLabel();
if (viewPluralLabel != null) {
return viewPluralLabel;
}
PolyStringType viewLabel = viewDisplayType.getLabel();
if (viewLabel != null) {
return viewLabel;
}
}
if (collectionRefTarget != null) {
if (collectionRefTarget instanceof ObjectCollectionType) {
// MID-5709
// TODO: use collectionRefTarget.getDisplay() first - when the schema is updated
}
// TODO: try to use archetype policy?
return collectionRefTarget.getName();
}
return null;
}

public static ItemVisibility checkShadowActivationAndPasswordVisibility(ItemWrapper<?, ?, ?,?> itemWrapper,
ShadowType shadowType) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2017 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,12 @@ public class BaseMenuItem implements Serializable {
private VisibleEnableBehaviour visibleEnable;
private Class<? extends WebPage>[] aliases;
private String iconClass;
/**
* Optional field that can be used for sorting. Used for some dynamic submenus, such as collections.
* It does not affect the display of menu item in any way. It is just a convenient intermediary place to store
* the order for sorting the items before adding them to menu.
*/
private transient Integer displayOrder;

public BaseMenuItem(IModel<String> name, Class<? extends WebPage> page) {
this(name, "", page, null, null);
Expand Down Expand Up @@ -80,8 +86,16 @@ public VisibleEnableBehaviour getVisibleEnable() {
public String getIconClass() {
return iconClass;
}

public Integer getDisplayOrder() {
return displayOrder;
}

public void setDisplayOrder(Integer displayOrder) {
this.displayOrder = displayOrder;
}

public boolean isMenuActive(WebPage page) {
public boolean isMenuActive(WebPage page) {
if (page == null) {
return false;
}
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2017 Evolveum
~ Copyright (c) 2010-2019 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -186,23 +186,32 @@
<objectCollectionViews>
<objectCollectionView>
<identifier>my-cases</identifier>
<displayOrder>1000</displayOrder>
<type>CaseType</type>
<display>
<label>Case</label>
<pluralLabel>My Cases</pluralLabel>
<label>My cases</label>
<!-- We need to explicitly specify plural label here. Otherwise it will be overwritten by a plural label from archetype. -->
<pluralLabel>My cases</pluralLabel>
<singularLabel>My case</singularLabel>
<icon>
<cssClass>fe fe-case-object</cssClass>
</icon>
</display>
<displayOrder>1000</displayOrder>
<type>CaseType</type>
<collection>
<collectionRef oid="00000000-0000-0000-0000-000000000344" relation="org:default" type="c:ObjectCollectionType">
</collectionRef>
</collection>
</objectCollectionView>
<objectCollectionView>
<identifier>manual-case-view</identifier>
<displayOrder>1001</displayOrder>
<display>
<label>Manual cases</label> <!-- "Manual provisioning cases" is too long for the menu -->
<!-- We need to explicitly specify plural label here. Otherwise it will be overwritten by a plural label from archetype. -->
<pluralLabel>Manual cases</pluralLabel>
<singularLabel>Manual case</singularLabel>
<tooltip>Manual provisioning cases</tooltip>
</display>
<displayOrder>1010</displayOrder>
<type>CaseType</type>
<collection>
<collectionRef oid="00000000-0000-0000-0000-000000000340" relation="org:default" type="c:ArchetypeType">
Expand All @@ -211,7 +220,14 @@
</objectCollectionView>
<objectCollectionView>
<identifier>operation-request-case-view</identifier>
<displayOrder>1002</displayOrder>
<display>
<label>Requests</label> <!-- "Operation requests" is too long for the menu -->
<!-- We need to explicitly specify plural label here. Otherwise it will be overwritten by a plural label from archetype. -->
<pluralLabel>Requests</pluralLabel>
<singularLabel>Request</singularLabel>
<tooltip>Operation requests</tooltip>
</display>
<displayOrder>1020</displayOrder>
<type>CaseType</type>
<collection>
<collectionRef oid="00000000-0000-0000-0000-000000000341" relation="org:default" type="c:ArchetypeType">
Expand All @@ -220,7 +236,14 @@
</objectCollectionView>
<objectCollectionView>
<identifier>approval-case-view</identifier>
<displayOrder>1003</displayOrder>
<display>
<label>Approvals</label> <!-- "Approval cases" is too long for the menu -->
<!-- We need to explicitly specify plural label here. Otherwise it will be overwritten by a plural label from archetype. -->
<pluralLabel>Approvals</pluralLabel>
<singularLabel>Approval</singularLabel>
<tooltip>Approval cases</tooltip>
</display>
<displayOrder>1030</displayOrder>
<type>CaseType</type>
<collection>
<collectionRef oid="00000000-0000-0000-0000-000000000342" relation="org:default" type="c:ArchetypeType">
Expand Down

0 comments on commit f15a905

Please sign in to comment.