Search in sources :

Example 26 with ForumArea

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

the class WorkspaceForumRESTService method listThreads.

@GET
@Path("/workspaces/{WORKSPACEENTITYID}/forumAreas/{AREAID}/threads")
@RESTPermit(handling = Handling.INLINE)
public Response listThreads(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("AREAID") Long areaId, @QueryParam("firstResult") @DefaultValue("0") Integer firstResult, @QueryParam("maxResults") @DefaultValue("10") Integer maxResults) {
    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 == null) {
        return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
    }
    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)) {
        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 : WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ArrayList(java.util.ArrayList) 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 27 with ForumArea

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

the class ForumController method listLatestForumThreads.

public List<ForumThread> listLatestForumThreads(int firstResult, int maxResults) {
    List<EnvironmentForumArea> environmentForums = listEnvironmentForums();
    // List<WorkspaceForumArea> workspaceForums = listCourseForums();
    List<ForumArea> forumAreas = new ArrayList<ForumArea>();
    for (EnvironmentForumArea ef : environmentForums) {
        forumAreas.add(ef);
    }
    // for (WorkspaceForumArea wf : workspaceForums) {
    // forumAreas.add(wf);
    // }
    List<ForumThread> threads;
    if (!forumAreas.isEmpty())
        threads = forumThreadDAO.listLatestOrdered(forumAreas, firstResult, maxResults);
    else
        threads = new ArrayList<ForumThread>();
    return threads;
}
Also used : ArrayList(java.util.ArrayList) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea)

Example 28 with ForumArea

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

the class ForumPermissionResolver method hasEveryonePermission.

@Override
public boolean hasEveryonePermission(String permission, ContextReference contextReference) {
    ForumArea forumArea = getForumArea(contextReference);
    RoleEntity userRole = getEveryoneRole();
    Permission perm = permissionDAO.findByName(permission);
    if (forumArea == null)
        return false;
    return resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm);
}
Also used : RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea)

Example 29 with ForumArea

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

the class AcceptanceTestsRESTService method deleteDiscussion.

@DELETE
@Path("/discussiongroups/{GROUPID}/discussions/{DISCUSSIONID}")
@RESTPermit(handling = Handling.UNSECURED)
public Response deleteDiscussion(@PathParam("GROUPID") Long groupId, @PathParam("DISCUSSIONID") Long discussionId) {
    ForumAreaGroup group = forumController.findForumAreaGroup(groupId);
    if (group == null) {
        return Response.status(Status.NOT_FOUND).entity("Group not found").build();
    }
    ForumArea forumArea = forumController.getForumArea(discussionId);
    if (forumArea == null) {
        return Response.status(Status.NOT_FOUND).entity("Discussion not found").build();
    }
    List<ForumThread> threads = forumController.listForumThreads(forumArea, 0, Integer.MAX_VALUE, true);
    for (ForumThread thread : threads) {
        List<ForumThreadReply> replies = forumController.listForumThreadReplies(thread, 0, Integer.MAX_VALUE, true);
        for (ForumThreadReply reply : replies) {
            forumController.deleteReply(reply);
        }
        forumController.deleteThread(thread);
    }
    forumController.deleteArea(forumArea);
    return Response.noContent().build();
}
Also used : ForumAreaGroup(fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup) ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumThreadReply(fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.security.rest.RESTPermit)

Example 30 with ForumArea

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

the class AcceptanceTestsRESTService method createWorkspaceDiscussionThread.

@POST
@Path("/workspaces/{WORKSPACEENTITYID}/discussiongroups/{GROUPID}/discussions/{DISCUSSIONID}/threads")
@RESTPermit(handling = Handling.UNSECURED)
public Response createWorkspaceDiscussionThread(@PathParam("WORKSPACEENTITYID") Long workspaceEntityId, @PathParam("GROUPID") Long groupId, @PathParam("DISCUSSIONID") Long discussionId, fi.otavanopisto.muikku.atests.DiscussionThread payload) {
    WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceEntityId);
    if (workspaceEntity == null) {
        return Response.status(Status.NOT_FOUND).entity("WorkspaceEntity not found").build();
    }
    ForumAreaGroup group = forumController.findForumAreaGroup(groupId);
    if (group == null) {
        return Response.status(Status.NOT_FOUND).entity("Group not found").build();
    }
    ForumArea discussion = forumController.getForumArea(discussionId);
    if (discussion == null) {
        return Response.status(Status.NOT_FOUND).entity("Discussion not found").build();
    }
    return Response.ok(createRestEntity(forumController.createForumThread(discussion, payload.getTitle(), payload.getMessage(), payload.getSticky(), payload.getLocked()))).build();
}
Also used : WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) ForumAreaGroup(fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

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