Merge branch 'dmp-refactoring' of https://code-repo.d4science.org/MaDgiK-CITE/argos into dmp-refactoring

This commit is contained in:
Sofia Papacharalampous 2024-05-13 14:19:11 +03:00
commit c2f34f0299
2 changed files with 29 additions and 23 deletions

View File

@ -432,12 +432,18 @@ public class UserServiceImpl implements UserService {
UserEntity user = this.queryFactory.query(UserQuery.class).ids(userContactInfoEntity.getUserId()).isActive(IsActive.Active).first();
if (user == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{userContactInfoEntity.getUserId(), User.class.getSimpleName()}, LocaleContextHolder.getLocale()));
if (this.userScope.getUserIdSafe() == null) throw new MyForbiddenException(this.errors.getForbidden().getCode(), this.errors.getForbidden().getMessage());
String token = this.createMergeAccountConfirmation(model.getEmail());
this.createMergeNotificationEvent(token, user, model.getEmail(), NotificationContactType.EMAIL);
}
private void createMergeNotificationEvent(String token, UserEntity user, String email, NotificationContactType type) throws InvalidApplicationException {
UserEntity currentUser = this.entityManager.find(UserEntity.class, this.userScope.getUserIdSafe());
if (currentUser == null) throw new MyNotFoundException(this.messageSource.getMessage("General_ItemNotFound", new Object[]{ this.userScope.getUserIdSafe(), User.class.getSimpleName()}, LocaleContextHolder.getLocale()));
NotifyIntegrationEvent event = new NotifyIntegrationEvent();
event.setUserId(user.getId());
List<ContactPair> contactPairs = new ArrayList<>();
@ -448,7 +454,7 @@ public class UserServiceImpl implements UserService {
event.setNotificationType(this.notificationProperties.getMergeAccountConfirmationType());
NotificationFieldData data = new NotificationFieldData();
List<FieldInfo> fieldInfoList = new ArrayList<>();
fieldInfoList.add(new FieldInfo("{userName}", DataType.String, user.getName()));
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())));
data.setFields(fieldInfoList);
@ -515,7 +521,7 @@ public class UserServiceImpl implements UserService {
int hour = seconds / 60;
int min = hour % 60;
hour = hour / 60;
return (hour + ":" + min + ":" + sec);
return (String.format("%02d", hour) + ":" + String.format("%02d", min) + ":" + String.format("%02d", sec));
}
public void confirmMergeAccount(String token) throws IOException, InvalidApplicationException {

View File

@ -62,7 +62,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
nestedIndex = 0;
tenants: Observable<Array<string>>;
expandedPreferences: boolean = false;
organisationsSingleAutoCompleteConfiguration: SingleAutoCompleteConfiguration;
formGroup: UntypedFormGroup;
@ -96,11 +96,11 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
public getProviderIcons(userCredential: UserCredential, culture:string): string[] {
if (userCredential.data.externalProviderNames === undefined || userCredential.data.externalProviderNames?.length === 0) {
return [this.configurationService.authProviders.defaultAuthProvider.providerClass];
}
const providerNames: string[] = [];
for (let providerName of userCredential.data.externalProviderNames) {
const providerImage = this.configurationService.authProviders.findOrGetDefault(providerName.toString(), culture).providerClass;
@ -141,19 +141,19 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
this.currentUserId = this.authService.userId()?.toString();
this.user = this.userService.getSingle(
Guid.parse(this.currentUserId),
[
nameof<User>(x => x.id),
nameof<User>(x => x.name),
nameof<User>(x => x.additionalInfo.language),
nameof<User>(x => x.additionalInfo.timezone),
nameof<User>(x => x.additionalInfo.culture),
nameof<User>(x => x.additionalInfo.organization),
nameof<User>(x => x.additionalInfo.roleOrganization),
nameof<User>(x => x.createdAt),
nameof<User>(x => x.updatedAt),
nameof<User>(x => x.hash),
`${nameof<User>(x => x.credentials)}.${nameof<UserCredential>(x => x.data.email)}`,
`${nameof<User>(x => x.credentials)}.${nameof<UserCredential>(x => x.data.externalProviderNames)}`,
[
nameof<User>(x => x.id),
nameof<User>(x => x.name),
nameof<User>(x => x.additionalInfo.language),
nameof<User>(x => x.additionalInfo.timezone),
nameof<User>(x => x.additionalInfo.culture),
nameof<User>(x => x.additionalInfo.organization),
nameof<User>(x => x.additionalInfo.roleOrganization),
nameof<User>(x => x.createdAt),
nameof<User>(x => x.updatedAt),
nameof<User>(x => x.hash),
`${nameof<User>(x => x.credentials)}.${nameof<UserCredential>(x => x.data.email)}`,
`${nameof<User>(x => x.credentials)}.${nameof<UserCredential>(x => x.data.externalProviderNames)}`,
]
)
.pipe(map(result => {
@ -167,10 +167,10 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
// "email": "dmpadmin@dmp.com",
// "externalProviderNames": ["Google", "Facebook"]
// }
// };
// };
// result.credentials.push(fakecredentials);
// result.credentials[0].data.externalProviderNames = ['Google'];
this.userLanguage = result.additionalInfo.language;
this.firstEmail = result.credentials[0].data.email;
this.userCredentials = of(result.credentials);
@ -224,7 +224,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
if (culture == null
|| culture.displayName == null
|| culture.nativeName == null)
|| culture.nativeName == null)
return undefined;
return culture.displayName + '-' + culture.nativeName;
@ -323,7 +323,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
this.userService.removeCredentialAccount({ credentialId: userCredential.user.id }).subscribe(result => {
//TODO
},
error => console.error(error));
error => this.onCallbackError(error));
//TODO: refactor
// const unlinkAccountModel: UnlinkAccountRequestModel = {
@ -373,7 +373,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes
});
}
},
error => console.error(error)); //TODO how to handle this
error => this.onCallbackError(error)); //TODO how to handle this
//TODO refactor