fix link unlink account email

This commit is contained in:
Efstratios Giannopoulos 2024-06-10 16:21:53 +03:00
parent f2165c83a3
commit 1b193bb759
7 changed files with 63 additions and 35 deletions

View File

@ -20,7 +20,7 @@ public enum ActionConfirmationType implements DatabaseEnum<Short> {
@Override
@JsonValue
public Short getValue() {
return value;
return this.value;
}
private static final Map<Short, ActionConfirmationType> map = EnumUtils.getEnumValueMap(ActionConfirmationType.class);

View File

@ -536,9 +536,6 @@ public class UserServiceImpl implements UserService {
fieldInfoList.add(new FieldInfo("{userName}", DataType.String, currentUser.getName()));
fieldInfoList.add(new FieldInfo("{confirmationToken}", DataType.String, token));
fieldInfoList.add(new FieldInfo("{expiration_time}", DataType.String, this.secondsToTime(this.notificationProperties.getEmailExpirationTimeSeconds())));
if(this.tenantScope.getTenantCode() != null && !this.tenantScope.getTenantCode().equals(this.tenantScope.getDefaultTenantCode())){
fieldInfoList.add(new FieldInfo("{tenant-url-path}", DataType.String, String.format("/t/%s", this.tenantScope.getTenantCode())));
}
data.setFields(fieldInfoList);
event.setData(this.jsonHandlingService.toJsonSafe(data));
this.eventHandler.handle(event);
@ -563,9 +560,6 @@ public class UserServiceImpl implements UserService {
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{confirmationToken}", DataType.String, token));
fieldInfoList.add(new FieldInfo("{expiration_time}", DataType.String, this.secondsToTime(this.notificationProperties.getEmailExpirationTimeSeconds())));
if(this.tenantScope.getTenantCode() != null && !this.tenantScope.getTenantCode().equals(this.tenantScope.getDefaultTenantCode())){
fieldInfoList.add(new FieldInfo("{tenant-url-path}", DataType.String, String.format("/t/%s", this.tenantScope.getTenantCode())));
}
data.setFields(fieldInfoList);
event.setData(this.jsonHandlingService.toJsonSafe(data));
this.eventHandler.handle(event);
@ -579,9 +573,14 @@ public class UserServiceImpl implements UserService {
persist.setMergeAccountConfirmation(new MergeAccountConfirmationPersist());
persist.getMergeAccountConfirmation().setEmail(email);
persist.setExpiresAt(Instant.now().plusSeconds(this.notificationProperties.getEmailExpirationTimeSeconds()));
this.validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.actionConfirmationService.persist(persist, null);
try {
this.entityManager.disableTenantFilters();
} finally {
this.entityManager.reloadTenantFilters();
}
return persist.getToken();
}
@ -593,9 +592,13 @@ public class UserServiceImpl implements UserService {
persist.setRemoveCredentialRequest(new RemoveCredentialRequestPersist());
persist.getRemoveCredentialRequest().setCredentialId(credentialId);
persist.setExpiresAt(Instant.now().plusSeconds(this.notificationProperties.getEmailExpirationTimeSeconds()));
this.validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
this.actionConfirmationService.persist(persist, null);
this.validatorFactory.validator(ActionConfirmationPersist.ActionConfirmationPersistValidator.class).validateForce(persist);
try {
this.entityManager.disableTenantFilters();
this.actionConfirmationService.persist(persist, null);
} finally {
this.entityManager.reloadTenantFilters();
}
return persist.getToken();
}
@ -614,9 +617,14 @@ public class UserServiceImpl implements UserService {
}
public void confirmMergeAccount(String token) throws IOException, InvalidApplicationException {
ActionConfirmationEntity action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.MergeAccount).isActive(IsActive.Active).first();
ActionConfirmationEntity action;
try {
this.entityManager.disableTenantFilters();
action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.MergeAccount).isActive(IsActive.Active).first();
} finally {
this.entityManager.reloadTenantFilters();
}
if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.checkActionState(action);
MergeAccountConfirmationEntity mergeAccountConfirmationEntity = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, action.getData());
@ -637,11 +645,17 @@ public class UserServiceImpl implements UserService {
this.mergeNewUserToOld(newUser, userToBeMerge);
}
action.setUpdatedAt(Instant.now());
action.setStatus(ActionConfirmationStatus.Accepted);
this.entityManager.merge(action);
this.entityManager.flush();
try {
this.entityManager.disableTenantFilters();
action.setUpdatedAt(Instant.now());
action.setStatus(ActionConfirmationStatus.Accepted);
this.entityManager.merge(action);
this.entityManager.flush();
} finally {
this.entityManager.reloadTenantFilters();
}
this.userTouchedIntegrationEventHandler.handle(newUser.getId());
this.userRemovalIntegrationEventHandler.handle(userToBeMerge.getId());
@ -805,9 +819,15 @@ public class UserServiceImpl implements UserService {
}
public void confirmRemoveCredential(String token) throws InvalidApplicationException {
ActionConfirmationEntity action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.RemoveCredential).isActive(IsActive.Active).first();
ActionConfirmationEntity action;
try {
this.entityManager.disableTenantFilters();
action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.RemoveCredential).isActive(IsActive.Active).first();
} finally {
this.entityManager.reloadTenantFilters();
}
if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.checkActionState(action);
RemoveCredentialRequestEntity removeCredentialRequestEntity = this.xmlHandlingService.fromXmlSafe(RemoveCredentialRequestEntity.class, action.getData());
@ -828,11 +848,17 @@ public class UserServiceImpl implements UserService {
}
this.deleterFactory.deleter(UserCredentialDeleter.class).delete(List.of(userCredentialEntity));
action.setUpdatedAt(Instant.now());
action.setStatus(ActionConfirmationStatus.Accepted);
this.entityManager.merge(action);
this.entityManager.flush();
try {
this.entityManager.disableTenantFilters();
action.setUpdatedAt(Instant.now());
action.setStatus(ActionConfirmationStatus.Accepted);
this.entityManager.merge(action);
this.entityManager.flush();
} finally {
this.entityManager.reloadTenantFilters();
}
this.userTouchedIntegrationEventHandler.handle(userCredentialEntity.getUserId());
@ -854,10 +880,16 @@ public class UserServiceImpl implements UserService {
}
}
private UserEntity getUserEntityFromToken(String token) throws MyForbiddenException, MyNotFoundException {
ActionConfirmationEntity action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.MergeAccount).isActive(IsActive.Active).first();
private UserEntity getUserEntityFromToken(String token) throws MyForbiddenException, MyNotFoundException, InvalidApplicationException {
ActionConfirmationEntity action;
try {
this.entityManager.disableTenantFilters();
action = this.queryFactory.query(ActionConfirmationQuery.class).tokens(token).types(ActionConfirmationType.MergeAccount).isActive(IsActive.Active).first();
} finally {
this.entityManager.reloadTenantFilters();
}
if (action == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{token, ActionConfirmationEntity.class.getSimpleName()}, LocaleContextHolder.getLocale()));
this.checkActionState(action);
MergeAccountConfirmationEntity mergeAccountConfirmationEntity = this.xmlHandlingService.fromXmlSafe(MergeAccountConfirmationEntity.class, action.getData());

