Skip to content

Commit

Permalink
Reverted consolidation of UserInfo and UserBase (#3563)
Browse files Browse the repository at this point in the history
* Reverted consolidation of userinfo and user base

* removed redundant comment

* some small polish

* correct schema nullability
  • Loading branch information
JR-Morgan authored Jul 8, 2024
1 parent 2c6087c commit 84bdb4f
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class Client
/// <returns></returns>
/// <seealso cref="ActiveUserResource.Get"/>
[Obsolete($"Use client.{nameof(ActiveUser)}.{nameof(ActiveUserResource.Get)}")]
public async Task<UserInfo> ActiveUserGet(CancellationToken cancellationToken = default)
public async Task<User> ActiveUserGet(CancellationToken cancellationToken = default)
{
return await ActiveUser.Get(cancellationToken).ConfigureAwait(false);
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Api/GraphQL/Models/Responses/Responses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Speckle.Core.Api.GraphQL.Models.Responses;

internal record ProjectResponse([property: JsonRequired] Project project);

internal record ActiveUserResponse(UserInfo? activeUser);
internal record ActiveUserResponse(User? activeUser);

internal record LimitedUserResponse(LimitedUser? otherUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public override string ToString()
}
}

/// <remarks>
/// Named "User" in GraphQL Schema
/// </remarks>
public sealed class UserInfo : UserBase
public sealed class User : UserBase
{
public DateTime? createdAt { get; init; }
public string email { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Api/GraphQL/Resources/ActiveUserResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal ActiveUserResource(ISpeckleGraphQLClient client)
/// <returns></returns>
/// <returns>the requested user, or null if the user does not exist (i.e. <see cref="Client"/> was initialised with an unauthenticated account)</returns>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
public async Task<UserInfo?> Get(CancellationToken cancellationToken = default)
public async Task<User?> Get(CancellationToken cancellationToken = default)
{
//language=graphql
const string QUERY = """
Expand Down
27 changes: 17 additions & 10 deletions Core/Core/Credentials/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,29 @@ public static async Task<UserInfo> GetUserInfo(
new NewtonsoftJsonSerializer(),
httpClient
);

//language=graphql
var request = new GraphQLRequest { Query = " query { activeUser { name email id company } }" };

var response = await gqlClient.SendQueryAsync<ActiveUserResponse>(request, cancellationToken).ConfigureAwait(false);
const string QUERY = """
query {
data:activeUser {
name
email
id
company
}
}
""";
var request = new GraphQLRequest { Query = QUERY };

var response = await gqlClient
.SendQueryAsync<RequiredResponse<UserInfo>>(request, cancellationToken)
.ConfigureAwait(false);

if (response.Errors != null)
{
throw new SpeckleGraphQLException<ActiveUserResponse>(
$"GraphQL request {nameof(GetUserInfo)} failed",
request,
response
);
throw new SpeckleGraphQLException($"GraphQL request {nameof(GetUserInfo)} failed", request, response);
}

return response.Data.activeUser;
return response.Data.data;
}

/// <summary>
Expand Down
42 changes: 35 additions & 7 deletions Core/Core/Credentials/Responses.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
#nullable disable
using System;
using Speckle.Core.Api;
using Speckle.Core.Api.GraphQL.Models;

namespace Speckle.Core.Credentials;

public class ActiveUserServerInfoResponse
internal sealed class ActiveUserServerInfoResponse
{
public UserInfo activeUser { get; set; }
public ServerInfo serverInfo { get; set; }
public UserInfo activeUser { get; init; }
public ServerInfo serverInfo { get; init; }
}

public class TokenExchangeResponse
internal sealed class TokenExchangeResponse
{
public string token { get; set; }
public string refreshToken { get; set; }
public string token { get; init; }
public string refreshToken { get; init; }
}

public sealed class UserInfo
{
public string id { get; init; }
public string name { get; init; }
public string email { get; init; }
public string? company { get; init; }
public string? avatar { get; init; }

[Obsolete(DeprecationMessages.FE2_DEPRECATION_MESSAGE)]
public Streams streams { get; init; }

[Obsolete(DeprecationMessages.FE2_DEPRECATION_MESSAGE)]
public Commits commits { get; init; }
}

[Obsolete(DeprecationMessages.FE2_DEPRECATION_MESSAGE)]
public class Streams
{
public int totalCount { get; set; }
}

[Obsolete(DeprecationMessages.FE2_DEPRECATION_MESSAGE)]
public class Commits
{
public int totalCount { get; set; }
}
3 changes: 1 addition & 2 deletions Core/Tests/Speckle.Core.Tests.Integration/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ await tokenResponse.Content.ReadAsStringAsync()
},
serverInfo = Server
};
using var client = new Client(acc);

var user1 = await client.ActiveUserGet();
var user1 = await AccountManager.GetUserInfo(acc.token, acc.serverInfo.url);
acc.userInfo = user1;
return acc;
}
Expand Down

0 comments on commit 84bdb4f

Please sign in to comment.