-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Aguafrommars/feature/requestable
Feature/requestable
- Loading branch information
Showing
16 changed files
with
287 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Aguacongas.Identity.RavenDb; | ||
using Microsoft.AspNetCore.Identity; | ||
using System; | ||
using System.Reflection; | ||
|
||
namespace Raven.Client.Documents | ||
{ | ||
public static class DocumentStoreExtension | ||
{ | ||
public static IDocumentStore SetFindIdentityPropertyForIdentityModel(this IDocumentStore store) | ||
{ | ||
var findId = store.Conventions.FindIdentityProperty; | ||
store.Conventions.FindIdentityProperty = memberInfo => SetConventions(memberInfo, findId); | ||
return store; | ||
} | ||
|
||
private static bool SetConventions(MemberInfo memberInfo, Func<MemberInfo, bool> findId) | ||
{ | ||
if (memberInfo.DeclaringType == typeof(UserData)) | ||
{ | ||
return false; | ||
} | ||
if (memberInfo.DeclaringType == typeof(RoleData)) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityUser<>))) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityUserClaim<>))) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityUserRole<>))) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityUserLogin<>))) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityUserToken<>))) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityRole<>))) | ||
{ | ||
return false; | ||
} | ||
if (IsSubclassOf(memberInfo.DeclaringType, typeof(IdentityRoleClaim<>))) | ||
{ | ||
return false; | ||
} | ||
|
||
return findId(memberInfo); | ||
} | ||
|
||
private static bool IsSubclassOf(Type type, Type baseType) | ||
{ | ||
if (type == null || baseType == null || type == baseType) | ||
{ | ||
return false; | ||
} | ||
|
||
if (!baseType.IsGenericType) | ||
{ | ||
if (!type.IsGenericType) | ||
{ | ||
return type.IsSubclassOf(baseType); | ||
} | ||
} | ||
else | ||
{ | ||
baseType = baseType.GetGenericTypeDefinition(); | ||
} | ||
|
||
var objectType = typeof(object); | ||
while (type != objectType && type != null) | ||
{ | ||
var curentType = type.IsGenericType ? type.GetGenericTypeDefinition() : type; | ||
if (curentType == baseType) | ||
{ | ||
return true; | ||
} | ||
|
||
type = type.BaseType; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
// Project: Aguafrommars/Identity.RavenDb | ||
// Copyright (c) 2021 Olivier Lefebvre | ||
using Microsoft.AspNetCore.Identity; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Aguacongas.Identity.RavenDb | ||
{ | ||
[SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "All are needed")] | ||
public class RoleData<TKey, TRole, TRoleClaims> | ||
where TKey: IEquatable<TKey> | ||
where TRole : IdentityRole<TKey> | ||
where TRoleClaims: IdentityRoleClaim<TKey> | ||
public class RoleData | ||
{ | ||
public string Id { get; set; } | ||
|
||
public virtual TRole Role { get; set; } | ||
public string RoleId { get; set; } | ||
|
||
public virtual List<TRoleClaims> Claims { get; private set; } = new List<TRoleClaims>(); | ||
public List<string> ClaimIds { get; private set; } = new List<string>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
// Project: Aguafrommars/Identity.RavenDb | ||
// Copyright (c) 2021 Olivier Lefebvre | ||
using Microsoft.AspNetCore.Identity; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Aguacongas.Identity.RavenDb | ||
{ | ||
[SuppressMessage("Major Code Smell", "S2436:Types and methods should not have too many generic parameters", Justification = "All are needed")] | ||
public class UserData<TKey, TUser, TUserClaim, TUserLogin> | ||
where TKey: IEquatable<TKey> | ||
where TUser: IdentityUser<TKey> | ||
where TUserClaim : IdentityUserClaim<TKey> | ||
where TUserLogin : IdentityUserLogin<TKey> | ||
public class UserData | ||
{ | ||
public string Id { get; set; } | ||
|
||
public virtual TUser User { get; set; } | ||
public string UserId { get; set; } | ||
|
||
public virtual List<TUserClaim> Claims { get; private set; } = new List<TUserClaim>(); | ||
public List<string> ClaimIds { get; private set; } = new List<string>(); | ||
|
||
public virtual List<TUserLogin> Logins { get; private set; } = new List<TUserLogin>(); | ||
public List<string> LoginIds { get; private set; } = new List<string>(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.