use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class ForumCourseNodeWebService method addMessage.
/**
* Internal helper method to add a message to a forum.
* @param courseId
* @param nodeId
* @param parentMessageId can be null (will lead to new thread)
* @param title
* @param body
* @param identityName
* @param isSticky only necessary when adding new thread
* @param request
* @return
*/
private Response addMessage(Long courseId, String nodeId, Long parentMessageId, String title, String body, String identityName, Boolean isSticky, HttpServletRequest request) {
if (!isAuthor(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity identity;
if (identityName != null) {
identity = securityManager.findIdentityByName(identityName);
} else {
identity = RestSecurityHelper.getIdentity(request);
}
if (identity == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// load forum
ICourse course = CoursesWebService.loadCourse(courseId);
if (course == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(course, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CourseNode courseNode = getParentNode(course, nodeId);
if (courseNode == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
Property forumKeyProp = cpm.findCourseNodeProperty(courseNode, null, null, FOCourseNode.FORUM_KEY);
Forum forum = null;
ForumManager fom = ForumManager.getInstance();
if (forumKeyProp != null) {
// Forum does already exist, load forum with key from properties
Long forumKey = forumKeyProp.getLongValue();
forum = fom.loadForum(forumKey);
}
if (forum == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
MessageVO vo;
if (parentMessageId == null || parentMessageId == 0L) {
// creating the thread (a message without a parent message)
Message newThread = fom.createMessage(forum, identity, false);
if (isSticky != null && isSticky.booleanValue()) {
// set sticky
org.olat.modules.fo.Status status = new org.olat.modules.fo.Status();
status.setSticky(true);
newThread.setStatusCode(org.olat.modules.fo.Status.getStatusCode(status));
}
newThread.setTitle(title);
newThread.setBody(body);
// open a new thread
fom.addTopMessage(newThread);
vo = new MessageVO(newThread);
} else {
// adding response message (a message with a parent message)
Message threadMessage = fom.loadMessage(parentMessageId);
if (threadMessage == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
// create new message
Message message = fom.createMessage(forum, identity, false);
message.setTitle(title);
message.setBody(body);
fom.replyToMessage(message, threadMessage);
vo = new MessageVO(message);
}
return Response.ok(vo).build();
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class DENManager method getSelectedEventParticipants.
/**
* Little helper method, that gives you all participants of the selected events in the list
* @param dataList
* @param selection BitSet
* @return list of Identities
*/
protected List<Identity> getSelectedEventParticipants(List<KalendarEvent> dataList, BitSet selection) {
List<Identity> identities = new ArrayList<Identity>();
BaseSecurity manager = BaseSecurityManager.getInstance();
for (int i = 0; i < dataList.size(); i++) {
if (selection.get(i)) {
String[] parts = dataList.get(i).getParticipants();
if (parts != null) {
for (String participant : parts) {
Identity identity = manager.findIdentityByName(participant);
if (identity != null) {
identities.add(identity);
}
}
}
}
}
return identities;
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class DENManager method addDateInUserCalendar.
/**
* Add this event in the calendar of an enrolled user
* @param newEvent
*/
private void addDateInUserCalendar(KalendarEvent newEvent) {
String[] participants = newEvent.getParticipants();
// no users to update, cancel
if (participants == null)
return;
BaseSecurity manager = BaseSecurityManager.getInstance();
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
for (String participant : participants) {
Identity identity = manager.findIdentityByName(participant);
if (identity != null) {
Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
List<KalendarEvent> userEvents = new ArrayList<>();
userEvents.addAll(userCal.getEvents());
String eventId = CodeHelper.getGlobalForeverUniqueID();
KalendarEvent userNewEvent = new KalendarEvent(eventId, null, newEvent.getSubject(), newEvent.getBegin(), newEvent.getEnd());
userNewEvent.setLocation(newEvent.getLocation());
userNewEvent.setSourceNodeId(newEvent.getSourceNodeId());
userNewEvent.setClassification(KalendarEvent.CLASS_PRIVATE);
List<KalendarEventLink> kalendarEventLinks = userNewEvent.getKalendarEventLinks();
kalendarEventLinks.clear();
kalendarEventLinks.addAll(newEvent.getKalendarEventLinks());
calManager.addEventTo(userCal, userNewEvent);
}
}
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class QuotaManagerImpl method hasQuotaEditRights.
@Override
public boolean hasQuotaEditRights(Identity identity) {
BaseSecurity mgr = BaseSecurityManager.getInstance();
boolean hasQuoaRights = mgr.isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, OresHelper.lookupType(GenericQuotaEditController.class));
return hasQuoaRights;
}
use of org.olat.basesecurity.BaseSecurity in project openolat by klemens.
the class AdvancedPropertySearchForm method validateFormLogic.
@Override
protected boolean validateFormLogic(UserRequest ureq) {
int c = 0;
if (userName.getValue().length() > 0) {
c++;
BaseSecurity secMgr = BaseSecurityManager.getInstance();
identity = secMgr.findIdentityByName(userName.getValue());
if (identity == null) {
userName.setErrorKey("error.search.form.nousername", null);
return false;
}
}
if (resourceTypeName.getSelected() > 0)
c++;
if (resourceTypeId.getValue().length() > 0)
c++;
if (category.getValue().length() > 0)
c++;
if (propertyName.getValue().length() > 0)
c++;
if (c == 0) {
showInfo("error.search.form.notempty");
return false;
}
return true;
}
Aggregations