Skip to content

Commit 9afea0c

Browse files
committed
Merge branch 'hotfix-1.4.5'
2 parents eb0605f + 8bc5466 commit 9afea0c

22 files changed

+177
-138
lines changed

pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>ubc.pavlab</groupId>
77
<artifactId>rdp</artifactId>
8-
<version>1.4.4</version>
8+
<version>1.4.5</version>
99

1010
<developers>
1111
<developer>
@@ -210,6 +210,7 @@
210210
<featureBranchPrefix>feature-</featureBranchPrefix>
211211
<hotfixBranchPrefix>hotfix-</hotfixBranchPrefix>
212212
<supportBranchPrefix>support-</supportBranchPrefix>
213+
<versionTagPrefix>v</versionTagPrefix>
213214
</gitFlowConfig>
214215
</configuration>
215216
</plugin>

src/main/java/ubc/pavlab/rdp/controllers/LoginController.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import lombok.extern.apachecommons.CommonsLog;
44
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.context.ApplicationEventPublisher;
65
import org.springframework.http.HttpStatus;
76
import org.springframework.security.authentication.AnonymousAuthenticationToken;
87
import org.springframework.security.core.Authentication;
@@ -16,11 +15,9 @@
1615
import org.springframework.web.bind.annotation.RequestParam;
1716
import org.springframework.web.servlet.ModelAndView;
1817
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
19-
import ubc.pavlab.rdp.events.OnRegistrationCompleteEvent;
2018
import ubc.pavlab.rdp.exception.TokenException;
2119
import ubc.pavlab.rdp.model.Profile;
2220
import ubc.pavlab.rdp.model.User;
23-
import ubc.pavlab.rdp.model.VerificationToken;
2421
import ubc.pavlab.rdp.services.PrivacyService;
2522
import ubc.pavlab.rdp.services.UserService;
2623
import ubc.pavlab.rdp.settings.ApplicationSettings;
@@ -43,9 +40,6 @@ public class LoginController {
4340
@Autowired
4441
private ApplicationSettings applicationSettings;
4542

46-
@Autowired
47-
private ApplicationEventPublisher eventPublisher;
48-
4943
@GetMapping("/login")
5044
public ModelAndView login() {
5145
ModelAndView modelAndView = new ModelAndView( "login" );
@@ -67,7 +61,6 @@ public ModelAndView registration() {
6761
return modelAndView;
6862
}
6963

70-
@Transactional
7164
@PostMapping("/registration")
7265
public ModelAndView createNewUser( @Validated(User.ValidationUserAccount.class) User user,
7366
BindingResult bindingResult,
@@ -94,8 +87,7 @@ public ModelAndView createNewUser( @Validated(User.ValidationUserAccount.class)
9487
modelAndView.setStatus( HttpStatus.BAD_REQUEST );
9588
} else {
9689
user = userService.create( user );
97-
VerificationToken token = userService.createVerificationTokenForUser( user );
98-
eventPublisher.publishEvent( new OnRegistrationCompleteEvent( user, token, locale ) );
90+
userService.createVerificationTokenForUser( user, locale );
9991
redirectAttributes.addFlashAttribute( "message", "Your user account was registered successfully. Please check your email for completing the completing the registration process." );
10092
modelAndView.setViewName( "redirect:/login" );
10193
}
@@ -108,7 +100,6 @@ public ModelAndView resendConfirmation() {
108100
return new ModelAndView( "resendConfirmation" );
109101
}
110102

111-
@Transactional
112103
@PostMapping(value = "/resendConfirmation")
113104
public ModelAndView resendConfirmation( @RequestParam("email") String email, Locale locale ) {
114105
ModelAndView modelAndView = new ModelAndView( "resendConfirmation" );
@@ -125,8 +116,7 @@ public ModelAndView resendConfirmation( @RequestParam("email") String email, Loc
125116
modelAndView.addObject( "message", "User is already enabled." );
126117
return modelAndView;
127118
} else {
128-
VerificationToken token = userService.createVerificationTokenForUser( user );
129-
eventPublisher.publishEvent( new OnRegistrationCompleteEvent( user, token, locale ) );
119+
userService.createVerificationTokenForUser( user, locale );
130120
modelAndView.addObject( "message", "Confirmation email sent." );
131121
}
132122

src/main/java/ubc/pavlab/rdp/controllers/PasswordController.java

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package ubc.pavlab.rdp.controllers;
22

3+
import ch.qos.logback.core.joran.spi.EventPlayer;
34
import lombok.extern.apachecommons.CommonsLog;
45
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.context.ApplicationEventPublisher;
57
import org.springframework.http.HttpStatus;
68
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
79
import org.springframework.security.core.Authentication;
810
import org.springframework.security.core.context.SecurityContextHolder;
911
import org.springframework.stereotype.Controller;
12+
import org.springframework.transaction.annotation.Transactional;
1013
import org.springframework.validation.BindingResult;
1114
import org.springframework.web.bind.annotation.GetMapping;
1215
import org.springframework.web.bind.annotation.PostMapping;
1316
import org.springframework.web.bind.annotation.RequestParam;
1417
import org.springframework.web.servlet.ModelAndView;
18+
import ubc.pavlab.rdp.events.OnUserPasswordResetEvent;
1519
import ubc.pavlab.rdp.exception.TokenException;
1620
import ubc.pavlab.rdp.model.PasswordReset;
1721
import ubc.pavlab.rdp.model.PasswordResetToken;
@@ -35,9 +39,6 @@ public class PasswordController {
3539
@Autowired
3640
private UserService userService;
3741

38-
@Autowired
39-
private EmailService emailService;
40-
4142
@GetMapping(value = "/forgotPassword")
4243
public ModelAndView forgotPassword() {
4344
return new ModelAndView( "forgotPassword" );
@@ -57,16 +58,7 @@ public ModelAndView resetPassword( @RequestParam("email") String userEmail, Loca
5758
return modelAndView;
5859
}
5960

60-
PasswordResetToken token = userService.createPasswordResetTokenForUser( user );
61-
try {
62-
emailService.sendResetTokenMessage( user, token, locale );
63-
} catch ( MessagingException e ) {
64-
modelAndView.setStatus( HttpStatus.INTERNAL_SERVER_ERROR );
65-
modelAndView.addObject( "message", "We had trouble sending an email to your address." );
66-
modelAndView.addObject( "error", Boolean.TRUE );
67-
log.error( MessageFormat.format( "Failed to send reset token message to {0}.", user ), e );
68-
return modelAndView;
69-
}
61+
userService.createPasswordResetTokenForUser( user, locale );
7062

7163
modelAndView.addObject( "message", "Password reset instructions have been sent." );
7264
modelAndView.addObject( "error", Boolean.FALSE );

src/main/java/ubc/pavlab/rdp/controllers/SearchController.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import lombok.extern.apachecommons.CommonsLog;
55
import org.hibernate.validator.constraints.NotBlank;
66
import org.springframework.beans.factory.annotation.Autowired;
7-
import org.springframework.context.ApplicationEventPublisher;
87
import org.springframework.context.MessageSource;
98
import org.springframework.http.HttpStatus;
109
import org.springframework.security.access.PermissionEvaluator;
@@ -13,7 +12,6 @@
1312
import org.springframework.security.core.Authentication;
1413
import org.springframework.security.core.context.SecurityContextHolder;
1514
import org.springframework.stereotype.Controller;
16-
import org.springframework.transaction.annotation.Transactional;
1715
import org.springframework.validation.BindingResult;
1816
import org.springframework.web.bind.annotation.GetMapping;
1917
import org.springframework.web.bind.annotation.PathVariable;
@@ -23,7 +21,6 @@
2321
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
2422
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
2523
import org.springframework.web.servlet.view.RedirectView;
26-
import ubc.pavlab.rdp.events.OnRequestAccessEvent;
2724
import ubc.pavlab.rdp.exception.RemoteException;
2825
import ubc.pavlab.rdp.model.*;
2926
import ubc.pavlab.rdp.model.enums.ResearcherCategory;
@@ -68,9 +65,6 @@ public class SearchController {
6865
@Autowired
6966
private PermissionEvaluator permissionEvaluator;
7067

71-
@Autowired
72-
private ApplicationEventPublisher eventPublisher;
73-
7468
@PreAuthorize("hasPermission(null, 'search')")
7569
@GetMapping(value = "/search")
7670
public ModelAndView search() {
@@ -550,7 +544,6 @@ public Object requestGeneAccessView( @PathVariable UUID anonymousId,
550544
return modelAndView;
551545
}
552546

553-
@Transactional
554547
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
555548
@PostMapping("/search/gene/by-anonymous-id/{anonymousId}/request-access")
556549
public ModelAndView requestGeneAccess( @PathVariable UUID anonymousId,
@@ -570,7 +563,7 @@ public ModelAndView requestGeneAccess( @PathVariable UUID anonymousId,
570563
if ( bindingResult.hasErrors() ) {
571564
modelAndView.setStatus( HttpStatus.BAD_REQUEST );
572565
} else {
573-
eventPublisher.publishEvent( new OnRequestAccessEvent( userService.findCurrentUser(), userGene, requestAccessForm.reason ) );
566+
userService.sendGeneAccessRequest( userService.findCurrentUser(), userGene, requestAccessForm.getReason() );
574567
redirectAttributes.addFlashAttribute( "message", "An access request has been sent and will be reviewed." );
575568
return new ModelAndView( "redirect:/search" );
576569
}

src/main/java/ubc/pavlab/rdp/controllers/UserController.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
import org.springframework.security.access.annotation.Secured;
1313
import org.springframework.security.authentication.BadCredentialsException;
1414
import org.springframework.stereotype.Controller;
15-
import org.springframework.transaction.annotation.Transactional;
1615
import org.springframework.validation.BindingResult;
1716
import org.springframework.web.bind.annotation.*;
1817
import org.springframework.web.multipart.MultipartFile;
1918
import org.springframework.web.servlet.ModelAndView;
2019
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
21-
import ubc.pavlab.rdp.events.OnContactEmailUpdateEvent;
2220
import ubc.pavlab.rdp.exception.TokenException;
2321
import ubc.pavlab.rdp.model.*;
2422
import ubc.pavlab.rdp.model.enums.PrivacyLevelType;
@@ -56,9 +54,6 @@ public class UserController {
5654
@Autowired
5755
private EmailService emailService;
5856

59-
@Autowired
60-
private ApplicationEventPublisher eventPublisher;
61-
6257
@Autowired
6358
private ApplicationSettings applicationSettings;
6459

@@ -221,15 +216,13 @@ public ModelAndView changePassword( @Valid PasswordChange passwordChange, Bindin
221216
return modelAndView;
222217
}
223218

224-
@Transactional
225219
@PostMapping("/user/resend-contact-email-verification")
226220
public Object resendContactEmailVerification( RedirectAttributes redirectAttributes, Locale locale ) {
227221
User user = userService.findCurrentUser();
228222
if ( user.getProfile().isContactEmailVerified() ) {
229223
return ResponseEntity.badRequest().body( "Contact email is already verified." );
230224
}
231-
VerificationToken token = userService.createContactEmailVerificationTokenForUser( user );
232-
eventPublisher.publishEvent( new OnContactEmailUpdateEvent( user, token, locale ) );
225+
userService.createContactEmailVerificationTokenForUser( user, locale );
233226
redirectAttributes.addFlashAttribute( "message", MessageFormat.format( "We will send an email to {0} with a link to verify your contact email.", user.getProfile().getContactEmail() ) );
234227
return "redirect:/user/profile";
235228
}

src/main/java/ubc/pavlab/rdp/events/OnContactEmailUpdateEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Locale;
1010

1111
@Getter
12-
@EqualsAndHashCode(callSuper = true)
12+
@EqualsAndHashCode
1313
public class OnContactEmailUpdateEvent extends ApplicationEvent {
1414

1515
private final User user;

src/main/java/ubc/pavlab/rdp/events/OnRegistrationCompleteEvent.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Created by mjacobson on 22/01/18.
1414
*/
1515
@Getter
16-
@EqualsAndHashCode(callSuper = true)
16+
@EqualsAndHashCode
1717
public class OnRegistrationCompleteEvent extends ApplicationEvent {
1818

1919
private final User user;

src/main/java/ubc/pavlab/rdp/events/OnRequestAccessEvent.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package ubc.pavlab.rdp.events;
22

3+
import lombok.EqualsAndHashCode;
34
import lombok.Getter;
45
import org.springframework.context.ApplicationEvent;
56
import ubc.pavlab.rdp.model.User;
67

78
@Getter
9+
@EqualsAndHashCode
810
public class OnRequestAccessEvent<T> extends ApplicationEvent {
911

1012
private User user;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ubc.pavlab.rdp.events;
2+
3+
import lombok.EqualsAndHashCode;
4+
import lombok.Getter;
5+
import org.springframework.context.ApplicationEvent;
6+
import ubc.pavlab.rdp.model.PasswordResetToken;
7+
import ubc.pavlab.rdp.model.User;
8+
9+
import java.util.Locale;
10+
11+
@Getter
12+
@EqualsAndHashCode
13+
public class OnUserPasswordResetEvent extends ApplicationEvent {
14+
15+
private final User user;
16+
private final PasswordResetToken token;
17+
private final Locale locale;
18+
19+
public OnUserPasswordResetEvent( User user, PasswordResetToken token, Locale locale ) {
20+
super( user );
21+
this.user = user;
22+
this.token = token;
23+
this.locale = locale;
24+
}
25+
26+
}

src/main/java/ubc/pavlab/rdp/listeners/UserListener.java

+12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import lombok.extern.apachecommons.CommonsLog;
44
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.context.event.EventListener;
56
import org.springframework.stereotype.Component;
7+
import org.springframework.transaction.event.TransactionPhase;
68
import org.springframework.transaction.event.TransactionalEventListener;
79
import ubc.pavlab.rdp.events.OnContactEmailUpdateEvent;
810
import ubc.pavlab.rdp.events.OnRegistrationCompleteEvent;
911
import ubc.pavlab.rdp.events.OnRequestAccessEvent;
12+
import ubc.pavlab.rdp.events.OnUserPasswordResetEvent;
1013
import ubc.pavlab.rdp.model.UserGene;
1114
import ubc.pavlab.rdp.services.EmailService;
1215
import ubc.pavlab.rdp.settings.ApplicationSettings;
@@ -41,6 +44,15 @@ public void onRegistrationComplete( OnRegistrationCompleteEvent event ) {
4144
}
4245
}
4346

47+
@TransactionalEventListener
48+
public void onUserPasswordReset( OnUserPasswordResetEvent event ) {
49+
try {
50+
emailService.sendResetTokenMessage( event.getUser(), event.getToken(), event.getLocale() );
51+
} catch ( MessagingException e ) {
52+
log.error( MessageFormat.format( "Could not send password reset email to {0}.", event.getUser() ), e );
53+
}
54+
}
55+
4456
@TransactionalEventListener
4557
public void onContactEmailUpdate( OnContactEmailUpdateEvent event ) {
4658
try {

src/main/java/ubc/pavlab/rdp/model/GeneInfo.java

-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import lombok.Getter;
5-
import org.springframework.transaction.annotation.Transactional;
65

76
import javax.persistence.*;
8-
import java.io.Serializable;
97
import java.util.HashSet;
108
import java.util.Set;
119

@@ -21,7 +19,6 @@
2119
@Index(columnList = "gene_id, taxon_id"),
2220
@Index(columnList = "symbol, taxon_id") })
2321
@Getter
24-
@Transactional
2522
public class GeneInfo extends Gene {
2623

2724
@Id

src/main/java/ubc/pavlab/rdp/services/EmailService.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@
99
import javax.mail.MessagingException;
1010
import javax.servlet.http.HttpServletRequest;
1111
import java.util.Locale;
12+
import java.util.concurrent.Future;
1213

1314
/**
1415
*
1516
*/
1617
public interface EmailService {
1718

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

20-
void sendResetTokenMessage( User user, PasswordResetToken token, Locale locale ) throws MessagingException;
21+
Future<Void> sendResetTokenMessage( User user, PasswordResetToken token, Locale locale ) throws MessagingException;
2122

22-
void sendRegistrationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;
23+
Future<Void> sendRegistrationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;
2324

24-
void sendContactEmailVerificationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;
25+
Future<Void> sendContactEmailVerificationMessage( User user, VerificationToken token, Locale locale ) throws MessagingException;
2526

26-
void sendUserRegisteredEmail( User user ) throws MessagingException;
27+
Future<Void> sendUserRegisteredEmail( User user ) throws MessagingException;
2728

28-
void sendUserGeneAccessRequest( UserGene userGene, User by, String reason ) throws MessagingException;
29+
Future<Void> sendUserGeneAccessRequest( UserGene userGene, User by, String reason ) throws MessagingException;
2930
}

0 commit comments

Comments
 (0)