Skip to content

Commit

Permalink
self service - profile redirection fix (MID-7406)
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Nov 21, 2021
1 parent 881ae7c commit 81dae66
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected void onTemplateChosePerformed(CompiledObjectCollectionView collectionV
};
}

private Collection<CompiledObjectCollectionView> findAllApplicableArchetypeViews() {
protected Collection<CompiledObjectCollectionView> findAllApplicableArchetypeViews() {
return getCompiledGuiProfile().findAllApplicableArchetypeViews(getType(), OperationTypeType.ADD);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.Session;
Expand Down Expand Up @@ -87,6 +90,14 @@ public void setSaveOnConfigure(boolean saveOnConfigure) {
this.saveOnConfigure = saveOnConfigure;
}

@Override
protected Collection<CompiledObjectCollectionView> findAllApplicableArchetypeViews() {
if (getObjectDetailsModels().isSelfProfile()) {
return Collections.emptyList();
}
return super.findAllApplicableArchetypeViews();
}

@Override
protected FocusOperationalButtonsPanel<F> createButtonsPanel(String id, LoadableModel<PrismObjectWrapper<F>> wrapperModel) {
return new FocusOperationalButtonsPanel<>(id, wrapperModel, getObjectDetailsModels().getExecuteOptionsModel(), getObjectDetailsModels().isSelfProfile()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@

import java.util.*;

import com.evolveum.midpoint.security.api.SecurityUtil;
import com.evolveum.midpoint.web.page.admin.server.CasesTablePanel;

import com.evolveum.midpoint.web.session.UserProfileStorage;

import org.apache.commons.lang3.Validate;
import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.apache.wicket.Session;
Expand All @@ -33,15 +27,14 @@
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.security.api.MidPointPrincipal;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand All @@ -60,9 +53,11 @@
import com.evolveum.midpoint.web.page.admin.home.dto.AccountCallableResult;
import com.evolveum.midpoint.web.page.admin.home.dto.AssignmentItemDto;
import com.evolveum.midpoint.web.page.admin.home.dto.SimpleAccountDto;
import com.evolveum.midpoint.web.page.admin.server.CasesTablePanel;
import com.evolveum.midpoint.web.page.self.component.DashboardSearchPanel;
import com.evolveum.midpoint.web.page.self.component.LinksPanel;
import com.evolveum.midpoint.web.security.util.SecurityUtils;
import com.evolveum.midpoint.web.session.UserProfileStorage;
import com.evolveum.midpoint.wf.util.QueryUtils;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand Down Expand Up @@ -94,19 +89,10 @@ public class PageSelfDashboard extends PageSelf {
private static final String ID_ASSIGNMENTS = "assignments";

private static final String DOT_CLASS = PageSelfDashboard.class.getName() + ".";
private static final String OPERATION_LOAD_WORK_ITEMS = DOT_CLASS + "loadWorkItems";
private static final String OPERATION_LOAD_REQUESTS = DOT_CLASS + "loadRequests";
private static final String OPERATION_LOAD_ACCOUNTS = DOT_CLASS + "loadAccounts";
private static final String OPERATION_LOAD_ASSIGNMENTS = DOT_CLASS + "loadAssignments";
private static final String OPERATION_LOAD_USER = DOT_CLASS + "loadUser";
private static final String OPERATION_GET_SYSTEM_CONFIG = DOT_CLASS + "getSystemConfiguration";

// private final Model<PrismObject<? extends FocusType>> principalModel = new Model<>();
// private final CompiledGuiProfile compiledGuiProfile;

public PageSelfDashboard() {
// compiledGuiProfile = getPrincipal().getCompiledGuiProfile();
// principalModel.setObject(loadFocus());
setTimeZone(PageSelfDashboard.this);
initLayout();
}
Expand Down Expand Up @@ -154,7 +140,7 @@ public boolean isVisible() {
application = getApplication();
final Session session = Session.get();

AsyncDashboardPanel<Object, List<CaseWorkItemType>> workItemsPanel = new AsyncDashboardPanel<Object, List<CaseWorkItemType>>(
AsyncDashboardPanel<Object, List<CaseWorkItemType>> workItemsPanel = new AsyncDashboardPanel<>(
ID_WORK_ITEMS_PANEL,
createStringResource("PageSelfDashboard.workItems"),
GuiStyleConstants.CLASS_OBJECT_WORK_ITEM_ICON,
Expand All @@ -167,7 +153,7 @@ public boolean isVisible() {
protected SecurityContextAwareCallable<CallableResult<List<CaseWorkItemType>>> createCallable(
Authentication auth, IModel callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<List<CaseWorkItemType>>>(
return new SecurityContextAwareCallable<>(
getSecurityContextManager(), auth) {

@Override
Expand All @@ -185,8 +171,8 @@ protected Component getMainComponent(String markupId) {
@Override
protected ObjectFilter getCaseWorkItemsFilter() {
return QueryUtils.filterForNotClosedStateAndAssignees(getPrismContext().queryFor(CaseWorkItemType.class),
SecurityUtils.getPrincipalUser(),
OtherPrivilegesLimitationType.F_APPROVAL_WORK_ITEMS, getRelationRegistry())
SecurityUtils.getPrincipalUser(),
OtherPrivilegesLimitationType.F_APPROVAL_WORK_ITEMS, getRelationRegistry())
.desc(F_CREATE_TIMESTAMP)
.buildFilter();
}
Expand All @@ -206,7 +192,7 @@ public boolean isVisible() {
add(workItemsPanel);

AsyncDashboardPanel<Object, List<CaseType>> myRequestsPanel =
new AsyncDashboardPanel<Object, List<CaseType>>(ID_REQUESTS_PANEL,
new AsyncDashboardPanel<>(ID_REQUESTS_PANEL,
createStringResource("PageSelfDashboard.myRequests"),
GuiStyleConstants.CLASS_SHADOW_ICON_REQUEST,
GuiStyleConstants.CLASS_OBJECT_SERVICE_BOX_CSS_CLASSES, true) {
Expand All @@ -217,7 +203,7 @@ public boolean isVisible() {
protected SecurityContextAwareCallable<CallableResult<List<CaseType>>> createCallable(
Authentication auth, IModel callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<List<CaseType>>>(
return new SecurityContextAwareCallable<>(
getSecurityContextManager(), auth) {

@Override
Expand All @@ -229,13 +215,12 @@ public CallableResult<List<CaseType>> callWithContextPrepared() {

@Override
protected Component getMainComponent(String markupId) {
CasesTablePanel casesPanel = new CasesTablePanel(markupId) {
private static final long serialVersionUID = 1L;
return new CasesTablePanel(markupId) {

@Override
protected ObjectFilter getCasesFilter() {
return QueryUtils.filterForMyRequests(getPrismContext().queryFor(CaseType.class),
SecurityUtils.getPrincipalUser().getOid())
SecurityUtils.getPrincipalUser().getOid())
.desc(ItemPath.create(CaseType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP))
.buildFilter();
}
Expand All @@ -250,7 +235,6 @@ protected UserProfileStorage.TableId getTableId() {
return UserProfileStorage.TableId.PAGE_CASE_CHILD_CASES_TAB;
}
};
return casesPanel;
}
};

Expand All @@ -270,26 +254,6 @@ public boolean isVisible() {
initAssignments();
}

private PrismObject<? extends FocusType> loadFocus() {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
Validate.notNull(principal, "No principal");
if (principal.getOid() == null) {
throw new IllegalArgumentException("No OID in principal: " + principal);
}

Task task = createSimpleTask(OPERATION_LOAD_USER);
OperationResult result = task.getResult();
PrismObject<? extends FocusType> focus = WebModelServiceUtils.loadObject(FocusType.class,
principal.getOid(), PageSelfDashboard.this, task, result);
result.computeStatus();

if (!WebComponentUtil.isSuccessOrHandledError(result)) {
showResult(result);
}

return focus;
}

private List<RichHyperlinkType> loadLinksList() {
// PrismObject<? extends FocusType> focus = principalModel.getObject();
// if (focus == null) {
Expand All @@ -300,7 +264,7 @@ private List<RichHyperlinkType> loadLinksList() {
}

private void initMyAccounts(Session session) {
AsyncDashboardPanel<Object, List<SimpleAccountDto>> accounts = new AsyncDashboardPanel<Object, List<SimpleAccountDto>>(ID_ACCOUNTS,
AsyncDashboardPanel<Object, List<SimpleAccountDto>> accounts = new AsyncDashboardPanel<>(ID_ACCOUNTS,
createStringResource("PageDashboard.accounts"),
GuiStyleConstants.CLASS_SHADOW_ICON_ACCOUNT,
GuiStyleConstants.CLASS_OBJECT_SHADOW_BOX_CSS_CLASSES,
Expand All @@ -312,7 +276,7 @@ private void initMyAccounts(Session session) {
protected SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>> createCallable(
Authentication auth, IModel<Object> callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<List<SimpleAccountDto>>>(
return new SecurityContextAwareCallable<>(
getSecurityContextManager(), auth) {

@Override
Expand Down Expand Up @@ -372,9 +336,6 @@ private AccountCallableResult<List<SimpleAccountDto>> loadAccounts() {
List<SimpleAccountDto> list = new ArrayList<>();
callableResult.setValue(list);
FocusType focus = SecurityUtils.getPrincipalUser().getFocus();
if (focus == null) {
return callableResult;
}

Task task = createSimpleTask(OPERATION_LOAD_ACCOUNTS);
OperationResult result = task.getResult();
Expand Down Expand Up @@ -411,7 +372,7 @@ private AccountCallableResult<List<SimpleAccountDto>> loadAccounts() {
}

private void initAssignments() {
AsyncDashboardPanel<Object, List<AssignmentItemDto>> assignedOrgUnits = new AsyncDashboardPanel<Object, List<AssignmentItemDto>>(ID_ASSIGNMENTS,
AsyncDashboardPanel<Object, List<AssignmentItemDto>> assignedOrgUnits = new AsyncDashboardPanel<>(ID_ASSIGNMENTS,
createStringResource("PageDashboard.assignments"),
GuiStyleConstants.CLASS_ICON_ASSIGNMENTS,
GuiStyleConstants.CLASS_OBJECT_ROLE_BOX_CSS_CLASSES,
Expand All @@ -423,7 +384,7 @@ private void initAssignments() {
protected SecurityContextAwareCallable<CallableResult<List<AssignmentItemDto>>> createCallable(
Authentication auth, IModel callableParameterModel) {

return new SecurityContextAwareCallable<CallableResult<List<AssignmentItemDto>>>(
return new SecurityContextAwareCallable<>(
getSecurityContextManager(), auth) {

@Override
Expand Down Expand Up @@ -459,7 +420,7 @@ private CallableResult<List<AssignmentItemDto>> loadAssignments() {
callableResult.setValue(list);

FocusType focus = SecurityUtils.getPrincipalUser().getFocus();
if (focus == null || focus.getAssignment().isEmpty()) {
if (focus.getAssignment().isEmpty()) {
return callableResult;
}

Expand Down Expand Up @@ -541,15 +502,14 @@ private String getAssignmentDescription(PrismObject value) {
if (OrgType.class.isAssignableFrom(value.getCompileTimeClass())) {
orgIdentifier = value.getPropertyRealValue(OrgType.F_IDENTIFIER, String.class);
}
String description = (orgIdentifier != null ? orgIdentifier + " " : "") +
return (orgIdentifier != null ? orgIdentifier + " " : "") +
(value.asObjectable() instanceof ObjectType && value.asObjectable().getDescription() != null ?
value.asObjectable().getDescription() : "");
return description;
}

private UserInterfaceElementVisibilityType getComponentVisibility(PredefinedDashboardWidgetId componentId) {
CompiledGuiProfile compiledGuiProfile = getCompiledGuiProfile();
if (compiledGuiProfile == null || compiledGuiProfile.getUserDashboard() == null) {
if (compiledGuiProfile.getUserDashboard() == null) {
return UserInterfaceElementVisibilityType.AUTOMATIC;
}
List<DashboardWidgetType> widgetsList = compiledGuiProfile.getUserDashboard().getWidget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
*/
package com.evolveum.midpoint.web.page.self.component;

import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import java.util.List;
import javax.servlet.ServletContext;

import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -21,17 +17,17 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.protocol.http.WebApplication;

import javax.servlet.ServletContext;

import java.util.List;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RichHyperlinkType;

/**
* @author Kate Honchar
*/
public class LinksPanel extends BasePanel<List<RichHyperlinkType>> {

private static final String DOT_CLASS = LinksPanel.class.getName() + ".";

private static final String ID_IMAGE = "imageId";
private static final String ID_LINK = "link";
private static final String ID_LABEL = "labelId";
Expand Down Expand Up @@ -89,7 +85,7 @@ protected void initLayout() {
}

WebMarkupContainer column = new WebMarkupContainer(columnView.newChildId());
Link<Void> linkItem = new Link<Void>(ID_LINK) {
Link<Void> linkItem = new Link<>(ID_LINK) {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -137,28 +133,20 @@ protected void onComponentTag(final ComponentTag tag) {
}
});

linkItem.add(new Label(ID_LABEL, new IModel<String>() {

@Override
public String getObject() {
String key = link.getLabel();
if (key == null) {
return null;
}
return getString(key, null, key);
linkItem.add(new Label(ID_LABEL, (IModel<String>) () -> {
String key = link.getLabel();
if (key == null) {
return null;
}
return getString(key, null, key);
}));

Label description = new Label(ID_DESCRIPTION, new IModel<String>() {

@Override
public String getObject() {
String desc = link.getDescription();
if (desc == null) {
return null;
}
return getString(desc, null, desc);
Label description = new Label(ID_DESCRIPTION, (IModel<String>) () -> {
String desc = link.getDescription();
if (desc == null) {
return null;
}
return getString(desc, null, desc);
});
description.setEnabled(false);
linkItem.add(description);
Expand All @@ -175,7 +163,7 @@ public String getObject() {
}
}

if (row != null && columnView != null && !isRowAdded){
if (row != null && !isRowAdded){
row.add(columnView);
rowView.add(row);
}
Expand Down

0 comments on commit 81dae66

Please sign in to comment.