use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.
the class CommunicatorRESTService method deleteUserMessageTemplate.
@DELETE
@Path("/templates/{TEMPLATEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response deleteUserMessageTemplate(@PathParam("TEMPLATEID") Long templateId) throws AuthorizationException {
CommunicatorMessageTemplate messageTemplate = communicatorController.getMessageTemplate(templateId);
if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, messageTemplate)) {
return Response.status(Status.FORBIDDEN).build();
}
communicatorController.deleteMessageTemplate(messageTemplate);
return Response.noContent().build();
}
use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.
the class CommunicatorRESTService method editUserMessageTemplate.
@POST
@Path("/templates/{TEMPLATEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response editUserMessageTemplate(@PathParam("TEMPLATEID") Long templateId, CommunicatorMessageTemplateRESTModel template) throws AuthorizationException {
if (!template.getId().equals(templateId)) {
return Response.status(Response.Status.BAD_REQUEST).entity("Id is immutable").build();
}
CommunicatorMessageTemplate messageTemplate = communicatorController.getMessageTemplate(templateId);
if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, messageTemplate)) {
return Response.status(Status.FORBIDDEN).build();
}
CommunicatorMessageTemplate editMessageTemplate = communicatorController.editMessageTemplate(messageTemplate, template.getName(), template.getContent());
CommunicatorMessageTemplateRESTModel result = new CommunicatorMessageTemplateRESTModel(editMessageTemplate.getId(), editMessageTemplate.getName(), editMessageTemplate.getContent());
return Response.ok(result).build();
}
use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.
the class CommunicatorRESTService method getUserMessageTemplate.
@GET
@Path("/templates/{TEMPLATEID}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getUserMessageTemplate(@PathParam("TEMPLATEID") Long templateId) throws AuthorizationException {
CommunicatorMessageTemplate template = communicatorController.getMessageTemplate(templateId);
if (!sessionController.hasPermission(CommunicatorPermissionCollection.COMMUNICATOR_MANAGE_SETTINGS, template)) {
return Response.status(Status.FORBIDDEN).build();
}
CommunicatorMessageTemplateRESTModel result = new CommunicatorMessageTemplateRESTModel(template.getId(), template.getName(), template.getContent());
return Response.ok(result).build();
}
use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.
the class UserRESTService method createStudentFlag.
@POST
@Path("/students/{ID}/flags")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response createStudentFlag(@Context Request request, @PathParam("ID") String id, fi.otavanopisto.muikku.rest.model.StudentFlag payload) {
if (!sessionController.isLoggedIn()) {
return Response.status(Status.FORBIDDEN).build();
}
SchoolDataIdentifier studentIdentifier = SchoolDataIdentifier.fromId(id);
if (studentIdentifier == null) {
return Response.status(Response.Status.BAD_REQUEST).entity(String.format("Invalid studentIdentifier %s", id)).build();
}
if (payload.getFlagId() == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Missing flagId").build();
}
Flag flag = flagController.findFlagById(payload.getFlagId());
if (flag == null) {
return Response.status(Status.NOT_FOUND).entity(String.format("Flag #%d not found", payload.getFlagId())).build();
}
if (!flagController.hasFlagPermission(flag, sessionController.getLoggedUser())) {
return Response.status(Status.FORBIDDEN).entity(String.format("You do not have permission to flag students to flag %d", payload.getFlagId())).build();
}
return Response.ok(createRestModel(flagController.flagStudent(flag, studentIdentifier))).build();
}
use of fi.otavanopisto.security.rest.RESTPermit in project muikku by otavanopisto.
the class UserRESTService method getUserEntityProperty.
@GET
@Path("/property/{KEY}")
@RESTPermit(handling = Handling.INLINE, requireLoggedIn = true)
public Response getUserEntityProperty(@PathParam("KEY") String key) {
UserEntity loggedUserEntity = sessionController.getLoggedUserEntity();
UserEntityProperty property = userEntityController.getUserEntityPropertyByKey(loggedUserEntity, key);
return Response.ok(new fi.otavanopisto.muikku.rest.model.UserEntityProperty(key, property == null ? null : property.getValue())).build();
}
Aggregations