Skip to content

Commit

Permalink
fix for 9588 500 error when setting extended attribute in request access
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Apr 17, 2024
1 parent d1e9471 commit f99e984
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ public void showMainPopup(Popupable popupable, AjaxRequestTarget target) {

public void hideMainPopup(AjaxRequestTarget target) {
getMainPopup().close(target);
target.appendJavaScript("$('body').removeClass('modal-open');\n"
+ "$('.modal-backdrop').remove();");
}

private VisibleBehaviour createUserStatusBehaviour() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Set;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.page.PageBase;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
Expand Down Expand Up @@ -50,6 +52,8 @@ protected <PV extends PrismValue> PV createNewValue(PrismReferenceWrapper<R> ite

@Override
protected Component createDefaultPanel(String id) {
PageBase pageBase = getPageBase();

ValueChoosePanel<R> panel = new ValueChoosePanel<R>(id, new ItemRealValueModel<>(getModel())) {

private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -80,7 +84,7 @@ protected Set<SearchItemType> getSpecialSearchItem() {
protected <O extends ObjectType> void choosePerformed(AjaxRequestTarget target, O object) {
super.choosePerformed(target, object);
getBaseFormComponent().validate();
target.add(getPageBase().getFeedbackPanel());
target.add(pageBase.getFeedbackPanel());
target.add(getFeedback());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import java.util.Set;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.ObjectTypeListUtil;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.web.component.dialog.Popupable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SearchItemType;

import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -56,6 +59,8 @@ public class ValueChoosePanel<R extends Referencable> extends BasePanel<R> {
private static final String ID_FEEDBACK = "feedback";
private static final String ID_EDIT = "edit";

Popupable parentPopupableDialog = null;

public ValueChoosePanel(String id, IModel<R> value) {
super(id, value);
}
Expand All @@ -65,6 +70,7 @@ protected void onInitialize() {
super.onInitialize();
initLayout();
setOutputMarkupId(true);
initParentPopupableDialog();
}

private void initLayout() {
Expand Down Expand Up @@ -114,19 +120,23 @@ public boolean isEnabled() {
initButtons();
}

private void initParentPopupableDialog() {
parentPopupableDialog = findParent(Popupable.class);
}

protected boolean isEditButtonEnabled() {
return true;
}

protected void replaceIfEmpty(ObjectType object) {
ObjectReferenceType ort = ObjectTypeUtil.createObjectRef(object, getPageBase().getPrismContext());
ObjectReferenceType ort = ObjectTypeUtil.createObjectRef(object, PrismContext.get());
getModel().setObject((R) ort);

}

protected ObjectQuery createChooseQuery() {
ArrayList<String> oidList = new ArrayList<>();
ObjectQuery query = getPrismContext().queryFactory().createQuery();
ObjectQuery query = PrismContext.get().queryFactory().createQuery();
// TODO we should add to filter currently displayed value
// not to be displayed on ObjectSelectionPanel instead of saved value

Expand All @@ -141,8 +151,8 @@ protected ObjectQuery createChooseQuery() {

}

ObjectFilter oidFilter = getPrismContext().queryFactory().createInOid(oidList);
query.setFilter(getPrismContext().queryFactory().createNot(oidFilter));
ObjectFilter oidFilter = PrismContext.get().queryFactory().createInOid(oidList);
query.setFilter(PrismContext.get().queryFactory().createNot(oidFilter));

ObjectFilter customFilter = createCustomFilter();
if (customFilter != null) {
Expand Down Expand Up @@ -191,6 +201,7 @@ public void setObject(String object) {
}

protected <O extends ObjectType> void editValuePerformed(AjaxRequestTarget target) {
PageBase pageBase = getPageBase();
List<QName> supportedTypes = getSupportedTypes();
ObjectFilter filter = createChooseQuery() == null ? null
: createChooseQuery().getFilter();
Expand All @@ -199,19 +210,19 @@ protected <O extends ObjectType> void editValuePerformed(AjaxRequestTarget targe
}
Class<O> defaultType = getDefaultType(supportedTypes);
ObjectBrowserPanel<O> objectBrowserPanel = new ObjectBrowserPanel<O>(
getPageBase().getMainPopupBodyId(), defaultType, supportedTypes, false, getPageBase(),
pageBase.getMainPopupBodyId(), defaultType, supportedTypes, false, pageBase,
filter) {
private static final long serialVersionUID = 1L;

@Override
protected void onSelectPerformed(AjaxRequestTarget target, O object) {
getPageBase().hideMainPopup(target);
ValueChoosePanel.this.choosePerformed(target, object);
managePopupDialogContent(pageBase, target);
}

};

getPageBase().showMainPopup(objectBrowserPanel, target);
pageBase.showMainPopup(objectBrowserPanel, target);

}

Expand All @@ -224,7 +235,7 @@ public List<QName> getSupportedTypes() {
}

protected <O extends ObjectType> Class<O> getDefaultType(List<QName> supportedTypes) {
return (Class<O>) WebComponentUtil.qnameToClass(getPageBase().getPrismContext(), supportedTypes.iterator().next());
return (Class<O>) WebComponentUtil.qnameToClass(PrismContext.get(), supportedTypes.iterator().next());
}

/*
Expand Down Expand Up @@ -270,4 +281,15 @@ protected <O extends ObjectType> void choosePerformedHook(AjaxRequestTarget targ
public FormComponent<String> getBaseFormComponent() {
return (FormComponent<String>) getTextWrapperComponent().get(ID_TEXT);
}

//fix for open project ticket 9588
//if ValueChoosePanel is used in popup, ObjectBrowserPanel is opened in the second popup
//after the object is selected in ObjectBrowserPanel, the second popup is closed and the first one is shown again
private void managePopupDialogContent(PageBase pageBase, AjaxRequestTarget target) {
if (parentPopupableDialog != null) {
pageBase.showMainPopup(parentPopupableDialog, target);
} else {
pageBase.hideMainPopup(target);
}
}
}

0 comments on commit f99e984

Please sign in to comment.