Search in sources :

Example 21 with RESTPermit

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

the class CommunicatorLabelRESTService method createUserLabel.

@POST
@Path("/userLabels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createUserLabel(CommunicatorUserLabelRESTModel newUserLabel) throws AuthorizationException {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    // Creates only labels for logged user so we can consider this safe
    CommunicatorUserLabel userLabel = communicatorController.createUserLabel(newUserLabel.getName(), newUserLabel.getColor(), userEntity);
    return Response.ok(restModels.restUserLabel(userLabel)).build();
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) POST(javax.ws.rs.POST)

Example 22 with RESTPermit

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

the class CommunicatorLabelRESTService method getMessageIdLabel.

@GET
@Path("/messages/{COMMUNICATORMESSAGEID}/labels/{LABELID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getMessageIdLabel(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId, @PathParam("LABELID") Long labelId) throws AuthorizationException {
    CommunicatorMessageIdLabel label = communicatorController.findMessageIdLabelById(labelId);
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    if (!canAccessLabel(userEntity, label.getLabel())) {
        return Response.status(Status.FORBIDDEN).build();
    }
    return Response.ok(restModels.restLabel(label)).build();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 23 with RESTPermit

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

the class CommunicatorLabelRESTService method listUserLabels.

@GET
@Path("/userLabels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listUserLabels() throws AuthorizationException {
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    // Lists only labels of logged user so we can consider this safe
    List<CommunicatorUserLabel> userLabels = communicatorController.listUserLabelsByUserEntity(userEntity);
    return Response.ok(restModels.restUserLabel(userLabels)).build();
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) GET(javax.ws.rs.GET)

Example 24 with RESTPermit

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

the class CommunicatorLabelRESTService method editUserLabel.

@PUT
@Path("/userLabels/{USERLABELID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response editUserLabel(@PathParam("USERLABELID") Long userLabelId, CommunicatorUserLabelRESTModel updatedUserLabel) throws AuthorizationException {
    if (!updatedUserLabel.getId().equals(userLabelId)) {
        return Response.status(Response.Status.BAD_REQUEST).entity("Id is immutable").build();
    }
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    CommunicatorUserLabel userLabel = communicatorController.findUserLabelById(userLabelId);
    if ((userLabel != null) && canAccessLabel(userEntity, userLabel)) {
        CommunicatorUserLabel editedUserLabel = communicatorController.updateUserLabel(userLabel, updatedUserLabel.getName(), updatedUserLabel.getColor());
        return Response.ok(restModels.restUserLabel(editedUserLabel)).build();
    } else {
        return Response.status(Status.NOT_FOUND).build();
    }
}
Also used : CommunicatorUserLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorUserLabel) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.security.rest.RESTPermit) PUT(javax.ws.rs.PUT)

Example 25 with RESTPermit

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

the class CommunicatorLabelRESTService method listMessageIdLabels.

@GET
@Path("/messages/{COMMUNICATORMESSAGEID}/labels")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response listMessageIdLabels(@PathParam("COMMUNICATORMESSAGEID") Long communicatorMessageId) throws AuthorizationException {
    CommunicatorMessageId messageId = communicatorController.findCommunicatorMessageId(communicatorMessageId);
    // Lists only labels of logged user so we can consider this safe
    UserEntity userEntity = sessionController.getLoggedUserEntity();
    List<CommunicatorMessageIdLabel> labels = communicatorController.listMessageIdLabelsByUserEntity(userEntity, messageId);
    return Response.ok(restModels.restLabel(labels)).build();
}
Also used : CommunicatorMessageIdLabel(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageIdLabel) CommunicatorMessageId(fi.otavanopisto.muikku.plugins.communicator.model.CommunicatorMessageId) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity) 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