Skip to content

Commit

Permalink
MID-8842 ninja - user dashboard link processor + test
Browse files Browse the repository at this point in the history
(cherry picked from commit c6690e5)
  • Loading branch information
1azyman committed Aug 3, 2023
1 parent bf76941 commit 2317c2b
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.evolveum.midpoint.schema.validator.processor;

import java.util.Arrays;
import java.util.List;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.validator.UpgradeObjectProcessor;
import com.evolveum.midpoint.schema.validator.UpgradePhase;
import com.evolveum.midpoint.schema.validator.UpgradePriority;
import com.evolveum.midpoint.schema.validator.UpgradeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.lang3.StringUtils;

@SuppressWarnings("unused")
public class UserDashboardLinkProcessor implements UpgradeObjectProcessor<ObjectType> {

@Override
public UpgradePriority getPriority() {
return UpgradePriority.NECESSARY;
}

@Override
public UpgradeType getType() {
return UpgradeType.PREVIEW;
}

@Override
public UpgradePhase getPhase() {
return UpgradePhase.BEFORE;
}

@Override
public boolean isApplicable(PrismObject<?> object, ItemPath path) {
return matchParentTypeAndItemName(object, path, AdminGuiConfigurationType.class, AdminGuiConfigurationType.F_USER_DASHBOARD_LINK);
}

@Override
public String upgradeDescription(PrismObject<ObjectType> object, ItemPath path) {
return "Authorization of user dashboard links has to be configured manually via widget/visibility.";
}

@Override
public boolean process(PrismObject<ObjectType> object, ItemPath path) {
AdminGuiConfigurationType adminGuiConfig = getItemParent(object, path);
List<RichHyperlinkType> links = adminGuiConfig.getUserDashboardLink();

List<HomePageType> homePages = adminGuiConfig.getHomePage();
HomePageType userHome = homePages.stream()
.filter(hp -> UserType.COMPLEX_TYPE.equals(hp.getType()))
.findFirst().orElse(null);

if (userHome == null) {
userHome = new HomePageType();
userHome.setType(UserType.COMPLEX_TYPE);
userHome.setIdentifier("user");
homePages.add(userHome);
}

for (RichHyperlinkType link : links) {
PreviewContainerPanelConfigurationType widget = new PreviewContainerPanelConfigurationType();
userHome.getWidget().add(widget);

widget.setPanelType("linkWidget");
widget.setDocumentation(link.getDocumentation());

DisplayType display = new DisplayType();
widget.setDisplay(display);

if (link.getLabel() != null) {
display.setLabel(new PolyStringType(link.getLabel()));
}
if (link.getDescription() != null) {
display.setHelp(new PolyStringType(link.getDescription()));
}

display.setIcon(link.getIcon());

if (link.getColor() != null) {
IconType icon = display.getIcon();
if (icon == null) {
icon = new IconType();
display.setIcon(icon);
}

icon.setCssClass(StringUtils.join(Arrays.asList(
icon.getCssClass(), link.getColor()), " "));
}

List<GuiActionType> actions = widget.getAction();
GuiActionType action = new GuiActionType();
action.setIdentifier("link");
action.setTarget(new RedirectionTargetType()
.targetUrl(link.getTargetUrl()));
actions.add(action);
}

links.clear();

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ private void assertUpgrade(String file, UpgradeValidationResult result) {

String msg = "EXPECTED:\n" + PrismTestUtil.serializeObjectToString(expected) +
"\nUPDATED:\n" + PrismTestUtil.serializeObjectToString(updated) +
"\nORIGINAL:\n" + PrismTestUtil.serializeObjectToString(original);
"\nORIGINAL:\n" + PrismTestUtil.serializeObjectToString(original) +
"\nDELTA:\n" + updated.diff(expected).debugDump();

LOGGER.info(msg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
~ and European Union Public License. See LICENSE file for details.
-->
<systemConfiguration xmlns="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
xmlns:c="http://midpoint.evolveum.com/xml/ns/public/common/common-3"
oid="3947d3b1-b6e8-46ec-b382-1bde67da6f07">

<name>system-configuration</name>
Expand Down Expand Up @@ -112,9 +113,36 @@
</roleManagement>

<adminGuiConfiguration>
<userDashboardLink>
<targetUrl>https://google.com</targetUrl>
</userDashboardLink>
<homePage>
<identifier>user</identifier>
<type>c:UserType</type>
<widget>
<display>
<icon>
<cssClass>black red</cssClass>
</icon>
</display>
<panelType>linkWidget</panelType>
<action>
<identifier>link</identifier>
<target>
<targetUrl>https://google.com</targetUrl>
</target>
</action>
</widget>
<widget>
<display>
<label>Sample</label>
</display>
<panelType>linkWidget</panelType>
<action>
<identifier>link</identifier>
<target>
<targetUrl>https://sample.com</targetUrl>
</target>
</action>
</widget>
</homePage>
<objectForms>
<objectForm>
<type>OrgType</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@
</roleManagement>

<adminGuiConfiguration>
<userDashboardLink>
<userDashboardLink id="12">
<targetUrl>https://google.com</targetUrl>
<color>red</color>
<icon>
<cssClass>black</cssClass>
</icon>
</userDashboardLink>
<userDashboardLink id="13">
<targetUrl>https://sample.com</targetUrl>
<label>Sample</label>
</userDashboardLink>
<objectForms>
<objectForm>
Expand Down

0 comments on commit 2317c2b

Please sign in to comment.