Skip to content

Commit

Permalink
fix for MID-8977 Shopping cart: Assignment Constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Sep 7, 2023
1 parent 385e902 commit 180924f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ public List<QName> getNotAssignedRelationsList() {
return availableRelations;
}

public boolean isAssignable() {
public boolean isAssignable(QName selectedRelation) {
if (!isAlreadyAssigned) {
return true;
}
Expand All @@ -808,15 +808,12 @@ public boolean isAssignable() {
if (defaultAssignmentConstraints.isAllowSameTarget() && defaultAssignmentConstraints.isAllowSameRelation()) {
return true;
}
List<QName> availableRelations = WebComponentUtil.getCategoryRelationChoices(AreaCategoryType.ADMINISTRATION, pageBase);
int relationsListSize = availableRelations == null ? 0 : availableRelations.size();
if (defaultAssignmentConstraints.isAllowSameTarget() && !defaultAssignmentConstraints.isAllowSameRelation()
&& getAssignedRelationsList().size() < relationsListSize) {
return true;
}
if (!defaultAssignmentConstraints.isAllowSameTarget()) {
return false;
}
if (!defaultAssignmentConstraints.isAllowSameRelation() && !assignedRelationsList.contains(selectedRelation)) {
return true;
}
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ protected void onInitialize(){
}

private void initLayout(){
GridView gridView = new GridView(ID_ROWS, getModelObject()) {
GridView<AssignmentEditorDto> gridView = new GridView<>(ID_ROWS, getModelObject()) {
private static final long serialVersionUID = 1L;

@Override
protected void populateEmptyItem(Item item) {
protected void populateEmptyItem(Item<AssignmentEditorDto> item) {
GridViewComponent.this.populateEmptyItem(item);
}

@Override
protected void populateItem(Item item) {
protected void populateItem(Item<AssignmentEditorDto> item) {
GridViewComponent.this.populateItem(item);
item.add(AttributeAppender.append("class", getGridItemStyleClass(item.getModel())));
}
Expand Down Expand Up @@ -125,19 +125,19 @@ protected int getColsCount(){
return DEFAULT_COLS_COUNT;
}

protected void populateEmptyItem(Item item) {
protected void populateEmptyItem(Item<AssignmentEditorDto> item) {
item.add(new WebMarkupContainer(ID_CELL_ITEM));
}

protected String getGridItemStyleClass(IModel model){
protected String getGridItemStyleClass(IModel<AssignmentEditorDto> model){
return "";
}

public static String getCellItemId(){
return ID_CELL_ITEM;
}

protected abstract void populateItem(Item item);
protected abstract void populateItem(Item<AssignmentEditorDto> item);

public ObjectDataProvider<AssignmentEditorDto, AbstractRoleType> getProvider(){
return GridViewComponent.this.getModelObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private RoleCatalogStorage getRoleCatalogStorage(){
}

private boolean canAssign(AssignmentEditorDto assignment) {
return assignment.isAssignable();
return assignment.isAssignable(getRoleCatalogStorage().getSelectedRelation());
}

private void addAssignmentPerformed(AssignmentEditorDto assignment, AjaxRequestTarget target){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Map;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.schema.constants.SchemaConstants;

import org.apache.wicket.ajax.AjaxChannel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
Expand Down Expand Up @@ -123,7 +125,7 @@ public boolean isEnabled() {
AssignmentEditorDto dto = AssignmentEditorDto.createDtoFromObject(AbstractRoleMainPanel.this.getObject().asObjectable(),
UserDtoStatus.ADD, parentPage);
return !AssignmentsUtil.isShoppingCartAssignmentsLimitReached(assignmentsLimit, parentPage)
&& (storage.isMultiUserRequest() || dto.isAssignable());
&& (storage.isMultiUserRequest() || dto.isAssignable(SchemaConstants.ORG_DEFAULT));
}
});
addToCartButton.add(AttributeAppender.append("title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ public ItemPath getPath() {

@Override
public String getName() {
if (getDefinition() == null) {
return "";
}
if (getDefinition().getDisplayName() != null){
return WebComponentUtil.getTranslatedPolyString(getDefinition().getDisplayName());
}
if (getDefinition().getDef() == null) {
return "";
}
String key = getDefinition().getDef().getDisplayName();
if (StringUtils.isEmpty(key)) {
key = getSearch().getTypeClass().getSimpleName() + '.' + getDefinition().getDef().getItemName().getLocalPart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected ObjectDataProvider<AssignmentEditorDto, AbstractRoleType> load() {
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(Item item) {
protected void populateItem(Item<AssignmentEditorDto> item) {
item.add(new RoleCatalogItemButton(getCellItemId(), item.getModel()) {
private static final long serialVersionUID = 1L;

Expand All @@ -175,6 +175,7 @@ protected QName getNewAssignmentRelation() {
return AbstractShoppingCartTabPanel.this.getNewAssignmentRelation();
}
});
item.add(new VisibleBehaviour(() -> canBeAssigned(item.getModelObject())));
}
};
catalogItemsGrid.add(new VisibleEnableBehaviour() {
Expand Down Expand Up @@ -504,4 +505,8 @@ protected RoleCatalogStorage getRoleCatalogStorage() {
protected GridViewComponent getGridViewComponent() {
return (GridViewComponent) get(createComponentPath(ID_SHOPPING_CART_CONTAINER, ID_SHOPPING_CART_ITEMS_PANEL));
}

private boolean canBeAssigned(AssignmentEditorDto dto) {
return dto.isAssignable(getNewAssignmentRelation());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public class PageAssignmentShoppingCart extends PageSelf {
private static final String DOT_CLASS = PageAssignmentShoppingCart.class.getName() + ".";

private static final String OPERATION_GET_ASSIGNMENT_VIEW_LIST = DOT_CLASS + "getRoleCatalogViewsList";
private static final String OPERATION_LOAD_RELATION_DEFINITIONS = DOT_CLASS + "loadRelationDefinitions";
private static final String OPERATION_LOAD_ASSIGNMENTS_LIMIT = DOT_CLASS + "loadAssignmentsLimit";
private static final String OPERATION_LOAD_DEFAULT_VIEW_TYPE = DOT_CLASS + "loadDefaultViewType";
private static final Trace LOGGER = TraceManager.getTrace(PageAssignmentShoppingCart.class);

private IModel<RoleManagementConfigurationType> roleManagementConfigModel;
Expand Down

0 comments on commit 180924f

Please sign in to comment.