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