Search in sources :

Example 26 with Roles

use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.

the class IQRunController method createChangelogMsg.

/**
 * @param ureq
 * @return
 */
private StringBuilder createChangelogMsg(UserRequest ureq) {
    /*
		 * TODO:pb:is ImsRepositoryResolver the right place for getting the change log?
		 */
    // re could be null, but if we are here it should not be null!
    Roles userRoles = ureq.getUserSession().getRoles();
    boolean showAll = userRoles.isAuthor() || userRoles.isOLATAdmin();
    // get changelog
    Formatter formatter = Formatter.getInstance(ureq.getLocale());
    ImsRepositoryResolver resolver = new ImsRepositoryResolver(referenceTestEntry);
    QTIChangeLogMessage[] qtiChangeLog = resolver.getDocumentChangeLog();
    StringBuilder qtiChangelog = new StringBuilder();
    if (qtiChangeLog.length > 0) {
        // there are resource changes
        Arrays.sort(qtiChangeLog);
        for (int i = qtiChangeLog.length - 1; i >= 0; i--) {
            // show latest change first
            if (!showAll && qtiChangeLog[i].isPublic()) {
                // logged in person is a normal user, hence public messages only
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            } else if (showAll) {
                // logged in person is an author, olat admin, owner, show all messages
                Date msgDate = new Date(qtiChangeLog[i].getTimestmp());
                qtiChangelog.append("\nChange date: ").append(formatter.formatDateAndTime(msgDate)).append("\n");
                String msg = StringHelper.escapeHtml(qtiChangeLog[i].getLogMessage());
                qtiChangelog.append(msg);
                qtiChangelog.append("\n********************************\n");
            }
        // else non public messages are not shown to normal user
        }
    }
    return qtiChangelog;
}
Also used : QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) Formatter(org.olat.core.util.Formatter) ImsRepositoryResolver(org.olat.ims.qti.process.ImsRepositoryResolver) Roles(org.olat.core.id.Roles) Date(java.util.Date)

Example 27 with Roles

use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.

the class MyForumsWebService method getForums.

