Merge branch 'feature/filter-loader' of github.com:ONLYOFFICE/AppServer into feature/filter-loader

This commit is contained in:
Viktor Fomin 2020-11-06 18:46:03 +03:00
commit f6b82ac707
15 changed files with 214 additions and 115 deletions

View File

@ -53,5 +53,10 @@ namespace ASC.Core.Tenants
AuditTrailLifeTime = MaxLifeTime
};
}
}
public class TenantAuditSettingsWrapper
{
public TenantAuditSettings settings{ get; set; }
}
}

View File

@ -29,6 +29,7 @@ using System.Globalization;
using System.Linq;
using System.Net;
using System.Security.Authentication;
using System.Security.Claims;
using System.Security.Cryptography;
using System.Text;
using System.Text.Encodings.Web;
@ -36,10 +37,12 @@ using System.Threading.Tasks;
using ASC.Common;
using ASC.Common.Logging;
using ASC.Core.Common.Security;
using ASC.Security.Cryptography;
using ASC.Web.Core.Helpers;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@ -61,7 +64,8 @@ namespace ASC.ApiSystem.Classes
IConfiguration configuration,
IOptionsMonitor<ILog> option,
ApiSystemHelper apiSystemHelper,
MachinePseudoKeys machinePseudoKeys) :
MachinePseudoKeys machinePseudoKeys,
IHttpContextAccessor httpContextAccessor) :
base(options, logger, encoder, clock)
{
Configuration = configuration;
@ -70,6 +74,7 @@ namespace ASC.ApiSystem.Classes
ApiSystemHelper = apiSystemHelper;
MachinePseudoKeys = machinePseudoKeys;
HttpContextAccessor = httpContextAccessor;
}
private ILog Log { get; }
@ -78,6 +83,7 @@ namespace ASC.ApiSystem.Classes
private ApiSystemHelper ApiSystemHelper { get; }
private MachinePseudoKeys MachinePseudoKeys { get; }
private IHttpContextAccessor HttpContextAccessor { get; }
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
@ -103,7 +109,7 @@ namespace ASC.ApiSystem.Classes
var substring = "ASC";
if (!header.StartsWith(substring, StringComparison.InvariantCultureIgnoreCase))
if (header.StartsWith(substring, StringComparison.InvariantCultureIgnoreCase))
{
var splitted = header.Substring(substring.Length).Trim().Split(':', StringSplitOptions.RemoveEmptyEntries);
@ -159,9 +165,10 @@ namespace ASC.ApiSystem.Classes
return Task.FromResult(AuthenticateResult.Fail(new AuthenticationException(HttpStatusCode.InternalServerError.ToString())));
}
var identity = new ClaimsIdentity( Scheme.Name);
Log.InfoFormat("Auth success {0}", Scheme.Name);
if (HttpContextAccessor?.HttpContext != null) HttpContextAccessor.HttpContext.User = new CustomClaimsPrincipal(new ClaimsIdentity(Scheme.Name), identity);
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)));
}
}

View File

@ -47,7 +47,7 @@ namespace ASC.ApiSystem.Models
[StringLength(255)]
public string FirstName { get; set; }
[Email]
//todo [Email]
[StringLength(255)]
public string Email { get; set; }

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, (BackupStorageType)Int32.Parse(backupRestore.StorageType.ToString()), 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
@ -7,8 +8,8 @@ namespace ASC.Data.Backup.Models
public class BackupRestore
{
public string BackupId { get; set; }
public BackupStorageType StorageType { get; set; }
public Dictionary<string, string> StorageParams { get; set; }
public object StorageType { 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

@ -512,6 +512,7 @@ namespace ASC.Data.Backup.Service
try
{
tenant = tenantManager.GetTenant(TenantId);
tenantManager.SetCurrentTenant(tenant);
notifyHelper.SendAboutRestoreStarted(tenant, Notify);
var storage = backupStorageFactory.GetBackupStorage(StorageType, TenantId, StorageParams);
storage.Download(StoragePath, tempFile);
@ -561,7 +562,7 @@ namespace ASC.Data.Backup.Service
restoredTenant.MappedDomain = tenant.MappedDomain;
}
tenantManager.SaveTenant(restoredTenant);
tenantManager.SetCurrentTenant(restoredTenant);
// sleep until tenants cache expires
Thread.Sleep(TimeSpan.FromMinutes(2));
@ -592,6 +593,7 @@ namespace ASC.Data.Backup.Service
{
try
{
IsCompleted = true;
backupWorker.PublishProgress(this);
}
catch (Exception error)
@ -603,7 +605,6 @@ namespace ASC.Data.Backup.Service
{
File.Delete(tempFile);
}
IsCompleted = true;
}
}
@ -702,6 +703,8 @@ namespace ASC.Data.Backup.Service
{
try
{
IsCompleted = true;
backupWorker.PublishProgress(this);
}
catch (Exception error)
@ -713,7 +716,6 @@ namespace ASC.Data.Backup.Service
{
File.Delete(tempFile);
}
IsCompleted = true;
}
}

