Search in sources :

Example 61 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project openolat by klemens.

the class UsermanagerUserSearchForm method findIdentitiesFromSearchForm.

/**
 * @return List of identities that match the criterias from the search form
 */
private List<Identity> findIdentitiesFromSearchForm() {
    // get user attributes from form
    String login = searchform.getStringValue("login");
    // when searching for deleted users, add wildcard to match with backup prefix
    if (searchform.getStatus().equals(Identity.STATUS_DELETED)) {
        login = "*" + login;
    }
    Integer status = null;
    // get user fields from form
    // build user fields search map
    Map<String, String> userPropertiesSearch = new HashMap<String, String>();
    for (UserPropertyHandler userPropertyHandler : searchform.getPropertyHandlers()) {
        if (userPropertyHandler == null)
            continue;
        FormItem ui = searchform.getItem(userPropertyHandler.getName());
        String uiValue = userPropertyHandler.getStringValue(ui);
        if (userPropertyHandler.getName().startsWith("genericCheckboxProperty") && ui instanceof MultipleSelectionElement) {
            if (!"false".equals(uiValue)) {
                // ignore false for the search
                userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
            }
        } else if (StringHelper.containsNonWhitespace(uiValue)) {
            // when searching for deleted users, add wildcard to match with backup prefix
            if (userPropertyHandler instanceof EmailProperty && searchform.getStatus().equals(Identity.STATUS_DELETED)) {
                uiValue = "*" + uiValue;
            }
            userPropertiesSearch.put(userPropertyHandler.getName(), uiValue);
        }
    }
    if (userPropertiesSearch.isEmpty())
        userPropertiesSearch = null;
    // get group memberships from form
    List<SecurityGroup> groupsList = new ArrayList<SecurityGroup>();
    if (searchform.getRole("admin")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_ADMIN);
        groupsList.add(group);
    }
    if (searchform.getRole("author")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_AUTHORS);
        groupsList.add(group);
    }
    if (searchform.getRole("groupmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_GROUPMANAGERS);
        groupsList.add(group);
    }
    if (searchform.getRole("usermanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_USERMANAGERS);
        groupsList.add(group);
    }
    if (searchform.getRole("oresmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_INST_ORES_MANAGER);
        groupsList.add(group);
    }
    if (searchform.getRole("poolmanager")) {
        SecurityGroup group = securityManager.findSecurityGroupByName(Constants.GROUP_POOL_MANAGER);
        groupsList.add(group);
    }
    status = searchform.getStatus();
    SecurityGroup[] groups = groupsList.toArray(new SecurityGroup[groupsList.size()]);
    // no permissions in this form so far
    PermissionOnResourceable[] permissionOnResources = null;
    String[] authProviders = searchform.getAuthProviders();
    // get date constraints from form
    Date createdBefore = searchform.getBeforeDate();
    Date createdAfter = searchform.getAfterDate();
    Date userLoginBefore = searchform.getUserLoginBefore();
    Date userLoginAfter = searchform.getUserLoginAfter();
    // now perform power search
    List<Identity> myIdentities = securityManager.getIdentitiesByPowerSearch((login.equals("") ? null : login), userPropertiesSearch, true, groups, permissionOnResources, authProviders, createdAfter, createdBefore, userLoginAfter, userLoginBefore, status);
    return myIdentities;
}
Also used : HashMap(java.util.HashMap) FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) Date(java.util.Date) MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) PermissionOnResourceable(org.olat.basesecurity.PermissionOnResourceable)

Example 62 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project openolat by klemens.

the class UserBulkChangeManager method getDemoContext.

public Context getDemoContext(Translator propertyTrans) {
    Context vcContext = new VelocityContext();
    List<UserPropertyHandler> userPropertyHandlers2 = userManager.getAllUserPropertyHandlers();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers2) {
        String propertyName = userPropertyHandler.getName();
        String userValue = propertyTrans.translate("import.example." + userPropertyHandler.getName());
        vcContext.put(propertyName, userValue);
    }
    return vcContext;
}
Also used : Context(org.apache.velocity.context.Context) VelocityContext(org.apache.velocity.VelocityContext) VelocityContext(org.apache.velocity.VelocityContext) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 63 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project openolat by klemens.

the class NewUserForm method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    // validate if username does match the syntactical login requirements
    String loginName = usernameTextElement.getValue();
    if (usernameTextElement.isEmpty() || !UserManager.getInstance().syntaxCheckOlatLogin(loginName)) {
        usernameTextElement.setErrorKey("new.error.loginname.empty", new String[] {});
        return false;
    }
    // Check if login is still available
    Identity identity = BaseSecurityManager.getInstance().findIdentityByName(loginName);
    if (identity != null) {
        usernameTextElement.setErrorKey("new.error.loginname.choosen", new String[] {});
        return false;
    }
    usernameTextElement.clearError();
    // validate special rules for each user property
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        // we assume here that there are only textElements for the user properties
        FormItem formItem = flc.getFormComponent(userPropertyHandler.getName());
        if (!userPropertyHandler.isValid(null, formItem, null) || formItem.hasError()) {
            return false;
        }
        formItem.clearError();
    }
    // special test on email address: validate if email is already used
    String email = emailTextElement.getValue();
    if (!UserManager.getInstance().isEmailAllowed(email)) {
        emailTextElement.setErrorKey("new.error.email.choosen", new String[] {});
        return false;
    }
    // password fields depend on form configuration
    if (showPasswordFields && psw1TextElement != null && psw2TextElement != null && authCheckbox.isSelected(0)) {
        String pwd = psw1TextElement.getValue();
        if (psw1TextElement.isEmpty("new.form.mandatory") || psw1TextElement.hasError()) {
            return false;
        }
        if (!UserManager.getInstance().syntaxCheckOlatPassword(pwd)) {
            psw1TextElement.setErrorKey("form.checkPassword", new String[] {});
            return false;
        }
        psw1TextElement.clearError();
        if (psw2TextElement.isEmpty("new.form.mandatory") || psw2TextElement.hasError()) {
            return false;
        }
        // validate that both passwords are the same
        if (!pwd.equals(psw2TextElement.getValue())) {
            psw2TextElement.setErrorKey("new.error.password.nomatch", new String[] {});
            return false;
        }
        psw2TextElement.clearError();
    }
    // all checks passed
    return true;
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 64 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project openolat by klemens.

the class NewUserForm method doCreateAndPersistIdentity.

private Identity doCreateAndPersistIdentity() {
    String lang = languageSingleSelection.getSelectedKey();
    String username = usernameTextElement.getValue();
    String pwd = null;
    // use password only when configured to do so
    if (showPasswordFields && authCheckbox.isSelected(0)) {
        pwd = psw1TextElement.getValue();
        if (!StringHelper.containsNonWhitespace(pwd)) {
            // treat white-space passwords as no-password. This is fine, a password can be set later on
            pwd = null;
        }
    }
    // Create new user and identity and put user to users group
    // Create transient user without firstName,lastName, email
    UserManager um = UserManager.getInstance();
    User newUser = um.createUser(null, null, null);
    // Now add data from user fields (firstName,lastName and email are mandatory)
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        FormItem propertyItem = this.flc.getFormComponent(userPropertyHandler.getName());
        userPropertyHandler.updateUserFromFormItem(newUser, propertyItem);
    }
    // Init preferences
    newUser.getPreferences().setLanguage(lang);
    newUser.getPreferences().setInformSessionTimeout(true);
    // Save everything in database
    Identity ident = securityManager.createAndPersistIdentityAndUserWithDefaultProviderAndUserGroup(username, null, pwd, newUser);
    return ident;
}
Also used : User(org.olat.core.id.User) UserManager(org.olat.user.UserManager) FormItem(org.olat.core.gui.components.form.flexible.FormItem) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 65 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project openolat by klemens.

the class GroupChoiceForm method downloadResults.

private void downloadResults(UserRequest ureq) {
    int cdcnt = manageTableData.getColumnCount();
    int rcnt = manageTableData.getRowCount();
    StringBuilder sb = new StringBuilder();
    boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(ureq.getUserSession().getRoles());
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, isAdministrativeUser);
    // additional informations
    sb.append(translate("cl.course.title")).append('\t').append(course.getCourseTitle());
    sb.append('\n');
    String listTitle = checklist.getTitle() == null ? "" : checklist.getTitle();
    sb.append(translate("cl.title")).append('\t').append(listTitle);
    sb.append('\n').append('\n');
    // header
    for (int c = 0; c < (cdcnt - 1); c++) {
        // skip last column (action)
        ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
        String headerKey = cd.getHeaderKey();
        String headerVal = cd.translateHeaderKey() ? translate(headerKey) : headerKey;
        sb.append('\t').append(headerVal);
    }
    sb.append('\n');
    // checkpoint description
    if (isAdministrativeUser) {
        sb.append('\t');
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        sb.append('\t');
    }
    for (Checkpoint checkpoint : checklist.getCheckpoints()) {
        sb.append('\t').append(checkpoint.getDescription());
    }
    sb.append('\n');
    // data
    for (int r = 0; r < rcnt; r++) {
        for (int c = 0; c < (cdcnt - 1); c++) {
            // skip last column (action)
            ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
            StringOutput so = new StringOutput();
            cd.renderValue(so, r, null);
            String cellValue = so.toString();
            cellValue = StringHelper.stripLineBreaks(cellValue);
            sb.append('\t').append(cellValue);
        }
        sb.append('\n');
    }
    String res = sb.toString();
    String charset = UserManager.getInstance().getUserCharset(ureq.getIdentity());
    ExcelMediaResource emr = new ExcelMediaResource(res, charset);
    ureq.getDispatchResult().setResultingMediaResource(emr);
}
Also used : DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) StringOutput(org.olat.core.gui.render.StringOutput) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) ExcelMediaResource(org.olat.core.gui.media.ExcelMediaResource)

Aggregations

UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)319 Identity (org.olat.core.id.Identity)84 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)74 FlexiTableColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel)70 ArrayList (java.util.ArrayList)62 FormItem (org.olat.core.gui.components.form.flexible.FormItem)62 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)56 User (org.olat.core.id.User)52 HashMap (java.util.HashMap)40 StaticFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.StaticFlexiCellRenderer)36 FlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiColumnModel)34 Translator (org.olat.core.gui.translator.Translator)32 Date (java.util.Date)30 UserManager (org.olat.user.UserManager)28 TextFlexiCellRenderer (org.olat.core.gui.components.form.flexible.impl.elements.table.TextFlexiCellRenderer)24 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)24 File (java.io.File)22 BusinessGroup (org.olat.group.BusinessGroup)22 SortKey (org.olat.core.commons.persistence.SortKey)18 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)18