Search in sources :

Example 6 with UserSubstitution

use of com.haulmont.cuba.security.entity.UserSubstitution 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();
}
Also used : User(com.haulmont.cuba.security.entity.User) CubaComboBox(com.haulmont.cuba.web.toolkit.ui.CubaComboBox) UserSession(com.haulmont.cuba.security.global.UserSession) Label(com.vaadin.ui.Label) UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution) AppUI(com.haulmont.cuba.web.AppUI)

Example 7 with UserSubstitution

use of com.haulmont.cuba.security.entity.UserSubstitution in project cuba by cuba-platform.

the class WebUserIndicator method getUserSubstitutions.

protected List<UserSubstitution> getUserSubstitutions() {
    TimeSource timeSource = AppBeans.get(TimeSource.NAME);
    DataService dataService = AppBeans.get(DataService.NAME);
    UserSessionSource uss = AppBeans.get(UserSessionSource.NAME);
    LoadContext<UserSubstitution> ctx = new LoadContext<>(UserSubstitution.class);
    LoadContext.Query query = ctx.setQueryString("select us from sec$UserSubstitution us " + "where us.user.id = :userId and (us.endDate is null or us.endDate >= :currentDate) " + "and (us.startDate is null or us.startDate <= :currentDate) " + "and (us.substitutedUser.active = true or us.substitutedUser.active is null) order by us.substitutedUser.name");
    query.setParameter("userId", uss.getUserSession().getUser().getId());
    query.setParameter("currentDate", timeSource.currentTimestamp());
    ctx.setView("app");
    return dataService.loadList(ctx);
}
Also used : UserSubstitution(com.haulmont.cuba.security.entity.UserSubstitution) DataService(com.haulmont.cuba.core.app.DataService)

Aggregations

UserSubstitution (com.haulmont.cuba.security.entity.UserSubstitution)7 User (com.haulmont.cuba.security.entity.User)5 EntityManager (com.haulmont.cuba.core.EntityManager)4 Transaction (com.haulmont.cuba.core.Transaction)4 UserSession (com.haulmont.cuba.security.global.UserSession)3 Test (org.junit.Test)2 DataService (com.haulmont.cuba.core.app.DataService)1 View (com.haulmont.cuba.core.global.View)1 ViewRepository (com.haulmont.cuba.core.global.ViewRepository)1 Group (com.haulmont.cuba.security.entity.Group)1 AppUI (com.haulmont.cuba.web.AppUI)1 CubaComboBox (com.haulmont.cuba.web.toolkit.ui.CubaComboBox)1 Label (com.vaadin.ui.Label)1