use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class UserAdminController method allowedToManageUser.
/**
* Check if user allowed to modify this identity. Only modification of user
* that have lower rights is allowed. No one exept admins can manage usermanager
* and admins
* @param ureq
* @param identity
* @return boolean
*/
private boolean allowedToManageUser(UserRequest ureq, Identity identity) {
// prevent editing of users that are in frentix-superadmin group (except "frentix" wants to change own profile)
Identity editor = ureq.getUserSession().getIdentity();
SecurityGroup frentixSuperAdminGroup = securityManager.findSecurityGroupByName("fxadmins");
if (securityManager.isIdentityInSecurityGroup(identity, frentixSuperAdminGroup)) {
if (editor.equals(identity) || securityManager.isIdentityInSecurityGroup(editor, frentixSuperAdminGroup)) {
return true;
}
return false;
}
if (isOlatAdmin) {
return true;
}
// only admins can administrate admin and usermanager users
boolean isAdmin = securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_ADMIN);
boolean isUserManager = securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_USERMANAGER);
if (isAdmin || isUserManager) {
return false;
}
// if user is author ony allowed to edit if configured
boolean isAuthor = securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_AUTHOR);
Boolean canManageAuthor = BaseSecurityModule.USERMANAGER_CAN_MANAGE_AUTHORS;
if (isAuthor && !canManageAuthor.booleanValue()) {
return false;
}
// if user is groupmanager ony allowed to edit if configured
boolean isGroupManager = securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GROUPMANAGER);
Boolean canManageGroupmanager = BaseSecurityModule.USERMANAGER_CAN_MANAGE_GROUPMANAGERS;
if (isGroupManager && !canManageGroupmanager.booleanValue()) {
return false;
}
// if user is guest ony allowed to edit if configured
boolean isGuestOnly = securityManager.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_GUESTONLY);
Boolean canManageGuest = BaseSecurityModule.USERMANAGER_CAN_MANAGE_GUESTS;
if (isGuestOnly && !canManageGuest.booleanValue()) {
return false;
}
// passed all tests, current user is allowed to edit given identity
return true;
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class UserSearchController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
public void event(UserRequest ureq, Controller source, Event event) {
if (source == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
int rowid = te.getRowId();
Identity foundIdentity = tdm.getObject(rowid);
foundIdentities.add(foundIdentity);
// Tell parentController that a subject has been found
fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
}
} else if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
if (tmse.getAction().equals(ACTION_MULTISELECT_CHOOSE)) {
foundIdentities = tdm.getObjects(tmse.getSelection());
fireEvent(ureq, new MultiIdentityChosenEvent(foundIdentities));
}
}
} else if (source == autocompleterC) {
if (event instanceof EntriesChosenEvent) {
EntriesChosenEvent ece = (EntriesChosenEvent) event;
List<String> res = ece.getEntries();
// if we get the event, we have a result or an incorrect selection see OLAT-5114 -> check for empty
String mySel = res.isEmpty() ? null : (String) res.get(0);
if ((mySel == null) || mySel.trim().equals("")) {
getWindowControl().setWarning(translate("error.search.form.notempty"));
return;
}
// default not found
Long key = -1l;
try {
key = Long.valueOf(mySel);
if (key > 0) {
Identity chosenIdent = BaseSecurityManager.getInstance().loadIdentityByKey(key);
// No need to check for null, exception is thrown when identity does not exist which really
// should not happen at all.
// Tell that an identity has been chosen
fireEvent(ureq, new SingleIdentityChosenEvent(chosenIdent));
}
} catch (NumberFormatException e) {
getWindowControl().setWarning(translate("error.no.user.found"));
return;
}
}
} else if (source == searchform) {
if (event == Event.DONE_EVENT) {
// form validation was ok
doSearch(ureq);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class WaitingGroupController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller sourceController, Event event) {
if (sourceController == tableCtr) {
if (event.getCommand().equals(Table.COMMAND_MULTISELECT)) {
// Multiselect events
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
if (tmse.getAction().equals(COMMAND_MOVE_USER_WAITINGLIST)) {
if (tmse.getSelection().isEmpty()) {
getWindowControl().setWarning(translate("msg.selectionempty"));
} else {
List<Identity> objects = identitiesTableModel.getIdentities(tmse.getSelection());
toTransfer = objects;
removeAsListenerAndDispose(transferMailCtr);
transferMailCtr = new MailNotificationEditController(getWindowControl(), ureq, transferUserMailTempl, true, mandatoryEmail, true);
listenTo(transferMailCtr);
removeAsListenerAndDispose(cmc);
cmc = new CloseableModalController(getWindowControl(), translate("close"), transferMailCtr.getInitialComponent());
listenTo(cmc);
cmc.activate();
// don't execute super method
return;
}
}
}
} else if (sourceController == transferMailCtr) {
if (event == Event.DONE_EVENT) {
// fetch configured mail template and finish this controller workflow
MailTemplate customTransferTemplate = transferMailCtr.getMailTemplate();
cmc.deactivate();
IdentitiesMoveEvent identitiesMoveEvent = new IdentitiesMoveEvent(toTransfer);
identitiesMoveEvent.setMailTemplate(customTransferTemplate);
fireEvent(ureq, identitiesMoveEvent);
StringBuilder infoMessage = new StringBuilder();
for (Identity identity : identitiesMoveEvent.getNotMovedIdentities()) {
String fullName = userManager.getUserDisplayName(identity);
infoMessage.append(translate("msg.alreadyinwaiitinggroup", fullName)).append("<br />");
}
// report any errors on screen
if (infoMessage.length() > 0)
getWindowControl().setInfo(infoMessage.toString());
// don't execute super method
return;
} else if (event == Event.CANCELLED_EVENT) {
cmc.deactivate();
// don't execute super method
return;
} else {
throw new RuntimeException("unknown event ::" + event.getCommand());
}
}
// it is no WaitingGroupController event, forward it to super class GroupController
super.event(ureq, sourceController, event);
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class ImportToCalendarManager method check.
private boolean check(ImportedToCalendar importedToCalendar) {
String id = importedToCalendar.getToCalendarId();
String type = importedToCalendar.getToType();
if (CalendarManager.TYPE_USER.equals(type)) {
Identity identity = securityManager.findIdentityByNameCaseInsensitive(id);
return identity != null && identity.getStatus() != null && identity.getStatus().intValue() < Identity.STATUS_DELETED;
}
if (CalendarManager.TYPE_COURSE.equals(type)) {
Long resourceId = new Long(id);
RepositoryEntry entry = repositoryEntryDao.loadByResourceId("CourseModule", resourceId);
return entry != null;
}
if (CalendarManager.TYPE_GROUP.equals(type)) {
Long resourceId = new Long(id);
BusinessGroup group = businessGroupDao.loadByResourceId(resourceId);
return group != null;
}
return true;
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class InfoMessageFrontendManagerImpl method sendInfoMessage.
@Override
public boolean sendInfoMessage(InfoMessage infoMessage, MailFormatter mailFormatter, Locale locale, Identity from, List<Identity> tos) {
infoMessageManager.saveInfoMessage(infoMessage);
boolean send = false;
if (tos != null && !tos.isEmpty()) {
Set<Long> identityKeySet = new HashSet<Long>();
ContactList contactList = new ContactList("Infos");
for (Identity to : tos) {
if (identityKeySet.contains(to.getKey()))
continue;
contactList.add(to);
identityKeySet.add(to.getKey());
}
try {
String subject = null;
String body = null;
if (mailFormatter != null) {
subject = mailFormatter.getSubject(infoMessage);
body = mailFormatter.getBody(infoMessage);
}
if (!StringHelper.containsNonWhitespace(subject)) {
subject = infoMessage.getTitle();
}
if (!StringHelper.containsNonWhitespace(body)) {
body = infoMessage.getMessage();
}
File attachment = null;
if (StringHelper.containsNonWhitespace(infoMessage.getAttachmentPath())) {
File root = getStoragePath().getBasefile();
attachment = new File(root, infoMessage.getAttachmentPath());
}
MailContext context = new MailContextImpl(mailFormatter.getBusinessPath());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setFromId(from);
bundle.setContactList(contactList);
if (attachment != null) {
bundle.setContent(subject, body, attachment);
} else {
bundle.setContent(subject, body);
}
MailerResult result = mailManager.sendMessage(bundle);
send = result.isSuccessful();
} catch (Exception e) {
log.error("Cannot send info messages", e);
}
}
infoSubscriptionManager.markPublisherNews(infoMessage.getOLATResourceable(), infoMessage.getResSubPath());
MultiUserEvent mue = new MultiUserEvent("new_info_message");
coordinatorManager.getCoordinator().getEventBus().fireEventToListenersOf(mue, oresFrontend);
return send;
}
Aggregations