/**
 * Retrieves a list of forums on a user base. All forums of groups
 * where the user is participant/tutor + all forums in course where
 * the user is a participant (owner, tutor or participant)
 * @response.representation.200.qname {http://www.example.com}forumVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc The forums
 * @response.representation.200.example {@link org.olat.modules.fo.restapi.Examples#SAMPLE_FORUMVO}
 * @response.representation.401.doc The roles of the authenticated user are not sufficient
 * @param identityKey The key of the user (IdentityImpl)
 * @param httpRequest The HTTP request
 * @return The forums
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getForums(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    Roles roles;
    Identity retrievedUser = getIdentity(httpRequest);
    if (retrievedUser == null) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!identityKey.equals(retrievedUser.getKey())) {
        if (isAdmin(httpRequest)) {
            retrievedUser = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey);
            roles = BaseSecurityManager.getInstance().getRoles(retrievedUser);
        } else {
            return Response.serverError().status(Status.UNAUTHORIZED).build();
        }
    } else {
        roles = getRoles(httpRequest);
    }
    Map<Long, Long> groupNotified = new HashMap<Long, Long>();
    Map<Long, Collection<Long>> courseNotified = new HashMap<Long, Collection<Long>>();
    final Set<Long> subscriptions = new HashSet<Long>();
    NotificationsManager man = NotificationsManager.getInstance();
    {
        // collect subscriptions
        List<String> notiTypes = Collections.singletonList("Forum");
        List<Subscriber> subs = man.getSubscribers(retrievedUser, notiTypes);
        for (Subscriber sub : subs) {
            String resName = sub.getPublisher().getResName();
            Long forumKey = Long.parseLong(sub.getPublisher().getData());
            subscriptions.add(forumKey);
            if ("BusinessGroup".equals(resName)) {
                Long groupKey = sub.getPublisher().getResId();
                groupNotified.put(groupKey, forumKey);
            } else if ("CourseModule".equals(resName)) {
                Long courseKey = sub.getPublisher().getResId();
                if (!courseNotified.containsKey(courseKey)) {
                    courseNotified.put(courseKey, new ArrayList<Long>());
                }
                courseNotified.get(courseKey).add(forumKey);
            }
        }
    }
    final List<ForumVO> forumVOs = new ArrayList<ForumVO>();
    final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
    for (Map.Entry<Long, Collection<Long>> e : courseNotified.entrySet()) {
        final Long courseKey = e.getKey();
        final Collection<Long> forumKeys = e.getValue();
        final ICourse course = CourseFactory.loadCourse(courseKey);
        new CourseTreeVisitor(course, ienv).visit(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof FOCourseNode) {
                    FOCourseNode forumNode = (FOCourseNode) node;
                    ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
                    if (forumKeys.contains(forumVo.getForumKey())) {
                        forumVOs.add(forumVo);
                    }
                }
            }
        }, new VisibleTreeFilter());
    }
    /*
		RepositoryManager rm = RepositoryManager.getInstance();
		ACService acManager = CoreSpringFactory.getImpl(ACService.class);
		SearchRepositoryEntryParameters repoParams = new SearchRepositoryEntryParameters(retrievedUser, roles, "CourseModule");
		repoParams.setOnlyExplicitMember(true);
		List<RepositoryEntry> entries = rm.genericANDQueryWithRolesRestriction(repoParams, 0, -1, true);
		for(RepositoryEntry entry:entries) {
			AccessResult result = acManager.isAccessible(entry, retrievedUser, false);
			if(result.isAccessible()) {
				try {
					final ICourse course = CourseFactory.loadCourse(entry.getOlatResource());
					final IdentityEnvironment ienv = new IdentityEnvironment(retrievedUser, roles);
					new CourseTreeVisitor(course, ienv).visit(new Visitor() {
						@Override
						public void visit(INode node) {
							if(node instanceof FOCourseNode) {
								FOCourseNode forumNode = (FOCourseNode)node;	
								ForumVO forumVo = ForumCourseNodeWebService.createForumVO(course, forumNode, subscriptions);
								forumVOs.add(forumVo);
							}
						}
					});
				} catch (Exception e) {
					log.error("", e);
				}
			}
		}*/
    // start found forums in groups
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    SearchBusinessGroupParams params = new SearchBusinessGroupParams(retrievedUser, true, true);
    params.addTools(CollaborationTools.TOOL_FORUM);
    List<BusinessGroup> groups = bgs.findBusinessGroups(params, null, 0, -1);
    // list forum keys
    List<Long> groupIds = new ArrayList<Long>();
    Map<Long, BusinessGroup> groupsMap = new HashMap<Long, BusinessGroup>();
    for (BusinessGroup group : groups) {
        if (groupNotified.containsKey(group.getKey())) {
            ForumVO forumVo = new ForumVO();
            forumVo.setName(group.getName());
            forumVo.setGroupKey(group.getKey());
            forumVo.setForumKey(groupNotified.get(group.getKey()));
            forumVo.setSubscribed(true);
            forumVOs.add(forumVo);
            groupIds.remove(group.getKey());
        } else {
            groupIds.add(group.getKey());
            groupsMap.put(group.getKey(), group);
        }
    }
    PropertyManager pm = PropertyManager.getInstance();
    List<Property> forumProperties = pm.findProperties(OresHelper.calculateTypeName(BusinessGroup.class), groupIds, PROP_CAT_BG_COLLABTOOLS, KEY_FORUM);
    for (Property prop : forumProperties) {
        Long forumKey = prop.getLongValue();
        if (forumKey != null && groupsMap.containsKey(prop.getResourceTypeId())) {
            BusinessGroup group = groupsMap.get(prop.getResourceTypeId());
            ForumVO forumVo = new ForumVO();
            forumVo.setName(group.getName());
            forumVo.setGroupKey(group.getKey());
            forumVo.setForumKey(prop.getLongValue());
            forumVo.setSubscribed(false);
            forumVOs.add(forumVo);
        }
    }
    ForumVOes voes = new ForumVOes();
    voes.setForums(forumVOs.toArray(new ForumVO[forumVOs.size()]));
    voes.setTotalCount(forumVOs.size());
    return Response.ok(voes).build();
}
Also used : INode(org.olat.core.util.nodes.INode) Visitor(org.olat.core.util.tree.Visitor) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) HashMap(java.util.HashMap) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) PropertyManager(org.olat.properties.PropertyManager) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) FOCourseNode(org.olat.course.nodes.FOCourseNode) Subscriber(org.olat.core.commons.services.notifications.Subscriber) ArrayList(java.util.ArrayList) List(java.util.List) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) Property(org.olat.properties.Property) HashSet(java.util.HashSet) BusinessGroup(org.olat.group.BusinessGroup) CourseTreeVisitor(org.olat.course.run.userview.CourseTreeVisitor) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) SearchBusinessGroupParams(org.olat.group.model.SearchBusinessGroupParams) BusinessGroupService(org.olat.group.BusinessGroupService) NotificationsManager(org.olat.core.commons.services.notifications.NotificationsManager) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 28 with Roles

use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.

the class FeedMediaDispatcher method hasAccess.

/**
 * Verifiy if the identity has access to the feed.
 *
 * @param identity
 * @param token
 * @param feed
 * @return true if the identity has access.
 */
private boolean hasAccess(Identity identity, String token, OLATResourceable feed) {
    boolean hasAccess = false;
    RepositoryManager resMgr = RepositoryManager.getInstance();
    RepositoryEntry repoEntry = resMgr.lookupRepositoryEntry(feed, false);
    if (allowsGuestAccess(repoEntry)) {
        hasAccess = true;
    } else if (identity != null) {
        if (repoEntry != null) {
            final Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
            final boolean isAllowedToLaunch = resMgr.isAllowedToLaunch(identity, roles, repoEntry);
            if (isAllowedToLaunch && validAuthentication(identity, token)) {
                hasAccess = true;
            }
        } else {
            // no repository entry -> could be a feed without a repository-entry (ePortfolio-Blog-feed)
            EPFrontendManager ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean("epFrontendManager");
            if (ePFMgr.checkFeedAccess(feed, identity)) {
                return validAuthentication(identity, token);
            }
        }
    }
    return hasAccess;
}
Also used : RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) EPFrontendManager(org.olat.portfolio.manager.EPFrontendManager)

