Browse Source

1) Polling schema after creation.

2) Bugfix: Mongo subscription was not notified.
3) Bugfix: Incorrect error codes.
pull/95/head
Sebastian Stehle 8 years ago
parent
commit
1e8b0a1c06
  1. 2
      src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs
  2. 2
      src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs
  3. 29
      src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts
  4. 2
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html
  5. 9
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  6. 16
      src/Squidex/app/shared/interceptors/auth.interceptor.spec.ts
  7. 4
      src/Squidex/app/shared/interceptors/auth.interceptor.ts

2
src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs

@ -140,6 +140,8 @@ namespace Squidex.Infrastructure.CQRS.Events
}; };
await Collection.InsertOneAsync(document); await Collection.InsertOneAsync(document);
notifier.NotifyEventsStored();
} }
catch (MongoWriteException ex) catch (MongoWriteException ex)
{ {

2
src/Squidex/Pipeline/ApiExceptionFilterAttribute.cs

@ -64,7 +64,7 @@ namespace Squidex.Pipeline
{ {
error.StatusCode = statusCode; error.StatusCode = statusCode;
return new ObjectResult(error) { StatusCode = 412 }; return new ObjectResult(error) { StatusCode = statusCode };
} }
public override void OnActionExecuting(ActionExecutingContext context) public override void OnActionExecuting(ActionExecutingContext context)

29
src/Squidex/app/features/schemas/pages/schemas/schema-form.component.ts

@ -7,11 +7,15 @@
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms'; import { FormBuilder, Validators } from '@angular/forms';
import { Observable } from 'rxjs';
import { import {
ApiUrlConfig, ApiUrlConfig,
AuthService, AuthService,
fadeAnimation, fadeAnimation,
Notification,
NotificationService,
SchemaDetailsDto,
SchemaDto, SchemaDto,
SchemasService, SchemasService,
ValidatorsEx, ValidatorsEx,
@ -30,7 +34,7 @@ const FALLBACK_NAME = 'my-schema';
}) })
export class SchemaFormComponent { export class SchemaFormComponent {
@Output() @Output()
public created = new EventEmitter<SchemaDto>(); public created = new EventEmitter<{ schema: SchemaDto, isAvailable: boolean }>();
@Output() @Output()
public cancelled = new EventEmitter(); public cancelled = new EventEmitter();
@ -59,6 +63,7 @@ export class SchemaFormComponent {
constructor( constructor(
public readonly apiUrl: ApiUrlConfig, public readonly apiUrl: ApiUrlConfig,
private readonly notifications: NotificationService,
private readonly schemas: SchemasService, private readonly schemas: SchemasService,
private readonly formBuilder: FormBuilder, private readonly formBuilder: FormBuilder,
private readonly authService: AuthService private readonly authService: AuthService
@ -90,11 +95,25 @@ export class SchemaFormComponent {
const me = this.authService.user!.token; const me = this.authService.user!.token;
this.schemas.postSchema(this.appName, requestDto, me, undefined, schemaVersion) this.schemas.postSchema(this.appName, requestDto, me, undefined, schemaVersion)
.switchMap(dto => {
return this.schemas.getSchema(this.appName, dto.id)
.retryWhen(errors => errors
.delay(500)
.take(10)
.concat(Observable.throw(dto)));
})
.subscribe(dto => { .subscribe(dto => {
this.emitCreated(dto); this.emitCreated(dto, true);
this.resetCreateForm(); this.resetCreateForm();
}, error => { }, error => {
this.enableCreateForm(error.displayMessage); if (error instanceof SchemaDetailsDto) {
this.notifications.notify(Notification.error('Schema has been created but is awaiting to be processed. Reload in a few seconds.'));
this.emitCreated(error, false);
this.resetCreateForm();
} else {
this.enableCreateForm(error.displayMessage);
}
}); });
} }
} }
@ -103,8 +122,8 @@ export class SchemaFormComponent {
this.cancelled.emit(); this.cancelled.emit();
} }
private emitCreated(schema: SchemaDto) { private emitCreated(schema: SchemaDto, isAvailable: boolean) {
this.created.emit(schema); this.created.emit({ schema, isAvailable });
} }
private enableCreateForm(message: string) { private enableCreateForm(message: string) {

2
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.html

@ -66,7 +66,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<sqx-schema-form [appName]="appName() | async" (created)="onSchemaCreated($event)" (cancelled)="addSchemaDialog.hide()"></sqx-schema-form> <sqx-schema-form [appName]="appName() | async" (created)="onSchemaCreated($event.schema, $event.isAvailable)" (cancelled)="addSchemaDialog.hide()"></sqx-schema-form>
</div> </div>
</div> </div>
</div> </div>

9
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -6,7 +6,7 @@
*/ */
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
@ -46,6 +46,7 @@ export class SchemasPageComponent extends AppComponentBase implements OnDestroy,
constructor(apps: AppsStoreService, notifications: NotificationService, constructor(apps: AppsStoreService, notifications: NotificationService,
private readonly schemasService: SchemasService, private readonly schemasService: SchemasService,
private readonly messageBus: MessageBus, private readonly messageBus: MessageBus,
private readonly router: Router,
private readonly route: ActivatedRoute private readonly route: ActivatedRoute
) { ) {
super(notifications, apps); super(notifications, apps);
@ -96,10 +97,14 @@ export class SchemasPageComponent extends AppComponentBase implements OnDestroy,
}); });
} }
public onSchemaCreated(dto: SchemaDto) { public onSchemaCreated(dto: SchemaDto, isAvailable: boolean) {
this.updateSchemas(this.schemas.push(dto), this.schemaQuery); this.updateSchemas(this.schemas.push(dto), this.schemaQuery);
this.addSchemaDialog.hide(); this.addSchemaDialog.hide();
if (isAvailable) {
this.router.navigate([ dto.name ], { relativeTo: this.route });
}
} }
private updateSchemas(schemas: ImmutableArray<SchemaDto>, query?: string) { private updateSchemas(schemas: ImmutableArray<SchemaDto>, query?: string) {

16
src/Squidex/app/shared/interceptors/auth.interceptor.spec.ts

@ -88,22 +88,6 @@ describe('AuthInterceptor', () => {
expect(req.request.headers.get('Pragma')).toBeNull(); expect(req.request.headers.get('Pragma')).toBeNull();
})); }));
it(`should logout for 404 status code when user is expired.`,
inject([HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {
authService.setup(x => x.userChanges).returns(() => { return Observable.of(<any>{ authToken: 'letmein', isExpired: true }); });
http.get('http://service/p/apps').subscribe(
_ => { /* NOOP */ },
_ => { /* NOOP */ });
const req = httpMock.expectOne('http://service/p/apps');
req.error(<any>{}, { status: 404 });
authService.verify(x => x.logoutRedirect(), Times.once());
}));
it(`should logout for 401 status code`, it(`should logout for 401 status code`,
inject([HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => { inject([HttpClient, HttpTestingController], (http: HttpClient, httpMock: HttpTestingController) => {

4
src/Squidex/app/shared/interceptors/auth.interceptor.ts

@ -46,10 +46,6 @@ export class AuthInterceptor implements HttpInterceptor {
.catch((error: HttpErrorResponse) => { .catch((error: HttpErrorResponse) => {
if (error.status === 401 && renew) { if (error.status === 401 && renew) {
return this.authService.loginSilent().switchMap(u => this.makeRequest(req, next, u)); return this.authService.loginSilent().switchMap(u => this.makeRequest(req, next, u));
} else if (error.status === 404 && (!user || user.isExpired)) {
this.authService.logoutRedirect();
return Observable.empty<HttpEvent<any>>();
} else if (error.status === 401 || error.status === 403) { } else if (error.status === 401 || error.status === 403) {
this.authService.logoutRedirect(); this.authService.logoutRedirect();

Loading…
Cancel
Save