connect-controlPanel: fix branding, backup and restore

This commit is contained in:
SuhorukovAnton 2020-10-28 16:21:24 +03:00
parent 03ae9171b6
commit c94b0ee340
10 changed files with 152 additions and 68 deletions

View File

@ -1,17 +1,21 @@

using System;
using System.Collections.Generic;
using System.Linq;
using ASC.Api.Core.Middleware;
using ASC.Common;
using ASC.Core;
using ASC.Data.Backup.Contracts;
using ASC.Data.Backup.ModelApi;
using ASC.Data.Backup.Models;
using ASC.Web.Api.Routing;
using ASC.Web.Studio.Utility;
using Microsoft.AspNetCore.Mvc;
using static ASC.Data.Backup.BackupAjaxHandler;
namespace ASC.Data.Backup.Controllers
{
[DefaultRoute]
@ -57,14 +61,23 @@ namespace ASC.Data.Backup.Controllers
/// <param name="backupMail">Include mail in the backup</param>
/// <category>Backup</category>
[Create("createbackupschedule")]
public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary<string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
public bool CreateBackupSchedule(BackupSchedule backupSchedule)
{
if (CoreBaseSettings.Standalone)
{
TenantExtra.DemandControlPanelPermission();
}
BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
var storageType = backupSchedule.StorageType == null ? BackupStorageType.Documents : (BackupStorageType)Int32.Parse(backupSchedule.StorageType);
var storageParams = backupSchedule.StorageParams == null ? new Dictionary<string, string>() : backupSchedule.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString());
var backupStored = backupSchedule.BackupsStored == null ? 0 : Int32.Parse(backupSchedule.BackupsStored);
var cron = new CronParams()
{
Period = backupSchedule.CronParams.Period == null ? BackupPeriod.EveryDay : (BackupPeriod)Int32.Parse(backupSchedule.CronParams.Period),
Hour = backupSchedule.CronParams.Hour == null ? 0 : Int32.Parse(backupSchedule.CronParams.Hour),
Day = backupSchedule.CronParams.Day == null ? 0 : Int32.Parse(backupSchedule.CronParams.Day),
};
BackupHandler.CreateSchedule(storageType, storageParams, backupStored, cron, backupSchedule.BackupMail);
return true;
}
/// <summary>
@ -72,7 +85,7 @@ namespace ASC.Data.Backup.Controllers
/// </summary>
/// <category>Backup</category>
[Delete("deletebackupschedule")]
public void DeleteBackupSchedule()
public bool DeleteBackupSchedule()
{
if (CoreBaseSettings.Standalone)
{
@ -80,6 +93,8 @@ namespace ASC.Data.Backup.Controllers
}
BackupHandler.DeleteSchedule();
return true;
}
/// <summary>
@ -97,8 +112,9 @@ namespace ASC.Data.Backup.Controllers
{
TenantExtra.DemandControlPanelPermission();
}
BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary<string, string>(), backup.BackupMail);
var storageType = backup.StorageType == null ? BackupStorageType.Documents : (BackupStorageType)Int32.Parse(backup.StorageType);
var storageParams = backup.StorageParams == null ? new Dictionary<string, string>() : backup.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString());
BackupHandler.StartBackup(storageType, storageParams, backup.BackupMail);
return BackupHandler.GetBackupProgress();
}
@ -139,7 +155,7 @@ namespace ASC.Data.Backup.Controllers
/// </summary>
/// <category>Backup</category>
[Delete("deletebackup/{id}")]
public void DeleteBackup(Guid id)
public bool DeleteBackup(Guid id)
{
if (CoreBaseSettings.Standalone)
{
@ -147,6 +163,7 @@ namespace ASC.Data.Backup.Controllers
}
BackupHandler.DeleteBackup(id);
return true;
}
/// <summary>
@ -155,7 +172,7 @@ namespace ASC.Data.Backup.Controllers
/// <category>Backup</category>
/// <returns>Backup History</returns>
[Delete("deletebackuphistory")]
public void DeleteBackupHistory()
public bool DeleteBackupHistory()
{
if (CoreBaseSettings.Standalone)
{
@ -163,6 +180,7 @@ namespace ASC.Data.Backup.Controllers
}
BackupHandler.DeleteAllBackups();
return true;
}
/// <summary>
@ -181,8 +199,8 @@ namespace ASC.Data.Backup.Controllers
{
TenantExtra.DemandControlPanelPermission();
}
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify);
var storageParams = backupRestore.StorageParams == null ? new Dictionary<string, string>() : backupRestore.StorageParams.ToDictionary(r => r.Key.ToString(), r => r.Value.ToString());
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, storageParams, backupRestore.Notify);
return BackupHandler.GetBackupProgress();
}

