예제 #1
0
        public async Task Should_return_assets_results_if_found()
        {
            var permission = Permissions.ForApp(Permissions.AppAssetsRead, appId.Name);

            var ctx = ContextWithPermission(permission.Id);

            var asset1 = CreateAsset("logo1.png");
            var asset2 = CreateAsset("logo2.png");

            A.CallTo(() => urlGenerator.AssetsUI(appId, asset1.Id.ToString()))
            .Returns("assets-url1");

            A.CallTo(() => urlGenerator.AssetsUI(appId, asset2.Id.ToString()))
            .Returns("assets-url2");

            A.CallTo(() => assetQuery.QueryAsync(ctx, null, A <Q> .That.HasQuery("Filter: contains(fileName, 'logo'); Take: 5"), A <CancellationToken> ._))
            .Returns(ResultList.CreateFrom(2, asset1, asset2));

            var result = await sut.SearchAsync("logo", ctx, default);

            result.Should().BeEquivalentTo(
                new SearchResults()
                .Add("logo1.png", SearchResultType.Asset, "assets-url1")
                .Add("logo2.png", SearchResultType.Asset, "assets-url2"));
        }
예제 #2
0
        public async Task <SearchResults> SearchAsync(string query, Context context)
        {
            var result = new SearchResults();

            var permission = Permissions.ForApp(Permissions.AppAssetsRead, context.App.Name);

            if (context.Permissions.Allows(permission))
            {
                var filter = ClrFilter.Contains("fileName", query);

                var clrQuery = new ClrQuery {
                    Filter = filter, Take = 5
                };

                var assets = await assetQuery.QueryAsync(context, null, Q.Empty.WithQuery(clrQuery));

                if (assets.Count > 0)
                {
                    var url = urlGenerator.AssetsUI(context.App.NamedId(), query);

                    foreach (var asset in assets)
                    {
                        result.Add(asset.FileName, SearchResultType.Asset, url);
                    }
                }
            }

            return(result);
        }
예제 #3
0
        public Task <SearchResults> SearchAsync(string query, Context context)
        {
            var result = new SearchResults();

            var appId = context.App.NamedId();

            void Search(string term, string permissionId, Func <NamedId <DomainId>, string> generate, SearchResultType type)
            {
                if (result.Count < MaxItems && term.Contains(query, StringComparison.OrdinalIgnoreCase))
                {
                    var permission = Permissions.ForApp(permissionId, appId.Name);

                    if (context.Permissions.Allows(permission))
                    {
                        var url = generate(appId);

                        result.Add(term, type, url);
                    }
                }
            }

            Search("Assets", Permissions.AppAssetsRead,
                   a => urlGenerator.AssetsUI(a), SearchResultType.Asset);

            Search("Backups", Permissions.AppBackupsRead,
                   urlGenerator.BackupsUI, SearchResultType.Setting);

            Search("Clients", Permissions.AppClientsRead,
                   urlGenerator.ClientsUI, SearchResultType.Setting);

            Search("Contributors", Permissions.AppContributorsRead,
                   urlGenerator.ContributorsUI, SearchResultType.Setting);

            Search("Dashboard", Permissions.AppUsage,
                   urlGenerator.DashboardUI, SearchResultType.Dashboard);

            Search("Languages", Permissions.AppLanguagesRead,
                   urlGenerator.LanguagesUI, SearchResultType.Setting);

            Search("Patterns", Permissions.AppPatternsRead,
                   urlGenerator.PatternsUI, SearchResultType.Setting);

            Search("Roles", Permissions.AppRolesRead,
                   urlGenerator.RolesUI, SearchResultType.Setting);

            Search("Rules", Permissions.AppRulesRead,
                   urlGenerator.RulesUI, SearchResultType.Rule);

            Search("Schemas", Permissions.AppSchemasRead,
                   urlGenerator.SchemasUI, SearchResultType.Schema);

            Search("Subscription", Permissions.AppPlansRead,
                   urlGenerator.PlansUI, SearchResultType.Setting);

            Search("Workflows", Permissions.AppWorkflowsRead,
                   urlGenerator.WorkflowsUI, SearchResultType.Setting);

            return(Task.FromResult(result));
        }
        public async Task Should_return_assets_result_if_matching_and_permission_given()
        {
            var permission = Permissions.ForApp(Permissions.AppAssetsRead, appId.Name);

            var ctx = ContextWithPermission(permission.Id);

            A.CallTo(() => urlGenerator.AssetsUI(appId))
            .Returns("assets-url");

            var result = await sut.SearchAsync("assets", ctx);

            result.Should().BeEquivalentTo(
                new SearchResults()
                .Add("Assets", SearchResultType.Asset, "assets-url"));
        }