Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/src/Authorization/OpenIdConnectAuthorization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ CancellationToken cancellationToken
: [GraphQl.OpenIdConnect.Applications.OpenIdConnectConsentType.EXPLICIT];
}

internal async Task<IReadOnlyList<GraphQl.OpenIdConnect.Applications.OpenIdConnectEndpoint>> AuthorizedEndpoints(
internal static async Task<IReadOnlyList<GraphQl.OpenIdConnect.Applications.OpenIdConnectEndpoint>> AuthorizedEndpoints(
ClaimsPrincipal claimsPrincipal,
CancellationToken cancellationToken
)
Expand All @@ -167,7 +167,7 @@ CancellationToken cancellationToken
.AsReadOnly();
}

internal async Task<IReadOnlyList<GraphQl.OpenIdConnect.Applications.OpenIdConnectResponseType>> AuthorizedResponseTypes(
internal static async Task<IReadOnlyList<GraphQl.OpenIdConnect.Applications.OpenIdConnectResponseType>> AuthorizedResponseTypes(
ClaimsPrincipal claimsPrincipal,
CancellationToken cancellationToken
)
Expand Down
6 changes: 4 additions & 2 deletions backend/src/Configuration/AuthConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static void BootstrapCertificates(IClock clock)
distinguishedName,
validOnly: true
);
if (certificates.Count == 0)
if (certificates.Count is 0)
{
store.Add(
JwtSigningAndEncryptionCertificateRotationJob.CreateSigningCertificate(
Expand All @@ -73,7 +73,7 @@ private static void BootstrapCertificates(IClock clock)
distinguishedName,
validOnly: true
);
if (certificates.Count == 0)
if (certificates.Count is 0)
{
store.Add(
JwtSigningAndEncryptionCertificateRotationJob.CreateEncryptionCertificate(
Expand Down Expand Up @@ -483,6 +483,8 @@ AppSettings appSettings
// Register the OpenIddict validation components.
.AddValidation(_ =>
{
// The validation handler uses OpenID Connect discovery to
// retrieve the issuer signing keys used to validate tokens.
_.SetIssuer(appSettings.Uri);
// Configure the audience accepted by this resource server.
_.AddAudiences(OpenIdConnectConstants.Client.MetabaseClientId);
Expand Down
5 changes: 4 additions & 1 deletion backend/src/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ private void UpdateTimestamps()
switch (entry.State)
{
case EntityState.Added:
entry.Entity.CreatedAt = now;
if (entry.Entity.CreatedAt == default)
{
entry.Entity.CreatedAt = now;
}
entry.Entity.UpdatedAt = now;
break;
case EntityState.Modified:
Expand Down
22 changes: 22 additions & 0 deletions backend/src/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Text;

namespace Metabase.Extensions;

public static class StringExtensions
Expand All @@ -16,4 +19,23 @@ public static string FirstCharToLower(this string value)

public static string? NullIfWhitespace(this string value)
=> string.IsNullOrWhiteSpace(value) ? null : value;

public static string Base64Encode(this string plainText)
{
return Convert.ToBase64String(
Encoding.UTF8.GetBytes(plainText)
);
}

public static string Base64Decode(this string base64EncodedData)
{
return Encoding.UTF8.GetString(
Convert.FromBase64String(base64EncodedData)
);
}

public static string Enquote(this string str)
{
return "\"" + str + "\"";
}
}
1 change: 1 addition & 0 deletions backend/src/GraphQl/Associations/AssociationType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HotChocolate.Types;
using Metabase.Data;
using Metabase.GraphQl.Scalars;

namespace Metabase.GraphQl.Associations;

Expand Down
5 changes: 1 addition & 4 deletions backend/src/GraphQl/DataX/Data.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -70,9 +69,7 @@ CancellationToken cancellationToken
}

[ID]
public string Id => Convert.ToBase64String(
Encoding.UTF8.GetBytes($"{DatabaseId}:{Uuid}:{Locale ?? ""}:{DataId}")
);
public string Id => $"{DatabaseId}:{Uuid}:{Locale ?? ""}:{DataId}".Base64Encode();

public abstract DataKind Kind { get; }

Expand Down
1 change: 1 addition & 0 deletions backend/src/GraphQl/Entities/AuditableEntityFilterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ IFilterInputTypeDescriptor<TEntity> descriptor
descriptor.Field(x => x.Id);
descriptor.Field(x => x.CreatedAt);
descriptor.Field(x => x.UpdatedAt);
// TODO Do we want to filter by: descriptor.Field(x => x.Version);
}
}
1 change: 1 addition & 0 deletions backend/src/GraphQl/Entities/EntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using GreenDonut;
using HotChocolate.Types;
using Metabase.Data;
using Metabase.GraphQl.Scalars;

namespace Metabase.GraphQl.Entities;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GreenDonut.Data;
using HotChocolate;
using HotChocolate.Data.Filters;
using HotChocolate.Data.Sorting;
using HotChocolate.Resolvers;
Expand Down
1 change: 1 addition & 0 deletions backend/src/GraphQl/Filters/ScalarFilterInputTypes.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HotChocolate.Data.Filters;
using HotChocolate.Types;
using Metabase.GraphQl.Scalars;
using DateTimeType = HotChocolate.Types.NodaTime.DateTimeType;
using DurationType = HotChocolate.Types.NodaTime.DurationType;
using LocalDateTimeType = HotChocolate.Types.NodaTime.LocalDateTimeType;
Expand Down
1 change: 0 additions & 1 deletion backend/src/GraphQl/Methods/MethodQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using GreenDonut.Data;
using HotChocolate.Data;
using HotChocolate.Data.Sorting;
using HotChocolate.Resolvers;
using HotChocolate.Types;
using Metabase.Data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Metabase.Data.OpenIdConnect;
using Metabase.GraphQl.Users;
using Metabase.GraphQl.Entities;
using Metabase.GraphQl.Scalars;

namespace Metabase.GraphQl.OpenIdConnect.Applications;

Expand Down Expand Up @@ -228,7 +229,7 @@ IObjectTypeDescriptor<OpenIdConnectApplication> descriptor
}
var uris = JsonSerializer.Deserialize<List<string>>(urisJson)
?? throw new GraphQLException($"Could not deserialize `{urisJson}` into a list of strings.");
if (uris.Count == 0)
if (uris.Count is 0)
{
return null;
}
Expand Down
14 changes: 3 additions & 11 deletions backend/src/GraphQl/PaginationHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
using System;
using System.Text;
using Metabase.Extensions;

namespace Metabase.GraphQl;

public static class PaginationHelpers
{
public static string ConstructCursor(Guid id)
{
return Convert.ToBase64String(
Encoding.UTF8.GetBytes(
id.ToString("D")
)
);
return id.ToString("D").Base64Encode();
}

public static string ConstructCursor(Guid id1, Guid id2)
{
return Convert.ToBase64String(
Encoding.UTF8.GetBytes(
$"{id1:D}:{id2:D}"
)
);
return $"{id1:D}:{id2:D}".Base64Encode();
}
}
11 changes: 2 additions & 9 deletions backend/src/GraphQl/Requests/DataQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Text;
using System.Collections.Immutable;
using System.Linq;
using HotChocolate.Types.Pagination;
Expand Down Expand Up @@ -221,11 +220,7 @@ private sealed record CompoundCursor

private static string SerializeCompoundCursor(CompoundCursor cursor)
{
return Convert.ToBase64String(
Encoding.UTF8.GetBytes(
JsonSerializer.Serialize(cursor, JsonSerializerSettings.Compact)
)
);
return JsonSerializer.Serialize(cursor, JsonSerializerSettings.Compact).Base64Encode();
}

private static CompoundCursor? DeserializeCompoundCursor(string? cursors)
Expand All @@ -235,9 +230,7 @@ private static string SerializeCompoundCursor(CompoundCursor cursor)
return null;
}
return JsonSerializer.Deserialize<CompoundCursor>(
Encoding.UTF8.GetString(
Convert.FromBase64String(cursors)
),
cursors.Base64Decode(),
JsonSerializerSettings.Compact
);
}
Expand Down
4 changes: 2 additions & 2 deletions backend/src/GraphQl/Scalars/MyUriType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
using HotChocolate.Features;
using HotChocolate.Language;
using HotChocolate.Text.Json;
using Metabase.GraphQl;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Types;
namespace Metabase.GraphQl.Scalars;

// Inspired by https://github.com/ChilliCream/graphql-platform/blob/main/src/HotChocolate/Core/src/Types/Types/Scalars/UriType.cs
/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion backend/src/GraphQl/Scalars/NonNegativeIntType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Text.Json;
using HotChocolate.Language;
using HotChocolate.Text.Json;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;

namespace HotChocolate.Types;
namespace Metabase.GraphQl.Scalars;

/// <summary>
/// <para>
Expand Down
2 changes: 1 addition & 1 deletion backend/src/GraphQl/Users/UserMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ await userManager.VerifyTwoFactorTokenAsync(
};
}