View File

@ -97,6 +97,11 @@ server {
}
location /api/2.0 {
location ~* /(files|encryption) {
proxy_pass http://localhost:5007;
proxy_set_header X-REWRITER-URL $X_REWRITER_URL;
}
location ~* /(authentication|modules|portal|security|settings|smtpsettings|capabilities) {
proxy_pass http://localhost:5000;
proxy_set_header X-REWRITER-URL $X_REWRITER_URL;
@ -116,11 +121,6 @@ server {
proxy_set_header X-REWRITER-URL $X_REWRITER_URL;
}
location ~* /(files|encryption) {
proxy_pass http://localhost:5007;
proxy_set_header X-REWRITER-URL $X_REWRITER_URL;
}
location ~* /backup {
proxy_pass http://localhost:5012;
proxy_set_header X-REWRITER-URL $X_REWRITER_URL;

View File

@ -20,6 +20,8 @@ using ASC.Web.Core.Mobile;
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;
@ -49,7 +51,8 @@ namespace ASC.Web.Api.Controllers
private SettingsManager SettingsManager { get; }
private IMobileAppInstallRegistrator MobileAppInstallRegistrator { get; }
private IConfiguration Configuration { get; set; }
private ILog Log { get; }
private TenantExtra TenantExtra { get; set; }
public ILog Log { get; }
public PortalController(
@ -65,6 +68,7 @@ namespace ASC.Web.Api.Controllers
SecurityContext securityContext,
SettingsManager settingsManager,
IMobileAppInstallRegistrator mobileAppInstallRegistrator,
TenantExtra tenantExtra,
IConfiguration configuration
)
{
@ -81,6 +85,7 @@ namespace ASC.Web.Api.Controllers
SettingsManager = settingsManager;
MobileAppInstallRegistrator = mobileAppInstallRegistrator;
Configuration = configuration;
TenantExtra = tenantExtra;
}
[Read("")]
@ -121,6 +126,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()
@ -207,7 +226,7 @@ namespace ASC.Web.Api.Controllers
{
var currentUser = UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
MobileAppInstallRegistrator.RegisterInstall(currentUser.Email, model.Type);
}
}
}
public static class PortalControllerExtension
@ -229,7 +248,8 @@ namespace ASC.Web.Api.Controllers
.AddAuthContextService()
.AddWebItemSecurity()
.AddSecurityContextService()
.AddCachedMobileAppInstallRegistrator();
.AddCachedMobileAppInstallRegistrator()
.AddTenantExtraService();
}
}
}

View File

