use of org.pac4j.play.java.Secure in project civiform by seattle-uat.
the class AdminApplicationController method index.
/**
* Return a paginated HTML page displaying (part of) all applications to the program.
*/
@Secure(authorizers = Authorizers.Labels.ANY_ADMIN)
public Result index(Http.Request request, long programId, Optional<String> search, Optional<Integer> page) throws ProgramNotFoundException {
if (page.isEmpty()) {
return redirect(routes.AdminApplicationController.index(programId, search, Optional.of(1)));
}
final ProgramDefinition program;
try {
program = programService.getProgramDefinition(programId);
checkProgramAdminAuthorization(profileUtils, request, program.adminName()).join();
} catch (CompletionException e) {
return unauthorized();
}
var paginationSpec = new PageNumberBasedPaginationSpec(PAGE_SIZE, page.orElse(1));
PaginationResult<Application> applications = programService.getSubmittedProgramApplicationsAllVersions(programId, F.Either.Right(paginationSpec), search);
return ok(applicationListView.render(request, program, paginationSpec, applications, search));
}
use of org.pac4j.play.java.Secure in project civiform by seattle-uat.
the class AdminApplicationController method downloadSingleVersion.
/**
* Download a CSV file containing all applications to the specified program version. This was the
* original behavior for the program admin CSV download but is currently unused as of 10/13/2021.
*/
@Secure(authorizers = Authorizers.Labels.ANY_ADMIN)
public Result downloadSingleVersion(Http.Request request, long programId) throws ProgramNotFoundException {
try {
ProgramDefinition program = programService.getProgramDefinition(programId);
checkProgramAdminAuthorization(profileUtils, request, program.adminName()).join();
String filename = String.format("%s-%s.csv", program.adminName(), nowProvider.get());
String csv = exporterService.getProgramCsv(programId);
return ok(csv).as(Http.MimeTypes.BINARY).withHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
} catch (CompletionException e) {
return unauthorized();
}
}
use of org.pac4j.play.java.Secure in project civiform by seattle-uat.
the class AdminApplicationController method show.
/**
* Return a HTML page displaying the summary of the specified application.
*/
@Secure(authorizers = Authorizers.Labels.ANY_ADMIN)
public Result show(Http.Request request, long programId, long applicationId) throws ProgramNotFoundException {
String programName;
try {
ProgramDefinition program = programService.getProgramDefinition(programId);
programName = program.adminName();
checkProgramAdminAuthorization(profileUtils, request, program.adminName()).join();
} catch (CompletionException e) {
return unauthorized();
}
Optional<Application> applicationMaybe = this.applicationRepository.getApplication(applicationId).toCompletableFuture().join();
if (!applicationMaybe.isPresent()) {
return notFound(String.format("Application %d does not exist.", applicationId));
}
Application application = applicationMaybe.get();
Messages messages = messagesApi.preferred(request);
String applicantNameWithApplicationId = String.format("%s (%d)", ApplicantUtils.getApplicantName(application.getApplicantData().getApplicantName(), messages), application.id);
ReadOnlyApplicantProgramService roApplicantService = applicantService.getReadOnlyApplicantProgramService(application).toCompletableFuture().join();
ImmutableList<Block> blocks = roApplicantService.getAllActiveBlocks();
ImmutableList<AnswerData> answers = roApplicantService.getSummaryData();
return ok(applicationView.render(programId, programName, applicationId, applicantNameWithApplicationId, blocks, answers));
}
use of org.pac4j.play.java.Secure in project civiform by seattle-uat.
the class AdminApplicationController method downloadAll.
/**
* Download a CSV file containing all applications to all versions of the specified program.
*/
@Secure(authorizers = Authorizers.Labels.ANY_ADMIN)
public Result downloadAll(Http.Request request, long programId) throws ProgramNotFoundException {
try {
ProgramDefinition program = programService.getProgramDefinition(programId);
checkProgramAdminAuthorization(profileUtils, request, program.adminName()).join();
String filename = String.format("%s-%s.csv", program.adminName(), nowProvider.get());
String csv = exporterService.getProgramAllVersionsCsv(programId);
return ok(csv).as(Http.MimeTypes.BINARY).withHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", filename));
} catch (CompletionException e) {
return unauthorized();
}
}
use of org.pac4j.play.java.Secure in project civiform by seattle-uat.
the class AdminApplicationController method download.
/**
* Download a PDF file of the application to the program.
*/
@Secure(authorizers = Authorizers.Labels.ANY_ADMIN)
public Result download(Http.Request request, long programId, long applicationId) throws ProgramNotFoundException {
try {
ProgramDefinition program = programService.getProgramDefinition(programId);
checkProgramAdminAuthorization(profileUtils, request, program.adminName()).join();
} catch (CompletionException e) {
return unauthorized();
}
Optional<Application> applicationMaybe = this.applicationRepository.getApplication(applicationId).toCompletableFuture().join();
if (!applicationMaybe.isPresent()) {
return notFound(String.format("Application %d does not exist.", applicationId));
}
Application application = applicationMaybe.get();
PdfExporter.InMemoryPdf pdf;
try {
pdf = pdfExporter.export(application);
} catch (DocumentException | IOException e) {
throw new RuntimeException(e);
}
return ok(pdf.getByteArray()).as("application/pdf").withHeader("Content-Disposition", String.format("attachment; filename=\"%s\"", pdf.getFileName()));
}
Aggregations