use of org.jboss.hal.config.Settings.Key.RUN_AS in project console by hal.
the class HeaderView method updateRoles.
@Override
public void updateRoles(Environment environment, Settings settings, User user) {
for (Iterator<HTMLElement> iterator = Elements.iterator(userDropdown); iterator.hasNext(); ) {
HTMLElement element = iterator.next();
if (element == logoutItem) {
continue;
}
iterator.remove();
}
if (!user.getRoles().isEmpty()) {
String csr = user.getRoles().stream().sorted(Roles.STANDARD_FIRST.thenComparing(Roles.BY_NAME)).map(Role::getName).collect(joining(", "));
HTMLElement activeRoles = li().css(static_, CSS.activeRoles).textContent(resources.messages().activeRoles(csr)).title(resources.messages().activeRoles(csr)).element();
userDropdown.insertBefore(activeRoles, logoutItem);
userDropdown.insertBefore(divider(), logoutItem);
if (user.isSuperuser() && environment.getAccessControlProvider() == RBAC) {
Set<String> runAsRoleSetting = settings.get(RUN_AS).asSet();
HTMLElement runAs = li().css(static_).textContent(resources.constants().runAs()).element();
userDropdown.insertBefore(runAs, logoutItem);
stream(environment.getRoles().spliterator(), false).sorted(Roles.STANDARD_FIRST.thenComparing(Roles.BY_NAME)).forEach(role -> {
HTMLElement check, name;
HTMLElement runAsRole = li().add(a().css(clickable).on(click, event -> presenter.runAs(role.getName())).add(check = span().css(fontAwesome("check"), marginRight5).element()).add(name = span().textContent(role.getName()).element())).element();
if (!runAsRoleSetting.contains(role.getName())) {
// NON-NLS
check.style.visibility = "hidden";
}
if (role.isScoped()) {
name.title = role.getBaseRole().getName() + " / " + String.join(", ", role.getScope());
}
userDropdown.insertBefore(runAsRole, logoutItem);
});
if (runAsRoleSetting != null) {
HTMLElement clearRunAs = li().add(a().css(clickable).on(click, event -> presenter.clearRunAs()).textContent(resources.constants().clearRunAs())).element();
userDropdown.insertBefore(clearRunAs, logoutItem);
}
userDropdown.insertBefore(divider(), logoutItem);
}
}
}
Aggregations