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();
}
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();
}
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();
}
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();
}
}
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();
}
Aggregations