Creating a super role

Hi,

i’d want to create a super administrator role at design time, but i’d want to avoid the possibility to assign it to an user in RoleAssignmentView: how to exclude it from available roles?

Thanks in advance

Hi @m.russo

You can override ResourceRoleModelLookupView to achieve this.

NewView, select “Override an existing view” template.
Find resource-role-model-lookup-view.xml to override, select Extend layout of existing screen.

You will get the new ext-resource-role-model-lookup-view.xml descriptor and the ExtResourceRoleModelLookupView controller.

Override the loadRoles() method of the controller as follows:

package com.company.onboarding.view.resourcerolemodellookup;

import com.company.onboarding.view.main.MainView;
import com.vaadin.flow.router.Route;
import io.jmix.flowui.model.CollectionContainer;
import io.jmix.flowui.view.ViewComponent;
import io.jmix.flowui.view.ViewController;
import io.jmix.flowui.view.ViewDescriptor;
import io.jmix.securityflowui.component.rolefilter.RoleFilterChangeEvent;
import io.jmix.securityflowui.model.ResourceRoleModel;
import io.jmix.securityflowui.view.resourcerole.ResourceRoleModelLookupView;

@Route(value = "sec/resourcerolemodelslookup", layout = MainView.class)
@ViewController("sec_ResourceRoleModel.lookup")
@ViewDescriptor("ext-resource-role-model-lookup-view.xml")
public class ExtResourceRoleModelLookupView extends ResourceRoleModelLookupView {

    @ViewComponent
    private CollectionContainer<ResourceRoleModel> roleModelsDc;

    @Override
    protected void loadRoles(RoleFilterChangeEvent event) {
        super.loadRoles(event);
        roleModelsDc.getItems().stream()
                .filter(role ->
                        role.getCode().equals("system-full-access"))
                .findAny()
                .ifPresent(role ->
                        roleModelsDc.getMutableItems().remove(role));
    }
}

The role lookup will no longer include the “Full Access” role:
image