Skip to content

Commit b4e7123

Browse files
Merge pull request #263 from TechnologyEnhancedLearning/Develop/Fixes/Revert_User_profile_Migration_changes
Reverted User profile migration changes
2 parents cbafad3 + e3d268a commit b4e7123

File tree

5 files changed

+30
-106
lines changed

5 files changed

+30
-106
lines changed
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace LearningHub.Nhs.UserApi.Repository.Interface.LH
22
{
33
using System.Threading.Tasks;
4-
using elfhHub.Nhs.Models.Common;
5-
using elfhHub.Nhs.Models.Dto;
64
using LearningHub.Nhs.Models.Entities;
75

86
/// <summary>
@@ -20,38 +18,5 @@ public interface IUserRepository : IGenericLHRepository<User>
2018
/// The <see cref="Task"/>.
2119
/// </returns>
2220
Task<User> GetByIdAsync(int id);
23-
24-
/// <summary>
25-
/// The get user id by username async.
26-
/// </summary>
27-
/// <param name="username">
28-
/// The username.
29-
/// </param>
30-
/// <returns>
31-
/// The <see cref="Task"/>.
32-
/// </returns>
33-
Task<int> GetUserIdByUsernameAsync(string username);
34-
35-
/// <summary>
36-
/// The get by open athens id.
37-
/// </summary>
38-
/// <param name="openAthensId">
39-
/// The open athens id.
40-
/// </param>
41-
/// <returns>
42-
/// The <see cref="Task"/>.
43-
/// </returns>
44-
Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId);
45-
46-
/// <summary>
47-
/// The get user detail for the authentication.
48-
/// </summary>
49-
/// <param name = "username">
50-
/// username.
51-
/// </param>
52-
/// <returns>
53-
/// The <see cref="Task"/>.
54-
/// </returns>
55-
Task<UserAuthenticateDto> GetUserDetailForAuthentication(string username);
5621
}
5722
}

LearningHub.Nhs.UserApi.Repository/LH/LearningHubDbContext.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace LearningHub.Nhs.UserApi.Repository.LH
22
{
3-
using elfhHub.Nhs.Models.Dto;
43
using LearningHub.Nhs.Models.Entities;
54
using LearningHub.Nhs.Models.Entities.External;
65
using LearningHub.Nhs.Models.Entities.Messaging;
@@ -51,11 +50,6 @@ public LearningHubDbContext(LearningHubDbContextOptions options)
5150
/// </summary>
5251
public virtual DbSet<EmailTemplate> EmailTemplate { get; set; }
5352

54-
/// <summary>
55-
/// Gets or sets the UserAuthentiate Dto.
56-
/// </summary>
57-
public virtual DbSet<UserAuthenticateDto> UserAuthenticateDto { get; set; }
58-
5953
/// <summary>
6054
/// The on model creating.
6155
/// </summary>
Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
namespace LearningHub.Nhs.UserApi.Repository.LH
22
{
3-
using System.Data;
4-
using System.Linq;
53
using System.Threading.Tasks;
6-
using elfhHub.Nhs.Models.Common;
7-
using elfhHub.Nhs.Models.Dto;
84
using LearningHub.Nhs.Models.Entities;
95
using LearningHub.Nhs.UserApi.Repository;
106
using LearningHub.Nhs.UserApi.Repository.Interface.LH;
11-
using Microsoft.Data.SqlClient;
127
using Microsoft.EntityFrameworkCore;
138

149
/// <summary>
@@ -31,40 +26,5 @@ public async Task<User> GetByIdAsync(int id)
3126
{
3227
return await this.DbContext.User.FirstOrDefaultWithNoLockAsync(n => n.Id == id);
3328
}
34-
35-
/// <inheritdoc/>
36-
public async Task<int> GetUserIdByUsernameAsync(string username)
37-
{
38-
return await this.DbContext.User.AsNoTracking().Where(n => n.UserName == username).Select(n => n.Id).FirstOrDefaultWithNoLockAsync();
39-
}
40-
41-
/// <inheritdoc/>
42-
public async Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId)
43-
{
44-
var param = new SqlParameter("@OpenAthensId", openAthensId);
45-
46-
return await this.DbContext.Set<UserBasic>()
47-
.FromSqlRaw("EXEC elfh.proc_GetUserByOpenAthensId @OpenAthensId", param)
48-
.AsNoTracking()
49-
.FirstOrDefaultAsync();
50-
}
51-
52-
/// <summary>
53-
/// The get user detail for the authentication.
54-
/// </summary>
55-
/// <param name = "username">
56-
/// username.
57-
/// </param>
58-
/// <returns>
59-
/// The <see cref="Task"/>.
60-
/// </returns>
61-
public async Task<UserAuthenticateDto> GetUserDetailForAuthentication(string username)
62-
{
63-
var param0 = new SqlParameter("@userName", SqlDbType.VarChar) { Value = username };
64-
65-
var userAuthenticateDto = await this.DbContext.UserAuthenticateDto.FromSqlRaw("elfh.proc_UserDetailForAuthenticationByUserName @userName", param0).AsNoTracking().ToListAsync();
66-
67-
return userAuthenticateDto.FirstOrDefault();
68-
}
6929
}
7030
}

LearningHub.Nhs.UserApi.Services/ElfhUserService.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,14 @@ public async Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId)
158158
return null;
159159
}
160160

