Search in sources :

Example 1 with ModifyScopedRole

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);
}
Also used : Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Metadata(org.jboss.hal.meta.Metadata) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Settings(org.jboss.hal.config.Settings) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog) RemoveAssignments(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveAssignments) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) Elements.small(org.jboss.gwt.elemento.core.Elements.small) CSS.subtitle(org.jboss.hal.resources.CSS.subtitle) ModelNode(org.jboss.hal.dmr.ModelNode) RemoveScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveScopedRole) AsyncColumn(org.jboss.hal.spi.AsyncColumn) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) RemoveRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveRoleMapping) FinderColumn(org.jboss.hal.core.finder.FinderColumn) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Comparator.comparing(java.util.Comparator.comparing) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) AddressTemplates(org.jboss.hal.client.accesscontrol.AddressTemplates) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) CSS.itemText(org.jboss.hal.resources.CSS.itemText) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Form(org.jboss.hal.ballroom.form.Form) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog)

Aggregations

SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 HTMLElement (elemental2.dom.HTMLElement)1 ArrayList (java.util.ArrayList)1 Comparator.comparing (java.util.Comparator.comparing)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Inject (javax.inject.Inject)1 Provider (javax.inject.Provider)1 Elements.small (org.jboss.gwt.elemento.core.Elements.small)1 Elements.span (org.jboss.gwt.elemento.core.Elements.span)1 LabelBuilder (org.jboss.hal.ballroom.LabelBuilder)1 ReadChildrenAutoComplete (org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete)1 DialogFactory (org.jboss.hal.ballroom.dialog.DialogFactory)1 Form (org.jboss.hal.ballroom.form.Form)1 SingleSelectBoxItem (org.jboss.hal.ballroom.form.SingleSelectBoxItem)1 SwitchItem (org.jboss.hal.ballroom.form.SwitchItem)1 AddRoleMapping (org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping)1 AddScopedRole (org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole)1 CheckRoleMapping (org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)1