Skip to content

Commit

Permalink
Configure MongoDB and GraphQL and add client validation on save (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
glucaci committed Jun 3, 2022
1 parent 19e0bef commit 9e94d39
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "6.0.200"
"version": "6.0.300"
}
}
9 changes: 7 additions & 2 deletions src/Server/src/GraphQL/GraphQLServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using HotChocolate.Execution.Configuration;
using HotChocolate.Types;
using IdOps.Authorization;
Expand All @@ -12,13 +13,17 @@ namespace IdOps.GraphQL
{
public static class GrapQLServiceCollectionExtensions
{
public static IIdOpsServerBuilder AddGraphQLServer(this IIdOpsServerBuilder builder)
public static IIdOpsServerBuilder AddGraphQLServer(
this IIdOpsServerBuilder builder,
Action<IRequestExecutorBuilder>? configureRequestExecutorBuilder = default)
{
builder
IRequestExecutorBuilder requestExecutorBuilder = builder
.Services
.AddGraphQLServer()
.AddGraphQLTypes();

configureRequestExecutorBuilder?.Invoke(requestExecutorBuilder);

builder
.Services
.AddHttpResultSerializer<ForbiddenHttpResultSerializer>();
Expand Down
11 changes: 10 additions & 1 deletion src/Server/src/Store.Mongo/IdOpsDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
using System;
using IdOps.Model;
using IdOps.Server.Storage.Mongo.Configuration;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
using MongoDB.Extensions.Context;
using Environment = IdOps.Model.Environment;

namespace IdOps.Server.Storage.Mongo
{
public class IdOpsDbContext : MongoDbContext, IIdOpsDbContext
{
public IdOpsDbContext(MongoOptions mongoOptions)
private readonly Action<IMongoDatabaseBuilder>? _configureMongoDatabaseBuilder;

public IdOpsDbContext(
MongoOptions mongoOptions,
Action<IMongoDatabaseBuilder>? configureMongoDatabaseBuilder)
: base(mongoOptions)
{
_configureMongoDatabaseBuilder = configureMongoDatabaseBuilder;
}

protected override void OnConfiguring(IMongoDatabaseBuilder builder)
Expand Down Expand Up @@ -41,6 +48,8 @@ protected override void OnConfiguring(IMongoDatabaseBuilder builder)
.ConfigureCollection(new UserClaimRuleCollectionConfiguration())
.ConfigureCollection(new PersonalAccessTokenCollectionConfiguration())
.ConfigureCollection(new ApiResourceCollectionConfiguration());

_configureMongoDatabaseBuilder?.Invoke(builder);
}

public IMongoCollection<ApiResource> ApiResources
Expand Down
9 changes: 6 additions & 3 deletions src/Server/src/Store.Mongo/StoreServerCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using IdOps.Model;
using IdOps.Server.Storage;
using IdOps.Server.Storage.Mongo;
Expand All @@ -10,12 +11,15 @@ namespace IdOps
public static class StoreServerCollectionExtensions
{
public static IIdOpsServerBuilder AddMongoStore(
this IIdOpsServerBuilder builder)
this IIdOpsServerBuilder builder,
Action<IMongoDatabaseBuilder>? configureMongoDatabaseBuilder = default)
{
MongoOptions options = builder.Configuration.GetSection("Storage:Database")
.Get<MongoOptions>();

builder.Services.AddSingleton<IIdOpsDbContext>(new IdOpsDbContext(options));
builder.Services.AddSingleton<IIdOpsDbContext>(
new IdOpsDbContext(options, configureMongoDatabaseBuilder));

builder.Services.AddStores();

return builder;
Expand Down Expand Up @@ -43,7 +47,6 @@ private static IServiceCollection AddStores(this IServiceCollection services)
services.AddResourceStore<IResourceStore<UserClaimRule>, IUserClaimRuleStore, UserClaimRulesStore>();
services.AddResourceStore<IResourceStore<PersonalAccessToken>, IPersonalAccessTokenStore, PersonalAccessTokenStore>();


return services;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Server/test/GraphQL.Tests/RepositoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected virtual IdOpsDbContext CreateDbContext()
{
ConnectionString = MongoResource.ConnectionString,
DatabaseName = db.DatabaseNamespace.DatabaseName
});
}, default);
}
}
}
19 changes: 17 additions & 2 deletions src/UI/src/components/ResourceAuthor/EditClientView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,15 @@
dense
label="Name"
v-model="prop.key"
:rules="[(v) => !!v || 'Required']"
></v-text-field
></v-col>
<v-col md="7"
><v-text-field
dense
label="Value"
v-model="prop.value"
:rules="[(v) => !!v || 'Required']"
></v-text-field
></v-col>
<v-col md="1">
Expand All @@ -452,20 +454,23 @@
dense
label="Type"
v-model="claim.type"
:rules="[(v) => !!v || 'Required']"
></v-text-field
></v-col>
<v-col md="4"
><v-text-field
dense
label="Value"
v-model="claim.value"
:rules="[(v) => !!v || 'Required']"
></v-text-field
></v-col>
<v-col md="3"
><v-text-field
dense
label="ValueType"
v-model="claim.valueType"
:rules="[(v) => !!v || 'Required']"
></v-text-field
></v-col>
<v-col md="1">
Expand Down Expand Up @@ -713,7 +718,7 @@ export default {
});
},
onRemoveProperty: function (index) {
this.properties.splice(index, 1);
this.client.properties.splice(index, 1);
},
onAddNewClaim: function () {
Expand All @@ -727,7 +732,17 @@ export default {
this.client.claims.splice(index, 1);
},
async onSave(event) {
this.$refs.form.validate();
if(!this.$refs.form.validate())
{
this.$store.dispatch(
"shell/addMessage",
{ text: "Input validation failed.", type: "ERROR" },
{ root: true }
);
event.done(true);
return;
}
const update = Object.assign({}, this.client);
delete update.allowedScopes;
Expand Down

0 comments on commit 9e94d39

Please sign in to comment.