if (await userManager.CountRecoveryCodesAsync(user) == 0)
if (await userManager.CountRecoveryCodesAsync(user) is 0)
{
var recoveryCodes =
await userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
Expand Down
7 changes: 3 additions & 4 deletions backend/src/GraphQl/Users/UserType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ await Authorize(context, user => user.WebsiteLocator, Scopes.Profile)
.Field("authorizedOpenIdConnectResponseTypes")
.Cost(1)
.ResolveWith<UserResolvers>(x =>
UserResolvers.GetAuthorizedOpenIdConnectResponseTypesAsync(default!, default!, default!))
UserResolvers.GetAuthorizedOpenIdConnectResponseTypesAsync(default!, default!))
.UseUserManager();
descriptor
.Field("authorizedOpenIdConnectScopes")
Expand Down Expand Up @@ -418,7 +418,7 @@ public static Task<IReadOnlyList<OpenIdConnectEndpoint>> GetAuthorizedOpenIdConn
CancellationToken cancellationToken
)
{
return authorization.AuthorizedEndpoints(claimsPrincipal, cancellationToken);
return Authorization.OpenIdConnectAuthorization.AuthorizedEndpoints(claimsPrincipal, cancellationToken);
}

public static Task<IReadOnlyList<OpenIdConnectGrantType>> GetAuthorizedOpenIdConnectGrantTypesAsync(
Expand All @@ -432,11 +432,10 @@ CancellationToken cancellationToken

public static Task<IReadOnlyList<OpenIdConnectResponseType>> GetAuthorizedOpenIdConnectResponseTypesAsync(
ClaimsPrincipal claimsPrincipal,
Authorization.OpenIdConnectAuthorization authorization,
CancellationToken cancellationToken
)
{
return authorization.AuthorizedResponseTypes(claimsPrincipal, cancellationToken);
return Authorization.OpenIdConnectAuthorization.AuthorizedResponseTypes(claimsPrincipal, cancellationToken);
}

public static Task<IReadOnlyList<GraphQl.OpenIdConnect.OpenIdConnectScope>> GetAuthorizedOpenIdConnectScopesAsync(
Expand Down
18 changes: 14 additions & 4 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["dom", "es2017"],
"lib": [
"dom",
"es2017"
],
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
Expand All @@ -20,6 +23,13 @@
"incremental": true
// "verbatimModuleSyntax": true
},
"include": ["next-env.d.ts", ".next/types/**/*.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"include": [
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}