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);
}
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";
}
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);
}
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());
}
}
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());
}
}
Aggregations