View File

@ -1,14 +1,16 @@

using System.Collections.Generic;
using ASC.Api.Collections;
using ASC.Data.Backup.Contracts;
namespace ASC.Data.Backup.Models
{
public class Backup
{
public BackupStorageType StorageType { get; set; }
public string StorageType { get; set; }
public bool BackupMail { get; set; }
public Dictionary<string, string> StorageParams { get; set; }
public IEnumerable<ItemKeyValuePair<object, object>> StorageParams { get; set; }
}
}

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using ASC.Api.Collections;
using ASC.Data.Backup.Contracts;
namespace ASC.Data.Backup.Models
@ -8,7 +9,7 @@ namespace ASC.Data.Backup.Models
{
public string BackupId { get; set; }
public BackupStorageType StorageType { get; set; }
public Dictionary<string, string> StorageParams { get; set; }
public IEnumerable<ItemKeyValuePair<object, object>> StorageParams { get; set; }
public bool Notify { get; set; }
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ASC.Api.Collections;
using ASC.Data.Backup.Contracts;
using static ASC.Data.Backup.BackupAjaxHandler;
namespace ASC.Data.Backup.ModelApi
{
public class BackupSchedule
{
public string StorageType { get; set; }
public IEnumerable<ItemKeyValuePair<object, object>> StorageParams { get; set; }
public string BackupsStored { get; set; }
public Cron CronParams { get; set; }
public bool BackupMail { get; set; }
}
public class Cron
{
public string Period { get; set; }
public string Hour { get; set; }
public string Day { get; set; }
}
}

View File

@ -592,6 +592,7 @@ namespace ASC.Data.Backup.Service
{
try
{
IsCompleted = true;
backupWorker.PublishProgress(this);
}
catch (Exception error)
@ -603,7 +604,6 @@ namespace ASC.Data.Backup.Service
{
File.Delete(tempFile);
}
IsCompleted = true;
}
}
@ -702,6 +702,8 @@ namespace ASC.Data.Backup.Service
{
try
{
IsCompleted = true;
backupWorker.PublishProgress(this);
}
catch (Exception error)
@ -713,7 +715,6 @@ namespace ASC.Data.Backup.Service
{
File.Delete(tempFile);
}
IsCompleted = true;
}
}

View File

