mirror of https://github.com/Squidex/squidex.git
25 changed files with 341 additions and 141 deletions
@ -0,0 +1,58 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using GraphQL.Resolvers; |
|||
using GraphQL.Types; |
|||
using Squidex.Shared.Identity; |
|||
using Squidex.Shared.Users; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
|||
{ |
|||
internal sealed class UserGraphType : ObjectGraphType<IUser> |
|||
{ |
|||
public static readonly IGraphType Nullable = new UserGraphType(); |
|||
|
|||
public static readonly IGraphType NonNull = new NonNullGraphType(Nullable); |
|||
|
|||
public UserGraphType() |
|||
{ |
|||
Name = "User"; |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "id", |
|||
Resolver = Resolve(x => x.Id), |
|||
ResolvedType = AllTypes.NonNullString, |
|||
Description = "The id of the user." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "displayName", |
|||
Resolver = Resolve(x => x.Claims.DisplayName()), |
|||
ResolvedType = AllTypes.String, |
|||
Description = "The display name of the user." |
|||
}); |
|||
|
|||
AddField(new FieldType |
|||
{ |
|||
Name = "email", |
|||
Resolver = Resolve(x => x.Email), |
|||
ResolvedType = AllTypes.String, |
|||
Description = "The email of the user." |
|||
}); |
|||
|
|||
Description = "A user that created or modified a content or asset."; |
|||
} |
|||
|
|||
private static IFieldResolver Resolve<T>(Func<IUser, T> resolver) |
|||
{ |
|||
return Resolvers.Sync(resolver); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using System.Security.Claims; |
|||
using FakeItEasy; |
|||
using Squidex.Shared.Identity; |
|||
using Squidex.Shared.Users; |
|||
|
|||
namespace Squidex.Domain.Apps.Core.TestHelpers |
|||
{ |
|||
public static class UserMocks |
|||
{ |
|||
public static IUser User(string id, string? email = null, string? name = null, bool consent = false) |
|||
{ |
|||
var claims = new List<Claim>(); |
|||
|
|||
if (!string.IsNullOrWhiteSpace(name)) |
|||
{ |
|||
claims.Add(new Claim(SquidexClaimTypes.DisplayName, name)); |
|||
} |
|||
|
|||
if (consent) |
|||
{ |
|||
claims.Add(new Claim(SquidexClaimTypes.Consent, "True")); |
|||
} |
|||
|
|||
var user = A.Fake<IUser>(); |
|||
|
|||
A.CallTo(() => user.Id) |
|||
.Returns(id); |
|||
|
|||
A.CallTo(() => user.Email) |
|||
.Returns(email ?? id); |
|||
|
|||
A.CallTo(() => user.Claims) |
|||
.Returns(claims); |
|||
|
|||
return user; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue