Search in sources :

Example 51 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class UserVOFactory method post.

public static void post(User dbUser, UserVO user, Locale locale) {
    UserManager um = UserManager.getInstance();
    List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
    dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
    dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
    dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
    for (UserPropertyVO entry : user.getProperties()) {
        for (UserPropertyHandler propertyHandler : propertyHandlers) {
            if (entry.getName().equals(propertyHandler.getName())) {
                String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
                String parsedValue;
                if (propertyHandler instanceof DatePropertyHandler) {
                    parsedValue = formatDbDate(value, locale);
                } else if (propertyHandler instanceof GenderPropertyHandler) {
                    parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
                } else {
                    parsedValue = propertyHandler.getStringValue(value, locale);
                }
                dbUser.setProperty(entry.getName(), parsedValue);
                break;
            }
        }
    }
}
Also used : GenderPropertyHandler(org.olat.user.propertyhandlers.GenderPropertyHandler) UserManager(org.olat.user.UserManager) DatePropertyHandler(org.olat.user.propertyhandlers.DatePropertyHandler) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 52 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class UserWebService method validateUser.

private List<ErrorVO> validateUser(User user, UserVO userVo, HttpServletRequest request) {
    UserManager um = UserManager.getInstance();
    Locale locale = getLocale(request);
    List<ErrorVO> errors = new ArrayList<>();
    List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(PROPERTY_HANDLER_IDENTIFIER, false);
    validateProperty(user, UserConstants.FIRSTNAME, userVo.getFirstName(), propertyHandlers, errors, um, locale);
    validateProperty(user, UserConstants.LASTNAME, userVo.getLastName(), propertyHandlers, errors, um, locale);
    validateProperty(user, UserConstants.EMAIL, userVo.getEmail(), propertyHandlers, errors, um, locale);
    for (UserPropertyHandler propertyHandler : propertyHandlers) {
        if (!UserConstants.FIRSTNAME.equals(propertyHandler.getName()) && !UserConstants.LASTNAME.equals(propertyHandler.getName()) && !UserConstants.EMAIL.equals(propertyHandler.getName())) {
            validateProperty(user, userVo, propertyHandler, errors, um, locale);
        }
    }
    return errors;
}
Also used : Locale(java.util.Locale) RestSecurityHelper.getLocale(org.olat.restapi.security.RestSecurityHelper.getLocale) ErrorVO(org.olat.restapi.support.vo.ErrorVO) UserManager(org.olat.user.UserManager) RestSecurityHelper.isUserManager(org.olat.restapi.security.RestSecurityHelper.isUserManager) ArrayList(java.util.ArrayList) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 53 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class UserWebService method getUserListQuery.

