Search in sources :

Example 81 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class UserDeletionManager method deleteIdentity.

/**
 * Delete all user-data in registered deleteable resources.
 * @param identity
 * @return true
 */
public void deleteIdentity(Identity identity) {
    logInfo("Start deleteIdentity for identity=" + identity);
    String newName = getBackupStringWithDate(identity.getName());
    logInfo("Start Deleting user=" + identity);
    File archiveFilePath = getArchivFilePath(identity);
    Map<String, UserDataDeletable> userDataDeletableResourcesMap = CoreSpringFactory.getBeansOfType(UserDataDeletable.class);
    List<UserDataDeletable> userDataDeletableResources = new ArrayList<>(userDataDeletableResourcesMap.values());
    Collections.sort(userDataDeletableResources, new UserDataDeletableComparator());
    for (UserDataDeletable element : userDataDeletableResources) {
        logInfo("UserDataDeletable-Loop element=" + element);
        element.deleteUserData(identity, newName, archiveFilePath);
    }
    // Delete all authentications for certain identity
    List<Authentication> authentications = securityManager.getAuthentications(identity);
    for (Authentication auth : authentications) {
        logInfo("deleteAuthentication auth=" + auth);
        securityManager.deleteAuthentication(auth);
        logDebug("Delete auth=" + auth + "  of identity=" + identity);
    }
    // remove identity from its security groups
    List<SecurityGroup> securityGroups = securityManager.getSecurityGroupsForIdentity(identity);
    for (SecurityGroup secGroup : securityGroups) {
        securityManager.removeIdentityFromSecurityGroup(identity, secGroup);
        logInfo("Removing user=" + identity + " from security group=" + secGroup.toString());
    }
    // remove identity from groups
    groupDao.removeMemberships(identity);
    String key = identity.getUser().getProperty("emchangeKey", null);
    TemporaryKey tempKey = registrationManager.loadTemporaryKeyByRegistrationKey(key);
    if (tempKey != null) {
        registrationManager.deleteTemporaryKey(tempKey);
    }
    identity = securityManager.loadIdentityByKey(identity.getKey());
    // keep login-name only -> change email
    User persistedUser = identity.getUser();
    List<UserPropertyHandler> userPropertyHandlers = UserManager.getInstance().getAllUserPropertyHandlers();
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        String actualProperty = userPropertyHandler.getName();
        if (userPropertyHandler.isDeletable() && !(keepUserEmailAfterDeletion && UserConstants.EMAIL.equals(actualProperty))) {
            persistedUser.setProperty(actualProperty, null);
        }
        if ((!keepUserEmailAfterDeletion && UserConstants.EMAIL.equals(actualProperty))) {
            String oldEmail = userPropertyHandler.getUserProperty(persistedUser, null);
            String newEmail = "";
            if (StringHelper.containsNonWhitespace(oldEmail)) {
                newEmail = getBackupStringWithDate(oldEmail);
            }
            logInfo("Update user-property user=" + persistedUser);
            userPropertyHandler.setUserProperty(persistedUser, newEmail);
        }
    }
    UserManager.getInstance().updateUserFromIdentity(identity);
    logInfo("deleteUserProperties user=" + persistedUser);
    dbInstance.commit();
    identity = securityManager.loadIdentityByKey(identity.getKey());
    // keep email only -> change login-name
    if (!keepUserEmailAfterDeletion) {
        identity = securityManager.saveIdentityName(identity, newName, null);
    }
    // keep everything, change identity.status to deleted
    logInfo("Change stater identity=" + identity);
    identity = securityManager.saveIdentityStatus(identity, Identity.STATUS_DELETED);
    LifeCycleManager.createInstanceFor(identity).deleteTimestampFor(SEND_DELETE_EMAIL_ACTION);
    LifeCycleManager.createInstanceFor(identity).markTimestampFor(USER_DELETED_ACTION, createLifeCycleLogDataFor(identity));
    logAudit("User-Deletion: Delete all userdata for identity=" + identity);
}
Also used : User(org.olat.core.id.User) TemporaryKey(org.olat.registration.TemporaryKey) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) Authentication(org.olat.basesecurity.Authentication) UserDataDeletable(org.olat.user.UserDataDeletable) File(java.io.File) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 82 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class ExtendedIdentitiesTableDataModel method getValueAt.

/**
 * @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int)
 */
@Override
public final Object getValueAt(int row, int col) {
    Identity identity = getObject(row);
    User user = identity.getUser();
    int offSet = isAdministrativeUser ? 1 : 0;
    if (col == 0 && isAdministrativeUser) {
        return identity.getName();
    }
    if (col >= offSet && col < userPropertyHandlers.size() + offSet) {
        // get user property for this column
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(col - offSet);
        String value = userPropertyHandler.getUserProperty(user, getLocale());
        return (value == null ? "n/a" : value);
    }
    if (col == userPropertyHandlers.size() + offSet) {
        return identity.getLastLogin();
    }
    if (col == userPropertyHandlers.size() + offSet + 1) {
        return user.getCreationDate();
    }
    return "error";
}
Also used : User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 83 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

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)

