Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
no more User.getCurrent()
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Nov 8, 2017
1 parent 60ba84c commit 73f1a98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
21 changes: 13 additions & 8 deletions src/main/java/io/cfp/controller/AdminSessionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
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.*;

Expand Down Expand Up @@ -66,7 +68,8 @@ public class AdminSessionController {
@Secured({Role.REVIEWER, Role.ADMIN})
@ResponseBody
@Deprecated
public List<TalkAdmin> getAllSessions(@RequestParam(name = "status", required = false) String status) {
public List<TalkAdmin> getAllSessions(@AuthenticationPrincipal User user,
@RequestParam(name = "status", required = false) String status) {

Talk.State[] accept;
if (status == null) {
Expand All @@ -75,7 +78,7 @@ public List<TalkAdmin> getAllSessions(@RequestParam(name = "status", required =
accept = new Talk.State[] { Talk.State.valueOf(status) };
}

return talkService.findAll(accept);
return talkService.findAll(user.getId(), accept);
}

/**
Expand All @@ -84,8 +87,8 @@ public List<TalkAdmin> getAllSessions(@RequestParam(name = "status", required =
@RequestMapping(value="/drafts", method= RequestMethod.GET)
@Secured(Role.ADMIN)
@ResponseBody
public List<TalkAdmin> getAllDrafts() {
return talkService.findAll(Talk.State.DRAFT);
public List<TalkAdmin> getAllDrafts(@AuthenticationPrincipal User user) {
return talkService.findAll(user.getId(), Talk.State.DRAFT);
}

/**
Expand Down Expand Up @@ -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")
Expand All @@ -185,7 +189,8 @@ public List<EventSched> 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();
Expand All @@ -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<TalkAdmin> sessions = getAllSessions(status);
List<TalkAdmin> sessions = getAllSessions(user, status);
for (TalkAdmin s : sessions) {
writer.writeValue(response.getOutputStream(), s);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/cfp/service/PdfCardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -57,7 +57,7 @@ public void export(OutputStream out) throws DocumentException {
Map<Integer, Format> formats = formatRepo.findByEventId(Event.current()).stream()
.collect(toMap(Format::getId, Function.identity()));

List<TalkAdmin> talks = talkAdminService.findAll(Talk.State.CONFIRMED).stream()
List<TalkAdmin> talks = talkAdminService.findAll(userId, Talk.State.CONFIRMED).stream()
.sorted(comparing(TalkAdmin::getMean, nullsLast(reverseOrder())))
.sorted(comparing(TalkAdmin::getFormat))
.collect(toList());
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/cfp/service/TalkAdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,15 @@ public class TalkAdminService {
* @param states List of states the talk must be
* @return List of talks
*/
public List<TalkAdmin> findAll(Talk.State... states) {
public List<TalkAdmin> findAll(int userId, Talk.State... states) {
List<TalkAdmin> talks = talkRepo.findByEventIdAndStatesFetch(Event.current(), Arrays.asList(states))
.stream().map(TalkAdmin::new)
.collect(Collectors.toList());

List<Rate> rates = rateRepo.findAllFetchAdmin(Event.current());

User user = User.getCurrent();
Map<Integer, List<Rate>> reviewed = rates.stream()
.filter(r -> user.getId() == r.getAdminUser().getId())
.filter(r -> userId == r.getAdminUser().getId())
.collect(groupingBy(r -> r.getTalk().getId()));

Map<Integer, Double> averages = rates.stream()
Expand Down

0 comments on commit 73f1a98

Please sign in to comment.