use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class LearningGroupWebService method addParticipant.
/**
* Adds a participant to the group.
* @response.representation.200.doc The user is added as participant 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}/participants/{identityKey}")
public Response addParticipant(@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();
}
BusinessGroupAddResponse state = bgs.addParticipants(ureq.getIdentity(), ureq.getUserSession().getRoles(), Collections.singletonList(identity), group, null);
if (state.getAddedIdentities().contains(identity)) {
return Response.ok().build();
} else if (state.getIdentitiesAlreadyInGroup().contains(identity)) {
return Response.ok().status(Status.NOT_MODIFIED).build();
}
return Response.serverError().status(Status.PRECONDITION_FAILED).build();
} catch (Exception e) {
log.error("Trying to add a participant to a group", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method addOwners.
@PUT
@Path("owners")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response addOwners(UserVO[] owners, @PathParam("repoEntryKey") String repoEntryKey, @Context HttpServletRequest request) {
try {
RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
if (repoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(repoEntry, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
List<Identity> identityToAdd = loadIdentities(owners);
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
repositoryManager.addOwners(ureq.getIdentity(), iae, repoEntry, new MailPackage(false));
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to add an owner to a repository entry", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method removeOwner.
/**
* Removes the owner from the repository entry.
* @response.representation.200.doc The user is removed as owner from the repository entry
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The repository entry or the user cannot be found
* @param repoEntryKey The key of the repository entry
* @param identityKey The user's id
* @param request The HTTP request
* @return
*/
@DELETE
@Path("owners/{identityKey}")
public Response removeOwner(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
try {
RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
if (repoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(repoEntry, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Identity identityToRemove = securityManager.loadIdentityByKey(identityKey);
if (identityToRemove == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
final UserRequest ureq = RestSecurityHelper.getUserRequest(request);
repositoryManager.removeOwners(ureq.getIdentity(), Collections.singletonList(identityToRemove), repoEntry, new MailPackage(false));
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to remove an owner to a repository entry", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method addOwner.
/**
* Adds an owner to the repository entry.
* @response.representation.200.doc The user is added as owner of the repository entry
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The repository entry or the user cannot be found
* @param repoEntryKey The key of the repository entry
* @param identityKey The user's id
* @param request The HTTP request
* @return
*/
@PUT
@Path("owners/{identityKey}")
public Response addOwner(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
try {
RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
if (repoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(repoEntry, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Identity identityToAdd = securityManager.loadIdentityByKey(identityKey);
if (identityToAdd == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
repositoryManager.addOwners(ureq.getIdentity(), iae, repoEntry, new MailPackage(false));
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to add an owner to a repository entry", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.olat.core.gui.UserRequest in project OpenOLAT by OpenOLAT.
the class RepositoryEntryResource method addCoach.
/**
* Adds a coach to the repository entry.
* @response.representation.200.doc The user is added as coach of the repository entry
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The repository entry or the user cannot be found
* @param repoEntryKey The key of the repository entry
* @param identityKey The user's id
* @param request The HTTP request
* @return
*/
@PUT
@Path("coaches/{identityKey}")
public Response addCoach(@PathParam("repoEntryKey") String repoEntryKey, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest request) {
try {
RepositoryEntry repoEntry = lookupRepositoryEntry(repoEntryKey);
if (repoEntry == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
} else if (!isAuthorEditor(repoEntry, request)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
Identity identityToAdd = securityManager.loadIdentityByKey(identityKey);
if (identityToAdd == null) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
UserRequest ureq = RestSecurityHelper.getUserRequest(request);
IdentitiesAddEvent iae = new IdentitiesAddEvent(identityToAdd);
repositoryManager.addTutors(ureq.getIdentity(), ureq.getUserSession().getRoles(), iae, repoEntry, null);
return Response.ok().build();
} catch (Exception e) {
log.error("Trying to add a coach to a repository entry", e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
Aggregations