Skip to content

Commit

Permalink
Support for dashboard setting in adminGuiConfig (MID-3755)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik authored and KaterynaHonchar committed Feb 27, 2017
1 parent 2d4b0f0 commit 11fe5cf
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 12 deletions.
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015-2016 Evolveum
* Copyright (c) 2015-2017 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,9 +17,13 @@

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AdminGuiConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardLayoutType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.DashboardWidgetType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFormType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectFormsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserInterfaceElementVisibilityType;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
Expand Down Expand Up @@ -71,6 +75,15 @@ private static void applyAdminGuiConfiguration(AdminGuiConfigurationType composi
}
}
}
if (adminGuiConfiguration.getUserDashboard() != null) {
if (composite.getUserDashboard() == null) {
composite.setUserDashboard(adminGuiConfiguration.getUserDashboard().clone());
} else {
for (DashboardWidgetType widget: adminGuiConfiguration.getUserDashboard().getWidget()) {
mergeWidget(composite.getUserDashboard(), widget);
}
}
}
}

private static void replaceForm(ObjectFormsType objectForms, ObjectFormType newForm) {
Expand All @@ -83,5 +96,49 @@ private static void replaceForm(ObjectFormsType objectForms, ObjectFormType newF
}
objectForms.getObjectForm().add(newForm);
}


private static void mergeWidget(DashboardLayoutType compositeDashboard, DashboardWidgetType newWidget) {
String newWidgetIdentifier = newWidget.getIdentifier();
DashboardWidgetType compositeWidget = findWidget(compositeDashboard, newWidgetIdentifier);
if (compositeWidget == null) {
compositeDashboard.getWidget().add(newWidget.clone());
} else {
mergeWidget(compositeWidget, newWidget);
}
}

private static void mergeWidget(DashboardWidgetType compositeWidget, DashboardWidgetType newWidget) {
UserInterfaceElementVisibilityType newCompositeVisibility = mergeVisibility(compositeWidget.getVisibility(), newWidget.getVisibility());
compositeWidget.setVisibility(newCompositeVisibility);
}

private static UserInterfaceElementVisibilityType mergeVisibility(
UserInterfaceElementVisibilityType compositeVisibility, UserInterfaceElementVisibilityType newVisibility) {
if (compositeVisibility == null) {
compositeVisibility = UserInterfaceElementVisibilityType.VACANT;
}
if (newVisibility == null) {
newVisibility = UserInterfaceElementVisibilityType.VACANT;
}
if (compositeVisibility == UserInterfaceElementVisibilityType.HIDDEN || newVisibility == UserInterfaceElementVisibilityType.HIDDEN) {
return UserInterfaceElementVisibilityType.HIDDEN;
}
if (compositeVisibility == UserInterfaceElementVisibilityType.VISIBLE || newVisibility == UserInterfaceElementVisibilityType.VISIBLE) {
return UserInterfaceElementVisibilityType.VISIBLE;
}
if (compositeVisibility == UserInterfaceElementVisibilityType.AUTOMATIC || newVisibility == UserInterfaceElementVisibilityType.AUTOMATIC) {
return UserInterfaceElementVisibilityType.AUTOMATIC;
}
return UserInterfaceElementVisibilityType.VACANT;
}

private static DashboardWidgetType findWidget(DashboardLayoutType dashboard, String widgetIdentifier) {
for (DashboardWidgetType widget: dashboard.getWidget()) {
if (widget.getIdentifier().equals(widgetIdentifier)) {
return widget;
}
}
return null;
}

}
Expand Up @@ -10669,6 +10669,7 @@
<xsd:annotation>
<xsd:documentation>
Application or shortcut links placed on end-user dashboard.
TODO: align with userDashboard
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Expand All @@ -10685,6 +10686,19 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="userDashboard" type="tns:DashboardLayoutType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
<p>
Specifies the layout of the user dashboard (home screen):
it defines which boxes should be visible, which should be hidden, etc.
</p>
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="defaultTimezone" type="xsd:string" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -10718,6 +10732,125 @@
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="DashboardLayoutType">
<xsd:annotation>
<xsd:documentation>
Specifies layout of a dashboard, such as the user dashboard (home screen)
or administration dashboard. It specifies which boxes should be visible, which
should be hidden and so on.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="widget" type="tns:DashboardWidgetType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="DashboardWidgetType">
<xsd:annotation>
<xsd:documentation>
Defines properties of a specific dashboard widget.
</xsd:documentation>
<xsd:appinfo>
<a:container/>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="identifier" type="xsd:anyURI" minOccurs="1" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Widget identifier. It defines the identity of the widget and currently
also the placement on the dashboard. The widget specifications that come
from different roles will be merged if they have the same identifier.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<!-- TODO: type
<xsd:element name="type" type="xsd:QName" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Type of the widget. It is an identifier that specifies the content
of the winget (e.g. what will be inside the box).
THIS IS NOT USED YET. It is only for future use.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
-->
<!-- TODO: placement -->
<xsd:element name="visibility" type="tns:UserInterfaceElementVisibilityType"
minOccurs="0" maxOccurs="1" default="vacant">
<xsd:annotation>
<xsd:documentation>
Defines, whether this widget will be visible or it will be hidden.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="UserInterfaceElementVisibilityType">
<xsd:annotation>
<xsd:documentation>
Defines, whether a user interface element (form, widget) will be visible or it will be hidden.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumClass/>
<a:since>3.6</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="automatic">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="AUTOMATIC"/>
</xsd:appinfo>
<xsd:documentation>
The element will be visible if the authorisations of the current user
allows to see (at least a part) of the content that the element displays.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="visible">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="VISIBLE"/>
</xsd:appinfo>
<xsd:documentation>
The element will be always visible.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="vacant">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="VACANT"/>
</xsd:appinfo>
<xsd:documentation>
The element will not be visible. Not even if the authorizations allow
to see its content. But if any other role specifies the element as visible
or automatic then it will be visible. This setting is easily overridden.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="hidden">
<xsd:annotation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="HIDDEN"/>
</xsd:appinfo>
<xsd:documentation>
The element is never visible. Even if any other role specifies the element as
visible then the element will still remain invisible. This setting cannot be
overridden.
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="RichHyperlinkType">
<xsd:annotation>
Expand Down Expand Up @@ -13588,7 +13721,6 @@
<xsd:element name="sequence" type="tns:SequenceType" />



