Search in sources :

Example 61 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class ForumRESTService method findAreaGroup.

@GET
@Path("/areagroups/{AREAGROUPID}")
@RESTPermit(ForumResourcePermissionCollection.FORUM_FIND_FORUMAREAGROUP)
public Response findAreaGroup(@PathParam("AREAGROUPID") Long areaGroupId) {
    ForumAreaGroup forumArea = forumController.findForumAreaGroup(areaGroupId);
    ForumAreaGroupRESTModel result = new ForumAreaGroupRESTModel(forumArea.getId(), forumArea.getName());
    return Response.ok(result).build();
}
Also used : ForumAreaGroup(fi.otavanopisto.muikku.plugins.forum.model.ForumAreaGroup) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 62 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class ForumRESTService method findArea.

@GET
@Path("/areas/{AREAID}")
@RESTPermit(handling = Handling.INLINE)
public Response findArea(@Context Request request, @PathParam("AREAID") Long areaId) {
    ForumArea forumArea = forumController.getForumArea(areaId);
    if (forumArea != null) {
        if (!(forumArea instanceof EnvironmentForumArea)) {
            logger.severe(String.format("Trying to access forum %d via incorrect REST endpoint", forumArea.getId()));
            return Response.status(Status.NOT_FOUND).build();
        }
        if (sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_ACCESSENVIRONMENTFORUM)) {
            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 : EntityTag(javax.ws.rs.core.EntityTag) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) CacheControl(javax.ws.rs.core.CacheControl) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) 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 63 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.

the class ForumRESTService method createReply.

@POST
@Path("/areas/{AREAID}/threads/{THREADID}/replies")
@RESTPermit(handling = Handling.INLINE)
public Response createReply(@PathParam("AREAID") Long areaId, @PathParam("THREADID") Long threadId, ForumThreadReplyRESTModel newReply) {
    try {
        ForumArea forumArea = forumController.getForumArea(areaId);
        if (forumArea == null) {
            return Response.status(Status.NOT_FOUND).entity("Forum area not found").build();
        }
        ForumThread forumThread = forumController.getForumThread(threadId);
        if (forumThread == null) {
            return Response.status(Status.NOT_FOUND).entity("Forum thread not found").build();
        }
        if (!forumArea.getId().equals(forumThread.getForumArea().getId())) {
            return Response.status(Status.NOT_FOUND).entity("Forum thread not found from the specified area").build();
        }
        if (forumThread.getLocked()) {
            return Response.status(Status.BAD_REQUEST).entity("Forum thread is locked").build();
        }
        if (!(forumArea instanceof EnvironmentForumArea)) {
            logger.severe(String.format("Trying to post thread reply for to non environment area (%d) from environment endpoint", forumArea.getId()));
            return Response.status(Status.BAD_REQUEST).build();
        }
        if (sessionController.hasEnvironmentPermission(ForumResourcePermissionCollection.FORUM_WRITE_ENVIRONMENT_MESSAGES)) {
            ForumThreadReply parentReply = null;
            if (newReply.getParentReplyId() != null) {
                parentReply = forumController.getForumThreadReply(newReply.getParentReplyId());
                if (parentReply == null) {
                    return Response.status(Status.BAD_REQUEST).entity("Invalid parent reply id").build();
                }
                if (!Objects.equals(parentReply.getThread().getId(), threadId)) {
                    return Response.status(Status.BAD_REQUEST).entity("Parent reply is in wrong thread").build();
                }
            }
            return Response.ok(createRestModel(forumController.createForumThreadReply(forumThread, newReply.getMessage(), parentReply))).build();
        } else {
            return Response.status(Status.FORBIDDEN).build();
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Failed to create new forum thread reply", e);
        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}
Also used : ForumThread(fi.otavanopisto.muikku.plugins.forum.model.ForumThread) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) ForumThreadReply(fi.otavanopisto.muikku.plugins.forum.model.ForumThreadReply) EnvironmentForumArea(fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 64 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit 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 65 with RESTPermit

use of fi.otavanopisto.security.rest.RESTPermit 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)

Aggregations

RESTPermit (fi.otavanopisto.security.rest.RESTPermit)215 Path (javax.ws.rs.Path)214 GET (javax.ws.rs.GET)99 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)90 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)83 SchoolDataIdentifier (fi.otavanopisto.muikku.schooldata.SchoolDataIdentifier)61 WorkspaceUserEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity)57 POST (javax.ws.rs.POST)51 DELETE (javax.ws.rs.DELETE)45 ArrayList (java.util.ArrayList)36 UserSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.UserSchoolDataIdentifier)30 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)30 PUT (javax.ws.rs.PUT)26 ForumThread (fi.otavanopisto.muikku.plugins.forum.model.ForumThread)24 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)21 CommunicatorMessageId (fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId)20 WorkspaceMaterial (fi.otavanopisto.muikku.plugins.workspace.model.WorkspaceMaterial)20 User (fi.otavanopisto.muikku.schooldata.entity.User)19 EnvironmentForumArea (fi.otavanopisto.muikku.plugins.forum.model.EnvironmentForumArea)18 Date (java.util.Date)16