Skip to content

Commit

Permalink
Merge pull request #91 from cabinetoffice/release/7.0
Browse files Browse the repository at this point in the history
Release/7.0
  • Loading branch information
iaincooper-tco authored Jan 17, 2024
2 parents 371ffd4 + 5aff41f commit 142bf4b
Show file tree
Hide file tree
Showing 71 changed files with 699 additions and 298 deletions.
1 change: 0 additions & 1 deletion DUMMY

This file was deleted.

4 changes: 2 additions & 2 deletions localdev/postgres/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
image: postgres
restart: always
ports:
- 5432:5432
- "5432:5432"
volumes:
- postgres:/var/lib/postgresql/data
environment:
Expand All @@ -17,7 +17,7 @@ services:
image: adminer
restart: always
ports:
- 8082:8080
- "8082:8080"

volumes:
postgres:
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
@ComponentScan(basePackages = "gov.cabinetoffice.gap")
public class ApplyBackendApplication {

public static void main(String[] args) {
SpringApplication.run(ApplyBackendApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(ApplyBackendApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SpringDocConfigProperties springDocConfigProperties() {
}

@Bean
ObjectMapperProvider objectMapperProvider(SpringDocConfigProperties springDocConfigProperties){
ObjectMapperProvider objectMapperProvider(SpringDocConfigProperties springDocConfigProperties) {
return new ObjectMapperProvider(springDocConfigProperties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public class S3ConfigProperties {

@NotNull
private String bucket;

@NotNull
private String attachmentsBucket;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class MandatoryQuestionConstants {
public static final String APPLICANT_FUNDING_LOCATION_TITLE = "Where will this funding be spent?";
public static final String APPLICANT_FUNDING_LOCATION_HINT_TEXT = "Select the location where the grant funding will be spent. You can choose more than one, if it is being spent in more than one location.\n\nSelect all that apply:";
public static final String APPLICANT_FUNDING_LOCATION_ADMIN_SUMMARY = "where the funding will be spent";
public static final String[] APPLICANT_FUNDING_LOCATION_OPTIONS = new String[] {
public static final String[] APPLICANT_FUNDING_LOCATION_OPTIONS = new String[]{
"North East England",
"North West England",
"South East England",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gov.cabinetoffice.gap.applybackend.dto.api;

import gov.cabinetoffice.gap.applybackend.enums.GrantApplicantStatus;
import gov.cabinetoffice.gap.applybackend.enums.GrantApplicationStatus;
import lombok.Data;
import lombok.RequiredArgsConstructor;

Expand All @@ -16,5 +16,5 @@ public class GetGrantApplicationDto {
private Instant lastUpdated;
private Integer lastUpdatedBy;
private String applicationName;
private GrantApplicantStatus applicationStatus;
private GrantApplicationStatus applicationStatus;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum GrantApplicantOrganisationType {

private String name;

private GrantApplicantOrganisationType(String name) {
GrantApplicantOrganisationType(String name) {
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gov.cabinetoffice.gap.applybackend.enums;

public enum GrantApplicantStatus {
public enum GrantApplicationStatus {
DRAFT,
PUBLISHED,
REMOVED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum GrantMandatoryQuestionOrgType {

private String name;

private GrantMandatoryQuestionOrgType(String name) {
GrantMandatoryQuestionOrgType(String name) {
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public enum SubmissionQuestionResponseType {
MultipleSelection,
Date,
SingleFileUpload,
Numeric;
Numeric
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,5 @@

public enum SubmissionStatus {
IN_PROGRESS,
INELIGABLE,
SUBMITTED,
UNDER_REVIEW,
AWARDED,
NOT_AWARDED,
WITHDRAWN
SUBMITTED
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gov.cabinetoffice.gap.applybackend.exception;

public class GrantApplicationNotPublishedException extends RuntimeException{
public class GrantApplicationNotPublishedException extends RuntimeException {

public GrantApplicationNotPublishedException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package gov.cabinetoffice.gap.applybackend.exception;

public class JwtExpiredTokenException extends RuntimeException{
public class JwtExpiredTokenException extends RuntimeException {

public JwtExpiredTokenException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public interface GrantMandatoryQuestionMapper {


@Mapping(source= "grantScheme.id", target = "schemeId")
@Mapping(source = "grantScheme.id", target = "schemeId")
@Mapping(source = "orgType", target = "orgType", qualifiedByName = "mapEntityOrgTypeToDtoOrgType")
@Mapping(source = "fundingAmount", target = "fundingAmount", qualifiedByName = "mapEntityFundingAmountToDtoFundingAmount")
@Mapping(source = "fundingLocation", target = "fundingLocation", qualifiedByName = "mapEntityFundingLocationToDtoFundingLocation")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gov.cabinetoffice.gap.applybackend.model;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import gov.cabinetoffice.gap.applybackend.enums.GrantApplicantStatus;
import gov.cabinetoffice.gap.applybackend.enums.GrantApplicationStatus;
import lombok.*;
import org.hibernate.annotations.Type;

Expand Down Expand Up @@ -45,7 +45,7 @@ public class GrantApplication extends BaseEntity {

@Column(name = "status")
@Enumerated(EnumType.STRING)
private GrantApplicantStatus applicationStatus;
private GrantApplicationStatus applicationStatus;

@Column(name = "definition", nullable = false, columnDefinition = "json")
@Type(type = "json")
Expand All @@ -56,7 +56,7 @@ public GrantApplication(GrantScheme grantScheme, String applicationName, Integer
this.version = 2;
this.created = Instant.now();
this.lastUpdated = Instant.now();
this.applicationStatus = GrantApplicantStatus.DRAFT;
this.applicationStatus = GrantApplicationStatus.DRAFT;
this.grantScheme = grantScheme;
this.lastUpdateBy = lastUpdateBy;
this.applicationName = applicationName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class GrantScheme {
@Builder.Default
@Column(name = "version", nullable = false)
private Integer version = 1;

@Builder.Default
@Column(name = "created_date", nullable = false)
private Instant createdDate = Instant.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
})
public class RegisterApplicant {
@NotBlank(message = "Enter a first name")
@ContainsOnlyAlphaChars(message="First name must contain only letters")
@ContainsOnlyAlphaChars(message = "First name must contain only letters")
private String firstName;

@NotBlank(message = "Enter a last name")
@ContainsOnlyAlphaChars(message="Last name must contain only letters")
@ContainsOnlyAlphaChars(message = "Last name must contain only letters")
private String lastName;

@NotBlank(message = "Enter an email address")
@Email(message = "Enter an email address in the correct format, like [email protected]")
@Size(max=254, message = "Email address must be 254 characters or less")
@Size(max = 254, message = "Email address must be 254 characters or less")
private String email;

@NotBlank(message = "Enter an email address")
@Email(message = "Enter an email address in the correct format, like [email protected]")
@Size(max=254, message = "Email address must be 254 characters or less")
@Size(max = 254, message = "Email address must be 254 characters or less")
private String emailConfirmed;

@PhoneNumberIsValid(message = "Enter a UK telephone number, like 07123456789", field="telephone")
@PhoneNumberIsValid(message = "Enter a UK telephone number, like 07123456789", field = "telephone")
private String telephone;

@NotBlank(message = "You must confirm that you have read and agreed to the privacy policy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@AllArgsConstructor
@Builder
@Entity
@Table(name= "spotlight_batch")
@Table(name = "spotlight_batch")
public class SpotlightBatch {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@AllArgsConstructor
@Builder
@Entity
@Table(name= "spotlight_submission")
@Table(name = "spotlight_submission")
public class SpotlightSubmission {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@AllArgsConstructor
@Builder
@Entity
@Table(name= "grant_submission")
@Table(name = "grant_submission")
public class Submission extends BaseEntity {
@Id
@GeneratedValue
Expand All @@ -46,7 +46,6 @@ public class Submission extends BaseEntity {
@JsonIgnoreProperties("submissions")
private GrantApplicant applicant;


@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "scheme_id")
private GrantScheme scheme;
Expand Down Expand Up @@ -95,6 +94,10 @@ public class Submission extends BaseEntity {
@Column(name = "last_required_checks_export")
private Instant lastRequiredChecksExport;

@Column
@Builder.Default
private Boolean mandatorySectionsCompleted = false;

public SubmissionSection getSection(String sectionId) {
return this.getDefinition()
.getSections()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@
@Repository
public interface GrantApplicantRepository extends JpaRepository<GrantApplicant, Long> {
Optional<GrantApplicant> findByUserId(String userid);

boolean existsByUserId(String userId);



}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gov.cabinetoffice.gap.applybackend.repository;

import gov.cabinetoffice.gap.applybackend.dto.api.GetGrantSchemeDto;
import gov.cabinetoffice.gap.applybackend.model.GrantScheme;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
public interface SubmissionRepository extends JpaRepository<Submission, UUID> {
List<Submission> findByApplicantId(long applicantId);
Optional<Submission> findByApplicantIdAndApplicationId(long applicantId, Integer applicationId);

Optional<Submission> findByIdAndApplicantUserId(UUID id, String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload;
import gov.cabinetoffice.gap.applybackend.service.JwtService;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand All @@ -29,9 +30,9 @@ public class JwtTokenFilter extends OncePerRequestFilter {
private final JwtService jwtService;

@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain chain)
protected void doFilterInternal(@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull FilterChain chain)
throws ServletException, IOException {

// Check if auth header exists. If not, return without setting authentication in the security context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import gov.cabinetoffice.gap.applybackend.model.GrantApplicantOrganisationProfile;
import gov.cabinetoffice.gap.applybackend.repository.GrantApplicantOrganisationProfileRepository;
import gov.cabinetoffice.gap.applybackend.repository.GrantApplicantRepository;
import gov.cabinetoffice.gap.applybackend.service.GrantApplicantOrganisationProfileService;
import gov.cabinetoffice.gap.applybackend.service.GrantApplicantService;
import gov.cabinetoffice.gap.applybackend.service.JwtService;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.http.HttpHeaders;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand All @@ -23,7 +23,6 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collections;
import java.util.Optional;

import static org.springframework.util.ObjectUtils.isEmpty;

Expand All @@ -40,9 +39,9 @@ public class JwtTokenFilterV2 extends OncePerRequestFilter {
private final GrantApplicantOrganisationProfileRepository grantApplicantOrganisationProfileRepository;

@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain chain)
protected void doFilterInternal(@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull FilterChain chain)
throws ServletException, IOException {

// Check if auth header exists. If not, return without setting authentication in the security context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@ public SecurityFilterChain filterChainPublic(HttpSecurity http) throws Exception
.anyRequest()
.authenticated();

if(oneLoginEnabled) {
http
.addFilterBefore(new JwtTokenFilterV2(jwtService, grantApplicantRepository, grantApplicantService, grantApplicantOrganisationProfileRepository), UsernamePasswordAuthenticationFilter.class);
if (oneLoginEnabled) {
http.addFilterBefore(
new JwtTokenFilterV2(
jwtService,
grantApplicantRepository,
grantApplicantService,
grantApplicantOrganisationProfileRepository
),
UsernamePasswordAuthenticationFilter.class
);
} else {
http
.addFilterBefore(new JwtTokenFilter(jwtService), UsernamePasswordAuthenticationFilter.class);
http.addFilterBefore(
new JwtTokenFilter(jwtService),
UsernamePasswordAuthenticationFilter.class
);
}

// disable a bunch of Spring Security default stuff we don't need
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public void deleteAttachment(final GrantAttachment attachment, final Integer app
final AmazonS3URI s3Uri = new AmazonS3URI(attachment.getLocation());
final String key = applicationId + "/" + submissionId + "/" + questionId + "/" + attachment.getFilename();
s3Client.deleteObject(new DeleteObjectRequest(s3Uri.getBucket(), key));
s3Client.deleteObject(new DeleteObjectRequest(s3Properties.getAttachmentsBucket(), key));
grantAttachmentRepository.delete(attachment);
} catch (SdkClientException e) {
log.error("An error occurred deleting the file: ", e);
e.printStackTrace();
}
}
}
Loading

0 comments on commit 142bf4b

Please sign in to comment.