Skip to content
Snippets Groups Projects
Commit f283b207 authored by Daniel Gerhardt's avatar Daniel Gerhardt
Browse files

Add API endpoint to create copies of public pool sessions

parent 826002e5
Branches
Tags
1 merge request!116Add API endpoint to create copies of public pool sessions
Pipeline #22540 passed with warnings with stages
in 1 minute and 2 seconds
......@@ -326,6 +326,15 @@ public class SessionController extends PaginationController {
return sessionInfo;
}
@ApiOperation(value = "copy a session from the public pool if enabled")
@RequestMapping(value = "/{sessionkey}/copyfrompublicpool", method = RequestMethod.POST)
public SessionInfo copyFromPublicPool(
@ApiParam(value = "session-key of the public pool session", required = true) @PathVariable final String sessionkey,
@ApiParam(value = "custom attributes for session", required = true) @RequestBody final Session sessionAttributes
) {
SessionInfo sessionInfo = sessionService.copySessionFromPublicPool(sessionkey, sessionAttributes);
return sessionInfo;
}
@ApiOperation(value = "Locks or unlocks a Session",
nickname = "lockSession")
......
......@@ -86,6 +86,8 @@ public interface ISessionService {
SessionInfo copySessionToPublicPool(String sessionkey, de.thm.arsnova.entities.transport.ImportExportSession.PublicPool pp);
SessionInfo copySessionFromPublicPool(String sessionkey, Session sessionAttributes);
SessionFeature getSessionFeatures(String sessionkey);
SessionFeature changeSessionFeatures(String sessionkey, SessionFeature features);
......
......@@ -446,6 +446,22 @@ public class SessionService implements ISessionService, ApplicationEventPublishe
return databaseDao.importSession(user, temp);
}
@Override
@PreAuthorize("isAuthenticated() and hasPermission(#sessionkey, 'session', 'read')")
public SessionInfo copySessionFromPublicPool(final String sessionkey, final Session sessionAttributes) {
final Session ppSession = databaseDao.getSessionFromKeyword(sessionkey);
if (!"public_pool".equals(ppSession.getSessionType())) {
throw new ForbiddenException();
}
final ImportExportSession sessionContainer = databaseDao.exportSession(sessionkey, false, false);
final ImportExportSession.ImportExportSesssion newSession = sessionContainer.getSession();
newSession.setSessionType("");
newSession.setName(sessionAttributes.getName());
newSession.setShortName(sessionAttributes.getShortName());
final User user = userService.getCurrentUser();
return databaseDao.importSession(user, sessionContainer);
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.publisher = publisher;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment