Skip to content

Commit

Permalink
#86 - do not return statistics to the application
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Nov 4, 2015
1 parent 32e205a commit be0d3b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/alfio/config/WebSecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected void configure(HttpSecurity http) throws Exception {
.and().csrf().disable()
.authorizeRequests()
.antMatchers(ADMIN_API + "/check-in/**").hasRole(OPERATOR)
.antMatchers(HttpMethod.GET, ADMIN_API + "/events/**").hasRole(OPERATOR)
.antMatchers(HttpMethod.GET, ADMIN_API + "/events").hasAnyRole(OPERATOR, SPONSOR)
.antMatchers(ADMIN_API + "/**").denyAll()
.antMatchers(HttpMethod.POST, "/api/attendees/sponsor-scan").hasRole(SPONSOR)
.antMatchers("/**").authenticated()
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/alfio/controller/api/admin/EventApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
*/
package alfio.controller.api.admin;

import alfio.controller.api.support.DescriptionsLoader;
import alfio.controller.api.support.EventListItem;
import alfio.controller.api.support.PublicEvent;
import alfio.manager.EventManager;
import alfio.manager.EventStatisticsManager;
import alfio.manager.TicketReservationManager;
import alfio.manager.user.UserManager;
import alfio.model.*;
import alfio.manager.i18n.I18nManager;
import alfio.manager.support.OrderSummary;
Expand Down Expand Up @@ -66,25 +70,31 @@ public class EventApiController {

private static final String OK = "OK";
private final EventManager eventManager;
private final UserManager userManager;
private final EventStatisticsManager eventStatisticsManager;
private final I18nManager i18nManager;
private final TicketReservationManager ticketReservationManager;
private final TicketCategoryDescriptionRepository ticketCategoryDescriptionRepository;
private final TicketFieldRepository ticketFieldRepository;
private final DescriptionsLoader descriptionsLoader;

@Autowired
public EventApiController(EventManager eventManager,
UserManager userManager,
EventStatisticsManager eventStatisticsManager,
I18nManager i18nManager,
TicketReservationManager ticketReservationManager,
TicketCategoryDescriptionRepository ticketCategoryDescriptionRepository,
TicketFieldRepository ticketFieldRepository) {
TicketFieldRepository ticketFieldRepository,
DescriptionsLoader descriptionsLoader) {
this.eventManager = eventManager;
this.userManager = userManager;
this.eventStatisticsManager = eventStatisticsManager;
this.i18nManager = i18nManager;
this.ticketReservationManager = ticketReservationManager;
this.ticketCategoryDescriptionRepository = ticketCategoryDescriptionRepository;
this.ticketFieldRepository = ticketFieldRepository;
this.descriptionsLoader = descriptionsLoader;
}

@ExceptionHandler(DataAccessException.class)
Expand All @@ -109,6 +119,14 @@ public List<PaymentProxy> getPaymentProxies() {
return PaymentProxy.availableProxies();
}

@RequestMapping(value = "/events", method = GET, headers = "Authorization=Basic*")
public List<EventListItem> getAllEventsForExternal(Principal principal, HttpServletRequest request) {
return eventStatisticsManager.getAllEventsWithStatistics(principal.getName()).stream()
.sorted()
.map(s -> new EventListItem(s.getEvent(), request.getContextPath(), descriptionsLoader.eventDescriptions()))
.collect(Collectors.toList());
}

@RequestMapping(value = "/events", method = GET)
public List<EventWithStatistics> getAllEvents(Principal principal) {
return eventStatisticsManager.getAllEventsWithStatistics(principal.getName()).stream()
Expand Down Expand Up @@ -202,7 +220,7 @@ public void downloadAllTicketsCSV(@PathVariable("eventName") String eventName, H
out.write(marker);
}
CSVWriter writer = new CSVWriter(new OutputStreamWriter(out));
writer.writeNext(fields.toArray(new String[]{}));
writer.writeNext(fields.toArray(new String[fields.size()]));

eventManager.findAllConfirmedTickets(eventName, principal.getName()).stream().map(t -> {
List<String> line = new ArrayList<>();
Expand All @@ -226,7 +244,7 @@ public void downloadAllTicketsCSV(@PathVariable("eventName") String eventName, H
line.add(additionalValues.getOrDefault(field, ""));
});

return line.toArray(new String[]{});
return line.toArray(new String[line.size()]);
}).forEachOrdered(writer::writeNext);
writer.flush();
out.flush();
Expand Down

0 comments on commit be0d3b0

Please sign in to comment.