Skip to content

Commit

Permalink
PII permission and frontend fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Sep 19, 2024
1 parent 25e6c6c commit c0ff1e1
Show file tree
Hide file tree
Showing 21 changed files with 340 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Cache;
using Squidex.Domain.Apps.Entities.Contents.Queries;
using Squidex.Infrastructure;
using Squidex.Shared;
using Squidex.Shared.Users;

namespace Squidex.Domain.Apps.Entities.Contents.GraphQL;
Expand All @@ -28,6 +29,8 @@ public sealed class GraphQLExecutionContext : QueryExecutionContext

public override Context Context { get; }

public bool CanExposePII { get; }

public GraphQLExecutionContext(
IDataLoaderContextAccessor dataLoaders,
IAssetQueryService assetQuery,
Expand Down Expand Up @@ -58,6 +61,8 @@ public GraphQLExecutionContext(
{
batchSize = Math.Max(MinBatchSize, Math.Min(MaxBatchSize, batchSize));
}

CanExposePII = Context.UserPermissions.Allows(PermissionIds.ForApp(PermissionIds.AppPii, context.App.Name));
}

public async ValueTask<IUser?> FindUserAsync(RefToken refToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public UserGraphType()
AddField(new FieldType
{
Name = "displayName",
Resolver = Resolve(x => x.Claims.DisplayName()),
Resolver = ResolveOrHide(x => x.Claims.DisplayName()),
ResolvedType = Scalars.String,
Description = FieldDescriptions.UserDisplayName
});

AddField(new FieldType
{
Name = "email",
Resolver = Resolve(x => x.Email),
Resolver = ResolveOrHide(x => x.Email),
ResolvedType = Scalars.String,
Description = FieldDescriptions.UserEmail
});
Expand All @@ -55,4 +55,17 @@ private static IFieldResolver Resolve<T>(Func<IUser, T> resolver)
{
return Resolvers.Sync(resolver);
}

private static IFieldResolver ResolveOrHide(Func<IUser, string?> resolver)
{
return Resolvers.Sync<IUser, string?>((source, _, context) =>
{
if (context.CanExposePII)
{
return resolver(source);
}
return "Hidden";
});
}
}
3 changes: 3 additions & 0 deletions backend/src/Squidex.Shared/PermissionIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public static class PermissionIds
// App Usage
public const string AppUsage = "squidex.apps.{app}.usage";

// App Expose Users
public const string AppPii = "squidex.apps.{app}.pii";

// App Comments
public const string AppComments = "squidex.apps.{app}.comments";
public const string AppCommentsRead = "squidex.apps.{app}.comments.read";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/Squidex/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"hideDateTimeModeButton": false,

// Show the exposed values as information on the apps overview page.
"showInfo": false,
"showInfo": true,

// The number of content items for dropdown selector.
"referencesDropdownItemCount": 100
Expand Down
2 changes: 1 addition & 1 deletion backend/src/Squidex/wwwroot/editor/squidex-editor.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c0ff1e1

Please sign in to comment.