public async Task <IActionResult> GetSwagger(string app) { var schemas = await appProvider.GetSchemasAsync(AppId); var swaggerDocument = await schemasSwaggerGenerator.Generate(App, schemas); return(Content(swaggerDocument.ToJson(), "application/json")); }
public async Task <IActionResult> GetSchemas(string app) { var schemas = await appProvider.GetSchemasAsync(AppId); var response = schemas.Select(s => s.ToModel()).ToList(); return(Ok(response)); }
public GraphQLTestBase() { schemaDef = new Schema("my-schema") .AddJson(1, "my-json", Partitioning.Invariant, new JsonFieldProperties()) .AddString(2, "my-string", Partitioning.Language, new StringFieldProperties()) .AddNumber(3, "my-number", Partitioning.Invariant, new NumberFieldProperties()) .AddNumber(4, "my_number", Partitioning.Invariant, new NumberFieldProperties()) .AddAssets(5, "my-assets", Partitioning.Invariant, new AssetsFieldProperties()) .AddBoolean(6, "my-boolean", Partitioning.Invariant, new BooleanFieldProperties()) .AddDateTime(7, "my-datetime", Partitioning.Invariant, new DateTimeFieldProperties()) .AddReferences(8, "my-references", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = schemaId }) .AddReferences(9, "my-invalid", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }) .AddGeolocation(10, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties()) .AddTags(11, "my-tags", Partitioning.Invariant, new TagsFieldProperties()) .AddString(12, "my-localized", Partitioning.Language, new StringFieldProperties()) .AddArray(13, "my-array", Partitioning.Invariant, f => f .AddBoolean(121, "nested-boolean") .AddNumber(122, "nested-number") .AddNumber(123, "nested_number")) .ConfigureScripts(new SchemaScripts { Query = "<query-script>" }) .Publish(); A.CallTo(() => app.Id).Returns(appId); A.CallTo(() => app.Name).Returns(appName); A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.DE, Language.GermanGermany)); context = QueryContext.Create(app, user); A.CallTo(() => schema.Id).Returns(schemaId); A.CallTo(() => schema.SchemaDef).Returns(schemaDef); var allSchemas = new List <ISchemaEntity> { schema }; A.CallTo(() => appProvider.GetSchemasAsync(appId)).Returns(allSchemas); sut = new CachingGraphQLService(cache, appProvider, assetQuery, contentQuery, new FakeUrlGenerator()); }
public async Task <IActionResult> GetSchemas(string app) { var schemas = await appProvider.GetSchemasAsync(AppId); var response = schemas.Select(SchemaDto.FromSchema).ToList(); Response.Headers["ETag"] = response.ToManyEtag(); return(Ok(response)); }
public async Task <IActionResult> GetSchemas(string app) { var schemas = await appProvider.GetSchemasAsync(AppId); var response = SchemasDto.FromSchemas(schemas, this, app); Response.Headers[HeaderNames.ETag] = response.ToEtag(); return(Ok(response)); }
private async Task <List <string> > GetSchemaNamesAsync(IAppEntity app) { var schemas = await appProvider.GetSchemasAsync(app.Id); var schemaNames = new List <string>();; schemaNames.Add(Permission.Any); schemaNames.AddRange(schemas.Select(x => x.Name)); return(schemaNames); }
public async Task Should_return_result_to_schema_only_if_user_has_no_permission() { var ctx = ContextWithPermission(); var schema1 = CreateSchema("schemaA1", false); A.CallTo(() => appProvider.GetSchemasAsync(appId.Id)) .Returns(new List <ISchemaEntity> { schema1 }); A.CallTo(() => urlGenerator.SchemaUI(appId, schema1.NamedId())) .Returns("schemaA1-url"); var result = await sut.SearchAsync("schema", ctx); result.Should().BeEquivalentTo( new SearchResults() .Add("schemaA1 Schema", SearchResultType.Schema, "schemaA1-url")); }
public ContentsSearchSourceTests() { A.CallTo(() => appProvider.GetSchemasAsync(appId.Id)) .Returns(new List <ISchemaEntity> { Mocks.Schema(appId, schemaId1), Mocks.Schema(appId, schemaId2), Mocks.Schema(appId, schemaId3) }); sut = new ContentsSearchSource(appProvider, contentQuery, contentIndex, urlGenerator); }
private Task <GraphQLModel> GetModelAsync(IAppEntity app) { var cacheKey = CreateCacheKey(app.Id, app.Version.ToString()); return(Cache.GetOrCreateAsync(cacheKey, async entry => { entry.AbsoluteExpirationRelativeToNow = CacheDuration; var allSchemas = await appProvider.GetSchemasAsync(app.Id); return new GraphQLModel(app, allSchemas, urlGenerator); })); }
public async Task <IActionResult> GetSchemas(string app) { var schemas = await appProvider.GetSchemasAsync(AppId); var response = Deferred.Response(() => { return(SchemasDto.FromSchemas(schemas, Resources)); }); Response.Headers[HeaderNames.ETag] = schemas.ToEtag(); return(Ok(response)); }
public GraphQLTestBase() { schemaDef = new Schema("my-schema") .AddJson(1, "my-json", Partitioning.Invariant, new JsonFieldProperties()) .AddString(2, "my-string", Partitioning.Language, new StringFieldProperties()) .AddNumber(3, "my-number", Partitioning.Invariant, new NumberFieldProperties()) .AddAssets(4, "my-assets", Partitioning.Invariant, new AssetsFieldProperties()) .AddBoolean(5, "my-boolean", Partitioning.Invariant, new BooleanFieldProperties()) .AddDateTime(6, "my-datetime", Partitioning.Invariant, new DateTimeFieldProperties()) .AddReferences(7, "my-references", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = schemaId }) .AddReferences(9, "my-invalid", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = Guid.NewGuid() }) .AddGeolocation(10, "my-geolocation", Partitioning.Invariant, new GeolocationFieldProperties()) .AddTags(11, "my-tags", Partitioning.Invariant, new TagsFieldProperties()); A.CallTo(() => app.Id).Returns(appId); A.CallTo(() => app.Name).Returns(appName); A.CallTo(() => app.LanguagesConfig).Returns(LanguagesConfig.Build(Language.DE)); context = QueryContext.Create(app, user); A.CallTo(() => schema.Id).Returns(schemaId); A.CallTo(() => schema.Name).Returns(schemaDef.Name); A.CallTo(() => schema.SchemaDef).Returns(schemaDef); A.CallTo(() => schema.IsPublished).Returns(true); A.CallTo(() => schema.ScriptQuery).Returns("<script-query>"); var allSchemas = new List <ISchemaEntity> { schema }; A.CallTo(() => appProvider.GetSchemasAsync(appId)).Returns(allSchemas); sut = new CachingGraphQLService(cache, appProvider, assetRepository, commandBus, contentQuery, new FakeUrlGenerator()); }
public async Task Should_provide_all_permissions() { A.CallTo(() => appProvider.GetSchemasAsync(A <DomainId> ._)) .Returns(new List <ISchemaEntity> { Mocks.Schema(appId, NamedId.Of(DomainId.NewGuid(), "schema1")), Mocks.Schema(appId, NamedId.Of(DomainId.NewGuid(), "schema2")) }); var result = await sut.GetPermissionsAsync(app); Assert.True(result.Contains("*")); Assert.True(result.Contains("clients.read")); Assert.True(result.Contains("schemas.*.update")); Assert.True(result.Contains("schemas.schema1.update")); Assert.True(result.Contains("schemas.schema2.update")); }
private async Task <GraphQLModel> GetModelAsync(IAppEntity app) { var cacheKey = CreateCacheKey(app.Id, app.Version.ToString()); var modelContext = Cache.Get <GraphQLModel>(cacheKey); if (modelContext == null) { var allSchemas = await appProvider.GetSchemasAsync(app.Id); modelContext = new GraphQLModel(app, allSchemas.Where(x => x.IsPublished), urlGenerator); Cache.Set(cacheKey, modelContext, CacheDuration); } return(modelContext); }
public async Task Should_provide_all_permissions() { A.CallTo(() => appProvider.GetSchemasAsync(A <Guid> .Ignored)) .Returns(new List <ISchemaEntity> { CreateSchema("schema1"), CreateSchema("schema2") }); var result = await sut.GetPermissionsAsync(app); Assert.True(result.Contains("*")); Assert.True(result.Contains("clients.read")); Assert.True(result.Contains("schemas.*.read")); Assert.True(result.Contains("schemas.schema1.read")); Assert.True(result.Contains("schemas.schema2.read")); }
private async Task <SearchFilter?> CreateSearchFilterAsync(Context context) { var allowedSchemas = new List <Guid>(); var schemas = await appProvider.GetSchemasAsync(context.App.Id); foreach (var schema in schemas) { if (HasPermission(context, schema.SchemaDef.Name)) { allowedSchemas.Add(schema.Id); } } if (allowedSchemas.Count == 0) { return(null); } return(SearchFilter.MustHaveSchemas(allowedSchemas.ToArray())); }
public ContentQueryServiceTests() { ct = cts.Token; var schemaDef = new Schema(schemaId.Name) .Publish() .SetScripts(new SchemaScripts { Query = "<query-script>" }); schema = Mocks.Schema(appId, schemaId, schemaDef); SetupEnricher(); A.CallTo(() => appProvider.GetSchemaAsync(appId.Id, schemaId.Name, A <bool> ._, ct)) .Returns(schema); A.CallTo(() => appProvider.GetSchemasAsync(appId.Id, ct)) .Returns(new List <ISchemaEntity> { schema }); A.CallTo(() => queryParser.ParseAsync(A <Context> ._, A <Q> ._, A <ISchemaEntity?> ._)) .ReturnsLazily(c => Task.FromResult(c.GetArgument <Q>(1) !)); var options = Options.Create(new ContentOptions()); sut = new ContentQueryService( appProvider, contentEnricher, contentRepository, contentVersionLoader, options, queryParser); }
private async Task <List <ISchemaEntity> > GetSchemasAsync(Context context) { var schemas = await appProvider.GetSchemasAsync(context.App.Id); return(schemas.Where(x => HasPermission(context, x, Permissions.AppContentsReadOwn)).ToList()); }