Skip to content

Commit d20cdd4

Browse files
committed
Merge branch 'v13/dev' of https://github.com/umbraco/Umbraco-CMS into v13/dev
2 parents a604b20 + e840a0c commit d20cdd4

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,17 @@ private void PerformGetReferencedDtos(List<UserDto> dtos)
372372

373373
List<int> userIds = dtos.Count == 1 ? new List<int> {dtos[0].Id} : dtos.Select(x => x.Id).ToList();
374374
Dictionary<int, UserDto>? xUsers = dtos.Count == 1 ? null : dtos.ToDictionary(x => x.Id, x => x);
375+
Sql<ISqlContext> sql;
375376

376377
// get users2groups
377378

378-
Sql<ISqlContext> sql = SqlContext.Sql()
379-
.Select<User2UserGroupDto>()
380-
.From<User2UserGroupDto>()
381-
.WhereIn<User2UserGroupDto>(x => x.UserId, userIds);
382-
383-
List<User2UserGroupDto>? user2Groups = Database.Fetch<User2UserGroupDto>(sql);
379+
var user2Groups = Database.FetchByGroups<User2UserGroupDto, int>(userIds, Constants.Sql.MaxParameterCount, ints =>
380+
{
381+
return SqlContext.Sql()
382+
.Select<User2UserGroupDto>()
383+
.From<User2UserGroupDto>()
384+
.WhereIn<User2UserGroupDto>(x => x.UserId, ints);
385+
}).ToList();
384386
var groupIds = user2Groups.Select(x => x.UserGroupId).ToList();
385387

386388
// get groups
@@ -422,12 +424,13 @@ private void PerformGetReferencedDtos(List<UserDto> dtos)
422424

423425
// get start nodes
424426

425-
sql = SqlContext.Sql()
426-
.Select<UserStartNodeDto>()
427-
.From<UserStartNodeDto>()
428-
.WhereIn<UserStartNodeDto>(x => x.UserId, userIds);
429-
430-
List<UserStartNodeDto>? startNodes = Database.Fetch<UserStartNodeDto>(sql);
427+
var startNodes = Database.FetchByGroups<UserStartNodeDto, int>(userIds, Constants.Sql.MaxParameterCount, ints =>
428+
{
429+
return SqlContext.Sql()
430+
.Select<UserStartNodeDto>()
431+
.From<UserStartNodeDto>()
432+
.WhereIn<UserStartNodeDto>(x => x.UserId, ints);
433+
}).ToList();
431434

432435
// get groups2languages
433436

src/Umbraco.Infrastructure/Security/IdentityMapDefinition.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void Map(IUser source, BackOfficeIdentityUser target)
129129
target.IsApproved = source.IsApproved;
130130
target.SecurityStamp = source.SecurityStamp;
131131
DateTime? lockedOutUntil = source.LastLockoutDate?.AddMinutes(_securitySettings.UserDefaultLockoutTimeInMinutes);
132-
target.LockoutEnd = source.IsLockedOut ? (lockedOutUntil ?? DateTime.MaxValue).ToUniversalTime() : null;
132+
target.LockoutEnd = source.IsLockedOut ? lockedOutUntil ?? DateTime.MaxValue : null;
133133
}
134134

135135
// Umbraco.Code.MapAll -Id -LockoutEnabled -PhoneNumber -PhoneNumberConfirmed -ConcurrencyStamp -NormalizedEmail -NormalizedUserName -Roles
@@ -146,17 +146,46 @@ private void Map(IMember source, MemberIdentityUser target)
146146
target.PasswordConfig = source.PasswordConfiguration;
147147
target.IsApproved = source.IsApproved;
148148
target.SecurityStamp = source.SecurityStamp;
149-
DateTime? lockedOutUntil = source.LastLockoutDate?.AddMinutes(_securitySettings.MemberDefaultLockoutTimeInMinutes);
150-
target.LockoutEnd = source.IsLockedOut ? (lockedOutUntil ?? DateTime.MaxValue).ToUniversalTime() : null;
149+
target.LockoutEnd = GetLockoutEnd(source);
150+
target.LastLockoutDateUtc = GetLastLockoutDateUtc(source);
151151
target.Comments = source.Comments;
152-
target.LastLockoutDateUtc = source.LastLockoutDate == DateTime.MinValue
153-
? null
154-
: source.LastLockoutDate?.ToUniversalTime();
155-
target.CreatedDateUtc = source.CreateDate.ToUniversalTime();
152+
target.CreatedDateUtc = EnsureUtcWithServerTime(source.CreateDate);
156153
target.Key = source.Key;
157154
target.MemberTypeAlias = source.ContentTypeAlias;
158155
target.TwoFactorEnabled = _twoFactorLoginService.IsTwoFactorEnabledAsync(source.Key).GetAwaiter().GetResult();
159156

160157
// NB: same comments re AutoMapper as per BackOfficeUser
161158
}
159+
160+
private DateTimeOffset? GetLockoutEnd(IMember source)
161+
{
162+
if (source.IsLockedOut is false)
163+
{
164+
return null;
165+
}
166+
167+
DateTime? lockedOutUntil = source.LastLockoutDate?.AddMinutes(_securitySettings.MemberDefaultLockoutTimeInMinutes);
168+
if (lockedOutUntil.HasValue is false)
169+
{
170+
return DateTime.MaxValue;
171+
}
172+
173+
return EnsureUtcWithServerTime(lockedOutUntil.Value);
174+
}
175+
176+
private static DateTime? GetLastLockoutDateUtc(IMember source)
177+
{
178+
if (source.LastLockoutDate is null || source.LastLockoutDate == DateTime.MinValue)
179+
{
180+
return null;
181+
}
182+
183+
return EnsureUtcWithServerTime(source.LastLockoutDate.Value);
184+
}
185+
186+
private static DateTime EnsureUtcWithServerTime(DateTime date) =>
187+
188+
// We have a server time value here, but the the Kind is UTC, so we can't use .ToUniversalTime() to convert to the UTC
189+
// value that the LockoutEnd property expects. We need to create a DateTimeOffset with the correct offset.
190+
DateTime.SpecifyKind(date, DateTimeKind.Local).ToUniversalTime();
162191
}

0 commit comments

Comments
 (0)