use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.
the class CertificatesSelectionController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FlexiTableColumnModel columnsModel = FlexiTableDataModelFactory.createFlexiTableColumnModel();
;
int colPos = 0;
if (isAdministrativeUser) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.name", CertificatesSelectionDataModel.USERNAME_COL));
}
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(AssessedIdentitiesTableDataModel.usageIdentifyer, isAdministrativeUser);
List<UserPropertyHandler> resultingPropertyHandlers = new ArrayList<UserPropertyHandler>();
// followed by the users fields
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = userManager.isMandatoryUserProperty(AssessedIdentitiesTableDataModel.usageIdentifyer, userPropertyHandler);
resultingPropertyHandlers.add(userPropertyHandler);
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel(visible, userPropertyHandler.i18nColumnDescriptorLabelKey(), colPos++, false, null));
}
if (hasAssessableNodes) {
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.passed", CertificatesSelectionDataModel.PASSED_COL, new PassedCellRenderer()));
columnsModel.addFlexiColumnModel(new DefaultFlexiColumnModel("table.header.score", CertificatesSelectionDataModel.SCORE_COL));
}
tableModel = new CertificatesSelectionDataModel(columnsModel, resultingPropertyHandlers);
Set<Integer> preselectedRows = new HashSet<>();
ICourse course = CourseFactory.loadCourse(courseEntry);
CourseNode rootNode = course.getRunStructure().getRootNode();
List<CertificateInfos> infos = new ArrayList<>(datas.size());
int count = 0;
for (AssessedIdentityWrapper data : datas) {
ScoreEvaluation scoreEval = data.getUserCourseEnvironment().getScoreAccounting().getScoreEvaluation(rootNode);
Float score = scoreEval == null ? null : scoreEval.getScore();
Boolean passed = scoreEval == null ? null : scoreEval.getPassed();
Identity assessedIdentity = data.getIdentity();
infos.add(new CertificateInfos(assessedIdentity, score, passed));
if (passed != null && passed.booleanValue()) {
preselectedRows.add(new Integer(count));
}
count++;
}
tableModel.setObjects(infos);
tableEl = uifactory.addTableElement(getWindowControl(), "selection", tableModel, getTranslator(), formLayout);
tableEl.setMultiSelect(true);
tableEl.setSelectAllEnable(true);
tableEl.setMultiSelectedIndex(preselectedRows);
}
use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.
the class UserBulkChangeManager method setUserContext.
/**
* @param identity
* @param vcContext
* @param isAdministrativeUser
*/
public void setUserContext(Identity identity, Context vcContext) {
List<UserPropertyHandler> userPropertyHandlers2 = userManager.getAllUserPropertyHandlers();
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers2) {
String propertyName = userPropertyHandler.getName();
String userValue = identity.getUser().getProperty(propertyName, null);
vcContext.put(propertyName, userValue);
}
}
use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.
the class UserBulkChangeManager method changeSelectedIdentities.
public void changeSelectedIdentities(List<Identity> selIdentities, Map<String, String> attributeChangeMap, Map<String, String> roleChangeMap, List<String> notUpdatedIdentities, boolean isAdministrativeUser, List<Long> ownGroups, List<Long> partGroups, Translator trans, Identity addingIdentity) {
Translator transWithFallback = userManager.getPropertyHandlerTranslator(trans);
String usageIdentifyer = UserBulkChangeStep00.class.getCanonicalName();
notUpdatedIdentities.clear();
List<Identity> changedIdentities = new ArrayList<>();
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
String[] securityGroups = { Constants.GROUP_USERMANAGERS, Constants.GROUP_GROUPMANAGERS, Constants.GROUP_AUTHORS, Constants.GROUP_ADMIN, Constants.GROUP_POOL_MANAGER, Constants.GROUP_INST_ORES_MANAGER };
// loop over users to be edited:
for (Identity identity : selIdentities) {
// reload identity from cache, to prevent stale object
identity = securityManager.loadIdentityByKey(identity.getKey());
User user = identity.getUser();
String oldEmail = user.getEmail();
String errorDesc = "";
boolean updateError = false;
// change pwd
if (attributeChangeMap.containsKey(PWD_IDENTIFYER)) {
String newPwd = attributeChangeMap.get(PWD_IDENTIFYER);
if (StringHelper.containsNonWhitespace(newPwd)) {
if (!userManager.syntaxCheckOlatPassword(newPwd)) {
errorDesc = transWithFallback.translate("error.password");
updateError = true;
}
} else {
newPwd = null;
}
olatAuthManager.changePasswordAsAdmin(identity, newPwd);
}
// set language
String userLanguage = user.getPreferences().getLanguage();
if (attributeChangeMap.containsKey(LANG_IDENTIFYER)) {
String inputLanguage = attributeChangeMap.get(LANG_IDENTIFYER);
if (!userLanguage.equals(inputLanguage)) {
Preferences preferences = user.getPreferences();
preferences.setLanguage(inputLanguage);
user.setPreferences(preferences);
}
}
Context vcContext = new VelocityContext();
// set all properties as context
setUserContext(identity, vcContext);
// org.olat.admin.user.bulkChange.UserBulkChangeStep00
for (int k = 0; k < userPropertyHandlers.size(); k++) {
UserPropertyHandler propHandler = userPropertyHandlers.get(k);
String propertyName = propHandler.getName();
String userValue = identity.getUser().getProperty(propertyName, null);
String inputFieldValue = "";
if (attributeChangeMap.containsKey(propertyName)) {
inputFieldValue = attributeChangeMap.get(propertyName);
inputFieldValue = inputFieldValue.replace("$", "$!");
String evaluatedInputFieldValue = evaluateValueWithUserContext(inputFieldValue, vcContext);
// validate evaluated property-value
ValidationError validationError = new ValidationError();
// do validation checks with users current locale!
Locale locale = transWithFallback.getLocale();
if (!propHandler.isValidValue(identity.getUser(), evaluatedInputFieldValue, validationError, locale)) {
errorDesc = transWithFallback.translate(validationError.getErrorKey(), validationError.getArgs()) + " (" + evaluatedInputFieldValue + ")";
updateError = true;
break;
}
if (!evaluatedInputFieldValue.equals(userValue)) {
String stringValue = propHandler.getStringValue(evaluatedInputFieldValue, locale);
propHandler.setUserProperty(user, stringValue);
}
}
}
// loop over securityGroups defined above
for (String securityGroup : securityGroups) {
SecurityGroup secGroup = securityManager.findSecurityGroupByName(securityGroup);
Boolean isInGroup = securityManager.isIdentityInSecurityGroup(identity, secGroup);
String thisRoleAction = "";
if (roleChangeMap.containsKey(securityGroup)) {
thisRoleAction = roleChangeMap.get(securityGroup);
// user not anymore in security group, remove him
if (isInGroup && thisRoleAction.equals("remove")) {
securityManager.removeIdentityFromSecurityGroup(identity, secGroup);
log.audit("User::" + addingIdentity.getName() + " removed system role::" + securityGroup + " from user::" + identity.getName(), null);
}
// user not yet in security group, add him
if (!isInGroup && thisRoleAction.equals("add")) {
securityManager.addIdentityToSecurityGroup(identity, secGroup);
log.audit("User::" + addingIdentity.getName() + " added system role::" + securityGroup + " to user::" + identity.getName(), null);
}
}
}
// set status
if (roleChangeMap.containsKey("Status")) {
Integer status = Integer.parseInt(roleChangeMap.get("Status"));
int oldStatus = identity.getStatus();
String oldStatusText = (oldStatus == Identity.STATUS_PERMANENT ? "permanent" : (oldStatus == Identity.STATUS_ACTIV ? "active" : (oldStatus == Identity.STATUS_LOGIN_DENIED ? "login_denied" : (oldStatus == Identity.STATUS_DELETED ? "deleted" : "unknown"))));
String newStatusText = (status == Identity.STATUS_PERMANENT ? "permanent" : (status == Identity.STATUS_ACTIV ? "active" : (status == Identity.STATUS_LOGIN_DENIED ? "login_denied" : (status == Identity.STATUS_DELETED ? "deleted" : "unknown"))));
if (oldStatus != status && status == Identity.STATUS_LOGIN_DENIED && Boolean.parseBoolean(roleChangeMap.get("sendLoginDeniedEmail"))) {
sendLoginDeniedEmail(identity);
}
identity = securityManager.saveIdentityStatus(identity, status);
log.audit("User::" + addingIdentity.getName() + " changed accout status for user::" + identity.getName() + " from::" + oldStatusText + " to::" + newStatusText, null);
}
// persist changes:
if (updateError) {
String errorOutput = identity.getName() + ": " + errorDesc;
log.debug("error during bulkChange of users, following user could not be updated: " + errorOutput);
notUpdatedIdentities.add(errorOutput);
} else {
userManager.updateUserFromIdentity(identity);
securityManager.deleteInvalidAuthenticationsByEmail(oldEmail);
changedIdentities.add(identity);
log.audit("User::" + addingIdentity.getName() + " successfully changed account data for user::" + identity.getName() + " in bulk change", null);
}
// commit changes for this user
dbInstance.commit();
}
// FXOLAT-101: add identity to new groups:
if (ownGroups.size() != 0 || partGroups.size() != 0) {
List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
for (Identity selIdentity : selIdentities) {
if (ownGroups != null && !ownGroups.isEmpty()) {
for (Long tutorGroupKey : ownGroups) {
BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(selIdentity, tutorGroupKey);
change.setTutor(Boolean.TRUE);
changes.add(change);
}
}
if (partGroups != null && !partGroups.isEmpty()) {
for (Long partGroupKey : partGroups) {
BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(selIdentity, partGroupKey);
change.setParticipant(Boolean.TRUE);
changes.add(change);
}
}
}
MailPackage mailing = new MailPackage();
businessGroupService.updateMemberships(addingIdentity, changes, mailing);
dbInstance.commit();
}
}
use of org.olat.user.propertyhandlers.UserPropertyHandler in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class GroupController method initGroupTable.
/**
* Init GroupList-table-controller for non-waitinglist (participant-list,
* owner-list).
*/
protected void initGroupTable(TableController tableController, UserRequest ureq, boolean enableTablePreferences, boolean enableUserSelection) {
List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser);
if (isAdministrativeUser) {
// first the login name, but only if administrative user
DefaultColumnDescriptor cd0 = new DefaultColumnDescriptor("table.user.login", 0, COMMAND_VCARD, ureq.getLocale());
cd0.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
tableController.addColumnDescriptor(cd0);
}
if (chatEnabled) {
tableController.addColumnDescriptor(new CustomRenderColumnDescriptor("table.header.online", 1, COMMAND_IM, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, new OnlineIconRenderer()));
}
int visibleColId = 0;
// followed by the users fields
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = userManager.isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
ColumnDescriptor cd = userPropertyHandler.getColumnDescriptor(i + 3, COMMAND_VCARD, ureq.getLocale());
// make all user attributes clickable to open visiting card
if (cd instanceof DefaultColumnDescriptor) {
DefaultColumnDescriptor dcd = (DefaultColumnDescriptor) cd;
dcd.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
}
tableController.addColumnDescriptor(visible, cd);
if (visible) {
visibleColId++;
}
}
// in the end
if (enableTablePreferences) {
DefaultColumnDescriptor dcd = new DefaultColumnDescriptor("table.subject.addeddate", 2, COMMAND_VCARD, ureq.getLocale());
dcd.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
tableController.addColumnDescriptor(true, dcd);
tableController.setSortColumn(++visibleColId, true);
}
if (enableUserSelection) {
tableController.addColumnDescriptor(new StaticColumnDescriptor(COMMAND_SELECTUSER, "table.subject.action", myTrans.translate("action.general")));
}
if (mayModifyMembers) {
tableController.addMultiSelectAction("action.remove", COMMAND_REMOVEUSER);
tableController.setMultiSelect(true);
}
}
Aggregations