Skip to content

Commit

Permalink
Merge branch 'hotfix-1.4.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Sep 16, 2021
2 parents eb0605f + 8bc5466 commit 9afea0c
Show file tree
Hide file tree
Showing 22 changed files with 177 additions and 138 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>ubc.pavlab</groupId>
<artifactId>rdp</artifactId>
<version>1.4.4</version>
<version>1.4.5</version>

<developers>
<developer>
Expand Down Expand Up @@ -210,6 +210,7 @@
<featureBranchPrefix>feature-</featureBranchPrefix>
<hotfixBranchPrefix>hotfix-</hotfixBranchPrefix>
<supportBranchPrefix>support-</supportBranchPrefix>
<versionTagPrefix>v</versionTagPrefix>
</gitFlowConfig>
</configuration>
</plugin>
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/ubc/pavlab/rdp/controllers/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.core.Authentication;
Expand All @@ -16,11 +15,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import ubc.pavlab.rdp.events.OnRegistrationCompleteEvent;
import ubc.pavlab.rdp.exception.TokenException;
import ubc.pavlab.rdp.model.Profile;
import ubc.pavlab.rdp.model.User;
import ubc.pavlab.rdp.model.VerificationToken;
import ubc.pavlab.rdp.services.PrivacyService;
import ubc.pavlab.rdp.services.UserService;
import ubc.pavlab.rdp.settings.ApplicationSettings;
Expand All @@ -43,9 +40,6 @@ public class LoginController {
@Autowired
private ApplicationSettings applicationSettings;

@Autowired
private ApplicationEventPublisher eventPublisher;

@GetMapping("/login")
public ModelAndView login() {
ModelAndView modelAndView = new ModelAndView( "login" );
Expand All @@ -67,7 +61,6 @@ public ModelAndView registration() {
return modelAndView;
}

@Transactional
@PostMapping("/registration")
public ModelAndView createNewUser( @Validated(User.ValidationUserAccount.class) User user,
BindingResult bindingResult,
Expand All @@ -94,8 +87,7 @@ public ModelAndView createNewUser( @Validated(User.ValidationUserAccount.class)
modelAndView.setStatus( HttpStatus.BAD_REQUEST );
} else {
user = userService.create( user );
VerificationToken token = userService.createVerificationTokenForUser( user );
eventPublisher.publishEvent( new OnRegistrationCompleteEvent( user, token, locale ) );
userService.createVerificationTokenForUser( user, locale );
redirectAttributes.addFlashAttribute( "message", "Your user account was registered successfully. Please check your email for completing the completing the registration process." );
modelAndView.setViewName( "redirect:/login" );
}
Expand All @@ -108,7 +100,6 @@ public ModelAndView resendConfirmation() {
return new ModelAndView( "resendConfirmation" );
}

@Transactional
@PostMapping(value = "/resendConfirmation")
public ModelAndView resendConfirmation( @RequestParam("email") String email, Locale locale ) {
ModelAndView modelAndView = new ModelAndView( "resendConfirmation" );
Expand All @@ -125,8 +116,7 @@ public ModelAndView resendConfirmation( @RequestParam("email") String email, Loc
modelAndView.addObject( "message", "User is already enabled." );
return modelAndView;
} else {
VerificationToken token = userService.createVerificationTokenForUser( user );
eventPublisher.publishEvent( new OnRegistrationCompleteEvent( user, token, locale ) );
userService.createVerificationTokenForUser( user, locale );
modelAndView.addObject( "message", "Confirmation email sent." );
}

Expand Down
18 changes: 5 additions & 13 deletions src/main/java/ubc/pavlab/rdp/controllers/PasswordController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package ubc.pavlab.rdp.controllers;

import ch.qos.logback.core.joran.spi.EventPlayer;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import ubc.pavlab.rdp.events.OnUserPasswordResetEvent;
import ubc.pavlab.rdp.exception.TokenException;
import ubc.pavlab.rdp.model.PasswordReset;
import ubc.pavlab.rdp.model.PasswordResetToken;
Expand All @@ -35,9 +39,6 @@ public class PasswordController {
@Autowired
private UserService userService;

@Autowired
private EmailService emailService;

@GetMapping(value = "/forgotPassword")
public ModelAndView forgotPassword() {
return new ModelAndView( "forgotPassword" );
Expand All @@ -57,16 +58,7 @@ public ModelAndView resetPassword( @RequestParam("email") String userEmail, Loca
return modelAndView;
}

PasswordResetToken token = userService.createPasswordResetTokenForUser( user );
try {
emailService.sendResetTokenMessage( user, token, locale );
} catch ( MessagingException e ) {
modelAndView.setStatus( HttpStatus.INTERNAL_SERVER_ERROR );
modelAndView.addObject( "message", "We had trouble sending an email to your address." );
modelAndView.addObject( "error", Boolean.TRUE );
log.error( MessageFormat.format( "Failed to send reset token message to {0}.", user ), e );
return modelAndView;
}
userService.createPasswordResetTokenForUser( user, locale );

modelAndView.addObject( "message", "Password reset instructions have been sent." );
modelAndView.addObject( "error", Boolean.FALSE );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.extern.apachecommons.CommonsLog;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.PermissionEvaluator;
Expand All @@ -13,7 +12,6 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -23,7 +21,6 @@
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.servlet.view.RedirectView;
import ubc.pavlab.rdp.events.OnRequestAccessEvent;
import ubc.pavlab.rdp.exception.RemoteException;
import ubc.pavlab.rdp.model.*;
import ubc.pavlab.rdp.model.enums.ResearcherCategory;
Expand Down Expand Up @@ -68,9 +65,6 @@ public class SearchController {
@Autowired
private PermissionEvaluator permissionEvaluator;

@Autowired
private ApplicationEventPublisher eventPublisher;

@PreAuthorize("hasPermission(null, 'search')")
@GetMapping(value = "/search")
public ModelAndView search() {
Expand Down Expand Up @@ -550,7 +544,6 @@ public Object requestGeneAccessView( @PathVariable UUID anonymousId,
return modelAndView;
}

@Transactional
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@PostMapping("/search/gene/by-anonymous-id/{anonymousId}/request-access")
public ModelAndView requestGeneAccess( @PathVariable UUID anonymousId,
Expand All @@ -570,7 +563,7 @@ public ModelAndView requestGeneAccess( @PathVariable UUID anonymousId,
if ( bindingResult.hasErrors() ) {
modelAndView.setStatus( HttpStatus.BAD_REQUEST );
} else {
eventPublisher.publishEvent( new OnRequestAccessEvent( userService.findCurrentUser(), userGene, requestAccessForm.reason ) );
userService.sendGeneAccessRequest( userService.findCurrentUser(), userGene, requestAccessForm.getReason() );
redirectAttributes.addFlashAttribute( "message", "An access request has been sent and will be reviewed." );
return new ModelAndView( "redirect:/search" );
}
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/ubc/pavlab/rdp/controllers/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import ubc.pavlab.rdp.events.OnContactEmailUpdateEvent;
import ubc.pavlab.rdp.exception.TokenException;
import ubc.pavlab.rdp.model.*;
import ubc.pavlab.rdp.model.enums.PrivacyLevelType;
Expand Down Expand Up @@ -56,9 +54,6 @@ public class UserController {
@Autowired
private EmailService emailService;

@Autowired
private ApplicationEventPublisher eventPublisher;

@Autowired
private ApplicationSettings applicationSettings;

Expand Down Expand Up @@ -221,15 +216,13 @@ public ModelAndView changePassword( @Valid PasswordChange passwordChange, Bindin
return modelAndView;
}

@Transactional
@PostMapping("/user/resend-contact-email-verification")
public Object resendContactEmailVerification( RedirectAttributes redirectAttributes, Locale locale ) {
User user = userService.findCurrentUser();
if ( user.getProfile().isContactEmailVerified() ) {
return ResponseEntity.badRequest().body( "Contact email is already verified." );
}
VerificationToken token = userService.createContactEmailVerificationTokenForUser( user );
eventPublisher.publishEvent( new OnContactEmailUpdateEvent( user, token, locale ) );
userService.createContactEmailVerificationTokenForUser( user, locale );
redirectAttributes.addFlashAttribute( "message", MessageFormat.format( "We will send an email to {0} with a link to verify your contact email.", user.getProfile().getContactEmail() ) );
return "redirect:/user/profile";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Locale;

@Getter
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
public class OnContactEmailUpdateEvent extends ApplicationEvent {

private final User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Created by mjacobson on 22/01/18.
*/
@Getter
@EqualsAndHashCode(callSuper = true)
@EqualsAndHashCode
public class OnRegistrationCompleteEvent extends ApplicationEvent {

private final User user;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ubc/pavlab/rdp/events/OnRequestAccessEvent.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ubc.pavlab.rdp.events;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
import ubc.pavlab.rdp.model.User;

@Getter
@EqualsAndHashCode
public class OnRequestAccessEvent<T> extends ApplicationEvent {

private User user;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/ubc/pavlab/rdp/events/OnUserPasswordResetEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ubc.pavlab.rdp.events;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;
import ubc.pavlab.rdp.model.PasswordResetToken;
import ubc.pavlab.rdp.model.User;

import java.util.Locale;

@Getter
@EqualsAndHashCode
public class OnUserPasswordResetEvent extends ApplicationEvent {

private final User user;
private final PasswordResetToken token;
private final Locale locale;

public OnUserPasswordResetEvent( User user, PasswordResetToken token, Locale locale ) {
super( user );
this.user = user;
this.token = token;
this.locale = locale;
}

}
12 changes: 12 additions & 0 deletions src/main/java/ubc/pavlab/rdp/listeners/UserListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;
import ubc.pavlab.rdp.events.OnContactEmailUpdateEvent;
import ubc.pavlab.rdp.events.OnRegistrationCompleteEvent;
import ubc.pavlab.rdp.events.OnRequestAccessEvent;
import ubc.pavlab.rdp.events.OnUserPasswordResetEvent;
import ubc.pavlab.rdp.model.UserGene;
import ubc.pavlab.rdp.services.EmailService;
import ubc.pavlab.rdp.settings.ApplicationSettings;
Expand Down Expand Up @@ -41,6 +44,15 @@ public void onRegistrationComplete( OnRegistrationCompleteEvent event ) {
}
}

@TransactionalEventListener
public void onUserPasswordReset( OnUserPasswordResetEvent event ) {
try {
emailService.sendResetTokenMessage( event.getUser(), event.getToken(), event.getLocale() );
} catch ( MessagingException e ) {
log.error( MessageFormat.format( "Could not send password reset email to {0}.", event.getUser() ), e );
}
}

@TransactionalEventListener
public void onContactEmailUpdate( OnContactEmailUpdateEvent event ) {
try {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/ubc/pavlab/rdp/model/GeneInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

Expand All @@ -21,7 +19,6 @@
@Index(columnList = "gene_id, taxon_id"),
@Index(columnList = "symbol, taxon_id") })
@Getter
@Transactional
public class GeneInfo extends Gene {

@Id
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/ubc/pavlab/rdp/services/EmailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import java.util.Locale;
import java.util.concurrent.Future;

/**
*
*/
public interface EmailService {

void sendSupportMessage( String message, String name, User user, String userAgent, MultipartFile attachment, Locale locale ) throws MessagingException;
Future<Void> sendSupportMessage( String message, String name, User user, String userAgent, MultipartFile attachment, Locale locale ) throws MessagingException;

void sendResetTokenMessage( User user, PasswordResetToken token, Locale locale ) throws MessagingException;
Future<Void> sendResetTokenMessage( User user, PasswordResetToken token, Locale locale ) throws MessagingException;

void sendRegistrationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;
Future<Void> sendRegistrationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;

void sendContactEmailVerificationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;
Future<Void> sendContactEmailVerificationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;

void sendUserRegisteredEmail( User user ) throws MessagingException;
Future<Void> sendUserRegisteredEmail( User user ) throws MessagingException;

void sendUserGeneAccessRequest( UserGene userGene, User by, String reason ) throws MessagingException;
Future<Void> sendUserGeneAccessRequest( UserGene userGene, User by, String reason ) throws MessagingException;
}
Loading

0 comments on commit 9afea0c

Please sign in to comment.