From 73f1a98d4d607bd6667f83d156b000b3e1fc6492 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Wed, 8 Nov 2017 15:23:54 +0100 Subject: [PATCH] no more User.getCurrent() Signed-off-by: Nicolas De Loof --- .../controller/AdminSessionController.java | 21 ++++++++++++------- .../java/io/cfp/service/PdfCardService.java | 4 ++-- .../java/io/cfp/service/TalkAdminService.java | 5 ++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/cfp/controller/AdminSessionController.java b/src/main/java/io/cfp/controller/AdminSessionController.java index 0eaa668b..d9d3380b 100644 --- a/src/main/java/io/cfp/controller/AdminSessionController.java +++ b/src/main/java/io/cfp/controller/AdminSessionController.java @@ -31,6 +31,7 @@ import io.cfp.entity.Event; import io.cfp.entity.Role; import io.cfp.entity.Talk; +import io.cfp.model.User; import io.cfp.repository.TalkRepo; import io.cfp.service.PdfCardService; import io.cfp.service.TalkAdminService; @@ -38,6 +39,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.security.access.annotation.Secured; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -66,7 +68,8 @@ public class AdminSessionController { @Secured({Role.REVIEWER, Role.ADMIN}) @ResponseBody @Deprecated - public List getAllSessions(@RequestParam(name = "status", required = false) String status) { + public List getAllSessions(@AuthenticationPrincipal User user, + @RequestParam(name = "status", required = false) String status) { Talk.State[] accept; if (status == null) { @@ -75,7 +78,7 @@ public List getAllSessions(@RequestParam(name = "status", required = accept = new Talk.State[] { Talk.State.valueOf(status) }; } - return talkService.findAll(accept); + return talkService.findAll(user.getId(), accept); } /** @@ -84,8 +87,8 @@ public List getAllSessions(@RequestParam(name = "status", required = @RequestMapping(value="/drafts", method= RequestMethod.GET) @Secured(Role.ADMIN) @ResponseBody - public List getAllDrafts() { - return talkService.findAll(Talk.State.DRAFT); + public List getAllDrafts(@AuthenticationPrincipal User user) { + return talkService.findAll(user.getId(), Talk.State.DRAFT); } /** @@ -168,9 +171,10 @@ public void deleteAll() { @RequestMapping(path = "/sessions/export/cards.pdf", produces = "application/pdf") @Secured(Role.ADMIN) - public void exportPdf(HttpServletResponse response) throws IOException, DocumentException { + public void exportPdf(@AuthenticationPrincipal User user, + HttpServletResponse response) throws IOException, DocumentException { response.addHeader(HttpHeaders.CONTENT_TYPE, "application/pdf"); - pdfCardService.export(response.getOutputStream()); + pdfCardService.export(user.getId(), response.getOutputStream()); } @RequestMapping(path = "/sessions/export/sched.json", produces = "application/json") @@ -185,7 +189,8 @@ public List exportSched(@RequestParam(required = false) Talk.State[] @RequestMapping(path = "/sessions/export/sessions.csv", produces = "text/csv") @Secured(Role.ADMIN) - public void exportCsv(HttpServletResponse response, @RequestParam(name = "status", required = false) String status) throws IOException { + public void exportCsv(@AuthenticationPrincipal User user, + HttpServletResponse response, @RequestParam(name = "status", required = false) String status) throws IOException { response.addHeader(HttpHeaders.CONTENT_TYPE, "text/csv"); CsvMapper mapper = new CsvMapper(); @@ -194,7 +199,7 @@ public void exportCsv(HttpServletResponse response, @RequestParam(name = "status CsvSchema schema = mapper.schemaFor(TalkAdmin.class).withHeader(); ObjectWriter writer = mapper.writer(schema); - List sessions = getAllSessions(status); + List sessions = getAllSessions(user, status); for (TalkAdmin s : sessions) { writer.writeValue(response.getOutputStream(), s); } diff --git a/src/main/java/io/cfp/service/PdfCardService.java b/src/main/java/io/cfp/service/PdfCardService.java index e07f1fb7..125923f4 100644 --- a/src/main/java/io/cfp/service/PdfCardService.java +++ b/src/main/java/io/cfp/service/PdfCardService.java @@ -40,7 +40,7 @@ public class PdfCardService { * Export all talks from the current event * @param out OutputStream to write PDF into */ - public void export(OutputStream out) throws DocumentException { + public void export(int userId, OutputStream out) throws DocumentException { Document document = new Document(PageSize.A4, 10, 10, 10, 10); PdfWriter writer = PdfWriter.getInstance(document, out); @@ -57,7 +57,7 @@ public void export(OutputStream out) throws DocumentException { Map formats = formatRepo.findByEventId(Event.current()).stream() .collect(toMap(Format::getId, Function.identity())); - List talks = talkAdminService.findAll(Talk.State.CONFIRMED).stream() + List talks = talkAdminService.findAll(userId, Talk.State.CONFIRMED).stream() .sorted(comparing(TalkAdmin::getMean, nullsLast(reverseOrder()))) .sorted(comparing(TalkAdmin::getFormat)) .collect(toList()); diff --git a/src/main/java/io/cfp/service/TalkAdminService.java b/src/main/java/io/cfp/service/TalkAdminService.java index 8ad43149..296d6ef2 100644 --- a/src/main/java/io/cfp/service/TalkAdminService.java +++ b/src/main/java/io/cfp/service/TalkAdminService.java @@ -96,16 +96,15 @@ public class TalkAdminService { * @param states List of states the talk must be * @return List of talks */ - public List findAll(Talk.State... states) { + public List findAll(int userId, Talk.State... states) { List talks = talkRepo.findByEventIdAndStatesFetch(Event.current(), Arrays.asList(states)) .stream().map(TalkAdmin::new) .collect(Collectors.toList()); List rates = rateRepo.findAllFetchAdmin(Event.current()); - User user = User.getCurrent(); Map> reviewed = rates.stream() - .filter(r -> user.getId() == r.getAdminUser().getId()) + .filter(r -> userId == r.getAdminUser().getId()) .collect(groupingBy(r -> r.getTalk().getId())); Map averages = rates.stream()