Skip to content

Commit cfcb708

Browse files
committed
Merge branch 'release/16.0' and enable package validation
2 parents 9a96ebf + 9812630 commit cfcb708

File tree

5 files changed

+515
-501
lines changed

5 files changed

+515
-501
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
<!-- Package Validation -->
4141
<PropertyGroup>
4242
<GenerateCompatibilitySuppressionFile>false</GenerateCompatibilitySuppressionFile>
43-
<EnablePackageValidation>false</EnablePackageValidation>
44-
<PackageValidationBaselineVersion>15.0.0</PackageValidationBaselineVersion>
43+
<EnablePackageValidation>true</EnablePackageValidation>
44+
<PackageValidationBaselineVersion>16.0.0</PackageValidationBaselineVersion>
4545
<EnableStrictModeForCompatibleFrameworksInPackage>true</EnableStrictModeForCompatibleFrameworksInPackage>
4646
<EnableStrictModeForCompatibleTfms>true</EnableStrictModeForCompatibleTfms>
4747
</PropertyGroup>

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,17 @@ public void DeleteUserLogins(Guid userOrMemberKey) =>
5757
Database.Delete<ExternalLoginDto>("WHERE userOrMemberKey=@userOrMemberKey", new { userOrMemberKey });
5858

5959
/// <inheritdoc />
60-
public void DeleteUserLoginsForRemovedProviders(IEnumerable<string> currentLoginProviders) =>
61-
Database.Execute(Sql()
62-
.Delete<ExternalLoginDto>()
63-
.WhereNotIn<ExternalLoginDto>(x => x.LoginProvider, currentLoginProviders));
60+
public void DeleteUserLoginsForRemovedProviders(IEnumerable<string> currentLoginProviders)
61+
{
62+
Sql<ISqlContext> sql = Sql()
63+
.Select<ExternalLoginDto>(x => x.Id)
64+
.From<ExternalLoginDto>()
65+
.Where<ExternalLoginDto>(x => !x.LoginProvider.StartsWith(Constants.Security.MemberExternalAuthenticationTypePrefix)) // Only remove external logins relating to backoffice users, not members.
66+
.WhereNotIn<ExternalLoginDto>(x => x.LoginProvider, currentLoginProviders);
67+
68+
var toDelete = Database.Query<ExternalLoginDto>(sql).Select(x => x.Id).ToList();
69+
DeleteExternalLogins(toDelete);
70+
}
6471

6572
/// <inheritdoc />
6673
public void Save(Guid userOrMemberKey, IEnumerable<IExternalLogin> logins)
@@ -100,13 +107,7 @@ public void Save(Guid userOrMemberKey, IEnumerable<IExternalLogin> logins)
100107
}
101108

102109
// do the deletes, updates and inserts
103-
if (toDelete.Count > 0)
104-
{
105-
// Before we can remove the external login, we must remove the external login tokens associated with that external login,
106-
// otherwise we'll get foreign key constraint errors
107-
Database.DeleteMany<ExternalLoginTokenDto>().Where(x => toDelete.Contains(x.ExternalLoginId)).Execute();
108-
Database.DeleteMany<ExternalLoginDto>().Where(x => toDelete.Contains(x.Id)).Execute();
109-
}
110+
DeleteExternalLogins(toDelete);
110111

111112
foreach (KeyValuePair<int, IExternalLogin> u in toUpdate)
112113
{
@@ -116,6 +117,19 @@ public void Save(Guid userOrMemberKey, IEnumerable<IExternalLogin> logins)
116117
Database.InsertBulk(toInsert.Select(i => ExternalLoginFactory.BuildDto(userOrMemberKey, i)));
117118
}
118119

120+
private void DeleteExternalLogins(List<int> externalLoginIds)
121+
{
122+
if (externalLoginIds.Count == 0)
123+
{
124+
return;
125+
}
126+
127+
// Before we can remove the external login, we must remove the external login tokens associated with that external login,
128+
// otherwise we'll get foreign key constraint errors
129+
Database.DeleteMany<ExternalLoginTokenDto>().Where(x => externalLoginIds.Contains(x.ExternalLoginId)).Execute();
130+
Database.DeleteMany<ExternalLoginDto>().Where(x => externalLoginIds.Contains(x.Id)).Execute();
131+
}
132+
119133
/// <inheritdoc />
120134
public void Save(Guid userOrMemberKey, IEnumerable<IExternalLoginToken> tokens)
121135
{

0 commit comments

Comments
 (0)