Search in sources :

Example 56 with BaseSecurity

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();
}
Also used : Status(javax.ws.rs.core.Response.Status) Message(org.olat.modules.fo.Message) ICourse(org.olat.course.ICourse) BaseSecurity(org.olat.basesecurity.BaseSecurity) Forum(org.olat.modules.fo.Forum) ForumManager(org.olat.modules.fo.manager.ForumManager) FOCourseNode(org.olat.course.nodes.FOCourseNode) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity) Property(org.olat.properties.Property) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 57 with BaseSecurity

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;
}
Also used : ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 58 with BaseSecurity

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);
        }
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 59 with BaseSecurity

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;
}
Also used : BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 60 with BaseSecurity

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;
}
Also used : BaseSecurity(org.olat.basesecurity.BaseSecurity)

Aggregations

BaseSecurity (org.olat.basesecurity.BaseSecurity)116 Identity (org.olat.core.id.Identity)88 Path (javax.ws.rs.Path)48 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)28 PUT (javax.ws.rs.PUT)24 Produces (javax.ws.rs.Produces)22 SecurityGroup (org.olat.basesecurity.SecurityGroup)20 RepositoryEntry (org.olat.repository.RepositoryEntry)20 DELETE (javax.ws.rs.DELETE)14 Authentication (org.olat.basesecurity.Authentication)14 MailPackage (org.olat.core.util.mail.MailPackage)14 RepositoryManager (org.olat.repository.RepositoryManager)14 Consumes (javax.ws.rs.Consumes)12 WebApplicationException (javax.ws.rs.WebApplicationException)12 CertificatesManager (org.olat.course.certificate.CertificatesManager)10 OLATResource (org.olat.resource.OLATResource)10 OLATResourceManager (org.olat.resource.OLATResourceManager)10 ArrayList (java.util.ArrayList)8 GET (javax.ws.rs.GET)8 IdentitiesAddEvent (org.olat.admin.securitygroup.gui.IdentitiesAddEvent)8