@ -18,6 +18,8 @@ using ASC.Web.Core;
using ASC.Web.Core.Utility;
using ASC.Web.Studio.Core;
using ASC.Web.Studio.Core.Notify;
using ASC.Web.Studio.UserControls.Management;
using ASC.Web.Studio.UserControls.Statistics;
using ASC.Web.Studio.Utility;
using Microsoft.AspNetCore.Mvc;
@ -46,6 +48,7 @@ namespace ASC.Web.Api.Controllers
private SecurityContext SecurityContext { get; }
private SettingsManager SettingsManager { get; }
private IConfiguration Configuration { get; set; }
private TenantExtra TenantExtra { get; set; }
public ILog Log { get; }
@ -61,7 +64,8 @@ namespace ASC.Web.Api.Controllers
WebItemSecurity webItemSecurity,
SecurityContext securityContext,
SettingsManager settingsManager,
IConfiguration configuration
IConfiguration configuration,
TenantExtra tenantExtra
)
{
Log = options.CurrentValue;
@ -76,6 +80,7 @@ namespace ASC.Web.Api.Controllers
SecurityContext = securityContext;
SettingsManager = settingsManager;
Configuration = configuration;
TenantExtra = tenantExtra;
}
[Read("")]
@ -116,6 +121,20 @@ namespace ASC.Web.Api.Controllers
}
}
[Read("tenantextra")]
public object GetTenantExtra()
{
return new
{
opensource = TenantExtra.Opensource,
enterprise = TenantExtra.Enterprise,
tariff = TenantExtra.GetCurrentTariff(),
quota = TenantExtra.GetTenantQuota(),
notPaid = TenantExtra.IsNotPaid(),
licenseAccept = SettingsManager.LoadForCurrentUser<TariffSettings>().LicenseAcceptSetting
};
}
[Read("usedspace")]
public double GetUsedSpace()
@ -216,7 +235,8 @@ namespace ASC.Web.Api.Controllers
.AddCommonLinkUtilityService()
.AddAuthContextService()
.AddWebItemSecurity()
.AddSecurityContextService();
.AddSecurityContextService()
.AddTenantExtraService();
}
}
}

View File

