use of org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole in project console by hal.
the class RoleColumn method editScopedRole.
private void editScopedRole(Role role, String type, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
item.setRequired(true);
return item;
}).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 2, resources.messages().includeAllHelpText()).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.getFormItem(INCLUDE_ALL).setValue(role.isIncludeAll());
form.attach();
ModelNode modelNode = new ModelNode();
modelNode.get(BASE_ROLE).set(role.getBaseRole().getName());
role.getScope().forEach(scope -> modelNode.get(scopeAttribute).add(scope));
new ModifyResourceDialog(resources.messages().modifyResourceTitle(type), form, (frm, changedValues) -> {
boolean includeAll = frm.<Boolean>getFormItem(INCLUDE_ALL).getValue();
boolean includeAllChanged = includeAll != role.isIncludeAll();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!changedValues.isEmpty()) {
tasks.add(new ModifyScopedRole(dispatcher, role, changedValues, metadata));
}
if (includeAllChanged) {
tasks.add(new ModifyIncludeAll(dispatcher, role, includeAll));
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().modifyResourceSuccess(type, role.getName())));
accessControl.reload(() -> {
refresh(role.getId());
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
}).show(modelNode);
}
Aggregations