use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method removeTutor.
/**
* Removes the owner from the group.
* @response.representation.200.doc The user is removed as owner from the group
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The business group or the user cannot be found
* @param groupKey The key of the group
* @param identityKey The user's id
* @param request The HTTP request
* @return
*/
@DELETE
@Path("{groupKey}/owners/{identityKey}")
public Response removeTutor(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
try {
if (!isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (identity == null || group == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
bgs.removeOwners(ureq.getIdentity(), Collections.singletonList(identity), group);
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to remove an owner to a group", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method removeParticipant.
/**
* Removes a participant from the group.
* @response.representation.200.doc The user is remove from the group as participant
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The business group or the user cannot be found
* @param groupKey The key of the group
* @param identityKey The id of the user
* @param request The HTTP request
* @return
*/
@DELETE
@Path("{groupKey}/participants/{identityKey}")
public Response removeParticipant(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
try {
if (!isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (identity == null || group == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
bgs.removeParticipants(ureq.getIdentity(), Collections.singletonList(identity), group, null);
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to remove a participant to a group", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method addTutor.
/**
* Adds an owner to the group.
* @response.representation.200.doc The user is added as owner of the group
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The business group or the user cannot be found
* @param groupKey The key of the group
* @param identityKey The user's id
* @param request The HTTP request
* @return
*/
@PUT
@Path("{groupKey}/owners/{identityKey}")
public Response addTutor(@PathParam("groupKey") Long groupKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
try {
if (!isGroupManager(request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
final BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
final BusinessGroup group = bgs.loadBusinessGroup(groupKey);
final Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(identityKey, false);
if (identity == null || group == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
bgs.addOwners(ureq.getIdentity(), ureq.getUserSession().getRoles(), Collections.singletonList(identity), group, null);
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to add an owner to a group", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method getInformations.
/**
* Returns the informations of the group specified by the groupKey.
* @response.representation.200.qname {http://www.example.com}groupInfoVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc Participants of the business group
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPINFOVO}
* @response.representation.404.doc The business group cannot be found
* @param groupKey The key of the group
* @param request The HTTP Request
* @return
*/
@GET
@Path("{groupKey}/infos")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getInformations(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
if (bg == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = RestSecurityHelper.getIdentity(request);
if (!isGroupManager(request)) {
if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
GroupInfoVO info = getInformation(identity, bg);
return Response.ok(info).build();
}
use of org.olat.group.BusinessGroupService in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method findById.
/**
* Return the group specified by the key of the group.
* @response.representation.200.qname {http://www.example.com}groupVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc A business group in the OLAT system
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_GROUPVO}
* @param groupKey The key of the group
* @param request The REST request
* @param httpRequest The HTTP request
* @return
*/
@GET
@Path("{groupKey}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response findById(@PathParam("groupKey") Long groupKey, @Context Request request, @Context HttpServletRequest httpRequest) {
BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
BusinessGroup bg = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(groupKey);
if (bg == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
Identity identity = RestSecurityHelper.getIdentity(httpRequest);
if (!isGroupManager(httpRequest) && !bgs.isIdentityInBusinessGroup(identity, bg)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Date lastModified = bg.getLastModified();
Response.ResponseBuilder response = request.evaluatePreconditions(lastModified);
if (response == null) {
GroupVO vo = ObjectFactory.get(bg);
response = Response.ok(vo);
}
return response.build();
}
Aggregations