@ -36,6 +36,8 @@ using System.ServiceModel.Security;
using System.Text.RegularExpressions;
using System.Web;
using ARSoft.Tools.Net.Dns;
using ASC.Api.Collections;
using ASC.Api.Core;
using ASC.Api.Utils;
@ -51,6 +53,7 @@ using ASC.Core.Common.Notify;
using ASC.Core.Common.Settings;
using ASC.Core.Tenants;
using ASC.Core.Users;
using ASC.Data.Backup;
using ASC.Data.Backup.Contracts;
using ASC.Data.Backup.Service;
using ASC.Data.Storage;
@ -166,6 +169,7 @@ namespace ASC.Api.Settings
private PasswordHasher PasswordHasher { get; }
private ILog Log { get; set; }
private TelegramHelper TelegramHelper { get; }
private BackupAjaxHandler BackupAjaxHandler { get; }
public SettingsController(
IOptionsMonitor<ILog> option,
@ -227,7 +231,8 @@ namespace ASC.Api.Settings
BackupServiceNotifier backupServiceNotifier,
ICacheNotify<DeleteSchedule> cacheDeleteSchedule,
EncryptionServiceNotifier encryptionServiceNotifier,
PasswordHasher passwordHasher)
PasswordHasher passwordHasher,
BackupAjaxHandler backupAjaxHandler)
{
Log = option.Get("ASC.Api");
WebHostEnvironment = webHostEnvironment;
@ -289,6 +294,7 @@ namespace ASC.Api.Settings
StorageFactory = storageFactory;
UrlShortener = urlShortener;
TelegramHelper = telegramHelper;
BackupAjaxHandler = backupAjaxHandler;
}
[Read("", Check = false)]
@ -939,7 +945,7 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Create("whitelabel/savefromfiles")]
public bool SaveWhiteLabelSettingsFromFiles([FromBody]WhiteLabelModel model, [FromQuery]WhiteLabelQuery query)
public bool SaveWhiteLabelSettingsFromFiles([FromForm]WhiteLabelModel1 model, [FromQuery]WhiteLabelQuery query)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -965,14 +971,14 @@ namespace ASC.Api.Settings
return true;
}
private void SaveWhiteLabelSettingsFromFilesForCurrentTenant(WhiteLabelModel model)
private void SaveWhiteLabelSettingsFromFilesForCurrentTenant(WhiteLabelModel1 model)
{
var settings = SettingsManager.Load<TenantWhiteLabelSettings>();
SaveWhiteLabelSettingsFromFilesForTenant(settings, null, Tenant.TenantId, model);
}
private void SaveWhiteLabelSettingsFromFilesForDefaultTenant(WhiteLabelModel model)
private void SaveWhiteLabelSettingsFromFilesForDefaultTenant(WhiteLabelModel1 model)
{
var settings = SettingsManager.LoadForDefaultTenant<TenantWhiteLabelSettings>();
var storage = StorageFactory.GetStorage(string.Empty, "static_partnerdata");
@ -980,7 +986,7 @@ namespace ASC.Api.Settings
SaveWhiteLabelSettingsFromFilesForTenant(settings, storage, Tenant.DEFAULT_TENANT, model);
}
private void SaveWhiteLabelSettingsFromFilesForTenant(TenantWhiteLabelSettings settings, IDataStore storage, int tenantId, WhiteLabelModel model)
private void SaveWhiteLabelSettingsFromFilesForTenant(TenantWhiteLabelSettings settings, IDataStore storage, int tenantId, WhiteLabelModel1 model)
{
foreach (var f in model.Attachments)
{
@ -1779,23 +1785,10 @@ namespace ASC.Api.Settings
return ServiceClient.GetProgress(Tenant.TenantId);
}
[Read("encryption")]
public void StartEncryption(EncryptionSettingsModel settings)
{
var encryptionSettingsProto = new EncryptionSettingsProto
{
NotifyUsers = settings.NotifyUsers,
Password = settings.Password,
Status = settings.Status,
ServerRootPath = settings.ServerRootPath
};
EncryptionServiceClient.Start(encryptionSettingsProto);
}
public readonly object Locker = new object();
[Create("encryption/start")]
public void StartStorageEncryption(StorageEncryptionModel storageEncryption)
public bool StartStorageEncryption(StorageEncryptionModel storageEncryption)
{
lock (Locker)
{
@ -1806,6 +1799,7 @@ namespace ASC.Api.Settings
StartEncryption(storageEncryption.NotifyUsers);
}
}
return true;
}
private void StartEncryption(bool notifyUsers)
@ -2082,29 +2076,29 @@ namespace ASC.Api.Settings
StorageSettingsHelper.Clear(SettingsManager.Load<CdnStorageSettings>());
}
//[Read("storage/backup")]
//public List<StorageWrapper> GetAllBackupStorages()
//{
// PermissionContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);
//if (CoreContext.Configuration.Standalone)
//{
// TenantExtra.DemandControlPanelPermission();
//}
// var schedule = new BackupAjaxHandler().GetSchedule();
// var current = new StorageSettings();
[Read("storage/backup")]
public List<StorageWrapper> GetAllBackupStorages()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
if (CoreBaseSettings.Standalone)
{
TenantExtra.DemandControlPanelPermission();
}
var schedule = BackupAjaxHandler.GetSchedule();
var current = new StorageSettings();
// if (schedule != null && schedule.StorageType == Contracts.BackupStorageType.ThirdPartyConsumer)
// {
// current = new StorageSettings
// {
// Module = schedule.StorageParams["module"],
// Props = schedule.StorageParams.Where(r => r.Key != "module").ToDictionary(r => r.Key, r => r.Value)
// };
// }
if (schedule != null && schedule.StorageType == BackupStorageType.ThirdPartyConsumer)
{
current = new StorageSettings
{
Module = schedule.StorageParams["module"],
Props = schedule.StorageParams.Where(r => r.Key != "module").ToDictionary(r => r.Key, r => r.Value)
};
}
// var consumers = ConsumerFactory.GetAll<DataStoreConsumer>().ToList();
// return consumers.Select(consumer => new StorageWrapper(consumer, current)).ToList();
//}
var consumers = ConsumerFactory.GetAll<DataStoreConsumer>().ToList();
return consumers.Select(consumer => new StorageWrapper(consumer, current)).ToList();
}
private void StartMigrate(StorageSettings settings)
{
@ -2138,15 +2132,16 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Create("rebranding/company")]
public void SaveCompanyWhiteLabelSettings(CompanyWhiteLabelSettings settings)
public bool SaveCompanyWhiteLabelSettings(CompanyWhiteLabelSettingsWrapper companyWhiteLabelSettingsWrapper)
{
if (settings == null) throw new ArgumentNullException("settings");
if (companyWhiteLabelSettingsWrapper.Settings == null) throw new ArgumentNullException("settings");
DemandRebrandingPermission();
settings.IsLicensorSetting = false; //TODO: CoreContext.TenantManager.GetTenantQuota(TenantProvider.CurrentTenantID).Branding && settings.IsLicensor
companyWhiteLabelSettingsWrapper.Settings.IsLicensorSetting = false; //TODO: CoreContext.TenantManager.GetTenantQuota(TenantProvider.CurrentTenantID).Branding && settings.IsLicensor
SettingsManager.SaveForDefaultTenant(settings);
SettingsManager.SaveForDefaultTenant(companyWhiteLabelSettingsWrapper.Settings);
return true;
}
///<visible>false</visible>
@ -2171,13 +2166,14 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Create("rebranding/additional")]
public void SaveAdditionalWhiteLabelSettings(AdditionalWhiteLabelSettings settings)
public bool SaveAdditionalWhiteLabelSettings(AdditionalWhiteLabelSettingsWrapper wrapper)
{
if (settings == null) throw new ArgumentNullException("settings");
if (wrapper.Settings == null) throw new ArgumentNullException("settings");
DemandRebrandingPermission();
SettingsManager.SaveForDefaultTenant(settings);
SettingsManager.SaveForDefaultTenant(wrapper.Settings);
return true;
}
///<visible>false</visible>
@ -2202,18 +2198,19 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Create("rebranding/mail")]
public void SaveMailWhiteLabelSettings(MailWhiteLabelSettings settings)
public bool SaveMailWhiteLabelSettings(MailWhiteLabelSettings settings)
{
if (settings == null) throw new ArgumentNullException("settings");
DemandRebrandingPermission();
SettingsManager.SaveForDefaultTenant(settings);
return true;
}
///<visible>false</visible>
[Update("rebranding/mail")]
public void UpdateMailWhiteLabelSettings(bool footerEnabled)
public bool UpdateMailWhiteLabelSettings(bool footerEnabled)
{
DemandRebrandingPermission();
@ -2222,6 +2219,8 @@ namespace ASC.Api.Settings
settings.FooterEnabled = footerEnabled;
SettingsManager.SaveForDefaultTenant(settings);
return true;
}
///<visible>false</visible>
@ -2463,7 +2462,8 @@ namespace ASC.Api.Settings
.AddEncryptionServiceNotifierService()
.AddTelegramLoginProviderService()
.AddTelegramHelperSerivce()
.AddPasswordHasherService();
.AddPasswordHasherService()
.AddBackupAjaxHandler();
}
}
}

View File

@ -12,6 +12,10 @@ namespace ASC.Web.Api.Models
public string LogoText { get; set; }
public IEnumerable<ItemKeyValuePair<string, string>> Logo { get; set; }
}
public class WhiteLabelModel1
{
public IEnumerable<IFormFile> Attachments { get; set; }
}
public class WhiteLabelQuery
{
public bool IsDefault { get; set; }

View File

@ -35,6 +35,11 @@ using Microsoft.Extensions.DependencyInjection;
namespace ASC.Web.Core.WhiteLabel
{
public class AdditionalWhiteLabelSettingsWrapper
{
public AdditionalWhiteLabelSettings Settings { get; set; }
}
[Serializable]
public class AdditionalWhiteLabelSettings : ISettings
{

View File

@ -34,7 +34,12 @@ using Microsoft.Extensions.DependencyInjection;
namespace ASC.Web.Core.WhiteLabel
{
{
public class CompanyWhiteLabelSettingsWrapper
{
public CompanyWhiteLabelSettings Settings { get; set; }
}
[Serializable]
public class CompanyWhiteLabelSettings : ISettings
{