예제 #1
0
        public ContentEnricherTests()
        {
            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema = Mocks.Schema(appId, schemaId);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, schemaId.Id.ToString()))
            .Returns(schema);
        }
예제 #2
0
        public async Task <IActionResult> GetContents(string app, string name, [FromQuery] string?ids = null, [FromQuery] string?q = null)
        {
            var schema = await contentQuery.GetSchemaOrThrowAsync(Context, name);

            var contents = await contentQuery.QueryAsync(Context, name, CreateQuery(ids, q));

            var response = Deferred.AsyncResponse(() =>
            {
                return(ContentsDto.FromContentsAsync(contents, Resources, schema, contentWorkflow));
            });

            return(Ok(response));
        }
        public ContentEnricherAssetsTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId, Language.DE));

            var schemaDef =
                new Schema(schemaId.Name)
                .AddAssets(1, "asset1", Partitioning.Invariant, new AssetsFieldProperties
            {
                ResolveImage = true,
                MinItems     = 2,
                MaxItems     = 3
            })
                .AddAssets(2, "asset2", Partitioning.Language, new AssetsFieldProperties
            {
                ResolveImage = true,
                MinItems     = 1,
                MaxItems     = 1
            })
                .ConfigureFieldsInLists("asset1", "asset2");

            A.CallTo(() => assetUrlGenerator.GenerateUrl(A <string> .Ignored))
            .ReturnsLazily(new Func <string, string>(id => $"url/to/{id}"));

            void SetupSchema(NamedId <Guid> id, Schema def)
            {
                var schemaEntity = Mocks.Schema(appId, id, def);

                A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, id.Id.ToString()))
                .Returns(schemaEntity);
            }

            SetupSchema(schemaId, schemaDef);

            sut = new ContentEnricher(assetQuery, assetUrlGenerator, new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
예제 #4
0
        public ContentEnricherTests()
        {
            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema = Mocks.Schema(appId, schemaId);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(A <Context> .Ignored, schemaId.Id.ToString()))
            .Returns(schema);

            sut = new ContentEnricher(assetQuery, assetUrlGenerator, new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
예제 #5
0
        public async Task <IActionResult> GetContents(string app, string name, [FromQuery] string?ids = null, [FromQuery] string?q = null)
        {
            var schema = await contentQuery.GetSchemaOrThrowAsync(Context, name);

            var contents = await contentQuery.QueryAsync(Context, name,
                                                         Q.Empty
                                                         .WithIds(ids)
                                                         .WithJsonQuery(q)
                                                         .WithODataQuery(Request.QueryString.ToString()));

            var response = Deferred.AsyncResponse(async() =>
            {
                return(await ContentsDto.FromContentsAsync(contents, Context, this, schema, contentWorkflow));
            });

            return(Ok(response));
        }
        public EnrichWithWorkflowsTests()
        {
            requestContext = new Context(Mocks.ApiUser(), Mocks.App(appId));

            schema         = Mocks.Schema(appId, schemaId);
            schemaProvider = x => Task.FromResult(schema);

            A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(A <Context> .Ignored, schemaId.Id.ToString()))
            .Returns(schema);

            sut = new EnrichWithWorkflows(contentWorkflow);
        }
예제 #7
0
        public ContentEnricherReferencesTests()
        {
            requestContext = new Context(Mocks.FrontendUser(), Mocks.App(appId, Language.DE));

            var refSchemaDef =
                new Schema("my-ref")
                .AddString(1, "name", Partitioning.Invariant,
                           new StringFieldProperties {
                IsReferenceField = true
            })
                .AddNumber(2, "number", Partitioning.Invariant,
                           new NumberFieldProperties {
                IsReferenceField = true
            });

            var schemaDef =
                new Schema(schemaId.Name)
                .AddReferences(1, "ref1", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                IsListField      = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId1.Id
            })
                .AddReferences(2, "ref2", Partitioning.Invariant, new ReferencesFieldProperties
            {
                ResolveReference = true,
                IsListField      = true,
                MinItems         = 1,
                MaxItems         = 1,
                SchemaId         = refSchemaId2.Id
            });

            void SetupSchema(NamedId <Guid> id, Schema def)
            {
                var schemaEntity = Mocks.Schema(appId, id, def);

                A.CallTo(() => contentQuery.GetSchemaOrThrowAsync(requestContext, id.Id.ToString()))
                .Returns(schemaEntity);
            }

            SetupSchema(schemaId, schemaDef);
            SetupSchema(refSchemaId1, refSchemaDef);
            SetupSchema(refSchemaId2, refSchemaDef);

            sut = new ContentEnricher(new Lazy <IContentQueryService>(() => contentQuery), contentWorkflow);
        }
예제 #8
0
        private async Task EnrichAndCheckPermissionAsync <T>(BulkTask task, T command, string permissionId) where T : ContentCommand
        {
            SimpleMapper.Map(task.Command, command);
            SimpleMapper.Map(task.CommandJob, command);

            if (!string.IsNullOrWhiteSpace(task.CommandJob.Schema))
            {
                var schema = await contentQuery.GetSchemaOrThrowAsync(contextProvider.Context, task.Schema);

                command.SchemaId = schema.NamedId();
            }

            if (!contextProvider.Context.Allows(permissionId, command.SchemaId.Name))
            {
                throw new DomainForbiddenException("Forbidden");
            }

            command.ExpectedVersion = task.Command.ExpectedVersion;
        }
예제 #9
0
        public async Task <IActionResult> GetContents(string app, string name, [FromQuery] string ids = null)
        {
            var context  = Context();
            var contents = await contentQuery.QueryAsync(context, name, Q.Empty.WithIds(ids).WithODataQuery(Request.QueryString.ToString()));

            var schema = await contentQuery.GetSchemaOrThrowAsync(context, name);

            var response = await ContentsDto.FromContentsAsync(contents, context, this, schema, contentWorkflow);

            if (ShouldProvideSurrogateKeys(response))
            {
                Response.Headers["Surrogate-Key"] = response.ToSurrogateKeys();
            }

            Response.Headers[HeaderNames.ETag] = response.ToEtag();

            return(Ok(response));
        }
예제 #10
0
        private async Task EnrichAsync <TCommand>(DomainId id, BulkTask task, TCommand command, string permissionId) where TCommand : ContentCommand
        {
            SimpleMapper.Map(task.Command, command);

            command.ContentId = id;

            if (!string.IsNullOrWhiteSpace(task.Job.Schema))
            {
                var schema = await contentQuery.GetSchemaOrThrowAsync(task.Context, task.Schema);

                command.SchemaId = schema.NamedId();
            }

            if (!task.Context.Allows(permissionId, command.SchemaId.Name))
            {
                throw new DomainForbiddenException("Forbidden");
            }

            command.ExpectedVersion = task.Command.ExpectedVersion;
        }