From e1f7b7365aa2ba43bb7bc1ddead2f374bbaa91a0 Mon Sep 17 00:00:00 2001 From: SuhorukovAnton <62381554+SuhorukovAnton@users.noreply.github.com> Date: Mon, 29 Jun 2020 14:40:42 +0300 Subject: [PATCH] api-defaultvalue: fix backup --- .../ASC.Data.Backup/BackupAjaxHandler.cs | 12 +- .../Controllers/BackupController.cs | 318 +++++++++--------- 2 files changed, 165 insertions(+), 165 deletions(-) diff --git a/common/services/ASC.Data.Backup/BackupAjaxHandler.cs b/common/services/ASC.Data.Backup/BackupAjaxHandler.cs index f4798f1c89..b599c37c4a 100644 --- a/common/services/ASC.Data.Backup/BackupAjaxHandler.cs +++ b/common/services/ASC.Data.Backup/BackupAjaxHandler.cs @@ -171,8 +171,8 @@ namespace ASC.Data.Backup StorageType = response.StorageType, StorageParams = response.StorageParams.ToDictionary(r => r.Key, r => r.Value) ?? new Dictionary(), CronParams = new CronParams(response.Cron), - BackupMail = response.BackupMail, - BackupsStored = response.NumberOfBackupsStored, + BackupMail = response.BackupMail ? (bool?)true : null, + BackupsStored = response.NumberOfBackupsStored == 0 ? null : (int?)response.NumberOfBackupsStored, LastBackupTime = response.LastBackupTime }; @@ -197,9 +197,9 @@ namespace ASC.Data.Backup var Schedule = new CreateScheduleRequest { TenantId = TenantManager.GetCurrentTenant().TenantId, - BackupMail = schedule.BackupMail, + BackupMail = schedule.BackupMail == null ? false : (bool)schedule.BackupMail, Cron = schedule.CronParams.ToString(), - NumberOfBackupsStored = schedule.BackupsStored, + NumberOfBackupsStored = schedule.BackupsStored == null ? 0 : (int)schedule.BackupsStored, StorageType = schedule.StorageType, StorageParams = schedule.StorageParams }; @@ -344,8 +344,8 @@ namespace ASC.Data.Backup public BackupStorageType StorageType { get; set; } public Dictionary StorageParams { get; set; } public CronParams CronParams { get; set; } - public bool BackupMail { get; set; } - public int BackupsStored { get; set; } + public bool? BackupMail { get; set; } + public int? BackupsStored { get; set; } public DateTime LastBackupTime { get; set; } } diff --git a/common/services/ASC.Data.Backup/Controllers/BackupController.cs b/common/services/ASC.Data.Backup/Controllers/BackupController.cs index fbbe763b95..787d97e6f9 100644 --- a/common/services/ASC.Data.Backup/Controllers/BackupController.cs +++ b/common/services/ASC.Data.Backup/Controllers/BackupController.cs @@ -1,161 +1,161 @@ - -using System; -using System.Collections.Generic; + +using System; +using System.Collections.Generic; -using ASC.Api.Core.Middleware; -using ASC.Common; -using ASC.Data.Backup.Contracts; -using ASC.Data.Backup.Models; -using ASC.Web.Api.Routing; +using ASC.Api.Core.Middleware; +using ASC.Common; +using ASC.Data.Backup.Contracts; +using ASC.Data.Backup.Models; +using ASC.Web.Api.Routing; -using Microsoft.AspNetCore.Mvc; - -namespace ASC.Data.Backup.Controllers -{ - [DefaultRoute] - [ApiController] - public class BackupController - { - private BackupAjaxHandler BackupHandler { get; } - public BackupController(BackupAjaxHandler backupAjaxHandler) - { - BackupHandler = backupAjaxHandler; - } - /// - /// Returns the backup schedule of the current portal - /// - /// Backup - /// Backup Schedule - [Read("getbackupschedule")] - public BackupAjaxHandler.Schedule GetBackupSchedule() - { - return BackupHandler.GetSchedule(); - } - - /// - /// Create the backup schedule of the current portal - /// - /// Storage type - /// Storage parameters - /// Max of the backup's stored copies - /// Cron parameters - /// Include mail in the backup - /// Backup - [Create("createbackupschedule")] - public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail) - { - BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail); - } - - /// - /// Delete the backup schedule of the current portal - /// - /// Backup - [Delete("deletebackupschedule")] - public void DeleteBackupSchedule() - { - BackupHandler.DeleteSchedule(); - } - - /// - /// Start a backup of the current portal - /// - /// Storage Type - /// Storage Params - /// Include mail in the backup - /// Backup - /// Backup Progress - [Create("startbackup")] - public BackupProgress StartBackup(Models.Backup backup) - { - BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary(), backup.BackupMail); - return BackupHandler.GetBackupProgress(); - } - - /// - /// Returns the progress of the started backup - /// - /// Backup - /// Backup Progress - [Read("getbackupprogress")] - public BackupProgress GetBackupProgress() - { - return BackupHandler.GetBackupProgress(); - } - - /// - /// Returns the backup history of the started backup - /// - /// Backup - /// Backup History - [Read("getbackuphistory")] - public List GetBackupHistory() - { - return BackupHandler.GetBackupHistory(); - } - - /// - /// Delete the backup with the specified id - /// - /// Backup - [Delete("deletebackup/{id}")] - public void DeleteBackup(Guid id) - { - BackupHandler.DeleteBackup(id); - } - - /// - /// Delete all backups of the current portal - /// - /// Backup - /// Backup History - [Delete("deletebackuphistory")] - public void DeleteBackupHistory() - { - BackupHandler.DeleteAllBackups(); - } - - /// - /// Start a data restore of the current portal - /// - /// Backup Id - /// Storage Type - /// Storage Params - /// Notify about backup to users - /// Backup - /// Restore Progress - [Create("startrestore")] - public BackupProgress StartBackupRestore(BackupRestore backupRestore) - { - BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify); - return BackupHandler.GetBackupProgress(); - } - - /// - /// Returns the progress of the started restore - /// - /// Backup - /// Restore Progress - [Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!! - public BackupProgress GetRestoreProgress() - { - return BackupHandler.GetRestoreProgress(); - } - - ///false - [Read("backuptmp")] - public string GetTempPath() - { - return BackupHandler.GetTmpFolder(); - } - } - public static class BackupControllerExtension - { - public static DIHelper AddBackupController(this DIHelper services) - { - return services - .AddBackupAjaxHandler() - .AddIpSecurityFilter(); - } - } -} +using Microsoft.AspNetCore.Mvc; + +namespace ASC.Data.Backup.Controllers +{ + [DefaultRoute] + [ApiController] + public class BackupController + { + private BackupAjaxHandler BackupHandler { get; } + public BackupController(BackupAjaxHandler backupAjaxHandler) + { + BackupHandler = backupAjaxHandler; + } + /// + /// Returns the backup schedule of the current portal + /// + /// Backup + /// Backup Schedule + [Read("getbackupschedule")] + public BackupAjaxHandler.Schedule GetBackupSchedule() + { + return BackupHandler.GetSchedule(); + } + + /// + /// Create the backup schedule of the current portal + /// + /// Storage type + /// Storage parameters + /// Max of the backup's stored copies + /// Cron parameters + /// Include mail in the backup + /// Backup + [Create("createbackupschedule")] + public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail) + { + BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail); + } + + /// + /// Delete the backup schedule of the current portal + /// + /// Backup + [Delete("deletebackupschedule")] + public void DeleteBackupSchedule() + { + BackupHandler.DeleteSchedule(); + } + + /// + /// Start a backup of the current portal + /// + /// Storage Type + /// Storage Params + /// Include mail in the backup + /// Backup + /// Backup Progress + [Create("startbackup")] + public BackupProgress StartBackup(Models.Backup backup) + { + BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary(), backup.BackupMail); + return BackupHandler.GetBackupProgress(); + } + + /// + /// Returns the progress of the started backup + /// + /// Backup + /// Backup Progress + [Read("getbackupprogress")] + public BackupProgress GetBackupProgress() + { + return BackupHandler.GetBackupProgress(); + } + + /// + /// Returns the backup history of the started backup + /// + /// Backup + /// Backup History + [Read("getbackuphistory")] + public List GetBackupHistory() + { + return BackupHandler.GetBackupHistory(); + } + + /// + /// Delete the backup with the specified id + /// + /// Backup + [Delete("deletebackup/{id}")] + public void DeleteBackup(Guid id) + { + BackupHandler.DeleteBackup(id); + } + + /// + /// Delete all backups of the current portal + /// + /// Backup + /// Backup History + [Delete("deletebackuphistory")] + public void DeleteBackupHistory() + { + BackupHandler.DeleteAllBackups(); + } + + /// + /// Start a data restore of the current portal + /// + /// Backup Id + /// Storage Type + /// Storage Params + /// Notify about backup to users + /// Backup + /// Restore Progress + [Create("startrestore")] + public BackupProgress StartBackupRestore(BackupRestore backupRestore) + { + BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify); + return BackupHandler.GetBackupProgress(); + } + + /// + /// Returns the progress of the started restore + /// + /// Backup + /// Restore Progress + [Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!! + public BackupProgress GetRestoreProgress() + { + return BackupHandler.GetRestoreProgress(); + } + + ///false + [Read("backuptmp")] + public string GetTempPath() + { + return BackupHandler.GetTmpFolder(); + } + } + public static class BackupControllerExtension + { + public static DIHelper AddBackupController(this DIHelper services) + { + return services + .AddBackupAjaxHandler() + .AddIpSecurityFilter(); + } + } +}