From 50669cb70738d48907061f661088aa391476aef5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 8 Nov 2016 08:40:15 +0100 Subject: [PATCH] Minor bugfixes --- src/Squidex/Program.cs | 2 +- src/Squidex/Startup.cs | 15 +++++++++------ .../components/layout/profile-menu.component.ts | 2 +- .../shared/services/apps-store.service.spec.ts | 10 +++++----- .../app/shared/services/apps-store.service.ts | 16 ++++++++++------ src/Squidex/app/shared/services/auth.service.ts | 11 ++++------- src/Squidex/project.json | 9 +++++---- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/Squidex/Program.cs b/src/Squidex/Program.cs index 1271d25cb..9ecc53c0d 100644 --- a/src/Squidex/Program.cs +++ b/src/Squidex/Program.cs @@ -16,7 +16,7 @@ namespace Squidex public static void Main(string[] args) { var host = new WebHostBuilder() - .UseKestrel() + .UseKestrel(k => { k.AddServerHeader = false; }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup() diff --git a/src/Squidex/Startup.cs b/src/Squidex/Startup.cs index 0ab3d8143..df05ccd37 100644 --- a/src/Squidex/Startup.cs +++ b/src/Squidex/Startup.cs @@ -67,6 +67,7 @@ namespace Squidex services.AddMemoryCache(); services.AddOptions(); services.AddRouting(); + services.AddResponseCompression(); services.AddWebpackBuilder(); services.Configure( @@ -93,19 +94,21 @@ namespace Squidex loggerFactory.AddConsole(); loggerFactory.AddDebug(); + app.UseResponseCompression(); + if (!Environment.IsDevelopment()) { app.UseMiddleware(); } - UseIdentity(app); - UseApi(app); - UseFrontend(app); + MapAndUseIdentity(app); + MapAndUseApi(app); + MapAndUseFrontend(app); app.UseMyEventStore(); } - private void UseIdentity(IApplicationBuilder app) + private void MapAndUseIdentity(IApplicationBuilder app) { app.Map(Constants.IdentityPrefix, identityApp => { @@ -127,7 +130,7 @@ namespace Squidex }); } - private void UseApi(IApplicationBuilder app) + private void MapAndUseApi(IApplicationBuilder app) { app.Map(Constants.ApiPrefix, appApi => { @@ -145,7 +148,7 @@ namespace Squidex }); } - private void UseFrontend(IApplicationBuilder app) + private void MapAndUseFrontend(IApplicationBuilder app) { if (Environment.IsDevelopment()) { diff --git a/src/Squidex/app/components/layout/profile-menu.component.ts b/src/Squidex/app/components/layout/profile-menu.component.ts index f677fd9fd..31e5cff49 100644 --- a/src/Squidex/app/components/layout/profile-menu.component.ts +++ b/src/Squidex/app/components/layout/profile-menu.component.ts @@ -36,7 +36,7 @@ export class ProfileMenuComponent implements Ng2.OnInit, Ng2.OnDestroy { public ngOnInit() { this.authenticationSubscription = - this.auth.isAuthenticatedChanges.subscribe(() => { + this.auth.isAuthenticated.subscribe(() => { const user = this.auth.user; if (user) { diff --git a/src/Squidex/app/shared/services/apps-store.service.spec.ts b/src/Squidex/app/shared/services/apps-store.service.spec.ts index da28ba73f..5073ae6d6 100644 --- a/src/Squidex/app/shared/services/apps-store.service.spec.ts +++ b/src/Squidex/app/shared/services/apps-store.service.spec.ts @@ -23,7 +23,7 @@ describe('AppsStoreService', () => { }); it('should load when authenticated once', () => { - authService.setup(x => x.isAuthenticatedChanges) + authService.setup(x => x.isAuthenticated) .returns(() => Observable.of(true)) .verifiable(TypeMoq.Times.once()); @@ -55,7 +55,7 @@ describe('AppsStoreService', () => { .returns(() => true) .verifiable(TypeMoq.Times.once()); - authService.setup(x => x.isAuthenticatedChanges) + authService.setup(x => x.isAuthenticated) .returns(() => Observable.of(true)) .verifiable(TypeMoq.Times.once()); @@ -85,7 +85,7 @@ describe('AppsStoreService', () => { }); it('should add app to cache when created', () => { - authService.setup(x => x.isAuthenticatedChanges) + authService.setup(x => x.isAuthenticated) .returns(() => Observable.of(true)) .verifiable(TypeMoq.Times.once()); @@ -119,7 +119,7 @@ describe('AppsStoreService', () => { }); it('should not add app to cache when cache is null', () => { - authService.setup(x => x.isAuthenticatedChanges) + authService.setup(x => x.isAuthenticated) .returns(() => Observable.of(false)) .verifiable(TypeMoq.Times.once()); @@ -143,7 +143,7 @@ describe('AppsStoreService', () => { }); it('should select app', () => { - authService.setup(x => x.isAuthenticatedChanges) + authService.setup(x => x.isAuthenticated) .returns(() => Observable.of(true)) .verifiable(TypeMoq.Times.once()); diff --git a/src/Squidex/app/shared/services/apps-store.service.ts b/src/Squidex/app/shared/services/apps-store.service.ts index f9f87891d..bcee3880f 100644 --- a/src/Squidex/app/shared/services/apps-store.service.ts +++ b/src/Squidex/app/shared/services/apps-store.service.ts @@ -24,20 +24,19 @@ import { AuthService } from './auth.service'; @Ng2.Injectable() export class AppsStoreService { private lastApps: AppDto[] | null = null; + private isAuthenticated = false; private readonly apps$ = new Subject(); private readonly appName$ = new BehaviorSubject(null); private readonly appsPublished$ = this.apps$ .distinctUntilChanged() - .publishReplay(1) - .refCount(); + .publishReplay(1); private readonly selectedApp$ = this.appsPublished$.combineLatest(this.appName$, (apps, name) => apps && name ? apps.find(x => x.name === name) || null : null) .distinctUntilChanged() - .publishReplay(1) - .refCount(); + .publishReplay(1); public get apps(): Observable { return this.appsPublished$; @@ -55,11 +54,16 @@ export class AppsStoreService { return; } + this.selectedApp$.connect(); + + this.appsPublished$.connect(); this.appsPublished$.subscribe(apps => { this.lastApps = apps; }); - this.auth.isAuthenticatedChanges.subscribe(isAuthenticated => { + this.auth.isAuthenticated.subscribe(isAuthenticated => { + this.isAuthenticated = isAuthenticated; + if (isAuthenticated) { this.load(); } @@ -67,7 +71,7 @@ export class AppsStoreService { } public reload() { - if (this.auth.isAuthenticated) { + if (this.isAuthenticated) { this.load(); } } diff --git a/src/Squidex/app/shared/services/auth.service.ts b/src/Squidex/app/shared/services/auth.service.ts index dd43b8a7c..e5615d0d6 100644 --- a/src/Squidex/app/shared/services/auth.service.ts +++ b/src/Squidex/app/shared/services/auth.service.ts @@ -43,18 +43,13 @@ export class AuthService { private readonly isAuthenticatedChangedPublished$ = this.isAuthenticatedChanged$ .distinctUntilChanged() - .publishReplay(1) - .refCount(); + .publishReplay(1); public get user(): Profile | null { return this.currentUser; } - public get isAuthenticated(): boolean { - return !!this.currentUser; - } - - public get isAuthenticatedChanges(): Observable { + public get isAuthenticated(): Observable { return this.isAuthenticatedChangedPublished$; } @@ -87,6 +82,8 @@ export class AuthService { this.checkLogin(); } + + this.isAuthenticatedChangedPublished$.connect(); } public checkLogin(): Promise { diff --git a/src/Squidex/project.json b/src/Squidex/project.json index 587ce4f2b..494e306b6 100644 --- a/src/Squidex/project.json +++ b/src/Squidex/project.json @@ -3,18 +3,19 @@ "Autofac": "4.1.1", "Autofac.Extensions.DependencyInjection": "4.0.0", "IdentityServer4": "1.0.0-rc2", - "IdentityServer4.AspNetIdentity": "1.0.0-rc2", "IdentityServer4.AccessTokenValidation": "1.0.1-rc2", - "Microsoft.AspNetCore.Identity": "1.0.0", + "IdentityServer4.AspNetIdentity": "1.0.0-rc2", "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", "Microsoft.AspNetCore.Authentication.Google": "1.0.0", "Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.0.0", "Microsoft.AspNetCore.Diagnostics": "1.0.0", + "Microsoft.AspNetCore.Identity": "1.0.0", "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Razor.Tools": { "version": "1.0.0-preview2-final", "type": "build" }, + "Microsoft.AspNetCore.ResponseCompression": "1.0.0-preview2-22573", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.AspNetCore.StaticFiles": "1.0.0", @@ -30,13 +31,13 @@ }, "MongoDB.Driver": "2.4.0-beta1", "OpenCover": "4.6.519", + "ReportGenerator": "2.5.0-beta1", "Squidex.Core": "1.0.0-*", "Squidex.Events": "1.0.0-*", "Squidex.Infrastructure": "1.0.0-*", "Squidex.Read": "1.0.0-*", "Squidex.Store.MongoDb": "1.0.0-*", - "Squidex.Write": "1.0.0-*", - "ReportGenerator": "2.5.0-beta1" + "Squidex.Write": "1.0.0-*" }, "tools": {