Skip to content

Commit

Permalink
MID-9380 Can't click the Save and Preview changes buttons when assigning
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Jan 22, 2024
1 parent 53444a6 commit 2f9ba4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,33 +301,9 @@ protected void showMainPopup(Popupable popupable, AjaxRequestTarget target) {
getPageBase().showMainPopup(popupable, target);
}

@Override
protected boolean isSavePreviewButtonEnabled() {
//in case user isn't allowed to modify focus data but has
// e.g. #assign authorization, Save button is disabled on page load.
// Save button becomes enabled just if some changes are made
// on the Assignments tab (in the use case with #assign authorization)
// PrismContainerDefinition def = getObjectWrapper().getDefinition();
return !ItemStatus.NOT_CHANGED.equals(getModelObject().getStatus()) || getModelObject().canModify() ||
isAssignmentAddedOrRemoved();
}

//if the user has just #assign authorization (no #edit), we need to enable Save/Preview buttons
// when the assignments model is changed
public boolean isAssignmentAddedOrRemoved() {
try {
PrismContainerWrapper<AssignmentType> assignmentsWrapper = getModelObject().findContainer(AssignmentHolderType.F_ASSIGNMENT);
if (assignmentsWrapper != null) {
for (PrismContainerValueWrapper<AssignmentType> assignmentWrapper : assignmentsWrapper.getValues()) {
if (ValueStatus.DELETED.equals(assignmentWrapper.getStatus()) ||
ValueStatus.ADDED.equals(assignmentWrapper.getStatus())) {
return true;
}
}
}
} catch (SchemaException e) {
LOGGER.error("Cannot find assignment wrapper: {}", e.getMessage());
return false;
}
return false;
!getModelObject().isReadOnly(); //this check was added due to MID-9380
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,34 @@
*/
package com.evolveum.midpoint.gui.impl.page.admin.component;

import java.util.List;

import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismObjectWrapper;
import com.evolveum.midpoint.web.component.assignment.AssignmentEditorDto;
import com.evolveum.midpoint.model.api.ModelAuthorizationAction;
import com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto;
import com.evolveum.midpoint.web.page.admin.users.dto.UserDtoStatus;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationPhaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

public class UserOperationalButtonsPanel extends FocusOperationalButtonsPanel<UserType> {
private static final long serialVersionUID = 1L;

private LoadableModel<List<AssignmentEditorDto>> delegationsModel;

public UserOperationalButtonsPanel(String id, LoadableModel<PrismObjectWrapper<UserType>> model, LoadableModel<List<AssignmentEditorDto>> delegationsModel, LoadableModel<ExecuteChangeOptionsDto> executeOptionsModel, boolean isSelfProfile) {
public UserOperationalButtonsPanel(String id, LoadableModel<PrismObjectWrapper<UserType>> model, LoadableModel<ExecuteChangeOptionsDto> executeOptionsModel, boolean isSelfProfile) {
super(id, model, executeOptionsModel, isSelfProfile);
this.delegationsModel = delegationsModel;
}

@Override
protected boolean isSavePreviewButtonEnabled() {
//in case user isn't allowed to modify focus data but has
// e.g. #assign authorization, Save button is disabled on page load.
// Save button becomes enabled if some changes are made
// on the Delegations panel
return isDelegationAddedOrRemoved() || super.isSavePreviewButtonEnabled();
return isAuthorizedToModifyUsers() || super.isSavePreviewButtonEnabled();
}


//when the user has just #assign authorization (no #edit), we need to enable Save/Preview buttons
// when the delegations model is changed
public boolean isDelegationAddedOrRemoved() {
for (AssignmentEditorDto dto : delegationsModel.getObject()) {
if (UserDtoStatus.ADD.equals(dto.getStatus()) || UserDtoStatus.DELETE.equals(dto.getStatus())) {
return true;
}
private boolean isAuthorizedToModifyUsers() {
try {
return getPageBase().isAuthorized(ModelAuthorizationAction.MODIFY.getUrl(),
AuthorizationPhaseType.EXECUTION, new UserType().asPrismObject(), null, null);
} catch (Exception e) {
return false;
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected void collectObjectsForPreview(Map<PrismObject<UserType>, ModelContext<

@Override
protected UserOperationalButtonsPanel createButtonsPanel(String id, LoadableModel<PrismObjectWrapper<UserType>> wrapperModel) {
return new UserOperationalButtonsPanel(id, wrapperModel, getObjectDetailsModels().getDelegationsModel(), getObjectDetailsModels().getExecuteOptionsModel(), getObjectDetailsModels().isSelfProfile()) {
return new UserOperationalButtonsPanel(id, wrapperModel, getObjectDetailsModels().getExecuteOptionsModel(), getObjectDetailsModels().isSelfProfile()) {

private static final long serialVersionUID = 1L;

Expand Down

0 comments on commit 2f9ba4a

Please sign in to comment.