@ -134,20 +134,20 @@ namespace ASC.Web.Api.Controllers
}
[Create("audit/settings/lifetime")]
public TenantAuditSettings SetAuditSettings(TenantAuditSettings settings)
public TenantAuditSettings SetAuditSettings(TenantAuditSettingsWrapper wrapper)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
if (settings.LoginHistoryLifeTime <= 0 || settings.LoginHistoryLifeTime > TenantAuditSettings.MaxLifeTime)
if (wrapper.settings.LoginHistoryLifeTime <= 0 || wrapper.settings.LoginHistoryLifeTime > TenantAuditSettings.MaxLifeTime)
throw new ArgumentException("LoginHistoryLifeTime");
if (settings.AuditTrailLifeTime <= 0 || settings.AuditTrailLifeTime > TenantAuditSettings.MaxLifeTime)
if (wrapper.settings.AuditTrailLifeTime <= 0 || wrapper.settings.AuditTrailLifeTime > TenantAuditSettings.MaxLifeTime)
throw new ArgumentException("AuditTrailLifeTime");
SettingsManager.SaveForTenant(settings, TenantManager.GetCurrentTenant().TenantId);
SettingsManager.SaveForTenant(wrapper.settings, TenantManager.GetCurrentTenant().TenantId);
MessageService.Send(MessageAction.AuditSettingsUpdated);
return settings;
return wrapper.settings;
}
}

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)]
@ -885,7 +891,7 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Create("whitelabel/save")]
public void SaveWhiteLabelSettings(WhiteLabelModel model)
public bool SaveWhiteLabelSettings([FromBody] WhiteLabelModel model, [FromQuery] WhiteLabelQuery query)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -894,7 +900,7 @@ namespace ASC.Api.Settings
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
if (model.IsDefault)
if (query.IsDefault)
{
DemandRebrandingPermission();
SaveWhiteLabelSettingsForDefaultTenant(model);
@ -903,6 +909,7 @@ namespace ASC.Api.Settings
{
SaveWhiteLabelSettingsForCurrentTenant(model);
}
return true;
}
private void SaveWhiteLabelSettingsForCurrentTenant(WhiteLabelModel model)
@ -925,7 +932,7 @@ namespace ASC.Api.Settings
if (model.Logo != null)
{
var logoDict = new Dictionary<int, string>();
model.Logo.ToList().ForEach(n => logoDict.Add(n.Key, n.Value));
model.Logo.ToList().ForEach(n => logoDict.Add(Int32.Parse(n.Key), n.Value));
TenantWhiteLabelSettingsHelper.SetLogo(settings, logoDict, storage);
}
@ -938,7 +945,7 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Create("whitelabel/savefromfiles")]
public void SaveWhiteLabelSettingsFromFiles(WhiteLabelModel model)
public bool SaveWhiteLabelSettingsFromFiles([FromQuery] WhiteLabelQuery query)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -947,40 +954,41 @@ namespace ASC.Api.Settings
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
if (model.Attachments == null || !model.Attachments.Any())
if (HttpContext.Request.Form?.Files == null || !HttpContext.Request.Form.Files.Any())
{
throw new InvalidOperationException("No input files");
}
if (model.IsDefault)
if (query.IsDefault)
{
DemandRebrandingPermission();
SaveWhiteLabelSettingsFromFilesForDefaultTenant(model);
SaveWhiteLabelSettingsFromFilesForDefaultTenant();
}
else
{
SaveWhiteLabelSettingsFromFilesForCurrentTenant(model);
SaveWhiteLabelSettingsFromFilesForCurrentTenant();
}
return true;
}
private void SaveWhiteLabelSettingsFromFilesForCurrentTenant(WhiteLabelModel model)
private void SaveWhiteLabelSettingsFromFilesForCurrentTenant()
{
var settings = SettingsManager.Load<TenantWhiteLabelSettings>();
SaveWhiteLabelSettingsFromFilesForTenant(settings, null, Tenant.TenantId, model);
SaveWhiteLabelSettingsFromFilesForTenant(settings, null, Tenant.TenantId);
}
private void SaveWhiteLabelSettingsFromFilesForDefaultTenant(WhiteLabelModel model)
private void SaveWhiteLabelSettingsFromFilesForDefaultTenant()
{
var settings = SettingsManager.LoadForDefaultTenant<TenantWhiteLabelSettings>();
var storage = StorageFactory.GetStorage(string.Empty, "static_partnerdata");
SaveWhiteLabelSettingsFromFilesForTenant(settings, storage, Tenant.DEFAULT_TENANT, model);
SaveWhiteLabelSettingsFromFilesForTenant(settings, storage, Tenant.DEFAULT_TENANT);
}
private void SaveWhiteLabelSettingsFromFilesForTenant(TenantWhiteLabelSettings settings, IDataStore storage, int tenantId, WhiteLabelModel model)
private void SaveWhiteLabelSettingsFromFilesForTenant(TenantWhiteLabelSettings settings, IDataStore storage, int tenantId)
{
foreach (var f in model.Attachments)
foreach (var f in HttpContext.Request.Form.Files)
{
var parts = f.FileName.Split('.');
var logoType = (WhiteLabelLogoTypeEnum)(Convert.ToInt32(parts[0]));
@ -1017,7 +1025,7 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Read("whitelabel/logos")]
public Dictionary<int, string> GetWhiteLabelLogos(WhiteLabelModel model)
public Dictionary<string, string> GetWhiteLabelLogos([FromQuery] WhiteLabelQuery query)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -1026,30 +1034,30 @@ namespace ASC.Api.Settings
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
Dictionary<int, string> result;
Dictionary<string, string> result;
if (model.IsDefault)
if (query.IsDefault)
{
DemandRebrandingPermission();
result = new Dictionary<int, string>
result = new Dictionary<string, string>
{
{ (int)WhiteLabelLogoTypeEnum.LightSmall, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.LightSmall, !model.IsRetina)) },
{ (int)WhiteLabelLogoTypeEnum.Dark, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Dark, !model.IsRetina)) },
{ (int)WhiteLabelLogoTypeEnum.Favicon, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Favicon, !model.IsRetina)) },
{ (int)WhiteLabelLogoTypeEnum.DocsEditor, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, !model.IsRetina)) }
{ ((int)WhiteLabelLogoTypeEnum.LightSmall).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.LightSmall, !query.IsRetina)) },
{ ((int)WhiteLabelLogoTypeEnum.Dark).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Dark, !query.IsRetina)) },
{ ((int)WhiteLabelLogoTypeEnum.Favicon).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.Favicon, !query.IsRetina)) },
{ ((int)WhiteLabelLogoTypeEnum.DocsEditor).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteDefaultLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, !query.IsRetina)) }
};
}
else
{
var _tenantWhiteLabelSettings = SettingsManager.Load<TenantWhiteLabelSettings>();
result = new Dictionary<int, string>
result = new Dictionary<string, string>
{
{ (int)WhiteLabelLogoTypeEnum.LightSmall, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.LightSmall, !model.IsRetina)) },
{ (int)WhiteLabelLogoTypeEnum.Dark, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Dark, !model.IsRetina)) },
{ (int)WhiteLabelLogoTypeEnum.Favicon, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Favicon, !model.IsRetina)) },
{ (int)WhiteLabelLogoTypeEnum.DocsEditor, CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.DocsEditor, !model.IsRetina)) }
{ ((int)WhiteLabelLogoTypeEnum.LightSmall).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.LightSmall, !query.IsRetina)) },
{ ((int)WhiteLabelLogoTypeEnum.Dark).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Dark, !query.IsRetina)) },
{ ((int)WhiteLabelLogoTypeEnum.Favicon).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.Favicon, !query.IsRetina)) },
{ ((int)WhiteLabelLogoTypeEnum.DocsEditor).ToString(), CommonLinkUtility.GetFullAbsolutePath(TenantWhiteLabelSettingsHelper.GetAbsoluteLogoPath(_tenantWhiteLabelSettings, WhiteLabelLogoTypeEnum.DocsEditor, !query.IsRetina)) }
};
}
@ -1058,7 +1066,7 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Read("whitelabel/logotext")]
public object GetWhiteLabelLogoText(WhiteLabelModel model)
public object GetWhiteLabelLogoText([FromQuery] WhiteLabelQuery query)
{
if (!TenantLogoManager.WhiteLabelEnabled)
{
@ -1066,12 +1074,12 @@ namespace ASC.Api.Settings
}
if (model.IsDefault)
if (query.IsDefault)
{
DemandRebrandingPermission();
}
var settings = model.IsDefault ? SettingsManager.LoadForDefaultTenant<TenantWhiteLabelSettings>() : SettingsManager.Load<TenantWhiteLabelSettings>();
var settings = query.IsDefault ? SettingsManager.LoadForDefaultTenant<TenantWhiteLabelSettings>() : SettingsManager.Load<TenantWhiteLabelSettings>();
return settings.LogoText ?? TenantWhiteLabelSettings.DefaultLogoText;
}
@ -1079,7 +1087,7 @@ namespace ASC.Api.Settings
///<visible>false</visible>
[Update("whitelabel/restore")]
public void RestoreWhiteLabelOptions(WhiteLabelModel model)
public bool RestoreWhiteLabelOptions(WhiteLabelQuery query)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
@ -1087,7 +1095,7 @@ namespace ASC.Api.Settings
{
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
if (model.IsDefault)
if (query.IsDefault)
{
DemandRebrandingPermission();
RestoreWhiteLabelOptionsForDefaultTenant();
@ -1096,6 +1104,7 @@ namespace ASC.Api.Settings
{
RestoreWhiteLabelOptionsForCurrentTenant();
}
return true;
}
private void RestoreWhiteLabelOptionsForCurrentTenant()
@ -1776,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)
{
@ -1803,6 +1799,7 @@ namespace ASC.Api.Settings
StartEncryption(storageEncryption.NotifyUsers);
}
}
return true;
}
private void StartEncryption(bool notifyUsers)
@ -2079,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)
{
@ -2135,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>
@ -2168,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>
@ -2199,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();
@ -2219,6 +2219,8 @@ namespace ASC.Api.Settings
settings.FooterEnabled = footerEnabled;
SettingsManager.SaveForDefaultTenant(settings);
return true;
}
///<visible>false</visible>
@ -2460,7 +2462,8 @@ namespace ASC.Api.Settings
.AddEncryptionServiceNotifierService()
.AddTelegramLoginProviderService()
.AddTelegramHelperSerivce()
.AddPasswordHasherService();
.AddPasswordHasherService()
.AddBackupAjaxHandler();
}
}
}

View File

@ -8,9 +8,12 @@ namespace ASC.Web.Api.Models
{
public class WhiteLabelModel
{
public IEnumerable<IFormFile> Attachments { get; set; }
public string LogoText { get; set; }
public IEnumerable<ItemKeyValuePair<int, string>> Logo { get; set; }
public IEnumerable<ItemKeyValuePair<string, string>> Logo { get; set; }
}
public class WhiteLabelQuery
{
public bool IsDefault { get; set; }
public bool IsRetina { 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
{