use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class WebUserIndicator method refreshUserSubstitutions.
@Override
public void refreshUserSubstitutions() {
component.removeAllComponents();
UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
List<UserSubstitution> substitutions = getUserSubstitutions();
User user = uss.getUserSession().getUser();
AppUI ui = AppUI.getCurrent();
String substitutedUserCaption = getSubstitutedUserCaption(user);
if (substitutions.isEmpty()) {
userComboBox = null;
userNameLabel = new Label(substitutedUserCaption);
userNameLabel.setStyleName("c-user-select-label");
userNameLabel.setSizeUndefined();
if (ui.isTestMode()) {
userNameLabel.setCubaId("currentUserLabel");
}
component.addComponent(userNameLabel);
component.setDescription(substitutedUserCaption);
} else {
userNameLabel = null;
userComboBox = new CubaComboBox();
userComboBox.setFilteringMode(FilteringMode.CONTAINS);
userComboBox.setNullSelectionAllowed(false);
userComboBox.setImmediate(true);
if (ui.isTestMode()) {
userComboBox.setCubaId("substitutedUserSelect");
userComboBox.setId(ui.getTestIdManager().getTestId("substitutedUserSelect"));
}
userComboBox.setStyleName("c-user-select-combobox");
userComboBox.addItem(user);
userComboBox.setItemCaption(user, substitutedUserCaption);
for (UserSubstitution substitution : substitutions) {
User substitutedUser = substitution.getSubstitutedUser();
userComboBox.addItem(substitutedUser);
userComboBox.setItemCaption(substitutedUser, getSubstitutedUserCaption(substitutedUser));
}
UserSession session = uss.getUserSession();
userComboBox.select(session.getSubstitutedUser() == null ? session.getUser() : session.getSubstitutedUser());
userComboBox.addValueChangeListener(new SubstitutedUserChangeListener(userComboBox));
component.addComponent(userComboBox);
component.setDescription(null);
}
adjustWidth();
adjustHeight();
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class WebUserIndicator method revertToCurrentUser.
protected void revertToCurrentUser() {
UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
UserSession us = uss.getUserSession();
userComboBox.select(us.getCurrentOrSubstitutedUser());
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class SpecificPermissionTreeDatasource method filterPermitted.
private Tree<BasicPermissionTarget> filterPermitted(Tree<BasicPermissionTarget> permissions) {
UserSession session = uss.getUserSession();
List<Node<BasicPermissionTarget>> newRootNodes = permissions.getRootNodes().stream().map(root -> filterNode(session, root)).filter(// empty nodes
root -> root.getNumberOfChildren() > 0).collect(Collectors.toCollection(LinkedList::new));
return new Tree<>(newRootNodes);
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class WindowCreationHelper method applyUiPermissions.
/**
* Apply UI permissions to a frame.
*
* @param container frame
*/
public static void applyUiPermissions(Frame container) {
Window window = container instanceof Window ? (Window) container : ComponentsHelper.getWindow(container);
if (window == null) {
log.warn(String.format("Unable to find window for container %s with id '%s'", container.getClass(), container.getId()));
return;
}
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
UserSession userSession = sessionSource.getUserSession();
String screenId = window.getId();
Map<String, Integer> uiPermissions = userSession.getPermissionsByType(PermissionType.UI);
for (Map.Entry<String, Integer> permissionEntry : uiPermissions.entrySet()) {
String target = permissionEntry.getKey();
String targetComponentId = getTargetComponentId(target, screenId);
if (targetComponentId != null) {
if (targetComponentId.contains("[")) {
applyCompositeComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
} else if (targetComponentId.contains(">")) {
applyComponentActionPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
} else {
applyComponentPermission(window, screenId, permissionEntry.getValue(), targetComponentId);
}
}
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class Param method createDateField.
protected Component createDateField(Class javaClass, final ValueProperty valueProperty) {
UserSession userSession = userSessionSource.getUserSession();
boolean supportTimezones = false;
boolean dateOnly = false;
if (property != null) {
TemporalType tt = (TemporalType) property.getAnnotations().get(MetadataTools.TEMPORAL_ANN_NAME);
dateOnly = (tt == TemporalType.DATE);
Object ignoreUserTimeZone = metadataTools.getMetaAnnotationValue(property, IgnoreUserTimeZone.class);
supportTimezones = !dateOnly && !Boolean.TRUE.equals(ignoreUserTimeZone);
} else if (javaClass.equals(java.sql.Date.class)) {
dateOnly = true;
if (useUserTimeZone) {
supportTimezones = true;
}
} else {
supportTimezones = true;
}
if (inExpr) {
ListEditor listEditor = componentsFactory.createComponent(ListEditor.class);
ListEditor.ItemType itemType = dateOnly ? ListEditor.ItemType.DATE : ListEditor.ItemType.DATETIME;
listEditor.setItemType(itemType);
if (userSession.getTimeZone() != null && supportTimezones) {
listEditor.setTimeZone(userSession.getTimeZone());
}
initListEditor(listEditor, valueProperty);
return listEditor;
}
DateField dateField = componentsFactory.createComponent(DateField.class);
DateField.Resolution resolution;
String formatStr;
Messages messages = AppBeans.get(Messages.NAME);
if (dateOnly) {
resolution = com.haulmont.cuba.gui.components.DateField.Resolution.DAY;
formatStr = messages.getMainMessage("dateFormat");
} else {
resolution = com.haulmont.cuba.gui.components.DateField.Resolution.MIN;
formatStr = messages.getMainMessage("dateTimeFormat");
}
dateField.setResolution(resolution);
dateField.setDateFormat(formatStr);
if (userSession.getTimeZone() != null && supportTimezones) {
dateField.setTimeZone(userSession.getTimeZone());
}
dateField.addValueChangeListener(e -> _setValue(e.getValue(), valueProperty));
dateField.setValue(_getValue(valueProperty));
return dateField;
}
Aggregations