Example 29 with Roles

use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.

the class RepositoryEntryLifecycleWebService method getPublicLifeCycles.

/**
 * List all public lifecycles
 * @response.representation.200.qname {http://www.example.com}repositoryEntryVO
 * @response.representation.200.mediaType text/plain, text/html, application/xml, application/json
 * @response.representation.200.doc List all entries in the repository
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_REPOENTRYVOes}
 * @param uriInfo The URI information
 * @param httpRequest The HTTP request
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getPublicLifeCycles(@Context HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    RepositoryEntryLifecycleDAO lifeCycleDao = CoreSpringFactory.getImpl(RepositoryEntryLifecycleDAO.class);
    List<RepositoryEntryLifecycle> publicLifeCycles = lifeCycleDao.loadPublicLifecycle();
    List<RepositoryEntryLifecycleVO> voList = new ArrayList<RepositoryEntryLifecycleVO>(publicLifeCycles.size());
    for (RepositoryEntryLifecycle lifeCycle : publicLifeCycles) {
        voList.add(new RepositoryEntryLifecycleVO(lifeCycle));
    }
    RepositoryEntryLifecycleVO[] voes = voList.toArray(new RepositoryEntryLifecycleVO[voList.size()]);
    return Response.ok(voes).build();
}
Also used : RepositoryEntryLifecycle(org.olat.repository.model.RepositoryEntryLifecycle) ArrayList(java.util.ArrayList) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) Roles(org.olat.core.id.Roles) RepositoryEntryLifecycleVO(org.olat.restapi.support.vo.RepositoryEntryLifecycleVO) RepositoryEntryLifecycleDAO(org.olat.repository.manager.RepositoryEntryLifecycleDAO) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 30 with Roles

use of org.olat.core.id.Roles in project OpenOLAT by OpenOLAT.

the class CoursesInfosWebService method getCourseInfo.

/**
 * Get course informations viewable by the authenticated user
 * @response.representation.200.qname {http://www.example.com}courseVO
 * @response.representation.200.mediaType application/xml, application/json
 * @response.representation.200.doc Course informations
 * @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSEINFOVO}
 * @param courseId The course id
 * @param httpRequest The HTTP request
 * @return
 */
@GET
@Path("{courseId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCourseInfo(@PathParam("courseId") Long courseId, @Context HttpServletRequest httpRequest) {
    Roles roles = getRoles(httpRequest);
    Identity identity = getIdentity(httpRequest);
    if (identity != null && roles != null) {
        Set<Long> forumNotified = new HashSet<Long>();
        Map<Long, Set<String>> courseNotified = new HashMap<Long, Set<String>>();
        collectSubscriptions(identity, forumNotified, courseNotified);
        ICourse course = CourseFactory.loadCourse(courseId);
        RepositoryEntry entry = RepositoryManager.getInstance().lookupRepositoryEntry(course, true);
        CourseInfoVO info = collect(identity, roles, entry, forumNotified, courseNotified);
        return Response.ok(info).build();
    } else {
        return Response.serverError().status(Status.FORBIDDEN).build();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Roles(org.olat.core.id.Roles) RestSecurityHelper.getRoles(org.olat.restapi.security.RestSecurityHelper.getRoles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity) CourseInfoVO(org.olat.restapi.support.vo.CourseInfoVO) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Roles (org.olat.core.id.Roles)338 Identity (org.olat.core.id.Identity)146 RepositoryEntry (org.olat.repository.RepositoryEntry)104 Test (org.junit.Test)94 GroupRoles (org.olat.basesecurity.GroupRoles)94 ArrayList (java.util.ArrayList)56 SearchRepositoryEntryParameters (org.olat.repository.model.SearchRepositoryEntryParameters)54 RestSecurityHelper.getRoles (org.olat.restapi.security.RestSecurityHelper.getRoles)50 ICourse (org.olat.course.ICourse)44 Produces (javax.ws.rs.Produces)42 BusinessGroup (org.olat.group.BusinessGroup)38 Translator (org.olat.core.gui.translator.Translator)36 NodeRunConstructionResult (org.olat.course.run.navigation.NodeRunConstructionResult)36 GET (javax.ws.rs.GET)34 Controller (org.olat.core.gui.control.Controller)34 TabbableController (org.olat.core.gui.control.generic.tabbable.TabbableController)34 NodeEditController (org.olat.course.editor.NodeEditController)34 Path (javax.ws.rs.Path)30 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)30 RepositoryManager (org.olat.repository.RepositoryManager)30