/**
 * Search users and return them in a simple form (without user properties). User properties
 * can be added two the query parameters. If the authUsername and the authProvider are set,
 * the search is made only with these two parameters because they are sufficient to return
 * a single user.<br>
 * The search with login and user properties are made default with wild cards. If an exact
 * match is needed, the parameter msut be quoted:<br>
 * users?login="username"<br>
 * Don't forget the right escaping in the URL!<br>
 * You can make a search with the user properties like this:<br>
 * users?telMobile=39847592&login=test
 * <br >/ The lookup is possible for authors, usermanagers and system administrators. Normal
 * users are not allowed to use the lookup service.
 *
 * @response.representation.200.qname {http://www.example.com}userVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The list of all users in the OLAT system
 * @response.representation.200.example {@link org.olat.user.restapi.Examples#SAMPLE_USERVOes}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param login The login (search with like)
 * @param authProvider An authentication provider (optional)
 * @param authUsername An specific username from the authentication provider
 * @param uriInfo The URI infos
 * @param httpRequest The HTTP request
 * @return An array of users
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getUserListQuery(@QueryParam("login") String login, @QueryParam("authProvider") String authProvider, @QueryParam("authUsername") String authUsername, @QueryParam("statusVisibleLimit") String statusVisibleLimit, @Context UriInfo uriInfo, @Context HttpServletRequest httpRequest) {
    // User lookup allowed for authors, usermanagers and admins. For
    // usernamanger and up are considered "administrative" when it comes to
    // lookup of the user properties
    boolean isAdministrativeUser = isUserManager(httpRequest);
    if (!isAdministrativeUser && !isAuthor(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
    List<Identity> identities;
    // make only a search by authUsername
    if (StringHelper.containsNonWhitespace(authProvider) && StringHelper.containsNonWhitespace(authUsername)) {
        Authentication auth = BaseSecurityManager.getInstance().findAuthenticationByAuthusername(authUsername, authProvider);
        if (auth == null) {
            identities = Collections.emptyList();
        } else {
            identities = Collections.singletonList(auth.getIdentity());
        }
    } else {
        String[] authProviders = null;
        if (StringHelper.containsNonWhitespace(authProvider)) {
            authProviders = new String[] { authProvider };
        }
        // retrieve and convert the parameters value
        Map<String, String> userProps = new HashMap<String, String>();
        if (!params.isEmpty()) {
            UserManager um = UserManager.getInstance();
            Locale locale = getLocale(httpRequest);
            List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(PROPERTY_HANDLER_IDENTIFIER, isAdministrativeUser);
            for (UserPropertyHandler handler : propertyHandlers) {
                if (!params.containsKey(handler.getName()))
                    continue;
                List<String> values = params.get(handler.getName());
                if (values.isEmpty())
                    continue;
                String value = formatDbUserProperty(values.get(0), handler, locale);
                userProps.put(handler.getName(), value);
            }
        }
        Integer status = Identity.STATUS_VISIBLE_LIMIT;
        if (isAdministrativeUser && "all".equalsIgnoreCase(statusVisibleLimit)) {
            status = null;
        }
        identities = BaseSecurityManager.getInstance().getIdentitiesByPowerSearch(login, userProps, true, null, null, authProviders, null, null, null, null, status);
    }
    int count = 0;
    UserVO[] userVOs = new UserVO[identities.size()];
    for (Identity identity : identities) {
        userVOs[count++] = get(identity);
    }
    return Response.ok(userVOs).build();
}
Also used : Locale(java.util.Locale) RestSecurityHelper.getLocale(org.olat.restapi.security.RestSecurityHelper.getLocale) HashMap(java.util.HashMap) Authentication(org.olat.basesecurity.Authentication) UserManager(org.olat.user.UserManager) RestSecurityHelper.isUserManager(org.olat.restapi.security.RestSecurityHelper.isUserManager) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 54 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class GenericSelectionPropertyHandler method addFormItem.

/**
 * @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale,
 *      org.olat.core.id.User, java.lang.String, boolean,
 *      org.olat.core.gui.components.form.flexible.FormItemContainer)
 */
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    FormItem newItem = null;
    if (isMultiselect) {
        MultipleSelectionElement mse = FormUIFactory.getInstance().addCheckboxesHorizontal(getName(), i18nFormElementLabelKey(), formItemContainer, selectionKeys, getTranslatedValues(selectionKeys, locale));
        for (String sKey : getSelectedKeys(user)) {
            mse.select(sKey, true);
        }
        newItem = mse;
    } else {
        String[] allKeys = new String[selectionKeys.length + 1];
        System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
        allKeys[0] = NO_SEL_KEY;
        SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
        // make pre-selection of the formItem
        String internalValue = getInternalValue(user);
        if (isValidValue(user, internalValue, null, null) && internalValue != null)
            sse.select(internalValue, true);
        newItem = sse;
    }
    // enable/disable according to settings
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        newItem.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        newItem.setMandatory(true);
    }
    return newItem;
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) FormItem(org.olat.core.gui.components.form.flexible.FormItem) UserManager(org.olat.user.UserManager)

Example 55 with UserManager

use of org.olat.user.UserManager in project openolat by klemens.

the class YearPropertyHandler method addFormItem.

@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
    /* let's load the years */
    loadSelectionKeysFromConfig();
    // add the no-selection entry to the dropdown
    String[] allKeys = new String[selectionKeys.length + 1];
    System.arraycopy(selectionKeys, 0, allKeys, 1, selectionKeys.length);
    allKeys[0] = NO_SEL_KEY;
    SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, allKeys, null);
    String internalValue = getInternalValue(user);
    if (isValidValue(user, internalValue, null, null) && internalValue != null)
        sse.select(internalValue, true);
    // enable/disable according to settings
    UserManager um = UserManager.getInstance();
    if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
        sse.setEnabled(false);
    }
    if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
        sse.setMandatory(true);
    }
    return sse;
}
Also used : SingleSelection(org.olat.core.gui.components.form.flexible.elements.SingleSelection) UserManager(org.olat.user.UserManager)

Aggregations

UserManager (org.olat.user.UserManager)64 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)22 Locale (java.util.Locale)12 Identity (org.olat.core.id.Identity)12 Date (java.util.Date)10 FormItem (org.olat.core.gui.components.form.flexible.FormItem)10 Translator (org.olat.core.gui.translator.Translator)10 User (org.olat.core.id.User)10 ArrayList (java.util.ArrayList)8 File (java.io.File)6 SingleSelection (org.olat.core.gui.components.form.flexible.elements.SingleSelection)6 RestSecurityHelper.getLocale (org.olat.restapi.security.RestSecurityHelper.getLocale)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 ValidationError (org.olat.core.gui.components.form.ValidationError)4 SelectionElement (org.olat.core.gui.components.form.flexible.elements.SelectionElement)4 ItemValidatorProvider (org.olat.core.gui.components.form.flexible.impl.elements.ItemValidatorProvider)4 AssertException (org.olat.core.logging.AssertException)4 ICourse (org.olat.course.ICourse)4 RestSecurityHelper.isUserManager (org.olat.restapi.security.RestSecurityHelper.isUserManager)4