161-
var user = await this.lhUserRepository.GetByOpenAthensIdAsync(openAthensId);
161+
var user = await this.elfhUserRepository.GetByOpenAthensIdAsync(openAthensId);
162162

163-
// if (user != null)
164-
// {
165-
// await this.SyncLHUserAsync(user.Id, user.UserName);
166-
// }
167-
return user;
163+
if (user != null)
164+
{
165+
await this.SyncLHUserAsync(user.Id, user.UserName);
166+
}
167+
168+
return user?.ToBasicUser();
168169
}
169170

170171
/// <inheritdoc/>
@@ -180,13 +181,13 @@ public async Task<User> GetByUsernameAsync(string userName, UserIncludeCollectio
180181
/// <returns>The <see cref="Task"/>.</returns>
181182
public async Task<int> GetUserIdByUsernameAsync(string userName)
182183
{
183-
return await this.lhUserRepository.GetUserIdByUsernameAsync(userName);
184+
return await this.elfhUserRepository.GetUserIdByUsernameAsync(userName);
184185
}
185186

186187
/// <inheritdoc/>
187188
public async Task<UserAuthenticateDto> GetUserDetailForAuthenticateAsync(string userName)
188189
{
189-
return await this.lhUserRepository.GetUserDetailForAuthentication(userName);
190+
return await this.elfhUserRepository.GetUserDetailForAuthentication(userName);
190191
}
191192

192193
/// <inheritdoc/>
@@ -228,14 +229,14 @@ public async Task<string> GetUserRoleAsync(int id)
228229
/// <inheritdoc/>
229230
public async Task RecordSuccessfulSigninAsync(int id, CancellationToken token = default)
230231
{
231-
var user = await this.lhUserRepository.GetByIdAsync(id);
232+
var user = await this.elfhUserRepository.GetByIdAsync(id);
232233

233234
if (user.PasswordLifeCounter != 0 || user.SecurityLifeCounter != 0)
234235
{
235236
user.PasswordLifeCounter = 0;
236237
user.SecurityLifeCounter = 0;
237238

238-
await this.lhUserRepository.UpdateAsync(id, user);
239+
await this.elfhUserRepository.UpdateAsync(id, user);
239240

240241
await this.InvalidateElfhUserCacheAsync(user.Id, user.UserName, token);
241242
}
@@ -244,11 +245,11 @@ public async Task RecordSuccessfulSigninAsync(int id, CancellationToken token =
244245
/// <inheritdoc/>
245246
public async Task RecordUnsuccessfulSigninAsync(int id, CancellationToken token = default)
246247
{
247-
var user = await this.lhUserRepository.GetByIdAsync(id);
248+
var user = await this.elfhUserRepository.GetByIdAsync(id);
248249

249250
user.PasswordLifeCounter++;
250251

251-
await this.lhUserRepository.UpdateAsync(id, user);
252+
await this.elfhUserRepository.UpdateAsync(id, user);
252253

253254
await this.InvalidateElfhUserCacheAsync(user.Id, user.UserName, token);
254255
}
@@ -958,14 +959,14 @@ public async Task<bool> ValidateUserRoleUpgrade(string currentPrimaryEmail, stri
958959
/// <inheritdoc/>
959960
public async Task<bool> CheckSamePrimaryemailIsPendingToValidate(string secondaryEmail, int currentUserId)
960961
{
961-
var userRoleUpgrades = this.userRoleUpgradeRepository.GetByEmailAddressAsync(secondaryEmail, currentUserId);
962+
var userRoleUpgrades = this.userRoleUpgradeRepository.GetByEmailAddressAsync(secondaryEmail, currentUserId);
962963

963-
if (userRoleUpgrades.Count() > 0)
964-
{
964+
if (userRoleUpgrades.Count() > 0)
965+
{
965966
return true;
966-
}
967+
}
967968

968-
return false;
969+
return false;
969970
}
970971

971972
/// <summary>
@@ -977,6 +978,8 @@ public async Task<bool> CheckSamePrimaryemailIsPendingToValidate(string secondar
977978
public async Task UpdateMyAccountPersonalDetails(PersonalDetailsViewModel personalDetailsViewModel, int currentUserId)
978979
{
979980
User user = await this.elfhUserRepository.GetByIdAsync(personalDetailsViewModel.UserId);
981+
user.FirstName = personalDetailsViewModel.FirstName;
982+
user.LastName = personalDetailsViewModel.LastName;
980983
user.PreferredName = personalDetailsViewModel.PreferredName;
981984
user.AltEmailAddress = personalDetailsViewModel.SecondaryEmailAddress;
982985

LearningHub.Nhs.UserApi/Controllers/AuthenticationController.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ public async Task<IActionResult> AuthenticateElfhHubAsync([FromBody] Login login
5353
{
5454
var loginResult = await this.authenticationService.AuthenticateAsync(login);
5555

56-
// if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
57-
// {
58-
// await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
59-
// }
56+
if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
57+
{
58+
await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
59+
}
60+
6061
return this.Ok(loginResult);
6162
}
6263

@@ -80,10 +81,11 @@ public async Task<IActionResult> AuthenticateSsoAsync([FromBody] LoginSso reques
8081

8182
var loginResult = await this.authenticationService.CheckUserCredentialsSsoAsync(request.UserId);
8283

83-
// if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
84-
// {
85-
// await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
86-
// }
84+
if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
85+
{
86+
await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
87+
}
88+
8789
return this.Ok(loginResult);
8890
}
8991

0 commit comments

Comments
 (0)