Search in sources :

Example 1 with Secure

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));
}
Also used : PageNumberBasedPaginationSpec(services.PageNumberBasedPaginationSpec) CompletionException(java.util.concurrent.CompletionException) ProgramDefinition(services.program.ProgramDefinition) Application(models.Application) Secure(org.pac4j.play.java.Secure)

Example 2 with Secure

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();
    }
}
Also used : CompletionException(java.util.concurrent.CompletionException) ProgramDefinition(services.program.ProgramDefinition) Secure(org.pac4j.play.java.Secure)

Example 3 with Secure

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));
}
Also used : AnswerData(services.applicant.AnswerData) Messages(play.i18n.Messages) CompletionException(java.util.concurrent.CompletionException) Block(services.applicant.Block) ProgramDefinition(services.program.ProgramDefinition) Application(models.Application) ReadOnlyApplicantProgramService(services.applicant.ReadOnlyApplicantProgramService) Secure(org.pac4j.play.java.Secure)

Example 4 with Secure

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();
    }
}
Also used : CompletionException(java.util.concurrent.CompletionException) ProgramDefinition(services.program.ProgramDefinition) Secure(org.pac4j.play.java.Secure)

Example 5 with Secure

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()));
}
Also used : CompletionException(java.util.concurrent.CompletionException) DocumentException(com.itextpdf.text.DocumentException) ProgramDefinition(services.program.ProgramDefinition) PdfExporter(services.export.PdfExporter) IOException(java.io.IOException) Application(models.Application) Secure(org.pac4j.play.java.Secure)

Aggregations

Secure (org.pac4j.play.java.Secure)33 ProgramDefinition (services.program.ProgramDefinition)16 ProgramNotFoundException (services.program.ProgramNotFoundException)16 CompletionException (java.util.concurrent.CompletionException)10 CiviFormError (services.CiviFormError)9 ProgramBlockDefinitionNotFoundException (services.program.ProgramBlockDefinitionNotFoundException)7 QuestionNotFoundException (services.question.exceptions.QuestionNotFoundException)7 QuestionDefinition (services.question.types.QuestionDefinition)6 Locale (java.util.Locale)5 DynamicForm (play.data.DynamicForm)5 Result (play.mvc.Result)5 InvalidQuestionTypeException (services.question.exceptions.InvalidQuestionTypeException)5 EnumeratorQuestionDefinition (services.question.types.EnumeratorQuestionDefinition)5 Optional (java.util.Optional)4 Inject (javax.inject.Inject)4 FormFactory (play.data.FormFactory)4 MultiOptionQuestionDefinition (services.question.types.MultiOptionQuestionDefinition)4 ProfileUtils (auth.ProfileUtils)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 ImmutableList (com.google.common.collect.ImmutableList)3