<!-- ============================================================== -->
<!-- FORMS -->
<!-- ============================================================== -->
Expand Down
Expand Up @@ -458,7 +458,7 @@ public void test130GetAdminGuiConfig() throws Exception {
result.computeStatus();
TestUtil.assertSuccess(result);

assertAdminGuiConfigurations(adminGuiConfiguration, 0, 1, 1);
assertAdminGuiConfigurations(adminGuiConfiguration, 0, 1, 1, 0);

RichHyperlinkType link = adminGuiConfiguration.getUserDashboardLink().get(0);
assertEquals("Bad link label", "Foo", link.getLabel());
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2016 Evolveum
* Copyright (c) 2010-2017 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 @@ -542,7 +542,7 @@ public void test100JackRolePirate() throws Exception {
assertNotAuthorized(principal, AUTZ_LOOT_URL, null);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);

assertAdminGuiConfigurations(principal, 1, 2, 2);
assertAdminGuiConfigurations(principal, 1, 2, 2, 2);
}

@Test
Expand All @@ -568,7 +568,7 @@ public void test109JackUnassignRolePirate() throws Exception {
assertNotAuthorized(principal, AUTZ_LOOT_URL);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);

assertAdminGuiConfigurations(principal, 0, 1, 1);
assertAdminGuiConfigurations(principal, 0, 1, 1, 0);
}

@Test
Expand Down
10 changes: 10 additions & 0 deletions model/model-intest/src/test/resources/common/role-pirate.xml
Expand Up @@ -144,5 +144,15 @@
</formSpecification>
</objectForm>
</objectForms>
<userDashboard>
<widget>
<identifier>http://midpoint.evolveum.com/xml/ns/test#widget1</identifier>
<visibility>automatic</visibility>
</widget>
<widget>
<identifier>http://midpoint.evolveum.com/xml/ns/test#widget2</identifier>
<visibility>vacant</visibility>
</widget>
</userDashboard>
</adminGuiConfiguration>
</role>
Expand Up @@ -3486,22 +3486,33 @@ protected void assertNoAuthorizations(MidPointPrincipal principal) {
}
}

protected void assertAdminGuiConfigurations(MidPointPrincipal principal, int expectedMenuLinks,
int expectedDashboardLinks, int expectedObjectForms) {
protected AdminGuiConfigurationType assertAdminGuiConfigurations(MidPointPrincipal principal, int expectedMenuLinks,
int expectedDashboardLinks, int expectedObjectForms, int expecteduserDashboardWidgets) {
AdminGuiConfigurationType adminGuiConfiguration = principal.getAdminGuiConfiguration();
display("Admin GUI config for "+principal.getUsername(), adminGuiConfiguration);
assertAdminGuiConfigurations(adminGuiConfiguration, expectedMenuLinks, expectedDashboardLinks, expectedObjectForms);
assertAdminGuiConfigurations(adminGuiConfiguration,
expectedMenuLinks, expectedDashboardLinks, expectedObjectForms, expecteduserDashboardWidgets);
return adminGuiConfiguration;
}

protected void assertAdminGuiConfigurations(AdminGuiConfigurationType adminGuiConfiguration, int expectedMenuLinks,
int expectedDashboardLinks, int expectedObjectForms) {
protected void assertAdminGuiConfigurations(AdminGuiConfigurationType adminGuiConfiguration,
int expectedMenuLinks, int expectedDashboardLinks, int expectedObjectForms, int expecteduserDashboardWidgets) {
assertNotNull("No admin GUI configuration", adminGuiConfiguration);
assertEquals("Wrong number of menu links in",
expectedMenuLinks, adminGuiConfiguration.getAdditionalMenuLink().size());
assertEquals("Wrong number of menu links in",
expectedDashboardLinks, adminGuiConfiguration.getUserDashboardLink().size());
assertEquals("Wrong number of object forms in admin GUI configuration",
expectedObjectForms, adminGuiConfiguration.getObjectForms().getObjectForm().size());
if ( adminGuiConfiguration.getUserDashboard() == null) {
if (expecteduserDashboardWidgets != 0) {
AssertJUnit.fail("Wrong number of widgets in user dashboard admin GUI configuration, expected "
+ expecteduserDashboardWidgets + " but there was none");
}
} else {
assertEquals("Wrong number of widgets in user dashboard admin GUI configuration",
expectedObjectForms, adminGuiConfiguration.getUserDashboard().getWidget().size());
}
}

protected void createSecurityContext(MidPointPrincipal principal) {
Expand Down

0 comments on commit 11fe5cf

Please sign in to comment.