use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class NewUserForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.newuser");
setFormDescription("new.form.please.enter");
setFormContextHelp("User management");
formLayout.setElementCssClass("o_sel_id_create");
usernameTextElement = uifactory.addTextElement(LOGINNAME, "username", 128, "", formLayout);
usernameTextElement.setMandatory(true);
usernameTextElement.setDisplaySize(30);
usernameTextElement.setElementCssClass("o_sel_id_username");
UserManager um = UserManager.getInstance();
userPropertyHandlers = um.getUserPropertyHandlersFor(formIdentifyer, true);
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem formItem = userPropertyHandler.addFormItem(ureq.getLocale(), null, formIdentifyer, true, formLayout);
// special case to handle email field
if (userPropertyHandler.getName().equals(UserConstants.EMAIL)) {
emailTextElement = (TextElement) formItem;
if (!userModule.isEmailMandatory()) {
formItem.setMandatory(false);
}
}
formItem.setElementCssClass("o_sel_id_" + userPropertyHandler.getName().toLowerCase());
}
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
ArrayHelper.sort(langKeys, langValues, false, true, false);
// Build css classes for reference languages
languageSingleSelection = uifactory.addDropdownSingleselect("new.form.language", formLayout, langKeys, langValues, null);
// select default language in form
languageSingleSelection.select(I18nModule.getDefaultLocale().toString(), true);
// add password fields!!!
if (showPasswordFields) {
uifactory.addStaticTextElement("heading2", null, translate("new.form.please.enter.pwd"), formLayout);
// checkBox: generate user with OLAT authentication or not
String[] authKeys = { "xx" };
String[] authValues = { translate("new.form.auth.true") };
authCheckbox = uifactory.addCheckboxesHorizontal("new.form.auth", formLayout, authKeys, authValues);
authCheckbox.select("xx", showPasswordFields);
authCheckbox.addActionListener(FormEvent.ONCLICK);
// if OLAT authentication is used, use the pwd below
psw1TextElement = uifactory.addPasswordElement(PASSWORD_NEW1, "new.form.password.new1", 255, "", formLayout);
psw1TextElement.setMandatory(true);
psw1TextElement.setDisplaySize(30);
psw1TextElement.setVisible(showPasswordFields);
psw1TextElement.setElementCssClass("o_sel_id_password1");
psw1TextElement.setAutocomplete("new-password");
psw2TextElement = uifactory.addPasswordElement(PASSWORD_NEW2, "new.form.password.new2", 255, "", formLayout);
psw2TextElement.setMandatory(true);
psw2TextElement.setDisplaySize(30);
psw2TextElement.setVisible(showPasswordFields);
psw2TextElement.setElementCssClass("o_sel_id_password2");
psw2TextElement.setAutocomplete("new-password");
}
uifactory.addFormSubmitButton("save", "submit.save", formLayout);
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
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.UserManager in project OpenOLAT by OpenOLAT.
the class PublishProcess method applyPublishSet.
/**
* @param identity
* @param locale
* @param newCourse Optimization for new courses, it doesn't call upddateOnPublish of inserted/updated course nodes
*/
public void applyPublishSet(Identity identity, Locale locale, boolean newCourse) {
// the active runstructure and the new created runstructure
Structure existingCourseRun = course.getRunStructure();
EventBus orec = CoordinatorManager.getInstance().getCoordinator().getEventBus();
/*
* use book keeping lists for publish event
*/
Set<String> deletedCourseNodeIds = new HashSet<String>();
if (editorModelDeletedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
deletedCourseNodeIds.add(cn.getIdent());
}
}
Set<String> insertedCourseNodeIds = new HashSet<String>();
if (editorModelInsertedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
insertedCourseNodeIds.add(cn.getIdent());
}
}
Set<String> modifiedCourseNodeIds = new HashSet<String>();
if (editorModelModifiedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
modifiedCourseNodeIds.add(cn.getIdent());
}
}
/*
* broadcast PRE PUBLISH event that a publish will take place
*/
PublishEvent beforePublish = new PublishEvent(course, identity);
beforePublish.setDeletedCourseNodeIds(deletedCourseNodeIds);
beforePublish.setInsertedCourseNodeIds(insertedCourseNodeIds);
beforePublish.setModifiedCourseNodeIds(modifiedCourseNodeIds);
beforePublish.setState(PublishEvent.PRE_PUBLISH);
// old course structure accessible
orec.fireEventToListenersOf(beforePublish, course);
/*
* TODO:pb: discuss with fj: listeners could add information to
* beforePublish event such as a right to veto or add identities who is
* currently in the course, thus stopping the publishing author from
* publishing! i.e. if people are in a test or something like this.... we
* could the ask here beforePublish.accepted() and proceed only in this
* case.
*/
//
/*
* remove new nodes which were marked as delete and deletion is published.
*/
UserManager um = UserManager.getInstance();
String charset = um.getUserCharset(identity);
if (editorModelDeletedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelDeletedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
// null
if (oldCn != null) {
if (!(cn.getIdent().equals(oldCn.getIdent()))) {
throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
}
}
cetn.removeFromParent();
if (!cetn.isNewnode() && oldCn != null) {
// only clean up and archive of nodes which were already in run
// save data, remove references
deleteRefs(oldCn);
archiveDeletedNode(identity, cn, oldCn, locale, charset);
// 2) delete all user data
oldCn.cleanupOnDelete(course);
}
}
}
/*
* mark modified ones as no longer dirty
*/
if (editorModelModifiedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelModifiedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
// null
if (oldCn != null) {
if (!(cn.getIdent().equals(oldCn.getIdent()))) {
throw new AssertException("deleted cn.getIdent != oldCn.getIdent");
}
}
cetn.setDirty(false);
//
updateRefs(cn, oldCn);
}
}
/*
* mark newly published ones is no longer new and dirty
*/
if (editorModelInsertedNodes.size() > 0) {
for (Iterator<CourseEditorTreeNode> iter = editorModelInsertedNodes.iterator(); iter.hasNext(); ) {
CourseEditorTreeNode cetn = iter.next();
CourseNode cn = cetn.getCourseNode();
CourseNode oldCn = existingCourseRun.getNode(cetn.getIdent());
if (oldCn != null) {
throw new AssertException("new node has an oldCN??");
}
cetn.setDirty(false);
cetn.setNewnode(false);
//
updateRefs(cn, null);
}
}
/*
* saving
*/
long pubtimestamp = System.currentTimeMillis();
editorTreeModel.setLatestPublishTimestamp(pubtimestamp);
// set the new runstructure and save it.
existingCourseRun.setRootNode(resultingCourseRun.getRootNode());
CourseFactory.saveCourse(course.getResourceableId());
// on old course, apply update to published nodes
if (!newCourse) {
for (CourseEditorTreeNode cetn : editorModelInsertedNodes) {
cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
}
for (CourseEditorTreeNode cetn : editorModelModifiedNodes) {
cetn.getCourseNode().updateOnPublish(locale, course, identity, publishEvents);
}
}
// commit all changes before sending an event
DBFactory.getInstance().commitAndCloseSession();
/*
* broadcast event
*/
PublishEvent publishEvent = new PublishEvent(course, identity);
publishEvent.setDeletedCourseNodeIds(deletedCourseNodeIds);
publishEvent.setInsertedCourseNodeIds(insertedCourseNodeIds);
publishEvent.setModifiedCourseNodeIds(modifiedCourseNodeIds);
// new course structure accessible
// CourseFactory is one listener, which removes the course from the
// cache.
orec.fireEventToListenersOf(publishEvent, course);
/*
* END NEW STYLE PUBLISH
*/
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class ReturnboxFullAccessCallback method init.
protected void init(UserRequest ureq) {
myContent = createVelocityContainer("dropboxscoring");
taskLaunchButton = LinkFactory.createButton("task.launch", myContent, this);
cancelTaskButton = LinkFactory.createButton("task.cancel", myContent, this);
cancelTaskButton.setVisible(!userCourseEnv.isCourseReadOnly());
putInitialPanel(myContent);
ModuleConfiguration modConfig = node.getModuleConfiguration();
Boolean bValue = (Boolean) modConfig.get(TACourseNode.CONF_TASK_ENABLED);
myContent.contextPut("hasTask", (bValue != null) ? bValue : new Boolean(false));
// configured value
Boolean hasDropbox = (Boolean) modConfig.get(TACourseNode.CONF_DROPBOX_ENABLED);
Boolean hasDropboxValue = (hasDropbox != null) ? hasDropbox : new Boolean(true);
myContent.contextPut("hasDropbox", hasDropboxValue);
Boolean hasReturnbox = (Boolean) modConfig.get(TACourseNode.CONF_RETURNBOX_ENABLED);
myContent.contextPut("hasReturnbox", (hasReturnbox != null) ? hasReturnbox : hasDropboxValue);
// dropbox display
Identity assessee = userCourseEnv.getIdentityEnvironment().getIdentity();
String assesseeName = assessee.getName();
UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
String assesseeFullName = StringHelper.escapeHtml(userManager.getUserDisplayName(assessee));
// notification
if (hasNotification) {
subsContext = DropboxFileUploadNotificationHandler.getSubscriptionContext(userCourseEnv.getCourseEnvironment(), node);
if (subsContext != null) {
String path = DropboxController.getDropboxPathRelToFolderRoot(userCourseEnv.getCourseEnvironment(), node);
contextualSubscriptionCtr = AbstractTaskNotificationHandler.createContextualSubscriptionController(ureq, this.getWindowControl(), path, subsContext, DropboxController.class);
myContent.put("subscription", contextualSubscriptionCtr.getInitialComponent());
myContent.contextPut("hasNotification", Boolean.TRUE);
}
} else {
myContent.contextPut("hasNotification", Boolean.FALSE);
}
OlatRootFolderImpl rootDropbox = new OlatRootFolderImpl(getDropboxFilePath(assesseeName), null);
rootDropbox.setLocalSecurityCallback(getDropboxVfsSecurityCallback());
OlatNamedContainerImpl namedDropbox = new OlatNamedContainerImpl(assesseeFullName, rootDropbox);
namedDropbox.setLocalSecurityCallback(getDropboxVfsSecurityCallback());
dropboxFolderRunController = new FolderRunController(namedDropbox, false, ureq, getWindowControl());
listenTo(dropboxFolderRunController);
myContent.put("dropbox", dropboxFolderRunController.getInitialComponent());
Identity assessedIdentity = userCourseEnv.getIdentityEnvironment().getIdentity();
// returnbox display
OlatRootFolderImpl rootReturnbox = new OlatRootFolderImpl(getReturnboxFilePath(assesseeName), null);
VFSSecurityCallback secCallback = getReturnboxVfsSecurityCallback(rootReturnbox.getRelPath(), assessedIdentity);
rootReturnbox.setLocalSecurityCallback(secCallback);
OlatNamedContainerImpl namedReturnbox = new OlatNamedContainerImpl(assesseeFullName, rootReturnbox);
namedReturnbox.setLocalSecurityCallback(secCallback);
returnboxFolderRunController = new FolderRunController(namedReturnbox, false, ureq, getWindowControl());
returnboxFolderRunController.disableSubscriptionController();
listenTo(returnboxFolderRunController);
myContent.put("returnbox", returnboxFolderRunController.getInitialComponent());
// insert Status Pull-Down Menu depending on user role == author
boolean isAuthor = ureq.getUserSession().getRoles().isAuthor();
boolean isTutor = userCourseEnv.getCourseEnvironment().getCourseGroupManager().isIdentityCourseCoach(ureq.getIdentity());
if (((AssessableCourseNode) node).hasStatusConfigured() && (isAuthor || isTutor)) {
myContent.contextPut("hasStatusPullDown", Boolean.TRUE);
statusForm = new StatusForm(ureq, getWindowControl(), userCourseEnv.isCourseReadOnly());
listenTo(statusForm);
// get identity not from request (this would be an author)
StatusManager.getInstance().loadStatusFormData(statusForm, node, userCourseEnv);
myContent.put("statusForm", statusForm.getInitialComponent());
}
assignedTask = TaskController.getAssignedTask(assessedIdentity, userCourseEnv.getCourseEnvironment(), node);
if (assignedTask != null) {
myContent.contextPut("assignedtask", assignedTask);
myContent.contextPut("taskIcon", CSSHelper.createFiletypeIconCssClassFor(assignedTask));
if (!(assignedTask.toLowerCase().endsWith(".html") || assignedTask.toLowerCase().endsWith(".htm") || assignedTask.toLowerCase().endsWith(".txt"))) {
taskLaunchButton.setTarget("_blank");
}
}
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class GTACourseNode method validateInternalConfiguration.
private List<StatusDescription> validateInternalConfiguration(CourseEditorEnv cev) {
List<StatusDescription> sdList = new ArrayList<>(5);
ModuleConfiguration config = getModuleConfiguration();
boolean hasScoring = config.getBooleanSafe(GTASK_GRADING);
if (hasScoring) {
if (!config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_PASSED_FIELD) && !config.getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_COMMENT_FIELD)) {
addStatusErrorDescription("error.missing.score.config", GTAEditController.PANE_TAB_GRADING, sdList);
}
}
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
List<Long> groupKeys = config.getList(GTACourseNode.GTASK_GROUPS, Long.class);
List<Long> areaKeys = config.getList(GTACourseNode.GTASK_AREAS, Long.class);
if (groupKeys.isEmpty() && areaKeys.isEmpty()) {
addStatusErrorDescription("error.missing.group", GTAEditController.PANE_TAB_GRADING, sdList);
}
}
// at least one step
if (!config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) && !config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) && !config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION) && !config.getBooleanSafe(GTACourseNode.GTASK_REVISION_PERIOD) && !config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION) && !config.getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
addStatusErrorDescription("error.select.atleastonestep", GTAEditController.PANE_TAB_WORKLOW, sdList);
}
if (cev != null) {
// check assignment
GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
RepositoryEntry courseRe = cev.getCourseGroupManager().getCourseEntry();
ICourse course = CourseFactory.loadCourse(courseRe);
if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT)) {
File taskDirectory = gtaManager.getTasksDirectory(course.getCourseEnvironment(), this);
if (!TaskHelper.hasDocuments(taskDirectory)) {
if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
} else {
addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
}
} else {
List<TaskDefinition> taskList = gtaManager.getTaskDefinitions(course.getCourseEnvironment(), this);
if (taskList == null || taskList.isEmpty()) {
if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
addStatusWarningDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
} else {
addStatusErrorDescription("error.missing.tasks", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
}
} else {
String[] filenames = taskDirectory.list();
for (TaskDefinition taskDef : taskList) {
boolean found = false;
for (String filename : filenames) {
if (filename.equals(taskDef.getFilename())) {
found = true;
break;
}
}
if (!found) {
addStatusWarningDescription("error.missing.file", GTAEditController.PANE_TAB_ASSIGNMENT, sdList);
}
}
}
}
}
// check solutions
if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
File solutionDirectory = gtaManager.getSolutionsDirectory(course.getCourseEnvironment(), this);
if (!TaskHelper.hasDocuments(solutionDirectory)) {
if (config.getBooleanSafe(GTACourseNode.GTASK_COACH_ALLOWED_UPLOAD_TASKS, false)) {
addStatusWarningDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
} else {
addStatusErrorDescription("error.missing.solutions", GTAEditController.PANE_TAB_SOLUTIONS, sdList);
}
}
}
List<IdentityRef> participants = gtaManager.getDuplicatedMemberships(this);
if (participants.size() > 0) {
UserManager um = CoreSpringFactory.getImpl(UserManager.class);
StringBuilder sb = new StringBuilder();
for (IdentityRef participant : participants) {
String fullname = um.getUserDisplayName(participant.getKey());
if (sb.length() > 0)
sb.append(", ");
sb.append(fullname);
}
String[] params = new String[] { getShortTitle(), sb.toString() };
StatusDescription sd = new StatusDescription(StatusDescription.WARNING, "error.duplicate.memberships", "error.duplicate.memberships", params, PACKAGE_GTA);
sd.setDescriptionForUnit(getIdent());
sd.setActivateableViewIdentifier(GTAEditController.PANE_TAB_WORKLOW);
sdList.add(sd);
}
}
return sdList;
}
Aggregations