private ContentDto CreateLinksAsync(IEnrichedContentEntity content, Resources resources, string schema) { var app = resources.App; var values = new { app, schema, id = Id }; AddSelfLink(resources.Url <ContentsController>(x => nameof(x.GetContent), values)); if (Version > 0) { var versioned = new { app, schema, values.id, version = Version - 1 }; AddGetLink("previous", resources.Url <ContentsController>(x => nameof(x.GetContentVersion), versioned)); } if (NewStatus != null) { if (resources.CanDeleteContentVersion(schema)) { AddDeleteLink("draft/delete", resources.Url <ContentsController>(x => nameof(x.DeleteVersion), values)); } } else if (Status == Status.Published) { if (resources.CanCreateContentVersion(schema)) { AddPostLink("draft/create", resources.Url <ContentsController>(x => nameof(x.CreateDraft), values)); } } if (content.NextStatuses != null && resources.CanChangeStatus(schema)) { foreach (var next in content.NextStatuses) { AddPutLink($"status/{next.Status}", resources.Url <ContentsController>(x => nameof(x.PutContentStatus), values), next.Color); } } if (content.ScheduleJob != null && resources.CanCancelContentStatus(schema)) { AddDeleteLink($"cancel", resources.Url <ContentsController>(x => nameof(x.DeleteContentStatus), values)); } if (!content.IsSingleton && resources.CanDeleteContent(schema)) { AddDeleteLink("delete", resources.Url <ContentsController>(x => nameof(x.DeleteContent), values)); } if (content.CanUpdate && resources.CanUpdateContent(schema)) { AddPatchLink("patch", resources.Url <ContentsController>(x => nameof(x.PatchContent), values)); } if (content.CanUpdate && resources.CanUpdateContent(schema)) { AddPutLink("update", resources.Url <ContentsController>(x => nameof(x.PutContent), values)); } return(this); }
public static ContentDto FromContent(IEnrichedContentEntity content, Resources resources) { var response = SimpleMapper.Map(content, new ContentDto()); if (resources.Context.ShouldFlatten()) { response.Data = content.Data.ToFlatten(); } else { response.Data = content.Data; } if (content.ReferenceFields != null) { response.ReferenceFields = content.ReferenceFields.Select(FieldDto.FromField).ToArray(); } if (content.ScheduleJob != null) { response.ScheduleJob = new ScheduleJobDto { Color = content.ScheduledStatusColor ! }; SimpleMapper.Map(content.ScheduleJob, response.ScheduleJob); } return(response.CreateLinksAsync(content, resources, content.SchemaId.Name)); }
public static ContentDto FromContent(Context context, IEnrichedContentEntity content, ApiController controller) { var response = SimpleMapper.Map(content, new ContentDto()); if (context.IsFlatten()) { response.Data = content.Data?.ToFlatten(); response.DataDraft = content.DataDraft?.ToFlatten(); } else { response.Data = content.Data; response.DataDraft = content.DataDraft; } if (content.ReferenceFields != null) { response.ReferenceFields = content.ReferenceFields.Select(FieldDto.FromField).ToArray(); } if (content.ScheduleJob != null) { response.ScheduleJob = SimpleMapper.Map(content.ScheduleJob, new ScheduleJobDto()); } return(response.CreateLinksAsync(content, controller, content.AppId.Name, content.SchemaId.Name)); }
public static object FlatResponse(IEnrichedContentEntity content) { return(new { id = content.Id, version = 1, created = content.Created, createdBy = content.CreatedBy.ToString(), createdByUser = new { id = content.CreatedBy.Identifier, email = $"{content.CreatedBy.Identifier}@email.com", displayName = $"name_{content.CreatedBy.Identifier}" }, lastModified = content.LastModified, lastModifiedBy = content.LastModifiedBy.ToString(), lastModifiedByUser = new { id = content.LastModifiedBy.Identifier, email = $"{content.LastModifiedBy}", displayName = content.LastModifiedBy.Identifier }, status = "DRAFT", statusColor = "red", newStatus = "PUBLISHED", newStatusColor = "blue", url = $"contents/my-schema/{content.Id}", flatData = FlatData(content) }); }
public GraphQLMutationTests() { content = TestContent.Create(contentId, TestSchemas.Ref1.Id, TestSchemas.Ref2.Id, null); A.CallTo(() => commandBus.PublishAsync(A <ICommand> .Ignored)) .Returns(commandContext); }
private async Task TestContentAsyc(IEnrichedContentEntity content, string expectedName) { var ctx = ContextWithPermissions(schemaId1, schemaId2); var searchFilter = SearchFilter.MustHaveSchemas(schemaId1.Id, schemaId2.Id); var ids = new List <Guid> { content.Id }; A.CallTo(() => contentIndex.SearchAsync("query~", ctx.App, A <SearchFilter> .That.IsEqualTo(searchFilter), ctx.Scope())) .Returns(ids); A.CallTo(() => contentQuery.QueryAsync(ctx, ids)) .Returns(ResultList.CreateFrom(1, content)); A.CallTo(() => urlGenerator.ContentUI(appId, schemaId1, content.Id)) .Returns("content-url"); var result = await sut.SearchAsync("query", ctx); result.Should().BeEquivalentTo( new SearchResults() .Add(expectedName, SearchResultType.Content, "content-url")); }
private ContentDto CreateLinksAsync(IEnrichedContentEntity content, ApiController controller, string app, string schema) { var values = new { app, name = schema, id = Id }; AddSelfLink(controller.Url <ContentsController>(x => nameof(x.GetContent), values)); if (Version > 0) { var versioned = new { app, name = schema, id = Id, version = Version - 1 }; AddGetLink("previous", controller.Url <ContentsController>(x => nameof(x.GetContentVersion), versioned)); } if (!content.IsSingleton) { if (NewStatus.HasValue) { if (controller.HasPermission(Permissions.AppContentsVersionDelete, app, schema)) { AddDeleteLink("draft/delete", controller.Url <ContentsController>(x => nameof(x.DeleteVersion), values)); } } else if (Status == Status.Published) { if (controller.HasPermission(Permissions.AppContentsVersionCreate, app, schema)) { AddPostLink("draft/create", controller.Url <ContentsController>(x => nameof(x.CreateDraft), values)); } } if (content.NextStatuses != null) { foreach (var next in content.NextStatuses) { AddPutLink($"status/{next.Status}", controller.Url <ContentsController>(x => nameof(x.PutContentStatus), values), next.Color); } } if (controller.HasPermission(Permissions.AppContentsDelete, app, schema)) { AddDeleteLink("delete", controller.Url <ContentsController>(x => nameof(x.DeleteContent), values)); } } if (content.CanUpdate) { if (controller.HasPermission(Permissions.AppContentsUpdate, app, schema)) { AddPutLink("update", controller.Url <ContentsController>(x => nameof(x.PutContent), values)); } if (controller.HasPermission(Permissions.AppContentsUpdatePartial, app, schema)) { AddPatchLink("patch", controller.Url <ContentsController>(x => nameof(x.PatchContent), values)); } } return(this); }
private ContentDto CreateLinksAsync(IEnrichedContentEntity content, ApiController controller, string app, string schema) { var values = new { app, name = schema, id = Id }; AddSelfLink(controller.Url <ContentsController>(x => nameof(x.GetContent), values)); if (Version > 0) { var versioned = new { app, name = schema, id = Id, version = Version - 1 }; AddGetLink("prev", controller.Url <ContentsController>(x => nameof(x.GetContentVersion), versioned)); } if (IsPending) { if (controller.HasPermission(Permissions.AppContentsDraftDiscard, app, schema)) { AddPutLink("draft/discard", controller.Url <ContentsController>(x => nameof(x.DiscardDraft), values)); } if (controller.HasPermission(Permissions.AppContentsDraftPublish, app, schema)) { AddPutLink("draft/publish", controller.Url <ContentsController>(x => nameof(x.PutContentStatus), values)); } } if (controller.HasPermission(Permissions.AppContentsUpdate, app, schema)) { if (content.CanUpdate) { AddPutLink("update", controller.Url <ContentsController>(x => nameof(x.PutContent), values)); } if (Status == Status.Published) { AddPutLink("draft/propose", controller.Url <ContentsController>(x => nameof(x.PutContent), values) + "?asDraft=true"); } AddPatchLink("patch", controller.Url <ContentsController>(x => nameof(x.PatchContent), values)); if (content.Nexts != null) { foreach (var next in content.Nexts) { AddPutLink($"status/{next.Status}", controller.Url <ContentsController>(x => nameof(x.PutContentStatus), values), next.Color); } } } if (controller.HasPermission(Permissions.AppContentsDelete, app, schema)) { AddDeleteLink("delete", controller.Url <ContentsController>(x => nameof(x.DeleteContent), values)); } return(this); }
private string FormatName(IEnrichedContentEntity content, string masterLanguage) { var sb = new StringBuilder(); IJsonValue?GetValue(NamedContentData?data, RootField field) { if (data != null && data.TryGetValue(field.Name, out var fieldValue) && fieldValue != null) { var isInvariant = field.Partitioning.Equals(Partitioning.Invariant); if (isInvariant && fieldValue.TryGetValue("iv", out var value)) { return(value); } if (!isInvariant && fieldValue.TryGetValue(masterLanguage, out value)) { return(value); } } return(null); } if (content.ReferenceFields != null) { foreach (var field in content.ReferenceFields) { var value = GetValue(content.ReferenceData, field) ?? GetValue(content.Data, field); var formatted = StringFormatter.Format(value, field); if (!string.IsNullOrWhiteSpace(formatted)) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(formatted); } } } if (sb.Length == 0) { return("Content"); } return(sb.ToString()); }
public static object Response(IEnrichedContentEntity content) { return(new { id = content.Id, version = 1, created = content.Created, createdBy = "subject:user1", lastModified = content.LastModified, lastModifiedBy = "subject:user2", status = "DRAFT", statusColor = "red", url = $"contents/my-schema/{content.Id}", data = Data(content) }); }
public static ContentDto FromContent(QueryContext context, IEnrichedContentEntity content, ApiController controller) { var response = SimpleMapper.Map(content, new ContentDto()); if (context?.Flatten == true) { response.Data = content.Data?.ToFlatten(); response.DataDraft = content.DataDraft?.ToFlatten(); } else { response.Data = content.Data; response.DataDraft = content.DataDraft; } if (content.ScheduleJob != null) { response.ScheduleJob = SimpleMapper.Map(content.ScheduleJob, new ScheduleJobDto()); } return(response.CreateLinksAsync(content, controller, content.AppId.Name, content.SchemaId.Name)); }