View File

@ -208,8 +208,6 @@ notification:
optional:
- key: "{expiration_time}"
value: ---
- key: "{tenant-url-path}"
value:
formatting:
'[{userName}]': null
'[{installation-url}]': null
@ -235,8 +233,6 @@ notification:
value: email
- key: "{expiration_time}"
value: --
- key: "{tenant-url-path}"
value:
formatting:
'[{email}]': null
'[{tenant-url-path}]': null

View File

@ -271,7 +271,7 @@
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td> <a href="{installation-url}{tenant-url-path}/login/merge/confirmation/{confirmationToken}" target="_blank">Confirm Merge Request</a> </td>
<td> <a href="{installation-url}/login/merge/confirmation/{confirmationToken}" target="_blank">Confirm Merge Request</a> </td>
</tr>
</tbody>
</table>

View File

@ -9,6 +9,6 @@
<h2>User {userName} have sent you a merge Request.</h2>
<p>Please confirm that you want to merge your {installation-url} account with that account.
<br/>The link will expire in {expiration_time}.</p>
<a href="{installation-url}{tenant-url-path}/login/merge/confirmation/{confirmationToken}" target="_blank">Confirm Merge Request</a>
<a href="{installation-url}/login/merge/confirmation/{confirmationToken}" target="_blank">Confirm Merge Request</a>
</body>
</html>

View File

@ -271,7 +271,7 @@
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td> <a href="{installation-url}{tenant-url-path}/login/unlink/confirmation/{confirmationToken}" target="_blank">Confirm Unlink Request</a> </td>
<td> <a href="{installation-url}/login/unlink/confirmation/{confirmationToken}" target="_blank">Confirm Unlink Request</a> </td>
</tr>
</tbody>
</table>

View File

@ -9,6 +9,6 @@
<h2>You have made a request to unlink your email account in OpenCDMP.</h2>
<p>Please confirm that you want to unlink your {email} account.
<br/>The link will expire in {expiration_time}.</p>
<a href="{installation-url}{tenant-url-path}/login/unlink/confirmation/{confirmationToken}" target="_blank">Confirm Unlink Request</a>
<a href="{installation-url}/login/unlink/confirmation/{confirmationToken}" target="_blank">Confirm Unlink Request</a>
</body>
</html>