Example 84 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class UserSearchFlexiController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    if (formLayout instanceof FormLayoutContainer) {
        FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
        // insert a autocompleter search
        Roles roles = ureq.getUserSession().getRoles();
        boolean autoCompleteAllowed = securityModule.isUserAllowedAutoComplete(roles);
        boolean ajax = Windows.getWindows(ureq).getWindowManager().isAjaxEnabled();
        if (ajax && autoCompleteAllowed) {
            // auto complete
            String velocityAutoCRoot = Util.getPackageVelocityRoot(FlexiAutoCompleterController.class);
            String autoCPage = velocityAutoCRoot + "/autocomplete.html";
            autoCompleterContainer = FormLayoutContainer.createCustomFormLayout("autocompletionsearch", getTranslator(), autoCPage);
            autoCompleterContainer.setRootForm(mainForm);
            layoutCont.add(autoCompleterContainer);
            layoutCont.add("autocompletionsearch", autoCompleterContainer);
            setupAutoCompleter(ureq, autoCompleterContainer, null, isAdministrativeUser, 60, 3, null);
        }
        // user search form
        backLink = uifactory.addFormLink("btn.back", formLayout);
        backLink.setIconLeftCSS("o_icon o_icon_back");
        searchFormContainer = FormLayoutContainer.createDefaultFormLayout("usersearchPanel", getTranslator());
        searchFormContainer.setRootForm(mainForm);
        searchFormContainer.setElementCssClass("o_sel_usersearch_searchform");
        searchFormContainer.setFormTitle(translate("header.normal"));
        layoutCont.add(searchFormContainer);
        layoutCont.add("usersearchPanel", searchFormContainer);
        loginEl = uifactory.addTextElement("login", "search.form.login", 128, "", searchFormContainer);
        loginEl.setVisible(isAdministrativeUser);
        propFormItems = new HashMap<>();
        for (UserPropertyHandler userPropertyHandler : userSearchFormPropertyHandlers) {
            if (userPropertyHandler == null)
                continue;
            FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, UserSearchForm.class.getCanonicalName(), false, searchFormContainer);
            // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
            if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
                TextElement textElement = (TextElement) fi;
                textElement.setItemValidatorProvider(null);
            }
            propFormItems.put(userPropertyHandler.getName(), fi);
        }
        FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
        buttonGroupLayout.setRootForm(mainForm);
        searchFormContainer.add(buttonGroupLayout);
        // Don't use submit button, form should not be marked as dirty since this is
        // not a configuration form but only a search form (OLAT-5626)
        searchButton = uifactory.addFormLink("submit.search", buttonGroupLayout, Link.BUTTON);
        layoutCont.contextPut("noList", "false");
        layoutCont.contextPut("showButton", "false");
        // add the table
        FlexiTableColumnModel tableColumnModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
        int colPos = 0;
        if (isAdministrativeUser) {
            tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.user.login", colPos++, true, "login"));
        }
        List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
        List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<>();
        // followed by the users fields
        for (int i = 0; i < userPropertyHandlers.size(); i++) {
            UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
            boolean visible = UserManager.getInstance().isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
            if (visible) {
                resultingPropertyHandlers.add(userPropertyHandler);
                tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel(userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, true, userPropertyHandler.getName()));
            }
        }
        tableColumnModel.addFlexiColumnModel(new DefaultFlexiColumnModel("select", translate("select"), "select"));
        Translator myTrans = userManager.getPropertyHandlerTranslator(getTranslator());
        userTableModel = new UserSearchFlexiTableModel(Collections.<Identity>emptyList(), resultingPropertyHandlers, isAdministrativeUser, getLocale(), tableColumnModel);
        tableEl = uifactory.addTableElement(getWindowControl(), "users", userTableModel, 250, false, myTrans, formLayout);
        tableEl.setCustomizeColumns(false);
        tableEl.setMultiSelect(true);
        tableEl.setSelectAllEnable(true);
        layoutCont.put("userTable", tableEl.getComponent());
    }
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Roles(org.olat.core.id.Roles) EmailProperty(org.olat.user.propertyhandlers.EmailProperty) Translator(org.olat.core.gui.translator.Translator) FlexiTableColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.FlexiTableColumnModel) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) DefaultFlexiColumnModel(org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)

Example 85 with UserPropertyHandler

use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.

the class UserSearchForm method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_user_search_form");
    login = uifactory.addTextElement("login", "search.form.login", 128, "", formLayout);
    login.setVisible(isAdminProps);
    login.setElementCssClass("o_sel_user_search_username");
    Translator tr = Util.createPackageTranslator(UserPropertyHandler.class, getLocale(), getTranslator());
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, getClass().getCanonicalName(), false, formLayout);
        fi.setTranslator(tr);
        // DO NOT validate email field => see OLAT-3324, OO-155, OO-222
        if (userPropertyHandler instanceof EmailProperty && fi instanceof TextElement) {
            TextElement textElement = (TextElement) fi;
            textElement.setItemValidatorProvider(null);
        }
        fi.setElementCssClass("o_sel_user_search_".concat(userPropertyHandler.getName().toLowerCase()));
        propFormItems.put(userPropertyHandler.getName(), fi);
    }
    FormLayoutContainer buttonGroupLayout = FormLayoutContainer.createButtonLayout("buttonGroupLayout", getTranslator());
    formLayout.add(buttonGroupLayout);
    // Don't use submit button, form should not be marked as dirty since this is
    // not a configuration form but only a search form (OLAT-5626)
    searchButton = uifactory.addFormLink("submit.search", buttonGroupLayout, Link.BUTTON);
    searchButton.setElementCssClass("o_sel_user_search_button");
    if (cancelButton) {
        uifactory.addFormCancelButton("cancel", buttonGroupLayout, ureq, getWindowControl());
    }
}
Also used : EmailProperty(org.olat.user.propertyhandlers.EmailProperty) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) Translator(org.olat.core.gui.translator.Translator) FormItem(org.olat.core.gui.components.form.flexible.FormItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

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