Search in sources :

Example 6 with ForumArea

use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.

the class ForumRESTService method listThreads.

@GET
@Path("/areas/{AREAID}/threads")
@RESTPermit(handling = Handling.INLINE)
public Response listThreads(@PathParam("AREAID") Long areaId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
    ForumArea forumArea = forumController.getForumArea(areaId);
    if (forumArea == null) {
        return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
    }
    if (!(forumArea instanceof EnvironmentForumArea)) {
        logger.severe(String.format("Trying to list non environment forum area (%d) threads from environment endpoint", forumArea.getId()));
        return Response.status(Status.BAD_REQUEST).build();
    }
    if (sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_READ_ENVIRONMENT_MESSAGES)) {
        List<ForumThread> threads = forumController.listForumThreads(forumArea, firstResult, maxResults);
        List<ForumThreadRESTModel> result = new ArrayList<ForumThreadRESTModel>();
        for (ForumThread thread : threads) {
            long numReplies = forumController.getThreadReplyCount(thread);
            result.add(new ForumThreadRESTModel(thread.getId(), thread.getTitle(), thread.getMessage(), thread.getCreator(), thread.getCreated(), thread.getForumArea().getId(), thread.getSticky(), thread.getLocked(), thread.getUpdated(), numReplies, thread.getLastModified()));
        }
        return Response.ok(result).build();
    } else {
        return Response.status(Status.FORBIDDEN).build();
    }
}
Also used : ArrayList(java.util.ArrayList) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 7 with ForumArea

use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.

the class SystemForumRESTService method resetForumAreaRights.

@GET
@Path("/resetForumAreaRights/{FORUMAREAID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response resetForumAreaRights(@PathParam("FORUMAREAID") Long forumAreaId, @Context Request request) {
    logger.info(String.format("Resetting rights of forum area %d", forumAreaId));
    if (sessionController.hasPermission(MuikkuPermissions.ADMIN, null)) {
        ForumArea forumArea = forumController.findForumAreaById(forumAreaId);
        if (forumArea != null) {
            Long resourceRightsIds = forumArea.getRights();
            if (resourceRightsIds != null) {
                ResourceRights resourceRights = resourceRightsController.findResourceRightsById(resourceRightsIds);
                resourceRightsController.deleteByResourceRights(resourceRights);
            } else {
                return Response.status(Status.NOT_FOUND).entity(String.format("Forum area %d has no rights", forumAreaId)).build();
            }
        } else {
            return Response.status(Status.NOT_FOUND).entity(String.format("Forum area %d not found", forumAreaId)).build();
        }
    } else {
        return Response.status(Status.FORBIDDEN).entity("Not admin").build();
    }
    return Response.status(Status.OK).entity(String.format("Forum area %d rights reset", forumAreaId)).build();
}
Also used : ResourceRights(fi.otavanopisto.muikku.model.security.ResourceRights) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 8 with ForumArea

use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.

the class WorkspaceForumRESTService method findThread.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads/{THREADID}")
@RESTPermit(handling = Handling.INLINE)
public Response findThread(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    ForumThread thread = forumController.getForumThread(threadId);
    if (thread == null) {
        return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
    }
    ForumArea forumArea = thread.getForumArea();
    if (!(forumArea instanceof WorkspaceForumArea)) {
        logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
        return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
    }
    if (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_READ_WORKSPACE_MESSAGES, workspaceEntity)) {
        long numReplies = forumController.getThreadReplyCount(thread);
        ForumThreadRESTModel result = new ForumThreadRESTModel(thread.getId(), thread.getTitle(), thread.getMessage(), thread.getCreator(), thread.getCreated(), thread.getForumArea().getId(), thread.getSticky(), thread.getLocked(), thread.getUpdated(), numReplies, thread.getLastModified());
        return Response.ok(result).build();
    } else {
        return Response.status(Status.FORBIDDEN).build();
    }
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 9 with ForumArea

use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.

the class WorkspaceForumRESTService method findWorkspaceArea.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response findWorkspaceArea(@Context Request request, @PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId) {
    ForumArea forumArea = forumController.getForumArea(areaId);
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    if (forumArea != null) {
        if (!(forumArea instanceof WorkspaceForumArea)) {
            logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
            return Response.status(Status.NOT_FOUND).build();
        }
        if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
            return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
        }
        if (sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_ACCESSWORKSPACEFORUMS, workspaceEntity)) {
            Long numThreads = forumController.getThreadCount(forumArea);
            EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(forumArea.getVersion()) + String.valueOf(numThreads)));
            ResponseBuilder builder = request.evaluatePreconditions(tag);
            if (builder != null) {
                return builder.build();
            }
            CacheControl cacheControl = new CacheControl();
            cacheControl.setMustRevalidate(true);
            ForumAreaRESTModel result = new ForumAreaRESTModel(forumArea.getId(), forumArea.getName(), forumArea.getDescription(), forumArea.getGroup() != null ? forumArea.getGroup().getId() : null, numThreads);
            return Response.ok(result).cacheControl(cacheControl).tag(tag).build();
        } else {
            return Response.status(Status.FORBIDDEN).build();
        }
    } else {
        return Response.status(Status.NOT_FOUND).build();
    }
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) EntityTag(javax.ws.rs.core.EntityTag) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 10 with ForumArea

use of fi.otavanopisto.muikku.plugins.forum.model.ForumArea in project muikku by otavanopisto.

the class WorkspaceForumRESTService method archiveWorkspaceForumArea.

@DELETE
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response archiveWorkspaceForumArea(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity(String.format("Workspace entity %d not found", workspaceEntityId)).build();
    }
    ForumArea forumArea = forumController.getForumArea(areaId);
    if (!(forumArea instanceof WorkspaceForumArea)) {
        logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
        return Response.status(Status.NOT_FOUND).build();
    }
    if (!workspaceEntity.getId().equals(((WorkspaceForumArea) forumArea).getWorkspace())) {
        return Response.status(Status.NOT_FOUND).entity(String.format("WorkspaceForumArea %d does not belong to workspace entity %d", forumArea.getId(), workspaceEntity.getId())).build();
    }
    if (sessionController.hasPermission(MuikkuPermissions.OWNER, forumArea) || sessionController.hasWorkspacePermission(ForumResourcePermissionCollection.FORUM_DELETEWORKSPACEFORUM, workspaceEntity)) {
        forumController.archiveArea(forumArea);
    } else {
        return Response.status(Status.FORBIDDEN).build();
    }
    return Response.noContent().build();
}
Also used : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Aggregations

ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)34 RESTPermit (fi.otavanopisto.security.rest.RESTPermit)30 Path (javax.ws.rs.Path)30 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)23 ForumThread (fi.otavanopisto.muikku.plugins.forum.model.ForumThread)22 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)17 EnvironmentForumArea (fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea)17 ForumThreadReply (fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply)11 GET (javax.ws.rs.GET)10 DELETE (javax.ws.rs.DELETE)8 ForumAreaGroup (fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup)6 POST (javax.ws.rs.POST)6 PUT (javax.ws.rs.PUT)6 ArrayList (java.util.ArrayList)4 Permission (fi.otavanopisto.muikku.model.security.Permission)2 RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)2 CacheControl (javax.ws.rs.core.CacheControl)2 EntityTag (javax.ws.rs.core.EntityTag)2 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)2 Document (org.jsoup.nodes.Document)2