mirror of https://github.com/Squidex/squidex.git
18 changed files with 1757 additions and 1099 deletions
@ -0,0 +1,55 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using NSwag.Annotations; |
|||
using Squidex.Infrastructure.Assets; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Pipeline; |
|||
|
|||
namespace Squidex.Areas.Api.Controllers.Backups |
|||
{ |
|||
/// <summary>
|
|||
/// Manages backups for app.
|
|||
/// </summary>
|
|||
[ApiAuthorize] |
|||
[ApiExceptionFilter] |
|||
[AppApi] |
|||
[SwaggerTag(nameof(Backups))] |
|||
public class BackupsContentController : ApiController |
|||
{ |
|||
private readonly IAssetStore assetStore; |
|||
|
|||
public BackupsContentController(ICommandBus commandBus, IAssetStore assetStore) |
|||
: base(commandBus) |
|||
{ |
|||
this.assetStore = assetStore; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get the backup content.
|
|||
/// </summary>
|
|||
/// <param name="app">The name of the app.</param>
|
|||
/// <param name="id">The id of the asset.</param>
|
|||
/// <returns>
|
|||
/// 200 => Backup found and content returned.
|
|||
/// 404 => Backup or app not found.
|
|||
/// </returns>
|
|||
[HttpGet] |
|||
[Route("apps/{app}/backups/{id}")] |
|||
[ProducesResponseType(200)] |
|||
[ApiCosts(0)] |
|||
public IActionResult GetBackupContent(string app, Guid id) |
|||
{ |
|||
return new FileCallbackResult("application/zip", "Backup.zip", bodyStream => |
|||
{ |
|||
return assetStore.DownloadAsync(id.ToString(), 0, null, bodyStream); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -1,2 +1,28 @@ |
|||
@import '_vars'; |
|||
@import '_mixins'; |
|||
@import '_mixins'; |
|||
|
|||
$cicle-size: 2.8rem; |
|||
|
|||
.backup-status { |
|||
& { |
|||
@include circle($cicle-size); |
|||
line-height: $cicle-size; |
|||
text-align: center; |
|||
font-size: .4 * $cicle-size; |
|||
font-weight: normal; |
|||
background: $color-border; |
|||
color: $color-dark-foreground; |
|||
} |
|||
|
|||
&-pending { |
|||
color: inherit; |
|||
} |
|||
|
|||
&-failed { |
|||
background: $color-theme-error; |
|||
} |
|||
|
|||
&-success { |
|||
background: $color-theme-green; |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
/* |
|||
* Squidex Headless CMS |
|||
* |
|||
* @license |
|||
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved. |
|||
*/ |
|||
|
|||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; |
|||
import { inject, TestBed } from '@angular/core/testing'; |
|||
|
|||
import { |
|||
AnalyticsService, |
|||
ApiUrlConfig, |
|||
BackupDto, |
|||
BackupsService, |
|||
DateTime |
|||
} from './../'; |
|||
|
|||
describe('BackupsService', () => { |
|||
beforeEach(() => { |
|||
TestBed.configureTestingModule({ |
|||
imports: [ |
|||
HttpClientTestingModule |
|||
], |
|||
providers: [ |
|||
BackupsService, |
|||
{ provide: ApiUrlConfig, useValue: new ApiUrlConfig('http://service/p/') }, |
|||
{ provide: AnalyticsService, useValue: new AnalyticsService() } |
|||
] |
|||
}); |
|||
}); |
|||
|
|||
afterEach(inject([HttpTestingController], (httpMock: HttpTestingController) => { |
|||
httpMock.verify(); |
|||
})); |
|||
|
|||
it('should make get request to get backups', |
|||
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|||
|
|||
let backups: BackupDto[] | null = null; |
|||
|
|||
backupsService.getBackups('my-app').subscribe(result => { |
|||
backups = result; |
|||
}); |
|||
|
|||
const req = httpMock.expectOne('http://service/p/api/apps/my-app/backups'); |
|||
|
|||
expect(req.request.method).toEqual('GET'); |
|||
expect(req.request.headers.get('If-Match')).toBeNull(); |
|||
|
|||
req.flush([ |
|||
{ |
|||
id: '1', |
|||
started: '2017-02-03', |
|||
stopped: '2017-02-04', |
|||
handledEvents: 13, |
|||
handledAssets: 17, |
|||
isFailed: false |
|||
}, |
|||
{ |
|||
id: '2', |
|||
started: '2018-02-03', |
|||
stopped: null, |
|||
handledEvents: 23, |
|||
handledAssets: 27, |
|||
isFailed: true |
|||
} |
|||
]); |
|||
|
|||
expect(backups).toEqual([ |
|||
new BackupDto('1', DateTime.parseISO_UTC('2017-02-03'), DateTime.parseISO_UTC('2017-02-04'), 13, 17, false), |
|||
new BackupDto('2', DateTime.parseISO_UTC('2018-02-03'), null, 23, 27, true) |
|||
]); |
|||
})); |
|||
|
|||
it('should make post request to start backup', |
|||
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|||
|
|||
backupsService.postBackup('my-app').subscribe(); |
|||
|
|||
const req = httpMock.expectOne('http://service/p/api/apps/my-app/backups'); |
|||
|
|||
expect(req.request.method).toEqual('POST'); |
|||
expect(req.request.headers.get('If-Match')).toBeNull(); |
|||
|
|||
req.flush({}); |
|||
})); |
|||
|
|||
it('should make delete request to remove language', |
|||
inject([BackupsService, HttpTestingController], (backupsService: BackupsService, httpMock: HttpTestingController) => { |
|||
|
|||
backupsService.deleteBackup('my-app', '1').subscribe(); |
|||
|
|||
const req = httpMock.expectOne('http://service/p/api/apps/my-app/backups/1'); |
|||
|
|||
expect(req.request.method).toEqual('DELETE'); |
|||
expect(req.request.headers.get('If-Match')).toBeNull(); |
|||
|
|||
req.flush({}); |
|||
})); |
|||
}); |
|||
File diff suppressed because it is too large
Binary file not shown.
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 75 KiB |
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Loading…
Reference in new issue