private FluidValue ContentUrl(FluidValue input, FilterArguments arguments, TemplateContext context) { var value = input.ToObjectValue(); switch (value) { case DomainId id: { if (context.GetValue("event")?.ToObjectValue() is EnrichedContentEvent contentEvent) { var result = urlGenerator.ContentUI(contentEvent.AppId, contentEvent.SchemaId, id); return(new StringValue(result)); } break; } case EnrichedContentEvent contentEvent: { var result = urlGenerator.ContentUI(contentEvent.AppId, contentEvent.SchemaId, contentEvent.Id); return(new StringValue(result)); } } return(NilValue.Empty); }
public async Task Should_return_result_to_schema_and_contents_if_schema_is_singleton() { var permission = Permissions.ForApp(Permissions.AppContentsRead, appId.Name, "schemaA1"); var ctx = ContextWithPermission(permission.Id); var schema1 = CreateSchema("schemaA1", true); A.CallTo(() => appProvider.GetSchemasAsync(appId.Id)) .Returns(new List <ISchemaEntity> { schema1 }); A.CallTo(() => urlGenerator.SchemaUI(appId, schema1.NamedId())) .Returns("schemaA1-url"); A.CallTo(() => urlGenerator.ContentUI(appId, schema1.NamedId(), schema1.Id)) .Returns("schemaA1-content-url"); var result = await sut.SearchAsync("schemaA", ctx); result.Should().BeEquivalentTo( new SearchResults() .Add("schemaA1 Schema", SearchResultType.Schema, "schemaA1-url") .Add("schemaA1 Content", SearchResultType.Content, "schemaA1-content-url", "schemaA1")); }
public async Task <SearchResults> SearchAsync(string query, Context context) { var result = new SearchResults(); var searchFilter = await CreateSearchFilterAsync(context); if (searchFilter == null) { return(result); } var ids = await contentTextIndexer.SearchAsync($"{query}~", context.App, searchFilter, context.Scope()); if (ids == null || ids.Count == 0) { return(result); } var appId = context.App.NamedId(); var contents = await contentQuery.QueryAsync(context, ids); foreach (var content in contents) { var url = urlGenerator.ContentUI(appId, content.SchemaId, content.Id); var name = FormatName(content, context.App.LanguagesConfig.Master); result.Add(name, SearchResultType.Content, url, content.SchemaDisplayName); } return(result); }
public RuleEventFormatterTests() { A.CallTo(() => urlGenerator.ContentUI(appId, schemaId, contentId)) .Returns("content-url"); A.CallTo(() => urlGenerator.AssetContent(assetId)) .Returns("asset-content-url"); A.CallTo(() => user.Id) .Returns("user123"); A.CallTo(() => user.Email) .Returns("*****@*****.**"); A.CallTo(() => user.Claims) .Returns(new List <Claim> { new Claim(SquidexClaimTypes.DisplayName, "me") }); var extensions = new IScriptExtension[] { new DateTimeScriptExtension(), new EventScriptExtension(urlGenerator), new StringScriptExtension() }; var cache = new MemoryCache(Options.Create(new MemoryCacheOptions())); sut = new RuleEventFormatter(TestUtils.DefaultSerializer, urlGenerator, new JintScriptEngine(cache, extensions)); }
private async Task TestContentAsyc(ContentEntity content, string expectedName) { content.AppId = appId; var ctx = ContextWithPermissions(schemaId1, schemaId2); var ids = new List <DomainId> { content.Id }; A.CallTo(() => contentIndex.SearchAsync(ctx.App, A <TextQuery> .That.Matches(x => x.Text == "query~" && x.Filter != null), ctx.Scope())) .Returns(ids); A.CallTo(() => contentQuery.QueryAsync(ctx, A <Q> .That.HasIds(ids), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom <IEnrichedContentEntity>(1, content)); A.CallTo(() => urlGenerator.ContentUI(appId, schemaId1, content.Id)) .Returns("content-url"); var result = await sut.SearchAsync("query", ctx, default); result.Should().BeEquivalentTo( new SearchResults() .Add(expectedName, SearchResultType.Content, "content-url")); }
public void Extend(ExecutionContext context, bool async) { context.Engine.SetValue("contentAction", new EventDelegate(() => { if (context.TryGetValue("event", out var temp) && temp is EnrichedContentEvent contentEvent) { return(contentEvent.Status.ToString()); } return(JsValue.Null); })); context.Engine.SetValue("contentUrl", new EventDelegate(() => { if (context.TryGetValue("event", out var temp) && temp is EnrichedContentEvent contentEvent) { return(urlGenerator.ContentUI(contentEvent.AppId, contentEvent.SchemaId, contentEvent.Id)); } return(JsValue.Null); })); context.Engine.SetValue("assetContentUrl", new EventDelegate(() => { if (context.TryGetValue("event", out var temp) && temp is EnrichedAssetEvent assetEvent) { return(urlGenerator.AssetContent(assetEvent.Id)); } return(JsValue.Null); })); }
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 void AddContentsUrl(SearchResults result, NamedId <DomainId> appId, ISchemaEntity schema, NamedId <DomainId> schemaId, string name) { if (schema.SchemaDef.Type == SchemaType.Singleton) { var contentUrl = urlGenerator.ContentUI(appId, schemaId, schemaId.Id); result.Add(T.Get("search.contentResult", new { name }), SearchResultType.Content, contentUrl, name); } else { var contentUrl = urlGenerator.ContentsUI(appId, schemaId); result.Add(T.Get("search.contentsResult", new { name }), SearchResultType.Content, contentUrl, name); } }
private void AddContentsUrl(SearchResults result, NamedId <Guid> appId, ISchemaEntity schema, NamedId <Guid> schemaId, string name) { if (schema.SchemaDef.IsSingleton) { var contentUrl = urlGenerator.ContentUI(appId, schemaId, schemaId.Id); result.Add($"{name} Content", SearchResultType.Content, contentUrl, name); } else { var contentUrl = urlGenerator.ContentsUI(appId, schemaId); result.Add($"{name} Contents", SearchResultType.Content, contentUrl, name); } }
private FluidValue ContentUrl(FluidValue input, FilterArguments arguments, TemplateContext context) { if (input is ObjectValue objectValue) { if (context.GetValue("event")?.ToObjectValue() is EnrichedContentEvent contentEvent) { if (objectValue.ToObjectValue() is DomainId id && id != DomainId.Empty) { var result = urlGenerator.ContentUI(contentEvent.AppId, contentEvent.SchemaId, id); return(new StringValue(result)); } } } return(NilValue.Empty); }
public RuleEventFormatterTests() { A.CallTo(() => user.Id) .Returns("123"); A.CallTo(() => user.Email) .Returns("*****@*****.**"); A.CallTo(() => user.Claims) .Returns(new List <Claim> { new Claim(SquidexClaimTypes.DisplayName, "me") }); A.CallTo(() => urlGenerator.ContentUI(appId, schemaId, contentId)) .Returns("content-url"); sut = new RuleEventFormatter(TestUtils.DefaultSerializer, urlGenerator, new JintScriptEngine()); }
public async Task HandleHistoryEventAsync(Envelope <AppEvent> @event, HistoryEvent historyEvent) { if (client == null) { return; } if (IsTooOld(@event.Headers)) { return; } var appEvent = @event.Payload; var publishRequest = new PublishRequest { AppId = options.AppId }; foreach (var(key, value) in historyEvent.Parameters) { publishRequest.Properties.Add(key, value); } publishRequest.Properties["SquidexApp"] = appEvent.AppId.Name; if (appEvent is ContentEvent c && !(appEvent is ContentDeleted)) { var url = urlGenerator.ContentUI(c.AppId, c.SchemaId, c.ContentId); publishRequest.Properties["SquidexUrl"] = url; } publishRequest.TemplateCode = historyEvent.EventType; SetUser(appEvent, publishRequest); SetTopic(appEvent, publishRequest, historyEvent); await client.PublishAsync(publishRequest); }
public async Task <SearchResults> SearchAsync(string query, Context context, CancellationToken ct) { var result = new SearchResults(); var schemaIds = await GetSchemaIdsAsync(context, ct); if (schemaIds.Count == 0) { return(result); } var textQuery = new TextQuery($"{query}~", 10) { RequiredSchemaIds = schemaIds }; var ids = await contentTextIndexer.SearchAsync(context.App, textQuery, context.Scope(), ct); if (ids == null || ids.Count == 0) { return(result); } var appId = context.App.NamedId(); var contents = await contentQuery.QueryAsync(context, Q.Empty.WithIds(ids), ct); foreach (var content in contents) { var url = urlGenerator.ContentUI(appId, content.SchemaId, content.Id); var name = FormatName(content, context.App.Languages.Master); result.Add(name, SearchResultType.Content, url, content.SchemaDisplayName); } return(result); }