CoreDbContext -async
This commit is contained in:
parent
1d87baec93
commit
405ed839bb
@ -140,7 +140,7 @@ public class LdapOperationJob : DistributedTaskProgress
|
||||
{
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeAsync(Core.Configuration.Constants.CoreSystem);
|
||||
|
||||
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(_culture);
|
||||
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(_culture);
|
||||
|
@ -665,7 +665,7 @@ public class LdapUserManager
|
||||
var log = scope.ServiceProvider.GetRequiredService<ILogger<LdapUserManager>>();
|
||||
|
||||
tenantManager.SetCurrentTenant(tenant);
|
||||
securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem);
|
||||
await securityContext.AuthenticateMeAsync(Core.Configuration.Constants.CoreSystem);
|
||||
|
||||
var uInfo = await SyncLDAPUser(ldapUserInfo.Item1);
|
||||
|
||||
@ -710,7 +710,7 @@ public class LdapUserManager
|
||||
UserInfo userInfo;
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeAsync(Core.Configuration.Constants.CoreSystem);
|
||||
|
||||
userInfo = await SyncLDAPUser(ldapUserInfo.Item1);
|
||||
|
||||
|
@ -59,13 +59,13 @@ public class BasicAuthHandler : AuthenticationHandler<AuthenticationSchemeOption
|
||||
_passwordHasher = passwordHasher;
|
||||
}
|
||||
|
||||
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
Response.Headers.Add("WWW-Authenticate", "Basic");
|
||||
|
||||
if (!Request.Headers.ContainsKey("Authorization"))
|
||||
{
|
||||
return Task.FromResult(AuthenticateResult.Fail("Authorization header missing."));
|
||||
return AuthenticateResult.Fail("Authorization header missing.");
|
||||
}
|
||||
|
||||
// Get authorization key
|
||||
@ -74,7 +74,7 @@ public class BasicAuthHandler : AuthenticationHandler<AuthenticationSchemeOption
|
||||
|
||||
if (!authHeaderRegex.IsMatch(authorizationHeader))
|
||||
{
|
||||
return Task.FromResult(AuthenticateResult.Fail("Authorization code not formatted properly."));
|
||||
return AuthenticateResult.Fail("Authorization code not formatted properly.");
|
||||
}
|
||||
|
||||
var authBase64 = Encoding.UTF8.GetString(Convert.FromBase64String(authHeaderRegex.Replace(authorizationHeader, "$1")));
|
||||
@ -87,14 +87,14 @@ public class BasicAuthHandler : AuthenticationHandler<AuthenticationSchemeOption
|
||||
var userInfo = _userManager.GetUserByEmail(authUsername);
|
||||
var passwordHash = _passwordHasher.GetClientPassword(authPassword);
|
||||
|
||||
_securityContext.AuthenticateMe(userInfo.Email, passwordHash);
|
||||
await _securityContext.AuthenticateMeAsync(userInfo.Email, passwordHash);
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return Task.FromResult(AuthenticateResult.Fail("The username or password is not correct."));
|
||||
return AuthenticateResult.Fail("The username or password is not correct.");
|
||||
}
|
||||
|
||||
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(Context.User, Scheme.Name)));
|
||||
return AuthenticateResult.Success(new AuthenticationTicket(Context.User, Scheme.Name));
|
||||
}
|
||||
}
|
||||
|
@ -58,15 +58,15 @@ public class ConfirmAuthHandler : AuthenticationHandler<AuthenticationSchemeOpti
|
||||
_emailValidationKeyModelHelper = emailValidationKeyModelHelper;
|
||||
}
|
||||
|
||||
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||
{
|
||||
var emailValidationKeyModel = _emailValidationKeyModelHelper.GetModel();
|
||||
|
||||
if (!emailValidationKeyModel.Type.HasValue)
|
||||
{
|
||||
return _securityContext.IsAuthenticated
|
||||
? Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)))
|
||||
: Task.FromResult(AuthenticateResult.Fail(new AuthenticationException(nameof(HttpStatusCode.Unauthorized))));
|
||||
? AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name))
|
||||
: AuthenticateResult.Fail(new AuthenticationException(nameof(HttpStatusCode.Unauthorized)));
|
||||
}
|
||||
|
||||
EmailValidationKeyProvider.ValidationResult checkKeyResult;
|
||||
@ -112,7 +112,7 @@ public class ConfirmAuthHandler : AuthenticationHandler<AuthenticationSchemeOpti
|
||||
userId = _securityContext.CurrentAccount.ID;
|
||||
}
|
||||
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId, claims);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId, claims);
|
||||
}
|
||||
|
||||
var result = checkKeyResult switch
|
||||
@ -121,6 +121,6 @@ public class ConfirmAuthHandler : AuthenticationHandler<AuthenticationSchemeOpti
|
||||
_ => AuthenticateResult.Fail(new AuthenticationException(nameof(HttpStatusCode.Unauthorized)))
|
||||
};
|
||||
|
||||
return Task.FromResult(result);
|
||||
return result;
|
||||
}
|
||||
}
|
@ -215,12 +215,12 @@ public class ApiContext : ICloneable
|
||||
SortBy, SortDescending, FilterBy, FilterOp, FilterValue, UpdatedSince.Ticks, FilterToType);
|
||||
}
|
||||
|
||||
public void AuthByClaim()
|
||||
public async Task AuthByClaimAsync()
|
||||
{
|
||||
var id = _httpContextAccessor.HttpContext.User.Claims.FirstOrDefault(r => r.Type == ClaimTypes.Sid);
|
||||
if (Guid.TryParse(id?.Value, out var userId))
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ public abstract class BaseStartup
|
||||
|
||||
options.Events = new JwtBearerEvents
|
||||
{
|
||||
OnTokenValidated = ctx =>
|
||||
OnTokenValidated = async ctx =>
|
||||
{
|
||||
using var scope = ctx.HttpContext.RequestServices.CreateScope();
|
||||
|
||||
@ -213,9 +213,7 @@ public abstract class BaseStartup
|
||||
|
||||
var userId = new Guid(claimUserId);
|
||||
|
||||
securityContext.AuthenticateMeWithoutCookie(userId, ctx.Principal.Claims.ToList());
|
||||
|
||||
return Task.CompletedTask;
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(userId, ctx.Principal.Claims.ToList());
|
||||
}
|
||||
};
|
||||
})
|
||||
|
@ -53,7 +53,7 @@ public class PaymentFilter : IResourceFilter
|
||||
var header = context.HttpContext.Request.Headers["Payment-Info"];
|
||||
if (string.IsNullOrEmpty(header) || (bool.TryParse(header, out var flag) && flag))
|
||||
{
|
||||
if (_tenantExtra.IsNotPaid(false))
|
||||
if (_tenantExtra.IsNotPaidAsync(false).Result)
|
||||
{
|
||||
context.Result = new StatusCodeResult((int)HttpStatusCode.PaymentRequired);
|
||||
_logger.WarningPaymentRequired(context.HttpContext.Request.Url());
|
||||
|
@ -205,7 +205,7 @@ public class EmployeeFullDtoHelper : EmployeeDtoHelper
|
||||
|
||||
if (quotaSettings.EnableUserQuota)
|
||||
{
|
||||
result.UsedSpace = Math.Max(0, _quotaService.FindUserQuotaRows(_context.Tenant.Id, userInfo.Id).Where(r => !string.IsNullOrEmpty(r.Tag)).Sum(r => r.Counter));
|
||||
result.UsedSpace = Math.Max(0, (await _quotaService.FindUserQuotaRowsAsync(_context.Tenant.Id, userInfo.Id)).Where(r => !string.IsNullOrEmpty(r.Tag)).Sum(r => r.Counter));
|
||||
var userQuotaSettings = _settingsManager.Load<UserQuotaSettings>(userInfo);
|
||||
result.QuotaLimit = userQuotaSettings != null ? userQuotaSettings.UserQuota : quotaSettings.DefaultUserQuota;
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ namespace ASC.Core.Billing;
|
||||
public interface ITariffService
|
||||
{
|
||||
IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo(params string[] productIds);
|
||||
IEnumerable<PaymentInfo> GetPayments(int tenantId);
|
||||
Tariff GetTariff(int tenantId, bool withRequestToPaymentSystem = true);
|
||||
Task<Uri> GetShoppingUri(int tenant, string currency = null, string language = null, string customerEmail = null, Dictionary<string, int> quantity = null, string backUrl = null);
|
||||
Uri GetShoppingUri(int? tenant, int quotaId, string affiliateId, string currency = null, string language = null, string customerId = null, string quantity = null);
|
||||
Task<IEnumerable<PaymentInfo>> GetPaymentsAsync(int tenantId);
|
||||
Task<Tariff> GetTariffAsync(int tenantId, bool withRequestToPaymentSystem = true);
|
||||
Task<Uri> GetShoppingUriAsync(int tenant, string currency = null, string language = null, string customerEmail = null, Dictionary<string, int> quantity = null, string backUrl = null);
|
||||
Task<Uri> GetShoppingUriAsync(int? tenant, int quotaId, string affiliateId, string currency = null, string language = null, string customerId = null, string quantity = null);
|
||||
Uri GetShoppingUri(string[] productIds, string affiliateId = null, string currency = null, string language = null, string customerId = null, string quantity = null);
|
||||
void ClearCache(int tenantId);
|
||||
void DeleteDefaultBillingInfo();
|
||||
void SetTariff(int tenantId, Tariff tariff);
|
||||
Task DeleteDefaultBillingInfoAsync();
|
||||
Task SetTariffAsync(int tenantId, Tariff tariff);
|
||||
Uri GetAccountLink(int tenant, string backUrl);
|
||||
Task<bool> PaymentChange(int tenant, Dictionary<string, int> quantity);
|
||||
Task<bool> PaymentChangeAsync(int tenant, Dictionary<string, int> quantity);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ public class LicenseReader
|
||||
return File.OpenRead(path);
|
||||
}
|
||||
|
||||
public void RejectLicense()
|
||||
public Task RejectLicenseAsync()
|
||||
{
|
||||
if (File.Exists(_licensePathTemp))
|
||||
{
|
||||
@ -95,10 +95,10 @@ public class LicenseReader
|
||||
File.Delete(LicensePath);
|
||||
}
|
||||
|
||||
_tariffService.DeleteDefaultBillingInfo();
|
||||
return _tariffService.DeleteDefaultBillingInfoAsync();
|
||||
}
|
||||
|
||||
public void RefreshLicense()
|
||||
public async Task RefreshLicenseAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -121,7 +121,7 @@ public class LicenseReader
|
||||
var licenseJsonString = reader.ReadToEnd();
|
||||
var license = License.Parse(licenseJsonString);
|
||||
|
||||
LicenseToDB(license);
|
||||
await LicenseToDBAsync(license);
|
||||
|
||||
if (temp)
|
||||
{
|
||||
@ -188,13 +188,13 @@ public class LicenseReader
|
||||
return license.DueDate.Date;
|
||||
}
|
||||
|
||||
private void LicenseToDB(License license)
|
||||
private async Task LicenseToDBAsync(License license)
|
||||
{
|
||||
Validate(license);
|
||||
|
||||
CustomerId = license.CustomerId;
|
||||
|
||||
var defaultQuota = _tenantManager.GetTenantQuota(Tenant.DefaultTenant);
|
||||
var defaultQuota = await _tenantManager.GetTenantQuotaAsync(Tenant.DefaultTenant);
|
||||
|
||||
var quota = new TenantQuota(-1000)
|
||||
{
|
||||
@ -208,7 +208,7 @@ public class LicenseReader
|
||||
Trial = license.Trial
|
||||
};
|
||||
|
||||
_tenantManager.SaveTenantQuota(quota);
|
||||
await _tenantManager.SaveTenantQuotaAsync(quota);
|
||||
|
||||
var tariff = new Tariff
|
||||
{
|
||||
@ -216,7 +216,7 @@ public class LicenseReader
|
||||
DueDate = license.DueDate,
|
||||
};
|
||||
|
||||
_tariffService.SetTariff(-1, tariff);
|
||||
await _tariffService.SetTariffAsync(-1, tariff);
|
||||
}
|
||||
|
||||
private void LogError(Exception error)
|
||||
|
@ -24,6 +24,8 @@
|
||||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
||||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ASC.Core.Billing;
|
||||
|
||||
[Singletone]
|
||||
@ -156,7 +158,7 @@ public class TariffService : ITariffService
|
||||
//}
|
||||
}
|
||||
|
||||
public Tariff GetTariff(int tenantId, bool withRequestToPaymentSystem = true)
|
||||
public async Task<Tariff> GetTariffAsync(int tenantId, bool withRequestToPaymentSystem = true)
|
||||
{
|
||||
//single tariff for all portals
|
||||
if (_coreBaseSettings.Standalone)
|
||||
@ -164,13 +166,13 @@ public class TariffService : ITariffService
|
||||
tenantId = -1;
|
||||
}
|
||||
|
||||
var tariff = GetTariffFromCache(tenantId);
|
||||
var tariff = await GetTariffFromCacheAsync(tenantId);
|
||||
int? tariffId = null;
|
||||
|
||||
if (tariff == null)
|
||||
{
|
||||
tariff = GetBillingInfo(tenantId) ?? CreateDefault();
|
||||
tariff = CalculateTariff(tenantId, tariff);
|
||||
tariff = await GetBillingInfoAsync(tenantId) ?? await CreateDefaultAsync();
|
||||
tariff = await CalculateTariffAsync(tenantId, tariff);
|
||||
|
||||
if (string.IsNullOrEmpty(_cache.Get<string>(GetTariffNeedToUpdateCacheKey(tenantId))))
|
||||
{
|
||||
@ -188,12 +190,12 @@ public class TariffService : ITariffService
|
||||
throw new BillingNotFoundException("Empty PaymentLast");
|
||||
}
|
||||
|
||||
var asynctariff = CreateDefault(true);
|
||||
var asynctariff = await CreateDefaultAsync(true);
|
||||
string email = null;
|
||||
|
||||
foreach (var currentPayment in currentPayments)
|
||||
{
|
||||
var quota = _quotaService.GetTenantQuotas().SingleOrDefault(q => q.ProductId == currentPayment.ProductId.ToString());
|
||||
var quota = (await _quotaService.GetTenantQuotasAsync()).SingleOrDefault(q => q.ProductId == currentPayment.ProductId.ToString());
|
||||
if (quota == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Quota with id {currentPayment.ProductId} not found for portal {GetPortalId(tenantId)}.");
|
||||
@ -213,9 +215,9 @@ public class TariffService : ITariffService
|
||||
asynctariff.CustomerId = email;
|
||||
}
|
||||
|
||||
if (SaveBillingInfo(tenantId, asynctariff))
|
||||
if (await SaveBillingInfoAsync(tenantId, asynctariff))
|
||||
{
|
||||
asynctariff = CalculateTariff(tenantId, asynctariff);
|
||||
asynctariff = await CalculateTariffAsync(tenantId, asynctariff);
|
||||
tariff = asynctariff;
|
||||
tariffId = asynctariff.Id;
|
||||
}
|
||||
@ -224,7 +226,7 @@ public class TariffService : ITariffService
|
||||
{
|
||||
var freeTariff = tariff.Quotas.FirstOrDefault(tariffRow =>
|
||||
{
|
||||
var q = _quotaService.GetTenantQuota(tariffRow.Id);
|
||||
var q = _quotaService.GetTenantQuotaAsync(tariffRow.Id).Result;
|
||||
return q == null
|
||||
|| (_trialEnabled && q.Trial)
|
||||
|| q.Free
|
||||
@ -232,7 +234,7 @@ public class TariffService : ITariffService
|
||||
|| q.Custom;
|
||||
});
|
||||
|
||||
var asynctariff = CreateDefault();
|
||||
var asynctariff = await CreateDefaultAsync();
|
||||
|
||||
if (freeTariff == null)
|
||||
{
|
||||
@ -240,9 +242,9 @@ public class TariffService : ITariffService
|
||||
asynctariff.State = TariffState.NotPaid;
|
||||
}
|
||||
|
||||
if (SaveBillingInfo(tenantId, asynctariff))
|
||||
if (await SaveBillingInfoAsync(tenantId, asynctariff))
|
||||
{
|
||||
asynctariff = CalculateTariff(tenantId, asynctariff);
|
||||
asynctariff = await CalculateTariffAsync(tenantId, asynctariff);
|
||||
tariff = asynctariff;
|
||||
tariffId = asynctariff.Id;
|
||||
}
|
||||
@ -262,7 +264,7 @@ public class TariffService : ITariffService
|
||||
return tariff;
|
||||
}
|
||||
|
||||
public async Task<bool> PaymentChange(int tenantId, Dictionary<string, int> quantity)
|
||||
public async Task<bool> PaymentChangeAsync(int tenantId, Dictionary<string, int> quantity)
|
||||
{
|
||||
if (quantity == null || !quantity.Any()
|
||||
|| !_billingClient.Configured)
|
||||
@ -270,10 +272,10 @@ public class TariffService : ITariffService
|
||||
return false;
|
||||
}
|
||||
|
||||
var allQuotas = _quotaService.GetTenantQuotas().Where(q => !string.IsNullOrEmpty(q.ProductId));
|
||||
var allQuotas = (await _quotaService.GetTenantQuotasAsync()).Where(q => !string.IsNullOrEmpty(q.ProductId));
|
||||
var newQuotas = quantity.Keys.Select(name => allQuotas.FirstOrDefault(q => q.Name == name));
|
||||
|
||||
var tariff = GetTariff(tenantId);
|
||||
var tariff = await GetTariffAsync(tenantId);
|
||||
|
||||
// update the quantity of present quotas
|
||||
TenantQuota updatedQuota = null;
|
||||
@ -282,7 +284,7 @@ public class TariffService : ITariffService
|
||||
var quotaId = tariffRow.Id;
|
||||
var qty = tariffRow.Quantity;
|
||||
|
||||
var quota = _quotaService.GetTenantQuota(quotaId);
|
||||
var quota = await _quotaService.GetTenantQuotaAsync(quotaId);
|
||||
|
||||
var mustUpdateQuota = newQuotas.FirstOrDefault(q => q.Tenant == quota.Tenant);
|
||||
if (mustUpdateQuota != null)
|
||||
@ -306,7 +308,7 @@ public class TariffService : ITariffService
|
||||
updatedQuota += quota;
|
||||
}
|
||||
|
||||
await updatedQuota.Check(_serviceProvider);
|
||||
await updatedQuota.CheckAsync(_serviceProvider);
|
||||
|
||||
var productIds = newQuotas.Select(q => q.ProductId);
|
||||
|
||||
@ -330,18 +332,18 @@ public class TariffService : ITariffService
|
||||
}
|
||||
|
||||
|
||||
public void SetTariff(int tenantId, Tariff tariff)
|
||||
public async Task SetTariffAsync(int tenantId, Tariff tariff)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(tariff);
|
||||
|
||||
List<TenantQuota> quotas = null;
|
||||
if (tariff.Quotas == null ||
|
||||
(quotas = tariff.Quotas.Select(q => _quotaService.GetTenantQuota(q.Id)).ToList()).Any(q => q == null))
|
||||
(quotas = tariff.Quotas.Select(q => _quotaService.GetTenantQuotaAsync(q.Id).Result).ToList()).Any(q => q == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SaveBillingInfo(tenantId, tariff);
|
||||
await SaveBillingInfoAsync(tenantId, tariff);
|
||||
|
||||
if (quotas.Any(q => q.Trial))
|
||||
{
|
||||
@ -355,16 +357,16 @@ public class TariffService : ITariffService
|
||||
}
|
||||
}
|
||||
|
||||
internal Tariff GetTariffFromCache(int tenantId)
|
||||
internal Task<Tariff> GetTariffFromCacheAsync(int tenantId)
|
||||
{
|
||||
var id = _cache.Get<string>(GetTariffCacheKey(tenantId));
|
||||
|
||||
if (!int.TryParse(id, out var tariffId))
|
||||
{
|
||||
return null;
|
||||
return Task.FromResult<Tariff>(null);
|
||||
}
|
||||
|
||||
return GetBillingInfo(tenantId, tariffId);
|
||||
return GetBillingInfoAsync(tenantId, tariffId);
|
||||
}
|
||||
|
||||
|
||||
@ -394,7 +396,7 @@ public class TariffService : ITariffService
|
||||
_notify.Publish(new TariffCacheItem { TenantId = tenantId, TariffId = -1 }, CacheNotifyAction.Remove);
|
||||
}
|
||||
|
||||
public IEnumerable<PaymentInfo> GetPayments(int tenantId)
|
||||
public async Task<IEnumerable<PaymentInfo>> GetPaymentsAsync(int tenantId)
|
||||
{
|
||||
var key = GetBillingPaymentCacheKey(tenantId);
|
||||
var payments = _cache.Get<List<PaymentInfo>>(key);
|
||||
@ -405,7 +407,7 @@ public class TariffService : ITariffService
|
||||
{
|
||||
try
|
||||
{
|
||||
var quotas = _quotaService.GetTenantQuotas();
|
||||
var quotas = await _quotaService.GetTenantQuotasAsync();
|
||||
foreach (var pi in _billingClient.GetPayments(GetPortalId(tenantId)))
|
||||
{
|
||||
var quota = quotas.SingleOrDefault(q => q.ProductId == pi.ProductRef.ToString());
|
||||
@ -428,7 +430,7 @@ public class TariffService : ITariffService
|
||||
return payments;
|
||||
}
|
||||
|
||||
public async Task<Uri> GetShoppingUri(int tenant, string currency = null, string language = null, string customerEmail = null, Dictionary<string, int> quantity = null, string backUrl = null)
|
||||
public async Task<Uri> GetShoppingUriAsync(int tenant, string currency = null, string language = null, string customerEmail = null, Dictionary<string, int> quantity = null, string backUrl = null)
|
||||
{
|
||||
var hasQuantity = quantity != null && quantity.Any();
|
||||
var key = "shopingurl_" + (hasQuantity ? string.Join('_', quantity.Keys.ToArray()) : "all");
|
||||
@ -438,7 +440,7 @@ public class TariffService : ITariffService
|
||||
url = string.Empty;
|
||||
if (_billingClient.Configured)
|
||||
{
|
||||
var allQuotas = _quotaService.GetTenantQuotas().Where(q => !string.IsNullOrEmpty(q.ProductId) && q.Visible);
|
||||
var allQuotas = (await _quotaService.GetTenantQuotasAsync()).Where(q => !string.IsNullOrEmpty(q.ProductId) && q.Visible);
|
||||
var newQuotas = quantity.Select(item => allQuotas.FirstOrDefault(q => q.Name == item.Key));
|
||||
|
||||
TenantQuota updatedQuota = null;
|
||||
@ -452,7 +454,7 @@ public class TariffService : ITariffService
|
||||
updatedQuota += quota;
|
||||
}
|
||||
|
||||
await updatedQuota.Check(_serviceProvider);
|
||||
await updatedQuota.CheckAsync(_serviceProvider);
|
||||
|
||||
var productIds = newQuotas.Select(q => q.ProductId);
|
||||
|
||||
@ -496,9 +498,9 @@ public class TariffService : ITariffService
|
||||
return result;
|
||||
}
|
||||
|
||||
public Uri GetShoppingUri(int? tenant, int quotaId, string affiliateId, string currency = null, string language = null, string customerId = null, string quantity = null)
|
||||
public async Task<Uri> GetShoppingUriAsync(int? tenant, int quotaId, string affiliateId, string currency = null, string language = null, string customerId = null, string quantity = null)
|
||||
{
|
||||
var quota = _quotaService.GetTenantQuota(quotaId);
|
||||
var quota = await _quotaService.GetTenantQuotaAsync(quotaId);
|
||||
if (quota == null)
|
||||
{
|
||||
return null;
|
||||
@ -515,7 +517,7 @@ public class TariffService : ITariffService
|
||||
{
|
||||
try
|
||||
{
|
||||
var products = _quotaService.GetTenantQuotas()
|
||||
var products = (await _quotaService.GetTenantQuotasAsync())
|
||||
.Where(q => !string.IsNullOrEmpty(q.ProductId) && q.Visible == quota.Visible)
|
||||
.Select(q => q.ProductId)
|
||||
.ToArray();
|
||||
@ -659,9 +661,9 @@ public class TariffService : ITariffService
|
||||
}
|
||||
|
||||
|
||||
private Tariff GetBillingInfo(int? tenant = null, int? id = null)
|
||||
private async Task<Tariff> GetBillingInfoAsync(int? tenant = null, int? id = null)
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
var q = coreDbContext.Tariffs.AsQueryable();
|
||||
|
||||
if (tenant.HasValue)
|
||||
@ -681,32 +683,32 @@ public class TariffService : ITariffService
|
||||
return null;
|
||||
}
|
||||
|
||||
var tariff = CreateDefault(true);
|
||||
var tariff = await CreateDefaultAsync(true);
|
||||
tariff.DueDate = r.Stamp.Year < 9999 ? r.Stamp : DateTime.MaxValue;
|
||||
tariff.CustomerId = r.CustomerId;
|
||||
|
||||
var tariffRows = coreDbContext.TariffRows
|
||||
.Where(row => row.TariffId == r.Id && row.Tenant == tenant);
|
||||
|
||||
tariff.Quotas = tariffRows.Select(r => new Quota(r.Quota, r.Quantity)).ToList();
|
||||
|
||||
tariff.Quotas = await tariffRows.Select(r => new Quota(r.Quota, r.Quantity)).ToListAsync();
|
||||
|
||||
return tariff;
|
||||
}
|
||||
|
||||
private bool SaveBillingInfo(int tenant, Tariff tariffInfo)
|
||||
private async Task<bool> SaveBillingInfoAsync(int tenant, Tariff tariffInfo)
|
||||
{
|
||||
var inserted = false;
|
||||
var currentTariff = GetBillingInfo(tenant);
|
||||
var currentTariff = await GetBillingInfoAsync(tenant);
|
||||
if (!tariffInfo.EqualsByParams(currentTariff))
|
||||
{
|
||||
try
|
||||
{
|
||||
using var dbContext = _dbContextFactory.CreateDbContext();
|
||||
using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
var strategy = dbContext.Database.CreateExecutionStrategy();
|
||||
|
||||
strategy.Execute(() =>
|
||||
await strategy.ExecuteAsync(async () =>
|
||||
{
|
||||
using var dbContext = _dbContextFactory.CreateDbContext();
|
||||
using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
using var tx = dbContext.Database.BeginTransaction();
|
||||
|
||||
var stamp = tariffInfo.DueDate;
|
||||
@ -734,12 +736,12 @@ public class TariffService : ITariffService
|
||||
efTariff.CustomerId = "";
|
||||
}
|
||||
|
||||
efTariff = dbContext.AddOrUpdate(dbContext.Tariffs, efTariff);
|
||||
dbContext.SaveChanges();
|
||||
efTariff = await dbContext.AddOrUpdateAsync(q => q.Tariffs, efTariff);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
foreach (var q in tariffInfo.Quotas)
|
||||
{
|
||||
dbContext.AddOrUpdate(dbContext.TariffRows, new DbTariffRow
|
||||
await dbContext.AddOrUpdateAsync(q => q.TariffRows, new DbTariffRow
|
||||
{
|
||||
TariffId = efTariff.Id,
|
||||
Quota = q.Id,
|
||||
@ -748,11 +750,11 @@ public class TariffService : ITariffService
|
||||
});
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
inserted = true;
|
||||
|
||||
tx.Commit();
|
||||
await tx.CommitAsync();
|
||||
});
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
@ -776,12 +778,12 @@ public class TariffService : ITariffService
|
||||
return inserted;
|
||||
}
|
||||
|
||||
public void DeleteDefaultBillingInfo()
|
||||
public async Task DeleteDefaultBillingInfoAsync()
|
||||
{
|
||||
const int tenant = Tenant.DefaultTenant;
|
||||
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
var tariffs = coreDbContext.Tariffs.Where(r => r.Tenant == tenant).ToList();
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
var tariffs = await coreDbContext.Tariffs.Where(r => r.Tenant == tenant).ToListAsync();
|
||||
|
||||
foreach (var t in tariffs)
|
||||
{
|
||||
@ -789,19 +791,19 @@ public class TariffService : ITariffService
|
||||
t.CreateOn = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
coreDbContext.SaveChanges();
|
||||
await coreDbContext.SaveChangesAsync();
|
||||
|
||||
ClearCache(tenant);
|
||||
}
|
||||
|
||||
|
||||
private Tariff CalculateTariff(int tenantId, Tariff tariff)
|
||||
private async Task<Tariff> CalculateTariffAsync(int tenantId, Tariff tariff)
|
||||
{
|
||||
tariff.State = TariffState.Paid;
|
||||
|
||||
if (tariff.Quotas.Count == 0)
|
||||
{
|
||||
AddDefaultQuota(tariff);
|
||||
await AddDefaultQuotaAsync(tariff);
|
||||
}
|
||||
|
||||
var delay = 0;
|
||||
@ -809,7 +811,7 @@ public class TariffService : ITariffService
|
||||
|
||||
if (_trialEnabled)
|
||||
{
|
||||
var trial = tariff.Quotas.Exists(q => _quotaService.GetTenantQuota(q.Id).Trial);
|
||||
var trial = tariff.Quotas.Exists(q => _quotaService.GetTenantQuotaAsync(q.Id).Result.Trial);
|
||||
if (trial)
|
||||
{
|
||||
setDelay = false;
|
||||
@ -878,7 +880,7 @@ public class TariffService : ITariffService
|
||||
return _coreSettings.GetCampaign(tenant);
|
||||
}
|
||||
|
||||
private Tariff CreateDefault(bool empty = false)
|
||||
private async Task<Tariff> CreateDefaultAsync(bool empty = false)
|
||||
{
|
||||
var result = new Tariff
|
||||
{
|
||||
@ -892,15 +894,15 @@ public class TariffService : ITariffService
|
||||
|
||||
if (!empty)
|
||||
{
|
||||
AddDefaultQuota(result);
|
||||
await AddDefaultQuotaAsync(result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void AddDefaultQuota(Tariff tariff)
|
||||
private async Task AddDefaultQuotaAsync(Tariff tariff)
|
||||
{
|
||||
var allQuotas = _quotaService.GetTenantQuotas();
|
||||
var allQuotas = await _quotaService.GetTenantQuotasAsync();
|
||||
TenantQuota toAdd = null;
|
||||
if (_trialEnabled)
|
||||
{
|
||||
|
@ -24,6 +24,8 @@
|
||||
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
||||
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
||||
|
||||
using ASC.Core.Billing;
|
||||
|
||||
namespace ASC.Core.Caching;
|
||||
|
||||
[Singletone]
|
||||
@ -87,42 +89,48 @@ class CachedQuotaService : IQuotaService
|
||||
CacheNotify = quotaServiceCache.CacheNotify;
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuota> GetTenantQuotas()
|
||||
public Task<IEnumerable<TenantQuota>> GetTenantQuotasAsync()
|
||||
{
|
||||
var quotas = Cache.Get<IEnumerable<TenantQuota>>(QuotaServiceCache.KeyQuota);
|
||||
if (quotas == null)
|
||||
{
|
||||
quotas = Service.GetTenantQuotas();
|
||||
if (QuotaServiceCache.QuotaCacheEnabled)
|
||||
{
|
||||
Cache.Insert(QuotaServiceCache.KeyQuota, quotas, DateTime.UtcNow.Add(_cacheExpiration));
|
||||
}
|
||||
return GetTenantQuotasInternalAsync();
|
||||
}
|
||||
|
||||
return Task.FromResult(quotas);
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<TenantQuota>> GetTenantQuotasInternalAsync()
|
||||
{
|
||||
var quotas = await Service.GetTenantQuotasAsync();
|
||||
if (QuotaServiceCache.QuotaCacheEnabled)
|
||||
{
|
||||
Cache.Insert(QuotaServiceCache.KeyQuota, quotas, DateTime.UtcNow.Add(_cacheExpiration));
|
||||
}
|
||||
return quotas;
|
||||
}
|
||||
|
||||
public TenantQuota GetTenantQuota(int tenant)
|
||||
public async Task<TenantQuota> GetTenantQuotaAsync(int tenant)
|
||||
{
|
||||
return GetTenantQuotas().SingleOrDefault(q => q.Tenant == tenant);
|
||||
return (await GetTenantQuotasAsync()).SingleOrDefault(q => q.Tenant == tenant);
|
||||
}
|
||||
|
||||
public TenantQuota SaveTenantQuota(TenantQuota quota)
|
||||
public async Task<TenantQuota> SaveTenantQuotaAsync(TenantQuota quota)
|
||||
{
|
||||
var q = Service.SaveTenantQuota(quota);
|
||||
var q = await Service.SaveTenantQuotaAsync(quota);
|
||||
CacheNotify.Publish(new QuotaCacheItem { Key = QuotaServiceCache.KeyQuota }, CacheNotifyAction.Any);
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
public void RemoveTenantQuota(int tenant)
|
||||
public Task RemoveTenantQuotaAsync(int tenant)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void SetTenantQuotaRow(TenantQuotaRow row, bool exchange)
|
||||
public async Task SetTenantQuotaRowAsync(TenantQuotaRow row, bool exchange)
|
||||
{
|
||||
Service.SetTenantQuotaRow(row, exchange);
|
||||
await Service.SetTenantQuotaRowAsync(row, exchange);
|
||||
CacheNotify.Publish(new QuotaCacheItem { Key = GetKey(row.Tenant) }, CacheNotifyAction.Any);
|
||||
|
||||
if (row.UserId != Guid.Empty)
|
||||
@ -131,28 +139,28 @@ class CachedQuotaService : IQuotaService
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuotaRow> FindTenantQuotaRows(int tenantId)
|
||||
public async Task<IEnumerable<TenantQuotaRow>> FindTenantQuotaRowsAsync(int tenantId)
|
||||
{
|
||||
var key = GetKey(tenantId);
|
||||
var result = Cache.Get<IEnumerable<TenantQuotaRow>>(key);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = Service.FindTenantQuotaRows(tenantId);
|
||||
result = await Service.FindTenantQuotaRowsAsync(tenantId);
|
||||
Cache.Insert(key, result, DateTime.UtcNow.Add(_cacheExpiration));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuotaRow> FindUserQuotaRows(int tenantId, Guid userId)
|
||||
public async Task<IEnumerable<TenantQuotaRow>> FindUserQuotaRowsAsync(int tenantId, Guid userId)
|
||||
{
|
||||
var key = GetKey(tenantId, userId);
|
||||
var result = Cache.Get<IEnumerable<TenantQuotaRow>>(key);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
result = Service.FindUserQuotaRows(tenantId, userId);
|
||||
result = await Service.FindUserQuotaRowsAsync(tenantId, userId);
|
||||
Cache.Insert(key, result, DateTime.UtcNow.Add(_cacheExpiration));
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class TenantManager
|
||||
internal CoreBaseSettings CoreBaseSettings { get; set; }
|
||||
internal CoreSettings CoreSettings { get; set; }
|
||||
|
||||
private readonly static object _lock = new object();
|
||||
private readonly static SemaphoreSlim _semaphore = new SemaphoreSlim(1);
|
||||
|
||||
static TenantManager()
|
||||
{
|
||||
@ -273,34 +273,34 @@ public class TenantManager
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<TenantQuota> GetTenantQuotas()
|
||||
public Task<IEnumerable<TenantQuota>> GetTenantQuotasAsync()
|
||||
{
|
||||
return GetTenantQuotas(false);
|
||||
return GetTenantQuotasAsync(false);
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuota> GetTenantQuotas(bool all)
|
||||
public async Task<IEnumerable<TenantQuota>> GetTenantQuotasAsync(bool all)
|
||||
{
|
||||
return QuotaService.GetTenantQuotas().Where(q => q.Tenant < 0 && (all || q.Visible)).OrderByDescending(q => q.Tenant).ToList();
|
||||
return (await QuotaService.GetTenantQuotasAsync()).Where(q => q.Tenant < 0 && (all || q.Visible)).OrderByDescending(q => q.Tenant).ToList();
|
||||
}
|
||||
|
||||
public TenantQuota GetCurrentTenantQuota()
|
||||
public Task<TenantQuota> GetCurrentTenantQuotaAsync()
|
||||
{
|
||||
return GetTenantQuota(GetCurrentTenant().Id);
|
||||
return GetTenantQuotaAsync(GetCurrentTenant().Id);
|
||||
}
|
||||
|
||||
public TenantQuota GetTenantQuota(int tenant)
|
||||
public async Task<TenantQuota> GetTenantQuotaAsync(int tenant)
|
||||
{
|
||||
var defaultQuota = QuotaService.GetTenantQuota(tenant) ?? QuotaService.GetTenantQuota(Tenant.DefaultTenant) ?? TenantQuota.Default;
|
||||
var defaultQuota = await QuotaService.GetTenantQuotaAsync(tenant) ?? await QuotaService.GetTenantQuotaAsync(Tenant.DefaultTenant) ?? TenantQuota.Default;
|
||||
if (defaultQuota.Tenant != tenant && TariffService != null)
|
||||
{
|
||||
var tariff = TariffService.GetTariff(tenant);
|
||||
var tariff = await TariffService.GetTariffAsync(tenant);
|
||||
|
||||
TenantQuota currentQuota = null;
|
||||
foreach (var tariffRow in tariff.Quotas)
|
||||
{
|
||||
var qty = tariffRow.Quantity;
|
||||
|
||||
var quota = QuotaService.GetTenantQuota(tariffRow.Id);
|
||||
var quota = await QuotaService.GetTenantQuotaAsync(tariffRow.Id);
|
||||
|
||||
quota *= qty;
|
||||
currentQuota += quota;
|
||||
@ -312,9 +312,9 @@ public class TenantManager
|
||||
return defaultQuota;
|
||||
}
|
||||
|
||||
public IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo()
|
||||
public async Task<IDictionary<string, Dictionary<string, decimal>>> GetProductPriceInfoAsync()
|
||||
{
|
||||
var quotas = GetTenantQuotas(false);
|
||||
var quotas = await GetTenantQuotasAsync(false);
|
||||
var productIds = quotas
|
||||
.Select(p => p.ProductId)
|
||||
.Where(id => !string.IsNullOrEmpty(id))
|
||||
@ -326,23 +326,24 @@ public class TenantManager
|
||||
return result;
|
||||
}
|
||||
|
||||
public TenantQuota SaveTenantQuota(TenantQuota quota)
|
||||
public async Task<TenantQuota> SaveTenantQuotaAsync(TenantQuota quota)
|
||||
{
|
||||
quota = QuotaService.SaveTenantQuota(quota);
|
||||
quota = await QuotaService.SaveTenantQuotaAsync(quota);
|
||||
|
||||
return quota;
|
||||
}
|
||||
|
||||
public void SetTenantQuotaRow(TenantQuotaRow row, bool exchange)
|
||||
public async Task SetTenantQuotaRowAsync(TenantQuotaRow row, bool exchange)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
QuotaService.SetTenantQuotaRow(row, exchange);
|
||||
}
|
||||
await _semaphore.WaitAsync();
|
||||
|
||||
await QuotaService.SetTenantQuotaRowAsync(row, exchange);
|
||||
|
||||
_semaphore.Release();
|
||||
}
|
||||
|
||||
public List<TenantQuotaRow> FindTenantQuotaRows(int tenantId)
|
||||
public async Task<List<TenantQuotaRow>> FindTenantQuotaRowsAsync(int tenantId)
|
||||
{
|
||||
return QuotaService.FindTenantQuotaRows(tenantId).ToList();
|
||||
return (await QuotaService.FindTenantQuotaRowsAsync(tenantId)).ToList();
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class SecurityContext
|
||||
}
|
||||
|
||||
|
||||
public string AuthenticateMe(string login, string passwordHash, Func<int> funcLoginEvent = null)
|
||||
public Task<string> AuthenticateMeAsync(string login, string passwordHash, Func<int> funcLoginEvent = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(login);
|
||||
ArgumentNullException.ThrowIfNull(passwordHash);
|
||||
@ -92,7 +92,7 @@ public class SecurityContext
|
||||
var tenantid = _tenantManager.GetCurrentTenant().Id;
|
||||
var u = _userManager.GetUsersByPasswordHash(tenantid, login, passwordHash);
|
||||
|
||||
return AuthenticateMe(new UserAccount(u, tenantid, _userFormatter), funcLoginEvent);
|
||||
return AuthenticateMeAsync(new UserAccount(u, tenantid, _userFormatter), funcLoginEvent);
|
||||
}
|
||||
|
||||
public async Task<bool> AuthenticateMe(string cookie)
|
||||
@ -168,7 +168,7 @@ public class SecurityContext
|
||||
return false;
|
||||
}
|
||||
|
||||
AuthenticateMeWithoutCookie(new UserAccount(new UserInfo { Id = userid }, tenant, _userFormatter));
|
||||
await AuthenticateMeWithoutCookieAsync(new UserAccount(new UserInfo { Id = userid }, tenant, _userFormatter));
|
||||
return true;
|
||||
}
|
||||
catch (InvalidCredentialException ice)
|
||||
@ -188,15 +188,15 @@ public class SecurityContext
|
||||
return false;
|
||||
}
|
||||
|
||||
public string AuthenticateMe(Guid userId, Func<int> funcLoginEvent = null, List<Claim> additionalClaims = null)
|
||||
public Task<string> AuthenticateMeAsync(Guid userId, Func<int> funcLoginEvent = null, List<Claim> additionalClaims = null)
|
||||
{
|
||||
var account = _authentication.GetAccountByID(_tenantManager.GetCurrentTenant().Id, userId);
|
||||
return AuthenticateMe(account, funcLoginEvent, additionalClaims);
|
||||
return AuthenticateMeAsync(account, funcLoginEvent, additionalClaims);
|
||||
}
|
||||
|
||||
public string AuthenticateMe(IAccount account, Func<int> funcLoginEvent = null, List<Claim> additionalClaims = null)
|
||||
public async Task<string> AuthenticateMeAsync(IAccount account, Func<int> funcLoginEvent = null, List<Claim> additionalClaims = null)
|
||||
{
|
||||
AuthenticateMeWithoutCookie(account, additionalClaims);
|
||||
await AuthenticateMeWithoutCookieAsync(account, additionalClaims);
|
||||
|
||||
string cookie = null;
|
||||
|
||||
@ -214,7 +214,7 @@ public class SecurityContext
|
||||
return cookie;
|
||||
}
|
||||
|
||||
public void AuthenticateMeWithoutCookie(IAccount account, List<Claim> additionalClaims = null)
|
||||
public async Task AuthenticateMeWithoutCookieAsync(IAccount account, List<Claim> additionalClaims = null)
|
||||
{
|
||||
if (account == null || account.Equals(Configuration.Constants.Guest))
|
||||
{
|
||||
@ -246,7 +246,7 @@ public class SecurityContext
|
||||
// for LDAP users only
|
||||
if (u.Sid != null)
|
||||
{
|
||||
if (!_tenantManager.GetTenantQuota(tenant.Id).Ldap)
|
||||
if (!(await _tenantManager.GetTenantQuotaAsync(tenant.Id)).Ldap)
|
||||
{
|
||||
throw new BillingException("Your tariff plan does not support this option.", "Ldap");
|
||||
}
|
||||
@ -277,11 +277,11 @@ public class SecurityContext
|
||||
_authContext.Principal = new CustomClaimsPrincipal(new ClaimsIdentity(account, claims), account);
|
||||
}
|
||||
|
||||
public void AuthenticateMeWithoutCookie(Guid userId, List<Claim> additionalClaims = null)
|
||||
public Task AuthenticateMeWithoutCookieAsync(Guid userId, List<Claim> additionalClaims = null)
|
||||
{
|
||||
var account = _authentication.GetAccountByID(_tenantManager.GetCurrentTenant().Id, userId);
|
||||
|
||||
AuthenticateMeWithoutCookie(account, additionalClaims);
|
||||
return AuthenticateMeWithoutCookieAsync(account, additionalClaims);
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
|
@ -29,11 +29,11 @@ namespace ASC.Core;
|
||||
[Scope(typeof(CachedQuotaService))]
|
||||
public interface IQuotaService
|
||||
{
|
||||
IEnumerable<TenantQuota> GetTenantQuotas();
|
||||
IEnumerable<TenantQuotaRow> FindTenantQuotaRows(int tenantId);
|
||||
IEnumerable<TenantQuotaRow> FindUserQuotaRows(int tenantId, Guid userId);
|
||||
TenantQuota GetTenantQuota(int id);
|
||||
TenantQuota SaveTenantQuota(TenantQuota quota);
|
||||
void RemoveTenantQuota(int id);
|
||||
void SetTenantQuotaRow(TenantQuotaRow row, bool exchange);
|
||||
Task<IEnumerable<TenantQuota>> GetTenantQuotasAsync();
|
||||
Task<IEnumerable<TenantQuotaRow>> FindTenantQuotaRowsAsync(int tenantId);
|
||||
Task<IEnumerable<TenantQuotaRow>> FindUserQuotaRowsAsync(int tenantId, Guid userId);
|
||||
Task<TenantQuota> GetTenantQuotaAsync(int id);
|
||||
Task<TenantQuota> SaveTenantQuotaAsync(TenantQuota quota);
|
||||
Task RemoveTenantQuotaAsync(int id);
|
||||
Task SetTenantQuotaRowAsync(TenantQuotaRow row, bool exchange);
|
||||
}
|
||||
|
@ -37,105 +37,88 @@ class DbQuotaService : IQuotaService
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuota> GetTenantQuotas()
|
||||
public async Task<IEnumerable<TenantQuota>> GetTenantQuotasAsync()
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
return coreDbContext.Quotas
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await coreDbContext.Quotas
|
||||
.ProjectTo<TenantQuota>(_mapper.ConfigurationProvider)
|
||||
.ToList();
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public TenantQuota GetTenantQuota(int id)
|
||||
public async Task<TenantQuota> GetTenantQuotaAsync(int id)
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
return coreDbContext.Quotas
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
return await coreDbContext.Quotas
|
||||
.Where(r => r.Tenant == id)
|
||||
.ProjectTo<TenantQuota>(_mapper.ConfigurationProvider)
|
||||
.SingleOrDefault();
|
||||
.SingleOrDefaultAsync();
|
||||
}
|
||||
|
||||
public TenantQuota SaveTenantQuota(TenantQuota quota)
|
||||
public async Task<TenantQuota> SaveTenantQuotaAsync(TenantQuota quota)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(quota);
|
||||
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
coreDbContext.AddOrUpdate(coreDbContext.Quotas, _mapper.Map<TenantQuota, DbQuota>(quota));
|
||||
coreDbContext.SaveChanges();
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
await coreDbContext.AddOrUpdateAsync(q => q.Quotas, _mapper.Map<TenantQuota, DbQuota>(quota));
|
||||
await coreDbContext.SaveChangesAsync();
|
||||
|
||||
return quota;
|
||||
}
|
||||
|
||||
public void RemoveTenantQuota(int id)
|
||||
public async Task RemoveTenantQuotaAsync(int id)
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
var strategy = coreDbContext.Database.CreateExecutionStrategy();
|
||||
|
||||
strategy.Execute(() =>
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
using var tr = coreDbContext.Database.BeginTransaction();
|
||||
var d = coreDbContext.Quotas
|
||||
.Where(r => r.Tenant == id)
|
||||
.SingleOrDefault();
|
||||
|
||||
if (d != null)
|
||||
{
|
||||
coreDbContext.Quotas.Remove(d);
|
||||
coreDbContext.SaveChanges();
|
||||
}
|
||||
|
||||
tr.Commit();
|
||||
});
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
await coreDbContext.Quotas.Where(r => r.Tenant == id).ExecuteDeleteAsync();
|
||||
}
|
||||
|
||||
|
||||
public void SetTenantQuotaRow(TenantQuotaRow row, bool exchange)
|
||||
public async Task SetTenantQuotaRowAsync(TenantQuotaRow row, bool exchange)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(row);
|
||||
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
var strategy = coreDbContext.Database.CreateExecutionStrategy();
|
||||
|
||||
strategy.Execute(() =>
|
||||
await strategy.ExecuteAsync(async () =>
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
using var tx = coreDbContext.Database.BeginTransaction();
|
||||
|
||||
|
||||
AddQuota(coreDbContext, row.UserId);
|
||||
await AddQuotaAsync(coreDbContext, row.UserId);
|
||||
|
||||
tx.Commit();
|
||||
await tx.CommitAsync();
|
||||
});
|
||||
|
||||
void AddQuota(CoreDbContext coreDbContext, Guid userId)
|
||||
async Task AddQuotaAsync(CoreDbContext coreDbContext, Guid userId)
|
||||
{
|
||||
var dbTenantQuotaRow = _mapper.Map<TenantQuotaRow, DbQuotaRow>(row);
|
||||
dbTenantQuotaRow.UserId = userId;
|
||||
|
||||
if (exchange)
|
||||
{
|
||||
var counter = coreDbContext.QuotaRows
|
||||
var counter = await coreDbContext.QuotaRows
|
||||
.Where(r => r.Path == row.Path && r.Tenant == row.Tenant && r.UserId == userId)
|
||||
.Select(r => r.Counter)
|
||||
.Take(1)
|
||||
.FirstOrDefault();
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
dbTenantQuotaRow.Counter = counter + row.Counter;
|
||||
}
|
||||
|
||||
coreDbContext.AddOrUpdate(coreDbContext.QuotaRows, dbTenantQuotaRow);
|
||||
coreDbContext.SaveChanges();
|
||||
|
||||
await coreDbContext.AddOrUpdateAsync(q => q.QuotaRows, dbTenantQuotaRow);
|
||||
await coreDbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuotaRow> FindTenantQuotaRows(int tenantId)
|
||||
public Task<IEnumerable<TenantQuotaRow>> FindTenantQuotaRowsAsync(int tenantId)
|
||||
{
|
||||
return FindUserQuotaRows(tenantId, Guid.Empty);
|
||||
return FindUserQuotaRowsAsync(tenantId, Guid.Empty);
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuotaRow> FindUserQuotaRows(int tenantId, Guid userId)
|
||||
public async Task<IEnumerable<TenantQuotaRow>> FindUserQuotaRowsAsync(int tenantId, Guid userId)
|
||||
{
|
||||
using var coreDbContext = _dbContextFactory.CreateDbContext();
|
||||
using var coreDbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||
var q = coreDbContext.QuotaRows.Where(r => r.UserId == userId);
|
||||
|
||||
if (tenantId != Tenant.DefaultTenant)
|
||||
@ -143,6 +126,6 @@ class DbQuotaService : IQuotaService
|
||||
q = q.Where(r => r.Tenant == tenantId);
|
||||
}
|
||||
|
||||
return q.ProjectTo<TenantQuotaRow>(_mapper.ConfigurationProvider).ToList();
|
||||
return await q.ProjectTo<TenantQuotaRow>(_mapper.ConfigurationProvider).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
@ -203,38 +203,38 @@ public class HostedSolution
|
||||
return cookieStorage.EncryptCookie(tenantId, user.Id, tenantSettings.Index, expires, userSettings.Index, 0);
|
||||
}
|
||||
|
||||
public Tariff GetTariff(int tenant, bool withRequestToPaymentSystem = true)
|
||||
public Task<Tariff> GetTariffAsync(int tenant, bool withRequestToPaymentSystem = true)
|
||||
{
|
||||
return TariffService.GetTariff(tenant, withRequestToPaymentSystem);
|
||||
return TariffService.GetTariffAsync(tenant, withRequestToPaymentSystem);
|
||||
}
|
||||
|
||||
public TenantQuota GetTenantQuota(int tenant)
|
||||
public Task<TenantQuota> GetTenantQuotaAsync(int tenant)
|
||||
{
|
||||
return ClientTenantManager.GetTenantQuota(tenant);
|
||||
return ClientTenantManager.GetTenantQuotaAsync(tenant);
|
||||
}
|
||||
|
||||
public IEnumerable<TenantQuota> GetTenantQuotas()
|
||||
public Task<IEnumerable<TenantQuota>> GetTenantQuotasAsync()
|
||||
{
|
||||
return ClientTenantManager.GetTenantQuotas();
|
||||
return ClientTenantManager.GetTenantQuotasAsync();
|
||||
}
|
||||
|
||||
public TenantQuota SaveTenantQuota(TenantQuota quota)
|
||||
public Task<TenantQuota> SaveTenantQuotaAsync(TenantQuota quota)
|
||||
{
|
||||
return ClientTenantManager.SaveTenantQuota(quota);
|
||||
return ClientTenantManager.SaveTenantQuotaAsync(quota);
|
||||
}
|
||||
|
||||
public void SetTariff(int tenant, bool paid)
|
||||
public async Task SetTariffAsync(int tenant, bool paid)
|
||||
{
|
||||
var quota = QuotaService.GetTenantQuotas().FirstOrDefault(q => paid ? q.NonProfit : q.Trial);
|
||||
var quota = (await QuotaService.GetTenantQuotasAsync()).FirstOrDefault(q => paid ? q.NonProfit : q.Trial);
|
||||
if (quota != null)
|
||||
{
|
||||
TariffService.SetTariff(tenant, new Tariff { Quotas = new List<Quota> { new Quota(quota.Tenant, 1) }, DueDate = DateTime.MaxValue, });
|
||||
await TariffService.SetTariffAsync(tenant, new Tariff { Quotas = new List<Quota> { new Quota(quota.Tenant, 1) }, DueDate = DateTime.MaxValue, });
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTariff(int tenant, Tariff tariff)
|
||||
public Task SetTariffAsync(int tenant, Tariff tariff)
|
||||
{
|
||||
TariffService.SetTariff(tenant, tariff);
|
||||
return TariffService.SetTariffAsync(tenant, tariff);
|
||||
}
|
||||
|
||||
public IEnumerable<UserInfo> FindUsers(IEnumerable<Guid> userIds)
|
||||
|
@ -133,24 +133,24 @@ public class MultiRegionHostedSolution
|
||||
return GetRegionService(region).CreateAuthenticationCookie(_cookieStorage, tenantId, userId);
|
||||
}
|
||||
|
||||
public Tariff GetTariff(string region, int tenantId, bool withRequestToPaymentSystem = true)
|
||||
public Task<Tariff> GetTariffAsync(string region, int tenantId, bool withRequestToPaymentSystem = true)
|
||||
{
|
||||
return GetRegionService(region).GetTariff(tenantId, withRequestToPaymentSystem);
|
||||
return GetRegionService(region).GetTariffAsync(tenantId, withRequestToPaymentSystem);
|
||||
}
|
||||
|
||||
public void SetTariff(string region, int tenant, bool paid)
|
||||
public Task SetTariffAsync(string region, int tenant, bool paid)
|
||||
{
|
||||
GetRegionService(region).SetTariff(tenant, paid);
|
||||
return GetRegionService(region).SetTariffAsync(tenant, paid);
|
||||
}
|
||||
|
||||
public void SetTariff(string region, int tenant, Tariff tariff)
|
||||
public Task SetTariffAsync(string region, int tenant, Tariff tariff)
|
||||
{
|
||||
GetRegionService(region).SetTariff(tenant, tariff);
|
||||
return GetRegionService(region).SetTariffAsync(tenant, tariff);
|
||||
}
|
||||
|
||||
public TenantQuota GetTenantQuota(string region, int tenant)
|
||||
public Task<TenantQuota> GetTenantQuotaAsync(string region, int tenant)
|
||||
{
|
||||
return GetRegionService(region).GetTenantQuota(tenant);
|
||||
return GetRegionService(region).GetTenantQuotaAsync(tenant);
|
||||
}
|
||||
|
||||
public void CheckTenantAddress(string address)
|
||||
|
@ -47,18 +47,18 @@ public abstract class TenantQuotaFeatureChecker<T, T1> : ITenantQuotaFeatureChec
|
||||
|
||||
public virtual async Task CheckUsed(TenantQuota quota)
|
||||
{
|
||||
var used = await _tenantQuotaFeatureStatistic.GetValue();
|
||||
var used = await _tenantQuotaFeatureStatistic.GetValueAsync();
|
||||
Check(quota, used);
|
||||
}
|
||||
|
||||
public void CheckAdd(T1 newValue)
|
||||
public Task CheckAddAsync(T1 newValue)
|
||||
{
|
||||
CheckAdd(_tenantManager.GetCurrentTenant().Id, newValue);
|
||||
return CheckAddAsync(_tenantManager.GetCurrentTenant().Id, newValue);
|
||||
}
|
||||
|
||||
public virtual void CheckAdd(int tenantId, T1 newValue)
|
||||
public virtual async Task CheckAddAsync(int tenantId, T1 newValue)
|
||||
{
|
||||
var quota = _tenantManager.GetTenantQuota(tenantId);
|
||||
var quota = await _tenantManager.GetTenantQuotaAsync(tenantId);
|
||||
Check(quota, newValue);
|
||||
}
|
||||
|
||||
@ -81,6 +81,6 @@ public abstract class TenantQuotaFeatureCheckerCount<T> : TenantQuotaFeatureChec
|
||||
|
||||
public async Task CheckAppend()
|
||||
{
|
||||
CheckAdd((await _tenantQuotaFeatureStatistic.GetValue()) + 1);
|
||||
await CheckAddAsync((await _tenantQuotaFeatureStatistic.GetValueAsync()) + 1);
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ namespace ASC.Core.Common.Quota;
|
||||
|
||||
public interface ITenantQuotaFeatureStat<T>
|
||||
{
|
||||
Task<T> GetValue();
|
||||
Task<T> GetValueAsync();
|
||||
}
|
||||
|
||||
public interface ITenantQuotaFeatureStat<T, T1> : ITenantQuotaFeatureStat<T1> where T : TenantQuotaFeature<T1>
|
||||
|
@ -294,7 +294,7 @@ public class TenantQuota : IMapFrom<DbQuota>
|
||||
return obj is TenantQuota q && q.Tenant == Tenant;
|
||||
}
|
||||
|
||||
public async Task Check(IServiceProvider serviceProvider)
|
||||
public async Task CheckAsync(IServiceProvider serviceProvider)
|
||||
{
|
||||
foreach (var checker in serviceProvider.GetServices<ITenantQuotaFeatureChecker>())
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ public class BackupAjaxHandler
|
||||
return await _backupService.GetBackupHistory(GetCurrentTenantId());
|
||||
}
|
||||
|
||||
public void CreateSchedule(BackupStorageType storageType, Dictionary<string, string> storageParams, int backupsStored, CronParams cronParams)
|
||||
public async Task CreateScheduleAsync(BackupStorageType storageType, Dictionary<string, string> storageParams, int backupsStored, CronParams cronParams)
|
||||
{
|
||||
DemandPermissionsBackup();
|
||||
|
||||
@ -173,7 +173,7 @@ public class BackupAjaxHandler
|
||||
break;
|
||||
}
|
||||
|
||||
_backupService.CreateScheduleAsync(scheduleRequest);
|
||||
await _backupService.CreateScheduleAsync(scheduleRequest);
|
||||
}
|
||||
|
||||
public async Task<Schedule> GetScheduleAsync()
|
||||
@ -224,7 +224,7 @@ public class BackupAjaxHandler
|
||||
StorageParams = schedule.StorageParams
|
||||
};
|
||||
|
||||
_backupService.CreateScheduleAsync(Schedule);
|
||||
await _backupService.CreateScheduleAsync(Schedule);
|
||||
|
||||
}
|
||||
else if (response.StorageType != BackupStorageType.ThirdPartyConsumer)
|
||||
@ -256,9 +256,9 @@ public class BackupAjaxHandler
|
||||
|
||||
#region restore
|
||||
|
||||
public Task StartRestoreAsync(string backupId, BackupStorageType storageType, Dictionary<string, string> storageParams, bool notify)
|
||||
public async Task StartRestoreAsync(string backupId, BackupStorageType storageType, Dictionary<string, string> storageParams, bool notify)
|
||||
{
|
||||
DemandPermissionsRestore();
|
||||
await DemandPermissionsRestoreAsync();
|
||||
|
||||
var restoreRequest = new StartRestoreRequest
|
||||
{
|
||||
@ -282,7 +282,7 @@ public class BackupAjaxHandler
|
||||
}
|
||||
}
|
||||
|
||||
return _backupService.StartRestoreAsync(restoreRequest);
|
||||
await _backupService.StartRestoreAsync(restoreRequest);
|
||||
}
|
||||
|
||||
public BackupProgress GetRestoreProgress()
|
||||
@ -295,12 +295,13 @@ public class BackupAjaxHandler
|
||||
return result;
|
||||
}
|
||||
|
||||
public void DemandPermissionsRestore()
|
||||
public async Task DemandPermissionsRestoreAsync()
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
|
||||
var quota = await _tenantManager.GetTenantQuotaAsync(_tenantManager.GetCurrentTenant().Id);
|
||||
if (!SetupInfo.IsVisibleSettings("Restore") ||
|
||||
(!_coreBaseSettings.Standalone && !_tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).AutoBackupRestore))
|
||||
(!_coreBaseSettings.Standalone && !quota.AutoBackupRestore))
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "Restore");
|
||||
}
|
||||
@ -308,18 +309,18 @@ public class BackupAjaxHandler
|
||||
|
||||
if (!_coreBaseSettings.Standalone
|
||||
&& (!SetupInfo.IsVisibleSettings("Restore")
|
||||
|| !_tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).AutoBackupRestore))
|
||||
|| !quota.AutoBackupRestore))
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "Restore");
|
||||
}
|
||||
}
|
||||
|
||||
public void DemandPermissionsAutoBackup()
|
||||
public async Task DemandPermissionsAutoBackupAsync()
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
if (!SetupInfo.IsVisibleSettings("AutoBackup") ||
|
||||
(!_coreBaseSettings.Standalone && !_tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).AutoBackupRestore))
|
||||
(!_coreBaseSettings.Standalone && !(await _tenantManager.GetTenantQuotaAsync(_tenantManager.GetCurrentTenant().Id)).AutoBackupRestore))
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "AutoBackup");
|
||||
}
|
||||
@ -329,9 +330,9 @@ public class BackupAjaxHandler
|
||||
|
||||
#region transfer
|
||||
|
||||
public void StartTransfer(string targetRegion, bool notifyUsers)
|
||||
public async Task StartTransferAsync(string targetRegion, bool notifyUsers)
|
||||
{
|
||||
DemandPermissionsTransfer();
|
||||
await DemandPermissionsTransferAsync();
|
||||
|
||||
_messageService.Send(MessageAction.StartTransferSetting);
|
||||
_backupService.StartTransfer(
|
||||
@ -349,14 +350,14 @@ public class BackupAjaxHandler
|
||||
return _backupService.GetTransferProgress(GetCurrentTenantId());
|
||||
}
|
||||
|
||||
private void DemandPermissionsTransfer()
|
||||
private async Task DemandPermissionsTransferAsync()
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
var currentUser = _userManager.GetUsers(_securityContext.CurrentAccount.ID);
|
||||
if (!SetupInfo.IsVisibleSettings(nameof(ManagementType.Migration))
|
||||
|| !currentUser.IsOwner(_tenantManager.GetCurrentTenant())
|
||||
|| !SetupInfo.IsSecretEmail(currentUser.Email) && !_tenantManager.GetCurrentTenantQuota().AutoBackupRestore)
|
||||
|| !SetupInfo.IsSecretEmail(currentUser.Email) && !(await _tenantManager.GetCurrentTenantQuotaAsync()).AutoBackupRestore)
|
||||
{
|
||||
throw new InvalidOperationException(Resource.ErrorNotAllowedOption);
|
||||
}
|
||||
|
@ -73,15 +73,14 @@ public class DbBackupProvider : IBackupProvider
|
||||
return xml.AsEnumerable();
|
||||
}
|
||||
|
||||
public Task LoadFrom(IEnumerable<XElement> elements, int tenant, string[] configs, IDataReadOperator reader)
|
||||
public async Task LoadFromAsync(IEnumerable<XElement> elements, int tenant, string[] configs, IDataReadOperator reader)
|
||||
{
|
||||
_processedTables.Clear();
|
||||
|
||||
foreach (var connectionString in GetConnectionStrings(configs))
|
||||
{
|
||||
RestoreDatabase(connectionString, elements, reader);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
await RestoreDatabaseAsync(connectionString, elements, reader);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ConnectionStringSettings> GetConnectionStrings(string[] configs)
|
||||
@ -196,7 +195,7 @@ public class DbBackupProvider : IBackupProvider
|
||||
return xml;
|
||||
}
|
||||
|
||||
private void RestoreDatabase(ConnectionStringSettings connectionString, IEnumerable<XElement> elements, IDataReadOperator reader)
|
||||
private async Task RestoreDatabaseAsync(ConnectionStringSettings connectionString, IEnumerable<XElement> elements, IDataReadOperator reader)
|
||||
{
|
||||
var dbName = connectionString.Name;
|
||||
var dbElement = elements.SingleOrDefault(e => string.Equals(e.Name.LocalName, connectionString.Name, StringComparison.OrdinalIgnoreCase));
|
||||
@ -229,7 +228,7 @@ public class DbBackupProvider : IBackupProvider
|
||||
{
|
||||
var data = new DataTable();
|
||||
data.ReadXml(stream);
|
||||
_dbHelper.SetTable(data);
|
||||
await _dbHelper.SetTableAsync(data);
|
||||
}
|
||||
_processedTables.Add(table);
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ public class DbHelper : IDisposable
|
||||
}
|
||||
|
||||
|
||||
public void SetTable(DataTable table)
|
||||
public async Task SetTableAsync(DataTable table)
|
||||
{
|
||||
using var tx = _connect.BeginTransaction();
|
||||
try
|
||||
@ -167,11 +167,11 @@ public class DbHelper : IDisposable
|
||||
if ("tenants_tenants".Equals(table.TableName, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
// remove last tenant
|
||||
var tenant = _tenantDbContext.Tenants.LastOrDefault();
|
||||
var tenant = await _tenantDbContext.Tenants.LastOrDefaultAsync();
|
||||
if (tenant != null)
|
||||
{
|
||||
_tenantDbContext.Tenants.Remove(tenant);
|
||||
_tenantDbContext.SaveChanges();
|
||||
await _tenantDbContext.SaveChangesAsync();
|
||||
}
|
||||
/* var tenantid = CreateCommand("select id from tenants_tenants order by id desc limit 1").ExecuteScalar();
|
||||
CreateCommand("delete from tenants_tenants where id = " + tenantid).ExecuteNonQuery();*/
|
||||
@ -182,12 +182,10 @@ public class DbHelper : IDisposable
|
||||
r[table.Columns["mappeddomain"]] = null;
|
||||
if (table.Columns.Contains("id"))
|
||||
{
|
||||
var tariff = _coreDbContext.Tariffs.FirstOrDefault(t => t.Tenant == tenant.Id);
|
||||
tariff.Tenant = (int)r[table.Columns["id"]];
|
||||
tariff.CreateOn = DateTime.Now;
|
||||
// CreateCommand("update tenants_tariff set tenant = " + r[table.Columns["id"]] + " where tenant = " + tenantid).ExecuteNonQuery();
|
||||
_coreDbContext.Entry(tariff).State = EntityState.Modified;
|
||||
_coreDbContext.SaveChanges();
|
||||
await _coreDbContext.Tariffs.Where(t => t.Tenant == tenant.Id)
|
||||
.ExecuteUpdateAsync(q =>
|
||||
q.SetProperty(p => p.Tenant, (int)r[table.Columns["id"]])
|
||||
.SetProperty(p => p.CreateOn, DateTime.Now));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public interface IBackupProvider
|
||||
event EventHandler<ProgressChangedEventArgs> ProgressChanged;
|
||||
|
||||
Task<IEnumerable<XElement>> GetElements(int tenant, string[] configs, IDataWriteOperator writer);
|
||||
Task LoadFrom(IEnumerable<XElement> elements, int tenant, string[] configs, IDataReadOperator reader);
|
||||
Task LoadFromAsync(IEnumerable<XElement> elements, int tenant, string[] configs, IDataReadOperator reader);
|
||||
}
|
||||
|
||||
public class ProgressChangedEventArgs : EventArgs
|
||||
|
@ -94,7 +94,7 @@ public class NotifyHelper
|
||||
new TagValue(Tags.OwnerName, _userManager.GetUsers(userId).DisplayUserName(_displayUserSettingsHelper)));
|
||||
}
|
||||
|
||||
public void SendAboutRestoreStarted(Tenant tenant, bool notifyAllUsers)
|
||||
public async Task SendAboutRestoreStartedAsync(Tenant tenant, bool notifyAllUsers)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(tenant.Id);
|
||||
|
||||
@ -103,8 +103,8 @@ public class NotifyHelper
|
||||
var owner = _userManager.GetUsers(tenant.OwnerId);
|
||||
var users =
|
||||
notifyAllUsers
|
||||
? _studioNotifyHelper.RecipientFromEmail(_userManager.GetUsers(EmployeeStatus.Active).Where(r => r.ActivationStatus == EmployeeActivationStatus.Activated).Select(u => u.Email).ToList(), false)
|
||||
: owner.ActivationStatus == EmployeeActivationStatus.Activated ? _studioNotifyHelper.RecipientFromEmail(owner.Email, false) : new IDirectRecipient[0];
|
||||
? await _studioNotifyHelper.RecipientFromEmailAsync(_userManager.GetUsers(EmployeeStatus.Active).Where(r => r.ActivationStatus == EmployeeActivationStatus.Activated).Select(u => u.Email).ToList(), false)
|
||||
: owner.ActivationStatus == EmployeeActivationStatus.Activated ? await _studioNotifyHelper.RecipientFromEmailAsync(owner.Email, false) : new IDirectRecipient[0];
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.RestoreStarted,
|
||||
|
@ -69,7 +69,7 @@ public class BackupService : IBackupService
|
||||
return;
|
||||
}
|
||||
|
||||
await storage.Delete(backupRecord.StoragePath);
|
||||
await storage.DeleteAsync(backupRecord.StoragePath);
|
||||
}
|
||||
|
||||
public async Task DeleteAllBackupsAsync(int tenantId)
|
||||
@ -85,7 +85,7 @@ public class BackupService : IBackupService
|
||||
continue;
|
||||
}
|
||||
|
||||
await storage.Delete(backupRecord.StoragePath);
|
||||
await storage.DeleteAsync(backupRecord.StoragePath);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
@ -105,7 +105,7 @@ public class BackupService : IBackupService
|
||||
continue;
|
||||
}
|
||||
|
||||
if (await storage.IsExists(record.StoragePath))
|
||||
if (await storage.IsExistsAsync(record.StoragePath))
|
||||
{
|
||||
backupHistory.Add(new BackupHistoryRecord
|
||||
{
|
||||
|
@ -125,7 +125,7 @@ public class BackupProgressItem : BaseBackupProgressItem
|
||||
|
||||
if (writer.NeedUpload)
|
||||
{
|
||||
storagePath = await backupStorage.Upload(_storageBasePath, tempFile, _userId);
|
||||
storagePath = await backupStorage.UploadAsync(_storageBasePath, tempFile, _userId);
|
||||
hash = BackupWorker.GetBackupHash(tempFile);
|
||||
}
|
||||
else
|
||||
@ -133,7 +133,7 @@ public class BackupProgressItem : BaseBackupProgressItem
|
||||
storagePath = writer.StoragePath;
|
||||
hash = writer.Hash;
|
||||
}
|
||||
Link = await backupStorage.GetPublicLink(storagePath);
|
||||
Link = await backupStorage.GetPublicLinkAsync(storagePath);
|
||||
|
||||
var repo = _backupRepository;
|
||||
|
||||
|
@ -119,7 +119,7 @@ public class RestoreProgressItem : BaseBackupProgressItem
|
||||
|
||||
tenant = _tenantManager.GetTenant(TenantId);
|
||||
_tenantManager.SetCurrentTenant(tenant);
|
||||
_notifyHelper.SendAboutRestoreStarted(tenant, Notify);
|
||||
await _notifyHelper.SendAboutRestoreStartedAsync(tenant, Notify);
|
||||
tenant.SetStatus(TenantStatus.Restoring);
|
||||
_tenantManager.SaveTenant(tenant);
|
||||
|
||||
@ -127,7 +127,7 @@ public class RestoreProgressItem : BaseBackupProgressItem
|
||||
|
||||
var storage = _backupStorageFactory.GetBackupStorage(StorageType, TenantId, StorageParams);
|
||||
|
||||
await storage.Download(StoragePath, tempFile);
|
||||
await storage.DownloadAsync(StoragePath, tempFile);
|
||||
|
||||
if (!_coreBaseSettings.Standalone)
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ public class ConsumerBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
_sessionHolder = new CommonChunkedUploadSessionHolder(_tempPath, _logger, _store, Domain, _setupInfo.ChunkUploadSize);
|
||||
}
|
||||
|
||||
public async Task<string> Upload(string storageBasePath, string localPath, Guid userId)
|
||||
public async Task<string> UploadAsync(string storageBasePath, string localPath, Guid userId)
|
||||
{
|
||||
using var stream = File.OpenRead(localPath);
|
||||
var storagePath = Path.GetFileName(localPath);
|
||||
@ -76,14 +76,14 @@ public class ConsumerBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
return storagePath;
|
||||
}
|
||||
|
||||
public async Task Download(string storagePath, string targetLocalPath)
|
||||
public async Task DownloadAsync(string storagePath, string targetLocalPath)
|
||||
{
|
||||
using var source = await _store.GetReadStreamAsync(Domain, storagePath);
|
||||
using var destination = File.OpenWrite(targetLocalPath);
|
||||
await source.CopyToAsync(destination);
|
||||
}
|
||||
|
||||
public async Task Delete(string storagePath)
|
||||
public async Task DeleteAsync(string storagePath)
|
||||
{
|
||||
if (await _store.IsFileAsync(Domain, storagePath))
|
||||
{
|
||||
@ -91,7 +91,7 @@ public class ConsumerBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<bool> IsExists(string storagePath)
|
||||
public async Task<bool> IsExistsAsync(string storagePath)
|
||||
{
|
||||
if (_store != null)
|
||||
{
|
||||
@ -103,7 +103,7 @@ public class ConsumerBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> GetPublicLink(string storagePath)
|
||||
public async Task<string> GetPublicLinkAsync(string storagePath)
|
||||
{
|
||||
if (_isTemporary)
|
||||
{
|
||||
|
@ -69,17 +69,17 @@ public class DocumentsBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
_sessionHolder = new FilesChunkedUploadSessionHolder(_daoFactory, _tempPath, _logger, store, "", _setupInfo.ChunkUploadSize);
|
||||
}
|
||||
|
||||
public async Task<string> Upload(string folderId, string localPath, Guid userId)
|
||||
public async Task<string> UploadAsync(string folderId, string localPath, Guid userId)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(_tenantId);
|
||||
if (!userId.Equals(Guid.Empty))
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tenant = _tenantManager.GetTenant(_tenantId);
|
||||
_securityContext.AuthenticateMeWithoutCookie(tenant.OwnerId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(tenant.OwnerId);
|
||||
}
|
||||
|
||||
if (int.TryParse(folderId, out var fId))
|
||||
@ -90,7 +90,7 @@ public class DocumentsBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
return await Upload(folderId, localPath);
|
||||
}
|
||||
|
||||
public async Task Download(string fileId, string targetLocalPath)
|
||||
public async Task DownloadAsync(string fileId, string targetLocalPath)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(_tenantId);
|
||||
|
||||
@ -104,7 +104,7 @@ public class DocumentsBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
await DownloadDao(fileId, targetLocalPath);
|
||||
}
|
||||
|
||||
public async Task Delete(string fileId)
|
||||
public async Task DeleteAsync(string fileId)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(_tenantId);
|
||||
|
||||
@ -118,7 +118,7 @@ public class DocumentsBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
await DeleteDao(fileId);
|
||||
}
|
||||
|
||||
public async Task<bool> IsExists(string fileId)
|
||||
public async Task<bool> IsExistsAsync(string fileId)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(_tenantId);
|
||||
if (int.TryParse(fileId, out var fId))
|
||||
@ -129,7 +129,7 @@ public class DocumentsBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
return await IsExistsDao(fileId);
|
||||
}
|
||||
|
||||
public Task<string> GetPublicLink(string fileId)
|
||||
public Task<string> GetPublicLinkAsync(string fileId)
|
||||
{
|
||||
return Task.FromResult(String.Empty);
|
||||
}
|
||||
@ -213,12 +213,12 @@ public class DocumentsBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
_tenantManager.SetCurrentTenant(_tenantId);
|
||||
if (!userId.Equals(Guid.Empty))
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
var tenant = _tenantManager.GetTenant(_tenantId);
|
||||
_securityContext.AuthenticateMeWithoutCookie(tenant.OwnerId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(tenant.OwnerId);
|
||||
}
|
||||
if (int.TryParse(storageBasePath, out var fId))
|
||||
{
|
||||
|
@ -28,9 +28,9 @@ namespace ASC.Data.Backup.Storage;
|
||||
|
||||
public interface IBackupStorage
|
||||
{
|
||||
Task<bool> IsExists(string storagePath);
|
||||
Task<string> GetPublicLink(string storagePath);
|
||||
Task<string> Upload(string storageBasePath, string localPath, Guid userId);
|
||||
Task Delete(string storagePath);
|
||||
Task Download(string storagePath, string targetLocalPath);
|
||||
Task<bool> IsExistsAsync(string storagePath);
|
||||
Task<string> GetPublicLinkAsync(string storagePath);
|
||||
Task<string> UploadAsync(string storageBasePath, string localPath, Guid userId);
|
||||
Task DeleteAsync(string storagePath);
|
||||
Task DownloadAsync(string storagePath, string targetLocalPath);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace ASC.Data.Backup.Storage;
|
||||
[Scope]
|
||||
public class LocalBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
{
|
||||
public Task<string> Upload(string storageBasePath, string localPath, Guid userId)
|
||||
public Task<string> UploadAsync(string storageBasePath, string localPath, Guid userId)
|
||||
{
|
||||
if (!Directory.Exists(storageBasePath))
|
||||
{
|
||||
@ -45,24 +45,24 @@ public class LocalBackupStorage : IBackupStorage, IGetterWriteOperator
|
||||
return Task.FromResult(storagePath);
|
||||
}
|
||||
|
||||
public Task Download(string storagePath, string targetLocalPath)
|
||||
public Task DownloadAsync(string storagePath, string targetLocalPath)
|
||||
{
|
||||
File.Copy(storagePath, targetLocalPath, true);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Delete(string storagePath)
|
||||
public Task DeleteAsync(string storagePath)
|
||||
{
|
||||
File.Delete(storagePath);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task<bool> IsExists(string storagePath)
|
||||
public Task<bool> IsExistsAsync(string storagePath)
|
||||
{
|
||||
return Task.FromResult(File.Exists(storagePath));
|
||||
}
|
||||
|
||||
public Task<string> GetPublicLink(string storagePath)
|
||||
public Task<string> GetPublicLinkAsync(string storagePath)
|
||||
{
|
||||
return Task.FromResult(string.Empty);
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class RestorePortalTask : PortalTaskBase
|
||||
_options.DebugRefreshLicense();
|
||||
try
|
||||
{
|
||||
_licenseReader.RejectLicense();
|
||||
await _licenseReader.RejectLicenseAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -82,7 +82,7 @@ public class ReassignProgressItem : DistributedTaskProgress
|
||||
Percentage = 0;
|
||||
Status = DistributedTaskStatus.Running;
|
||||
|
||||
securityContext.AuthenticateMeWithoutCookie(_currentUserId);
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(_currentUserId);
|
||||
|
||||
logger.LogInformation("reassignment of data from {fromUser} to {toUser}", FromUser, ToUser);
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class RemoveProgressItem : DistributedTaskProgress
|
||||
Percentage = 0;
|
||||
Status = DistributedTaskStatus.Running;
|
||||
|
||||
securityContext.AuthenticateMeWithoutCookie(_currentUserId);
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(_currentUserId);
|
||||
|
||||
long crmSpace;
|
||||
var wrapper = await GetUsageSpace(webItemManagerSecurity);
|
||||
|
@ -334,19 +334,21 @@ public abstract class BaseStorage : IDataStore
|
||||
public abstract string GetPostParams(string domain, string directoryPath, long maxUploadSize, string contentType,
|
||||
string contentDisposition);
|
||||
|
||||
internal void QuotaUsedAdd(string domain, long size, bool quotaCheckFileSize = true)
|
||||
internal Task QuotaUsedAddAsync(string domain, long size, bool quotaCheckFileSize = true)
|
||||
{
|
||||
if (QuotaController != null)
|
||||
{
|
||||
QuotaController.QuotaUsedAdd(Modulename, domain, DataList.GetData(domain), size, quotaCheckFileSize);
|
||||
return QuotaController.QuotaUsedAddAsync(Modulename, domain, DataList.GetData(domain), size, quotaCheckFileSize);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
internal void QuotaUsedDelete(string domain, long size)
|
||||
internal async Task QuotaUsedDeleteAsync(string domain, long size)
|
||||
{
|
||||
if (QuotaController != null)
|
||||
{
|
||||
QuotaController.QuotaUsedDelete(Modulename, domain, DataList.GetData(domain), size);
|
||||
await QuotaController.QuotaUsedDeleteAsync(Modulename, domain, DataList.GetData(domain), size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,22 +148,22 @@ public class DiscDataStore : BaseStorage
|
||||
return (QuotaController != null) && !domain.EndsWith("_temp");
|
||||
}
|
||||
|
||||
public override Task<Uri> SaveAsync(string domain, string path, Stream stream)
|
||||
public override async Task<Uri> SaveAsync(string domain, string path, Stream stream)
|
||||
{
|
||||
Logger.DebugSavePath(path);
|
||||
|
||||
var buffered = _tempStream.GetBuffered(stream);
|
||||
|
||||
if (EnableQuotaCheck(domain))
|
||||
if (EnableQuotaCheck(domain))
|
||||
{
|
||||
QuotaController.QuotaUsedCheck(buffered.Length);
|
||||
await QuotaController.QuotaUsedCheckAsync(buffered.Length);
|
||||
}
|
||||
|
||||
ArgumentNullException.ThrowIfNull(path);
|
||||
ArgumentNullException.ThrowIfNull(stream);
|
||||
|
||||
//Try seek to start
|
||||
return InternalSaveAsync(domain, path, buffered);
|
||||
return await InternalSaveAsync(domain, path, buffered);
|
||||
}
|
||||
|
||||
private async Task<Uri> InternalSaveAsync(string domain, string path, Stream buffered)
|
||||
@ -193,7 +193,7 @@ public class DiscDataStore : BaseStorage
|
||||
fslen = fs.Length;
|
||||
}
|
||||
|
||||
QuotaUsedAdd(domain, fslen);
|
||||
await QuotaUsedAddAsync(domain, fslen);
|
||||
|
||||
_crypt.EncryptFile(target);
|
||||
|
||||
@ -226,7 +226,7 @@ public class DiscDataStore : BaseStorage
|
||||
return string.Format("{0}_{1}", chunkNumber, uploadId);
|
||||
}
|
||||
|
||||
public override Task<Uri> FinalizeChunkedUploadAsync(string domain, string path, string uploadId, Dictionary<int, string> eTags)
|
||||
public override async Task<Uri> FinalizeChunkedUploadAsync(string domain, string path, string uploadId, Dictionary<int, string> eTags)
|
||||
{
|
||||
var target = GetTarget(domain, path);
|
||||
|
||||
@ -238,12 +238,12 @@ public class DiscDataStore : BaseStorage
|
||||
}
|
||||
|
||||
var size = _crypt.GetFileSize(target);
|
||||
QuotaUsedAdd(domain, size);
|
||||
await QuotaUsedAddAsync(domain, size);
|
||||
}
|
||||
|
||||
_crypt.EncryptFile(target);
|
||||
|
||||
return GetUriAsync(domain, path);
|
||||
return await GetUriAsync(domain, path);
|
||||
}
|
||||
|
||||
public override Task AbortChunkedUploadAsync(string domain, string path, string uploadId)
|
||||
@ -258,7 +258,7 @@ public class DiscDataStore : BaseStorage
|
||||
|
||||
#endregion
|
||||
|
||||
public override Task DeleteAsync(string domain, string path)
|
||||
public override async Task DeleteAsync(string domain, string path)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(path);
|
||||
|
||||
@ -269,8 +269,7 @@ public class DiscDataStore : BaseStorage
|
||||
var size = _crypt.GetFileSize(target);
|
||||
File.Delete(target);
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
return Task.CompletedTask; ;
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -278,7 +277,7 @@ public class DiscDataStore : BaseStorage
|
||||
}
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, List<string> paths)
|
||||
public override async Task DeleteFilesAsync(string domain, List<string> paths)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(paths);
|
||||
|
||||
@ -294,13 +293,11 @@ public class DiscDataStore : BaseStorage
|
||||
var size = _crypt.GetFileSize(target);
|
||||
File.Delete(target);
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
||||
public override async Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(folderPath);
|
||||
|
||||
@ -313,9 +310,8 @@ public class DiscDataStore : BaseStorage
|
||||
{
|
||||
var size = _crypt.GetFileSize(entry);
|
||||
File.Delete(entry);
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -323,7 +319,7 @@ public class DiscDataStore : BaseStorage
|
||||
}
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate)
|
||||
public override async Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(folderPath);
|
||||
|
||||
@ -339,7 +335,7 @@ public class DiscDataStore : BaseStorage
|
||||
{
|
||||
var size = _crypt.GetFileSize(entry);
|
||||
File.Delete(entry);
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,8 +343,6 @@ public class DiscDataStore : BaseStorage
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Directory '{targetDir}' not found");
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task MoveDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
||||
@ -367,7 +361,7 @@ public class DiscDataStore : BaseStorage
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task<Uri> MoveAsync(string srcdomain, string srcpath, string newdomain, string newpath, bool quotaCheckFileSize = true)
|
||||
public override async Task<Uri> MoveAsync(string srcdomain, string srcpath, string newdomain, string newpath, bool quotaCheckFileSize = true)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(srcpath);
|
||||
ArgumentNullException.ThrowIfNull(newpath);
|
||||
@ -392,14 +386,14 @@ public class DiscDataStore : BaseStorage
|
||||
|
||||
File.Move(target, newtarget);
|
||||
|
||||
QuotaUsedDelete(srcdomain, flength);
|
||||
QuotaUsedAdd(newdomain, flength, quotaCheckFileSize);
|
||||
await QuotaUsedDeleteAsync(srcdomain, flength);
|
||||
await QuotaUsedAddAsync(newdomain, flength, quotaCheckFileSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
||||
}
|
||||
return GetUriAsync(newdomain, newpath);
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
|
||||
public override Task<bool> IsDirectoryAsync(string domain, string path)
|
||||
@ -415,7 +409,7 @@ public class DiscDataStore : BaseStorage
|
||||
return Task.FromResult(!string.IsNullOrEmpty(targetDir) && Directory.Exists(targetDir));
|
||||
}
|
||||
|
||||
public override Task DeleteDirectoryAsync(string domain, string path)
|
||||
public override async Task DeleteDirectoryAsync(string domain, string path)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(path);
|
||||
|
||||
@ -434,7 +428,7 @@ public class DiscDataStore : BaseStorage
|
||||
|
||||
if (!Directory.Exists(targetDir))
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
var entries = Directory.GetFiles(targetDir, "*.*", SearchOption.AllDirectories);
|
||||
@ -446,8 +440,7 @@ public class DiscDataStore : BaseStorage
|
||||
|
||||
Directory.Delete(targetDir, true);
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
return Task.CompletedTask;
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
|
||||
public override Task<long> GetFileSizeAsync(string domain, string path)
|
||||
@ -488,7 +481,7 @@ public class DiscDataStore : BaseStorage
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public override Task DeleteExpiredAsync(string domain, string folderPath, TimeSpan oldThreshold)
|
||||
public override async Task DeleteExpiredAsync(string domain, string folderPath, TimeSpan oldThreshold)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(folderPath);
|
||||
|
||||
@ -496,7 +489,7 @@ public class DiscDataStore : BaseStorage
|
||||
var targetDir = GetTarget(domain, folderPath);
|
||||
if (!Directory.Exists(targetDir))
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
var entries = Directory.GetFiles(targetDir, "*.*", SearchOption.TopDirectoryOnly);
|
||||
@ -508,11 +501,9 @@ public class DiscDataStore : BaseStorage
|
||||
var size = _crypt.GetFileSize(entry);
|
||||
File.Delete(entry);
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override string GetUploadForm(string domain, string directoryPath, string redirectTo, long maxUploadSize, string contentType, string contentDisposition, string submitLabel)
|
||||
@ -589,7 +580,7 @@ public class DiscDataStore : BaseStorage
|
||||
if (QuotaController != null)
|
||||
{
|
||||
var size = await GetUsedQuotaAsync(domain);
|
||||
QuotaController.QuotaUsedSet(Modulename, domain, DataList.GetData(domain), size);
|
||||
await QuotaController.QuotaUsedSetAsync(Modulename, domain, DataList.GetData(domain), size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -608,7 +599,7 @@ public class DiscDataStore : BaseStorage
|
||||
return Task.FromResult(size);
|
||||
}
|
||||
|
||||
public override Task<Uri> CopyAsync(string srcdomain, string srcpath, string newdomain, string newpath)
|
||||
public override async Task<Uri> CopyAsync(string srcdomain, string srcpath, string newdomain, string newpath)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(srcpath);
|
||||
ArgumentNullException.ThrowIfNull(newpath);
|
||||
@ -626,16 +617,16 @@ public class DiscDataStore : BaseStorage
|
||||
File.Copy(target, newtarget, true);
|
||||
|
||||
var flength = _crypt.GetFileSize(target);
|
||||
QuotaUsedAdd(newdomain, flength);
|
||||
await QuotaUsedAddAsync(newdomain, flength);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FileNotFoundException("File not found", Path.GetFullPath(target));
|
||||
}
|
||||
return GetUriAsync(newdomain, newpath);
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
|
||||
public override Task CopyDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
||||
public override async Task CopyDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
||||
{
|
||||
var target = GetTarget(srcdomain, srcdir);
|
||||
var newtarget = GetTarget(newdomain, newdir);
|
||||
@ -643,8 +634,7 @@ public class DiscDataStore : BaseStorage
|
||||
var diSource = new DirectoryInfo(target);
|
||||
var diTarget = new DirectoryInfo(newtarget);
|
||||
|
||||
CopyAll(diSource, diTarget, newdomain);
|
||||
return Task.CompletedTask;
|
||||
await CopyAllAsync(diSource, diTarget, newdomain);
|
||||
}
|
||||
|
||||
|
||||
@ -684,7 +674,7 @@ public class DiscDataStore : BaseStorage
|
||||
return SaveAsync(domain, path, stream);
|
||||
}
|
||||
|
||||
private void CopyAll(DirectoryInfo source, DirectoryInfo target, string newdomain)
|
||||
private async Task CopyAllAsync(DirectoryInfo source, DirectoryInfo target, string newdomain)
|
||||
{
|
||||
// Check if the target directory exists, if not, create it.
|
||||
if (!Directory.Exists(target.FullName))
|
||||
@ -698,14 +688,14 @@ public class DiscDataStore : BaseStorage
|
||||
var fp = CrossPlatform.PathCombine(target.ToString(), fi.Name);
|
||||
fi.CopyTo(fp, true);
|
||||
var size = _crypt.GetFileSize(fp);
|
||||
QuotaUsedAdd(newdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size);
|
||||
}
|
||||
|
||||
// Copy each subdirectory using recursion.
|
||||
foreach (var diSourceSubDir in source.GetDirectories())
|
||||
{
|
||||
var nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name);
|
||||
CopyAll(diSourceSubDir, nextTargetSubDir, newdomain);
|
||||
await CopyAllAsync(diSourceSubDir, nextTargetSubDir, newdomain);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
|
||||
if (EnableQuotaCheck(domain))
|
||||
{
|
||||
QuotaController.QuotaUsedCheck(buffered.Length);
|
||||
await QuotaController.QuotaUsedCheckAsync(buffered.Length);
|
||||
}
|
||||
|
||||
var mime = string.IsNullOrEmpty(contentType)
|
||||
@ -234,7 +234,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
|
||||
// InvalidateCloudFront(MakePath(domain, path));
|
||||
|
||||
QuotaUsedAdd(domain, buffered.Length);
|
||||
await QuotaUsedAddAsync(domain, buffered.Length);
|
||||
|
||||
return await GetUriAsync(domain, path);
|
||||
}
|
||||
@ -248,7 +248,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
|
||||
await storage.DeleteObjectAsync(_bucket, key);
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
|
||||
public override async Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
||||
@ -271,7 +271,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
await foreach (var obj in objToDel)
|
||||
{
|
||||
await storage.DeleteObjectAsync(_bucket, obj.Name);
|
||||
QuotaUsedDelete(domain, Convert.ToInt64(obj.Size));
|
||||
await QuotaUsedDeleteAsync(domain, Convert.ToInt64(obj.Size));
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,7 +325,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
|
||||
if (quotaUsed > 0)
|
||||
{
|
||||
QuotaUsedDelete(domain, quotaUsed);
|
||||
await QuotaUsedDeleteAsync(domain, quotaUsed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,7 +339,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
await foreach (var obj in objToDel)
|
||||
{
|
||||
await storage.DeleteObjectAsync(_bucket, obj.Name);
|
||||
QuotaUsedDelete(domain, Convert.ToInt64(obj.Size));
|
||||
await QuotaUsedDeleteAsync(domain, Convert.ToInt64(obj.Size));
|
||||
}
|
||||
}
|
||||
|
||||
@ -378,8 +378,8 @@ public class GoogleCloudStorage : BaseStorage
|
||||
|
||||
await DeleteAsync(srcdomain, srcpath);
|
||||
|
||||
QuotaUsedDelete(srcdomain, size);
|
||||
QuotaUsedAdd(newdomain, size, quotaCheckFileSize);
|
||||
await QuotaUsedDeleteAsync(srcdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size, quotaCheckFileSize);
|
||||
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
@ -455,7 +455,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
await foreach (var obj in objToDel)
|
||||
{
|
||||
await storage.DeleteObjectAsync(_bucket, obj.Name);
|
||||
QuotaUsedDelete(domain, Convert.ToInt64(obj.Size));
|
||||
await QuotaUsedDeleteAsync(domain, Convert.ToInt64(obj.Size));
|
||||
}
|
||||
}
|
||||
|
||||
@ -507,7 +507,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
}
|
||||
}
|
||||
|
||||
QuotaController.QuotaUsedSet(Modulename, domain, DataList.GetData(domain), size);
|
||||
await QuotaController.QuotaUsedSetAsync(Modulename, domain, DataList.GetData(domain), size);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -549,7 +549,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
|
||||
await storage.CopyObjectAsync(_bucket, MakePath(srcdomain, srcpath), _bucket, MakePath(newdomain, newpath), options);
|
||||
|
||||
QuotaUsedAdd(newdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size);
|
||||
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
@ -571,7 +571,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
DestinationPredefinedAcl = GetDomainACL(newdomain)
|
||||
});
|
||||
|
||||
QuotaUsedAdd(newdomain, Convert.ToInt64(obj.Size));
|
||||
await QuotaUsedAddAsync(newdomain, Convert.ToInt64(obj.Size));
|
||||
}
|
||||
}
|
||||
|
||||
@ -734,7 +734,7 @@ public class GoogleCloudStorage : BaseStorage
|
||||
if (QuotaController != null)
|
||||
{
|
||||
var size = await GetFileSizeAsync(domain, path);
|
||||
QuotaUsedAdd(domain, size);
|
||||
await QuotaUsedAddAsync(domain, size);
|
||||
}
|
||||
|
||||
return await GetUriAsync(domain, path);
|
||||
|
@ -29,11 +29,11 @@ namespace ASC.Data.Storage;
|
||||
public interface IQuotaController
|
||||
{
|
||||
//quotaCheckFileSize:hack for Backup bug 48873
|
||||
void QuotaUsedAdd(string module, string domain, string dataTag, long size, bool quotaCheckFileSize = true);
|
||||
Task QuotaUsedAddAsync(string module, string domain, string dataTag, long size, bool quotaCheckFileSize = true);
|
||||
|
||||
void QuotaUsedDelete(string module, string domain, string dataTag, long size);
|
||||
Task QuotaUsedDeleteAsync(string module, string domain, string dataTag, long size);
|
||||
|
||||
void QuotaUsedSet(string module, string domain, string dataTag, long size);
|
||||
Task QuotaUsedSetAsync(string module, string domain, string dataTag, long size);
|
||||
|
||||
void QuotaUsedCheck(long size);
|
||||
Task QuotaUsedCheckAsync(long size);
|
||||
}
|
||||
|
@ -192,15 +192,15 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
return (QuotaController != null) && !domain.EndsWith("_temp");
|
||||
}
|
||||
|
||||
public Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentType,
|
||||
public async Task<Uri> SaveAsync(string domain, string path, Stream stream, string contentType,
|
||||
string contentDisposition, ACL acl, string contentEncoding = null, int cacheDays = 5,
|
||||
DateTime? deleteAt = null, long? deleteAfter = null)
|
||||
{
|
||||
var buffered = _tempStream.GetBuffered(stream);
|
||||
|
||||
if (EnableQuotaCheck(domain))
|
||||
if (EnableQuotaCheck(domain))
|
||||
{
|
||||
QuotaController.QuotaUsedCheck(buffered.Length);
|
||||
await QuotaController.QuotaUsedCheckAsync(buffered.Length);
|
||||
}
|
||||
|
||||
var client = GetClient();
|
||||
@ -282,9 +282,9 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
_region
|
||||
);
|
||||
|
||||
QuotaUsedAdd(domain, buffered.Length);
|
||||
await QuotaUsedAddAsync(domain, buffered.Length);
|
||||
|
||||
return GetUriAsync(domain, path);
|
||||
return await GetUriAsync(domain, path);
|
||||
|
||||
}
|
||||
|
||||
@ -296,11 +296,11 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
client.DeleteObject(_private_container, MakePath(domain, path));
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
||||
public override async Task DeleteFilesAsync(string domain, string folderPath, string pattern, bool recursive)
|
||||
{
|
||||
var client = GetClient();
|
||||
|
||||
@ -309,7 +309,7 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
if (!files.Any())
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
@ -319,10 +319,8 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
if (QuotaController != null)
|
||||
{
|
||||
QuotaUsedDelete(domain, files.Select(x => x.Bytes).Sum());
|
||||
await QuotaUsedDeleteAsync(domain, files.Select(x => x.Bytes).Sum());
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, List<string> paths)
|
||||
@ -371,11 +369,11 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
if (quotaUsed > 0)
|
||||
{
|
||||
QuotaUsedDelete(domain, quotaUsed);
|
||||
await QuotaUsedDeleteAsync(domain, quotaUsed);
|
||||
}
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate)
|
||||
public override async Task DeleteFilesAsync(string domain, string folderPath, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
var client = GetClient();
|
||||
|
||||
@ -384,7 +382,7 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
if (!files.Any())
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
@ -394,10 +392,8 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
if (QuotaController != null)
|
||||
{
|
||||
QuotaUsedDelete(domain, files.Select(x => x.Bytes).Sum());
|
||||
await QuotaUsedDeleteAsync(domain, files.Select(x => x.Bytes).Sum());
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task MoveDirectoryAsync(string srcdomain, string srcdir, string newdomain, string newdir)
|
||||
@ -429,8 +425,8 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
await DeleteAsync(srcdomain, srcpath);
|
||||
|
||||
QuotaUsedDelete(srcdomain, size);
|
||||
QuotaUsedAdd(newdomain, size, quotaCheckFileSize);
|
||||
await QuotaUsedDeleteAsync(srcdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size, quotaCheckFileSize);
|
||||
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
@ -475,7 +471,7 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
return IsFileAsync(domain, path);
|
||||
}
|
||||
|
||||
public override Task DeleteDirectoryAsync(string domain, string path)
|
||||
public override async Task DeleteDirectoryAsync(string domain, string path)
|
||||
{
|
||||
var client = GetClient();
|
||||
|
||||
@ -484,9 +480,8 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
foreach (var obj in objToDel)
|
||||
{
|
||||
client.DeleteObject(_private_container, obj.Name);
|
||||
QuotaUsedDelete(domain, obj.Bytes);
|
||||
await QuotaUsedDeleteAsync(domain, obj.Bytes);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override Task<long> GetFileSizeAsync(string domain, string path)
|
||||
@ -521,7 +516,7 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
public override Task<long> ResetQuotaAsync(string domain)
|
||||
public override async Task<long> ResetQuotaAsync(string domain)
|
||||
{
|
||||
var client = GetClient();
|
||||
|
||||
@ -537,12 +532,12 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
size += obj.Bytes;
|
||||
}
|
||||
|
||||
QuotaController.QuotaUsedSet(Modulename, domain, DataList.GetData(domain), size);
|
||||
await QuotaController.QuotaUsedSetAsync(Modulename, domain, DataList.GetData(domain), size);
|
||||
|
||||
return Task.FromResult(size);
|
||||
return size;
|
||||
}
|
||||
|
||||
return Task.FromResult<long>(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override Task<long> GetUsedQuotaAsync(string domain)
|
||||
@ -571,12 +566,12 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
|
||||
client.CopyObject(_private_container, srcKey, _private_container, dstKey);
|
||||
|
||||
QuotaUsedAdd(newdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size);
|
||||
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
|
||||
public override Task CopyDirectoryAsync(string srcdomain, string dir, string newdomain, string newdir)
|
||||
public override async Task CopyDirectoryAsync(string srcdomain, string dir, string newdomain, string newdir)
|
||||
{
|
||||
var srckey = MakePath(srcdomain, dir);
|
||||
var dstkey = MakePath(newdomain, newdir);
|
||||
@ -588,9 +583,8 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
{
|
||||
client.CopyObject(_private_container, file.Name, _private_container, file.Name.Replace(srckey, dstkey));
|
||||
|
||||
QuotaUsedAdd(newdomain, file.Bytes);
|
||||
await QuotaUsedAddAsync(newdomain, file.Bytes);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public override async Task<string> SavePrivateAsync(string domain, string path, Stream stream, DateTime expires)
|
||||
@ -671,7 +665,7 @@ public class RackspaceCloudStorage : BaseStorage
|
||||
{
|
||||
var size = await GetFileSizeAsync(domain, path);
|
||||
|
||||
QuotaUsedAdd(domain, size);
|
||||
await QuotaUsedAddAsync(domain, size);
|
||||
}
|
||||
|
||||
return await GetUriAsync(domain, path);
|
||||
|
@ -199,7 +199,7 @@ public class S3Storage : BaseStorage
|
||||
|
||||
if (EnableQuotaCheck(domain))
|
||||
{
|
||||
QuotaController.QuotaUsedCheck(buffered.Length);
|
||||
await QuotaController.QuotaUsedCheckAsync(buffered.Length);
|
||||
}
|
||||
|
||||
using var client = GetClient();
|
||||
@ -262,7 +262,7 @@ public class S3Storage : BaseStorage
|
||||
|
||||
await InvalidateCloudFrontAsync(MakePath(domain, path));
|
||||
|
||||
QuotaUsedAdd(domain, buffered.Length);
|
||||
await QuotaUsedAddAsync(domain, buffered.Length);
|
||||
|
||||
return await GetUriAsync(domain, path);
|
||||
}
|
||||
@ -355,7 +355,7 @@ public class S3Storage : BaseStorage
|
||||
if (QuotaController != null)
|
||||
{
|
||||
var size = await GetFileSizeAsync(domain, path);
|
||||
QuotaUsedAdd(domain, size);
|
||||
await QuotaUsedAddAsync(domain, size);
|
||||
}
|
||||
|
||||
return await GetUriAsync(domain, path);
|
||||
@ -410,7 +410,7 @@ public class S3Storage : BaseStorage
|
||||
|
||||
await client.DeleteObjectAsync(request);
|
||||
|
||||
QuotaUsedDelete(domain, size);
|
||||
await QuotaUsedDeleteAsync(domain, size);
|
||||
}
|
||||
|
||||
public override Task DeleteFilesAsync(string domain, List<string> paths)
|
||||
@ -470,7 +470,7 @@ public class S3Storage : BaseStorage
|
||||
|
||||
if (quotaUsed > 0)
|
||||
{
|
||||
QuotaUsedDelete(domain, quotaUsed);
|
||||
await QuotaUsedDeleteAsync(domain, quotaUsed);
|
||||
}
|
||||
}
|
||||
|
||||
@ -496,7 +496,7 @@ public class S3Storage : BaseStorage
|
||||
|
||||
await client.DeleteObjectAsync(deleteRequest);
|
||||
|
||||
QuotaUsedDelete(domain, s3Object.Size);
|
||||
await QuotaUsedDeleteAsync(domain, s3Object.Size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -518,7 +518,7 @@ public class S3Storage : BaseStorage
|
||||
|
||||
await client.DeleteObjectAsync(deleteRequest);
|
||||
|
||||
QuotaUsedDelete(domain, s3Object.Size);
|
||||
await QuotaUsedDeleteAsync(domain, s3Object.Size);
|
||||
}
|
||||
}
|
||||
|
||||
@ -557,8 +557,8 @@ public class S3Storage : BaseStorage
|
||||
await CopyFileAsync(client, srcKey, dstKey, newdomain, S3MetadataDirective.REPLACE);
|
||||
await DeleteAsync(srcdomain, srcpath);
|
||||
|
||||
QuotaUsedDelete(srcdomain, size);
|
||||
QuotaUsedAdd(newdomain, size, quotaCheckFileSize);
|
||||
await QuotaUsedDeleteAsync(srcdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size, quotaCheckFileSize);
|
||||
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
@ -828,7 +828,7 @@ public class S3Storage : BaseStorage
|
||||
{
|
||||
var objects = await GetS3ObjectsAsync(domain);
|
||||
var size = objects.Sum(s3Object => s3Object.Size);
|
||||
QuotaController.QuotaUsedSet(Modulename, domain, DataList.GetData(domain), size);
|
||||
await QuotaController.QuotaUsedSetAsync(Modulename, domain, DataList.GetData(domain), size);
|
||||
|
||||
return size;
|
||||
}
|
||||
@ -851,7 +851,7 @@ public class S3Storage : BaseStorage
|
||||
using var client = GetClient();
|
||||
await CopyFileAsync(client, srcKey, dstKey, newdomain, S3MetadataDirective.REPLACE);
|
||||
|
||||
QuotaUsedAdd(newdomain, size);
|
||||
await QuotaUsedAddAsync(newdomain, size);
|
||||
|
||||
return await GetUriAsync(newdomain, newpath);
|
||||
}
|
||||
@ -869,7 +869,7 @@ public class S3Storage : BaseStorage
|
||||
{
|
||||
await CopyFileAsync(client, s3Object.Key, s3Object.Key.Replace(srckey, dstkey), newdomain);
|
||||
|
||||
QuotaUsedAdd(newdomain, s3Object.Size);
|
||||
await QuotaUsedAddAsync(newdomain, s3Object.Size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ public class UploadOperation
|
||||
path = path.TrimStart('/');
|
||||
var tenant = _tenantManager.GetTenant(tenantId);
|
||||
_tenantManager.SetCurrentTenant(tenant);
|
||||
_securityContext.AuthenticateMeWithoutCookie(tenant.OwnerId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(tenant.OwnerId);
|
||||
|
||||
var dataStore = _storageSettingsHelper.DataStore(_settingsManager.Load<CdnStorageSettings>());
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class MigrateOperation : DistributedTaskProgress
|
||||
var tenant = tenantManager.GetTenant(_tenantId);
|
||||
tenantManager.SetCurrentTenant(tenant);
|
||||
|
||||
securityContext.AuthenticateMeWithoutCookie(tenant.OwnerId);
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(tenant.OwnerId);
|
||||
|
||||
foreach (var module in _modules)
|
||||
{
|
||||
|
@ -62,25 +62,25 @@ public class TenantQuotaController : IQuotaController
|
||||
public void Init(int tenant)
|
||||
{
|
||||
_tenant = tenant;
|
||||
_lazyCurrentSize = new Lazy<long>(() => _tenantManager.FindTenantQuotaRows(tenant)
|
||||
_lazyCurrentSize = new Lazy<long>(() => _tenantManager.FindTenantQuotaRowsAsync(tenant).Result
|
||||
.Where(r => UsedInQuota(r.Tag))
|
||||
.Sum(r => r.Counter));
|
||||
}
|
||||
|
||||
public void QuotaUsedAdd(string module, string domain, string dataTag, long size, bool quotaCheckFileSize = true)
|
||||
public async Task QuotaUsedAddAsync(string module, string domain, string dataTag, long size, bool quotaCheckFileSize = true)
|
||||
{
|
||||
size = Math.Abs(size);
|
||||
if (UsedInQuota(dataTag))
|
||||
{
|
||||
QuotaUsedCheck(size, quotaCheckFileSize);
|
||||
await QuotaUsedCheckAsync(size, quotaCheckFileSize);
|
||||
CurrentSize += size;
|
||||
}
|
||||
|
||||
SetTenantQuotaRow(module, domain, size, dataTag, true, Guid.Empty);
|
||||
SetTenantQuotaRow(module, domain, size, dataTag, true, _authContext.CurrentAccount.ID);
|
||||
await SetTenantQuotaRowAsync(module, domain, size, dataTag, true, Guid.Empty);
|
||||
await SetTenantQuotaRowAsync(module, domain, size, dataTag, true, _authContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public void QuotaUsedDelete(string module, string domain, string dataTag, long size)
|
||||
public async Task QuotaUsedDeleteAsync(string module, string domain, string dataTag, long size)
|
||||
{
|
||||
size = -Math.Abs(size);
|
||||
if (UsedInQuota(dataTag))
|
||||
@ -88,11 +88,11 @@ public class TenantQuotaController : IQuotaController
|
||||
CurrentSize += size;
|
||||
}
|
||||
|
||||
SetTenantQuotaRow(module, domain, size, dataTag, true, Guid.Empty);
|
||||
SetTenantQuotaRow(module, domain, size, dataTag, true, _authContext.CurrentAccount.ID);
|
||||
await SetTenantQuotaRowAsync(module, domain, size, dataTag, true, Guid.Empty);
|
||||
await SetTenantQuotaRowAsync(module, domain, size, dataTag, true, _authContext.CurrentAccount.ID);
|
||||
}
|
||||
|
||||
public void QuotaUsedSet(string module, string domain, string dataTag, long size)
|
||||
public async Task QuotaUsedSetAsync(string module, string domain, string dataTag, long size)
|
||||
{
|
||||
size = Math.Max(0, size);
|
||||
if (UsedInQuota(dataTag))
|
||||
@ -100,35 +100,35 @@ public class TenantQuotaController : IQuotaController
|
||||
CurrentSize += size;
|
||||
}
|
||||
|
||||
SetTenantQuotaRow(module, domain, size, dataTag, false, Guid.Empty);
|
||||
await SetTenantQuotaRowAsync(module, domain, size, dataTag, false, Guid.Empty);
|
||||
}
|
||||
|
||||
public void QuotaUsedCheck(long size)
|
||||
public Task QuotaUsedCheckAsync(long size)
|
||||
{
|
||||
QuotaUsedCheck(size, true);
|
||||
return QuotaUsedCheckAsync(size, true);
|
||||
}
|
||||
|
||||
public void QuotaUsedCheck(long size, bool quotaCheckFileSize)
|
||||
public async Task QuotaUsedCheckAsync(long size, bool quotaCheckFileSize)
|
||||
{
|
||||
var quota = _tenantManager.GetTenantQuota(_tenant);
|
||||
var quota = await _tenantManager.GetTenantQuotaAsync(_tenant);
|
||||
if (quota != null)
|
||||
{
|
||||
if (quota.MaxFileSize != 0 && quotaCheckFileSize)
|
||||
{
|
||||
_maxFileSizeChecker.CheckAdd(_tenant, size);
|
||||
await _maxFileSizeChecker.CheckAddAsync(_tenant, size);
|
||||
}
|
||||
|
||||
if (quota.MaxTotalSize != 0)
|
||||
{
|
||||
_maxTotalSizeChecker.CheckAdd(_tenant, CurrentSize + size);
|
||||
await _maxTotalSizeChecker.CheckAddAsync(_tenant, CurrentSize + size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void SetTenantQuotaRow(string module, string domain, long size, string dataTag, bool exchange, Guid userId)
|
||||
private async Task SetTenantQuotaRowAsync(string module, string domain, long size, string dataTag, bool exchange, Guid userId)
|
||||
{
|
||||
_tenantManager.SetTenantQuotaRow(
|
||||
await _tenantManager.SetTenantQuotaRowAsync(
|
||||
new TenantQuotaRow { Tenant = _tenant, Path = $"/{module}/{domain}", Counter = size, Tag = dataTag, UserId = userId, LastModified = DateTime.UtcNow },
|
||||
exchange);
|
||||
|
||||
|
@ -29,7 +29,7 @@ namespace ASC.EventBus.Abstractions;
|
||||
public interface IIntegrationEventHandler<in TIntegrationEvent> : IIntegrationEventHandler
|
||||
where TIntegrationEvent : IntegrationEvent
|
||||
{
|
||||
Task Handle(TIntegrationEvent @event);
|
||||
Task HandleAsync(TIntegrationEvent @event);
|
||||
}
|
||||
|
||||
public interface IIntegrationEventHandler
|
||||
|
@ -241,7 +241,7 @@ public class MigrationController : ControllerBase
|
||||
/// </summary>
|
||||
/// <param name="isSendWelcomeEmail"></param>
|
||||
[HttpPost("finish")]
|
||||
public void Finish(bool isSendWelcomeEmail)
|
||||
public async Task FinishAsync(bool isSendWelcomeEmail)
|
||||
{
|
||||
if (!_coreBaseSettings.Standalone || !_userManager.IsDocSpaceAdmin(_authContext.CurrentAccount.ID))
|
||||
{
|
||||
@ -259,7 +259,7 @@ public class MigrationController : ControllerBase
|
||||
foreach (var gu in guidUsers)
|
||||
{
|
||||
var u = _userManager.GetUsers(gu);
|
||||
_studioNotifyService.UserInfoActivation(u);
|
||||
await _studioNotifyService.UserInfoActivationAsync(u);
|
||||
}
|
||||
}
|
||||
ClearCache();
|
||||
|
@ -228,11 +228,11 @@ namespace ASC.Migration.GoogleWorkspace
|
||||
try
|
||||
{
|
||||
var currentUser = _securityContext.CurrentAccount;
|
||||
_securityContext.AuthenticateMe(user.Guid);
|
||||
await _securityContext.AuthenticateMeAsync(user.Guid);
|
||||
user.MigratingFiles.SetUsersDict(usersForImport.Except(failedUsers));
|
||||
user.MigratingFiles.SetGroupsDict(groupsForImport);
|
||||
await user.MigratingFiles.Migrate();
|
||||
_securityContext.AuthenticateMe(currentUser.ID);
|
||||
await _securityContext.AuthenticateMeAsync(currentUser.ID);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -555,11 +555,11 @@ public class NextcloudWorkspaceMigration : AbstractMigration<NCMigrationInfo, NC
|
||||
try
|
||||
{
|
||||
var currentUser = _securityContext.CurrentAccount;
|
||||
_securityContext.AuthenticateMe(user.Guid);
|
||||
await _securityContext.AuthenticateMeAsync(user.Guid);
|
||||
user.MigratingFiles.SetUsersDict(usersForImport.Except(failedUsers));
|
||||
user.MigratingFiles.SetGroupsDict(groupsForImport);
|
||||
await user.MigratingFiles.Migrate();
|
||||
_securityContext.AuthenticateMe(currentUser.ID);
|
||||
await _securityContext.AuthenticateMeAsync(currentUser.ID);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -529,11 +529,11 @@ public class OwnCloudMigration : AbstractMigration<OCMigrationInfo, OCMigratingU
|
||||
try
|
||||
{
|
||||
var currentUser = _securityContext.CurrentAccount;
|
||||
_securityContext.AuthenticateMe(user.Guid);
|
||||
await _securityContext.AuthenticateMeAsync(user.Guid);
|
||||
user.MigratingFiles.SetUsersDict(usersForImport.Except(failedUsers));
|
||||
user.MigratingFiles.SetGroupsDict(groupsForImport);
|
||||
await user.MigratingFiles.Migrate();
|
||||
_securityContext.AuthenticateMe(currentUser.ID);
|
||||
await _securityContext.AuthenticateMeAsync(currentUser.ID);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -279,7 +279,7 @@ public class PortalController : ControllerBase
|
||||
Quotas = new List<Quota> { new Quota(trialQuotaId, 1) },
|
||||
DueDate = dueDate
|
||||
};
|
||||
_hostedSolution.SetTariff(t.Id, tariff);
|
||||
await _hostedSolution.SetTariffAsync(t.Id, tariff);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class TariffController : ControllerBase
|
||||
[HttpPut("set")]
|
||||
[AllowCrossSiteJson]
|
||||
[Authorize(AuthenticationSchemes = "auth:allowskip:default")]
|
||||
public IActionResult SetTariff(TariffModel model)
|
||||
public async Task<IActionResult> SetTariffAsync(TariffModel model)
|
||||
{
|
||||
if (!CommonMethods.GetTenant(model, out var tenant))
|
||||
{
|
||||
@ -111,7 +111,7 @@ public class TariffController : ControllerBase
|
||||
quota.MaxFileSize = model.MaxFileSize;
|
||||
}
|
||||
|
||||
HostedSolution.SaveTenantQuota(quota);
|
||||
await HostedSolution.SaveTenantQuotaAsync(quota);
|
||||
|
||||
var tariff = new Tariff
|
||||
{
|
||||
@ -119,15 +119,15 @@ public class TariffController : ControllerBase
|
||||
DueDate = model.DueDate != default ? model.DueDate : DateTime.MaxValue.AddSeconds(-1),
|
||||
};
|
||||
|
||||
HostedSolution.SetTariff(tenant.Id, tariff);
|
||||
await HostedSolution.SetTariffAsync(tenant.Id, tariff);
|
||||
|
||||
return GetTariff(tenant);
|
||||
return await GetTariffAsync(tenant);
|
||||
}
|
||||
|
||||
[HttpGet("get")]
|
||||
[AllowCrossSiteJson]
|
||||
[Authorize(AuthenticationSchemes = "auth:allowskip:default")]
|
||||
public IActionResult GetTariff([FromQuery] TariffModel model)
|
||||
public async Task<IActionResult> GetTariffAsync([FromQuery] TariffModel model)
|
||||
{
|
||||
if (!CommonMethods.GetTenant(model, out var tenant))
|
||||
{
|
||||
@ -151,14 +151,14 @@ public class TariffController : ControllerBase
|
||||
});
|
||||
}
|
||||
|
||||
return GetTariff(tenant);
|
||||
return await GetTariffAsync(tenant);
|
||||
}
|
||||
|
||||
[HttpGet("all")]
|
||||
[AllowCrossSiteJson]
|
||||
public IActionResult GetTariffs()
|
||||
public async Task<IActionResult> GetTariffsAsync()
|
||||
{
|
||||
var tariffs = HostedSolution.GetTenantQuotas()
|
||||
var tariffs = (await HostedSolution.GetTenantQuotasAsync())
|
||||
.Where(q => !q.Trial && !q.Free)
|
||||
.OrderBy(q => q.CountRoomAdmin)
|
||||
.ThenByDescending(q => q.Tenant)
|
||||
@ -174,11 +174,11 @@ public class TariffController : ControllerBase
|
||||
|
||||
#region private methods
|
||||
|
||||
private IActionResult GetTariff(Tenant tenant)
|
||||
private async Task<IActionResult> GetTariffAsync(Tenant tenant)
|
||||
{
|
||||
var tariff = HostedSolution.GetTariff(tenant.Id, false);
|
||||
var tariff = await HostedSolution.GetTariffAsync(tenant.Id, false);
|
||||
|
||||
var quota = HostedSolution.GetTenantQuota(tenant.Id);
|
||||
var quota = await HostedSolution.GetTenantQuotaAsync(tenant.Id);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ public class BackupDeleteScheldureRequestedIntegrationEventHandler : IIntegratio
|
||||
_backupService = backupService;
|
||||
}
|
||||
|
||||
public async Task Handle(IntegrationEvent @event)
|
||||
public async Task HandleAsync(IntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public class BackupRequestedIntegrationEventHandler : IIntegrationEventHandler<B
|
||||
_backupWorker = backupWorker;
|
||||
}
|
||||
|
||||
public async Task Handle(BackupRequestIntegrationEvent @event)
|
||||
public async Task HandleAsync(BackupRequestIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
@ -67,7 +67,7 @@ public class BackupRequestedIntegrationEventHandler : IIntegrationEventHandler<B
|
||||
}
|
||||
|
||||
_tenantManager.SetCurrentTenant(@event.TenantId);
|
||||
_securityContext.AuthenticateMeWithoutCookie(_authManager.GetAccountByID(@event.TenantId, @event.CreateBy));
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(_authManager.GetAccountByID(@event.TenantId, @event.CreateBy));
|
||||
|
||||
if (@event.IsScheduled)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public class BackupRestoreRequestedIntegrationEventHandler : IIntegrationEventHa
|
||||
_backupWorker = backupWorker;
|
||||
}
|
||||
|
||||
public async Task Handle(BackupRestoreRequestIntegrationEvent @event)
|
||||
public async Task HandleAsync(BackupRestoreRequestIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
@ -67,7 +67,7 @@ public class BackupRestoreRequestedIntegrationEventHandler : IIntegrationEventHa
|
||||
}
|
||||
|
||||
_tenantManager.SetCurrentTenant(@event.TenantId);
|
||||
_securityContext.AuthenticateMeWithoutCookie(_authManager.GetAccountByID(@event.TenantId, @event.CreateBy));
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(_authManager.GetAccountByID(@event.TenantId, @event.CreateBy));
|
||||
|
||||
await _backupAjaxHandler.StartRestoreAsync(@event.BackupId,
|
||||
@event.StorageType,
|
||||
|
@ -126,7 +126,7 @@ internal sealed class BackupCleanerService : BackgroundService
|
||||
continue;
|
||||
}
|
||||
|
||||
await backupStorage.Delete(backupRecord.StoragePath);
|
||||
await backupStorage.DeleteAsync(backupRecord.StoragePath);
|
||||
|
||||
await backupRepository.DeleteBackupRecordAsync(backupRecord.Id);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ internal sealed class BackupListenerService : IHostedService
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_cacheDeleteSchedule.Subscribe((n) => DeleteScheldureAsync(n), CacheNotifyAction.Insert);
|
||||
_cacheDeleteSchedule.Subscribe(async (n) => await DeleteScheldureAsync(n), CacheNotifyAction.Insert);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
@ -105,9 +105,9 @@ public sealed class BackupSchedulerService : BackgroundService
|
||||
|
||||
try
|
||||
{
|
||||
if (_coreBaseSettings.Standalone || tenantManager.GetTenantQuota(schedule.TenantId).AutoBackupRestore)
|
||||
if (_coreBaseSettings.Standalone || (await tenantManager.GetTenantQuotaAsync(schedule.TenantId)).AutoBackupRestore)
|
||||
{
|
||||
var tariff = tariffService.GetTariff(schedule.TenantId);
|
||||
var tariff = await tariffService.GetTariffAsync(schedule.TenantId);
|
||||
|
||||
if (tariff.State < TariffState.Delay)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ public class BackupController : ControllerBase
|
||||
/// <param name="cronParams">Cron parameters</param>
|
||||
/// <category>Backup</category>
|
||||
[HttpPost("createbackupschedule")]
|
||||
public bool CreateBackupSchedule(BackupScheduleDto backupSchedule)
|
||||
public async Task<bool> CreateBackupScheduleAsync(BackupScheduleDto backupSchedule)
|
||||
{
|
||||
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());
|
||||
@ -78,7 +78,7 @@ public class BackupController : ControllerBase
|
||||
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);
|
||||
await _backupHandler.CreateScheduleAsync(storageType, storageParams, backupStored, cron);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ public class EncryptionDataStorageRequestedIntegrationEventHandler : IIntegratio
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task Handle(EncryptionDataStorageRequestedIntegrationEvent @event)
|
||||
public async Task HandleAsync(EncryptionDataStorageRequestedIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
|
@ -163,12 +163,12 @@ public class SearchSettingsHelper
|
||||
return settings.IsEnabled(((ISearchItemDocument)_serviceProvider.GetService(t)).IndexName);
|
||||
}
|
||||
|
||||
public bool CanSearchByContent<T>() where T : class, ISearchItem
|
||||
public Task<bool> CanSearchByContentAsync<T>() where T : class, ISearchItem
|
||||
{
|
||||
return CanSearchByContent(typeof(T));
|
||||
return CanSearchByContentAsync(typeof(T));
|
||||
}
|
||||
|
||||
public bool CanSearchByContent(Type t)
|
||||
public async Task<bool> CanSearchByContentAsync(Type t)
|
||||
{
|
||||
var tenantId = _tenantManager.GetCurrentTenant().Id;
|
||||
if (!CanIndexByContent(t, tenantId))
|
||||
@ -181,7 +181,7 @@ public class SearchSettingsHelper
|
||||
return true;
|
||||
}
|
||||
|
||||
return _tenantManager.GetTenantQuota(tenantId).ContentSearch;
|
||||
return (await _tenantManager.GetTenantQuotaAsync(tenantId)).ContentSearch;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,11 @@ public class FeedAggregatorService : FeedBaseService
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryAuthenticate(SecurityContext securityContext, AuthManager authManager, int tenantId, Guid userid)
|
||||
private static async Task<bool> TryAuthenticateAsync(SecurityContext securityContext, AuthManager authManager, int tenantId, Guid userid)
|
||||
{
|
||||
try
|
||||
{
|
||||
securityContext.AuthenticateMeWithoutCookie(authManager.GetAccountByID(tenantId, userid));
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(authManager.GetAccountByID(tenantId, userid));
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
@ -157,7 +157,7 @@ public class FeedAggregatorService : FeedBaseService
|
||||
|
||||
foreach (var u in users)
|
||||
{
|
||||
if (!TryAuthenticate(securityContext, authManager, tenant1, u.Id))
|
||||
if (!await TryAuthenticateAsync(securityContext, authManager, tenant1, u.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class NotifyInvokeSendMethodRequestedIntegrationEventHandler : IIntegrati
|
||||
}
|
||||
|
||||
|
||||
public async Task Handle(NotifyInvokeSendMethodRequestedIntegrationEvent @event)
|
||||
public async Task HandleAsync(NotifyInvokeSendMethodRequestedIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public class NotifySendMessageRequestedIntegrationEventHandler : IIntegrationEve
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Handle(NotifySendMessageRequestedIntegrationEvent @event)
|
||||
public async Task HandleAsync(NotifySendMessageRequestedIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ public class TelegramSendMessageRequestedIntegrationEventHandler : IIntegrationE
|
||||
_telegramHandler = telegramHandler;
|
||||
}
|
||||
|
||||
public async Task Handle(NotifySendTelegramMessageRequestedIntegrationEvent @event)
|
||||
public async Task HandleAsync(NotifySendTelegramMessageRequestedIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
|
@ -135,7 +135,7 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage
|
||||
_tenantManager.SetCurrentTenant(TenantId);
|
||||
var size = await GetUserSpaceUsageAsync(userId);
|
||||
|
||||
_tenantManager.SetTenantQuotaRow(
|
||||
await _tenantManager.SetTenantQuotaRowAsync(
|
||||
new TenantQuotaRow { Tenant = TenantId, Path = $"/{FileConstant.ModuleId}/", Counter = size, Tag = WebItemManager.DocumentsProductID.ToString(), UserId = userId, LastModified = DateTime.UtcNow },
|
||||
false);
|
||||
}
|
||||
|
@ -38,14 +38,14 @@ public class CountRoomChecker : TenantQuotaFeatureCheckerCount<CountRoomFeature>
|
||||
_tariffService = tariffService;
|
||||
}
|
||||
|
||||
public override void CheckAdd(int tenantId, int newValue)
|
||||
public override async Task CheckAddAsync(int tenantId, int newValue)
|
||||
{
|
||||
if (_tariffService.GetTariff(tenantId).State > TariffState.Paid)
|
||||
if ((await _tariffService.GetTariffAsync(tenantId)).State > TariffState.Paid)
|
||||
{
|
||||
throw new BillingNotFoundException(Resource.ErrorNotAllowedOption, "room");
|
||||
}
|
||||
|
||||
base.CheckAdd(tenantId, newValue);
|
||||
await base.CheckAddAsync(tenantId, newValue);
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,7 +58,7 @@ public class CountRoomCheckerStatistic : ITenantQuotaFeatureStat<CountRoomFeatur
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public async Task<int> GetValue()
|
||||
public async Task<int> GetValueAsync()
|
||||
{
|
||||
var folderDao = _serviceProvider.GetService<IFolderDao<int>>();
|
||||
var globalFolderHelper = _serviceProvider.GetService<GlobalFolderHelper>();
|
||||
|
@ -422,7 +422,7 @@ internal class FileDao : AbstractDao, IFileDao<int>
|
||||
|
||||
if (quotaLimit != -1)
|
||||
{
|
||||
var userUsedSpace = Math.Max(0, _quotaService.FindUserQuotaRows(TenantID, user.Id).Where(r => !string.IsNullOrEmpty(r.Tag)).Sum(r => r.Counter));
|
||||
var userUsedSpace = Math.Max(0, (await _quotaService.FindUserQuotaRowsAsync(TenantID, user.Id)).Where(r => !string.IsNullOrEmpty(r.Tag)).Sum(r => r.Counter));
|
||||
|
||||
if (quotaLimit - userUsedSpace < file.ContentLength)
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ public class DbFile : BaseEntity, IDbFile, IDbSearch, ISearchItemDocument
|
||||
|
||||
public Expression<Func<ISearchItem, object[]>> GetSearchContentFields(SearchSettingsHelper searchSettings)
|
||||
{
|
||||
if (searchSettings.CanSearchByContent(GetType()))
|
||||
if (searchSettings.CanSearchByContentAsync(GetType()).Result)
|
||||
{
|
||||
return (a) => new[] { Title, Comment, Changes, Document.Attachment.Content };
|
||||
}
|
||||
|
@ -3267,7 +3267,7 @@ public class FileStorageService<T> //: IFileStorageService
|
||||
}
|
||||
|
||||
var link = _roomLinkService.GetInvitationLink(user.Email, share.Access, _authContext.CurrentAccount.ID);
|
||||
_studioNotifyService.SendEmailRoomInvite(user.Email, room.Title, link);
|
||||
await _studioNotifyService.SendEmailRoomInviteAsync(user.Email, room.Title, link);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class UsersInRoomStatistic : ITenantQuotaFeatureStat<UsersInRoomFeature,
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
public Task<int> GetValue()
|
||||
public Task<int> GetValueAsync()
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress
|
||||
PublishChanges();
|
||||
|
||||
var account = _authentication.GetAccountByID(TenantId, user.Id);
|
||||
_securityContext.AuthenticateMe(account);
|
||||
await _securityContext.AuthenticateMeAsync(account);
|
||||
|
||||
foreach (var item in webItems)
|
||||
{
|
||||
|
@ -173,7 +173,7 @@ public class ChunkedUploaderHandlerService
|
||||
if (request.Type(_instanceCrypto) == ChunkedRequestType.Initiate)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(request.TenantId);
|
||||
_securityContext.AuthenticateMeWithoutCookie(_authManager.GetAccountByID(_tenantManager.GetCurrentTenant().Id, request.AuthKey(_instanceCrypto)));
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(_authManager.GetAccountByID(_tenantManager.GetCurrentTenant().Id, request.AuthKey(_instanceCrypto)));
|
||||
var cultureInfo = request.CultureInfo(_setupInfo);
|
||||
if (cultureInfo != null)
|
||||
{
|
||||
@ -189,7 +189,7 @@ public class ChunkedUploaderHandlerService
|
||||
if (uploadSession != null)
|
||||
{
|
||||
_tenantManager.SetCurrentTenant(uploadSession.TenantId);
|
||||
_securityContext.AuthenticateMeWithoutCookie(_authManager.GetAccountByID(_tenantManager.GetCurrentTenant().Id, uploadSession.UserId));
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(_authManager.GetAccountByID(_tenantManager.GetCurrentTenant().Id, uploadSession.UserId));
|
||||
var culture = _setupInfo.GetPersonalCulture(uploadSession.CultureName).Value;
|
||||
if (culture != null)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ public class FileHandler
|
||||
|
||||
public async Task Invoke(HttpContext context, FileHandlerService fileHandlerService)
|
||||
{
|
||||
await fileHandlerService.Invoke(context);
|
||||
await fileHandlerService.InvokeAsync(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,19 +144,18 @@ public class FileHandlerService
|
||||
_thumbnailSettings = thumbnailSettings;
|
||||
}
|
||||
|
||||
public Task Invoke(HttpContext context)
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (_tenantExtra.IsNotPaid())
|
||||
if (await _tenantExtra.IsNotPaidAsync())
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.PaymentRequired;
|
||||
//context.Response.StatusDescription = "Payment Required.";
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
return InternalInvoke(context);
|
||||
await InternalInvokeAsync(context);
|
||||
}
|
||||
|
||||
private async Task InternalInvoke(HttpContext context)
|
||||
private async Task InternalInvokeAsync(HttpContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ public class DocuSignHandler
|
||||
|
||||
public async Task Invoke(HttpContext context, DocuSignHandlerService docuSignHandlerService)
|
||||
{
|
||||
await docuSignHandlerService.Invoke(context);
|
||||
await docuSignHandlerService.InvokeAsync(context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,9 +66,9 @@ public class DocuSignHandlerService
|
||||
_log = logger;
|
||||
}
|
||||
|
||||
public async Task Invoke(HttpContext context)
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (_tenantExtra.IsNotPaid())
|
||||
if (await _tenantExtra.IsNotPaidAsync())
|
||||
{
|
||||
context.Response.StatusCode = (int)HttpStatusCode.PaymentRequired;
|
||||
await context.Response.WriteAsync("Payment Required.");
|
||||
@ -146,7 +146,7 @@ public class DocuSignHandlerService
|
||||
|
||||
var customFieldUserIdNode = GetSingleNode(envelopeStatusNode, "CustomFields/" + XmlPrefix + ":CustomField[" + XmlPrefix + ":Name='" + DocuSignHelper.UserField + "']", mgr);
|
||||
var userIdString = GetSingleNode(customFieldUserIdNode, "Value", mgr).InnerText;
|
||||
Auth(userIdString);
|
||||
await AuthAsync(userIdString);
|
||||
|
||||
switch (status)
|
||||
{
|
||||
@ -205,14 +205,14 @@ public class DocuSignHandlerService
|
||||
}
|
||||
}
|
||||
|
||||
private void Auth(string userIdString)
|
||||
private async Task AuthAsync(string userIdString)
|
||||
{
|
||||
if (!Guid.TryParse(userIdString ?? "", out var userId))
|
||||
{
|
||||
throw new Exception("DocuSign incorrect User ID: " + userIdString);
|
||||
}
|
||||
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId);
|
||||
}
|
||||
|
||||
private static XmlNode GetSingleNode(XmlNode node, string xpath, XmlNamespaceManager mgr, bool canMiss = false)
|
||||
|
@ -309,8 +309,6 @@ public class EditorConfiguration<T>
|
||||
|
||||
public bool ModeWrite { get; set; }
|
||||
|
||||
public PluginsConfig Plugins { get; set; }
|
||||
|
||||
public List<RecentConfig> Recent
|
||||
{
|
||||
get
|
||||
@ -434,7 +432,6 @@ public class EditorConfiguration<T>
|
||||
FilesLinkUtility filesLinkUtility,
|
||||
FileUtility fileUtility,
|
||||
BaseCommonLinkUtility baseCommonLinkUtility,
|
||||
PluginsConfig pluginsConfig,
|
||||
EmbeddedConfig embeddedConfig,
|
||||
CustomizationConfig<T> customizationConfig,
|
||||
FilesSettingsHelper filesSettingsHelper,
|
||||
@ -452,7 +449,6 @@ public class EditorConfiguration<T>
|
||||
_daoFactory = daoFactory;
|
||||
_entryManager = entryManager;
|
||||
_documentServiceTrackerHelper = documentServiceTrackerHelper;
|
||||
Plugins = pluginsConfig;
|
||||
Embedded = embeddedConfig;
|
||||
_userInfo = userManager.GetUsers(authContext.CurrentAccount.ID);
|
||||
|
||||
@ -1010,56 +1006,6 @@ public class LogoConfig<T>
|
||||
}
|
||||
}
|
||||
|
||||
[Transient]
|
||||
public class PluginsConfig
|
||||
{
|
||||
private readonly BaseCommonLinkUtility _baseCommonLinkUtility;
|
||||
|
||||
private readonly ConsumerFactory _consumerFactory;
|
||||
|
||||
private readonly CoreBaseSettings _coreBaseSettings;
|
||||
private readonly TenantManager _tenantManager;
|
||||
|
||||
public string[] PluginsData
|
||||
{
|
||||
get
|
||||
{
|
||||
var plugins = new List<string>();
|
||||
|
||||
if (_coreBaseSettings.Standalone || !_tenantManager.GetCurrentTenantQuota().Free)
|
||||
{
|
||||
var easyBibHelper = _consumerFactory.Get<EasyBibHelper>();
|
||||
if (!string.IsNullOrEmpty(easyBibHelper.AppKey))
|
||||
{
|
||||
plugins.Add(_baseCommonLinkUtility.GetFullAbsolutePath("ThirdParty/plugin/easybib/config.json"));
|
||||
}
|
||||
|
||||
var wordpressLoginProvider = _consumerFactory.Get<WordpressLoginProvider>();
|
||||
if (!string.IsNullOrEmpty(wordpressLoginProvider.ClientID) &&
|
||||
!string.IsNullOrEmpty(wordpressLoginProvider.ClientSecret) &&
|
||||
!string.IsNullOrEmpty(wordpressLoginProvider.RedirectUri))
|
||||
{
|
||||
plugins.Add(_baseCommonLinkUtility.GetFullAbsolutePath("ThirdParty/plugin/wordpress/config.json"));
|
||||
}
|
||||
}
|
||||
|
||||
return plugins.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public PluginsConfig(
|
||||
ConsumerFactory consumerFactory,
|
||||
BaseCommonLinkUtility baseCommonLinkUtility,
|
||||
CoreBaseSettings coreBaseSettings,
|
||||
TenantManager tenantManager)
|
||||
{
|
||||
_consumerFactory = consumerFactory;
|
||||
_baseCommonLinkUtility = baseCommonLinkUtility;
|
||||
_coreBaseSettings = coreBaseSettings;
|
||||
_tenantManager = tenantManager;
|
||||
}
|
||||
}
|
||||
|
||||
public class RecentConfig
|
||||
{
|
||||
public string Folder { get; set; }
|
||||
@ -1093,7 +1039,6 @@ public static class ConfigurationExtention
|
||||
services.TryAdd<EditorConfiguration<string>>();
|
||||
services.TryAdd<EditorConfiguration<int>>();
|
||||
|
||||
services.TryAdd<PluginsConfig>();
|
||||
services.TryAdd<EmbeddedConfig>();
|
||||
|
||||
services.TryAdd<CustomizationConfig<string>>();
|
||||
|
@ -352,7 +352,7 @@ public class DocumentServiceTrackerHelper
|
||||
UserInfo user = null;
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId);
|
||||
|
||||
user = _userManager.GetUsers(userId);
|
||||
var culture = string.IsNullOrEmpty(user.CultureName) ? _tenantManager.GetCurrentTenant().GetCulture() : CultureInfo.GetCultureInfo(user.CultureName);
|
||||
@ -472,7 +472,7 @@ public class DocumentServiceTrackerHelper
|
||||
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(userId);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(userId);
|
||||
|
||||
var user = _userManager.GetUsers(userId);
|
||||
var culture = string.IsNullOrEmpty(user.CultureName) ? _tenantManager.GetCurrentTenant().GetCulture() : CultureInfo.GetCultureInfo(user.CultureName);
|
||||
|
@ -138,7 +138,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider
|
||||
|
||||
if (!string.IsNullOrEmpty(context.Request.Query["code"]))
|
||||
{
|
||||
await RequestCode(context);
|
||||
await RequestCodeAsync(context);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -338,7 +338,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider
|
||||
}
|
||||
|
||||
|
||||
private async Task RequestCode(HttpContext context)
|
||||
private async Task RequestCodeAsync(HttpContext context)
|
||||
{
|
||||
var token = GetToken(context.Request.Query["code"]);
|
||||
if (token == null)
|
||||
@ -373,7 +373,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider
|
||||
throw new Exception("Profile is null");
|
||||
}
|
||||
|
||||
_cookiesManager.AuthenticateMeAndSetCookies(userInfo.Tenant, userInfo.Id, MessageAction.LoginSuccessViaSocialApp);
|
||||
await _cookiesManager.AuthenticateMeAndSetCookiesAsync(userInfo.Tenant, userInfo.Id, MessageAction.LoginSuccessViaSocialApp);
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
@ -546,8 +546,8 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider
|
||||
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
userInfo = await _userManagerWrapper.AddUser(userInfo, UserManagerWrapper.GeneratePassword());
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
userInfo = await _userManagerWrapper.AddUserAsync(userInfo, UserManagerWrapper.GeneratePassword());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -376,7 +376,7 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider
|
||||
throw new Exception("Profile is null");
|
||||
}
|
||||
|
||||
_cookiesManager.AuthenticateMeAndSetCookies(userInfo.Tenant, userInfo.Id, MessageAction.LoginSuccessViaSocialApp);
|
||||
await _cookiesManager.AuthenticateMeAndSetCookiesAsync(userInfo.Tenant, userInfo.Id, MessageAction.LoginSuccessViaSocialApp);
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
@ -675,8 +675,8 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider
|
||||
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
userInfo = await _userManagerWrapper.AddUser(userInfo, UserManagerWrapper.GeneratePassword());
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
userInfo = await _userManagerWrapper.AddUserAsync(userInfo, UserManagerWrapper.GeneratePassword());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -150,7 +150,7 @@ public class FileSharingAceHelper<T>
|
||||
}
|
||||
else
|
||||
{
|
||||
_usersInRoomChecker.CheckAdd(usersInRoomCount + (i++));
|
||||
await _usersInRoomChecker.CheckAddAsync(usersInRoomCount + (i++));
|
||||
}
|
||||
|
||||
try
|
||||
@ -227,7 +227,7 @@ public class FileSharingAceHelper<T>
|
||||
if (emailInvite)
|
||||
{
|
||||
var link = _roomLinkService.GetInvitationLink(w.Email, share, _authContext.CurrentAccount.ID);
|
||||
_studioNotifyService.SendEmailRoomInvite(w.Email, entry.Title, link);
|
||||
await _studioNotifyService.SendEmailRoomInviteAsync(w.Email, entry.Title, link);
|
||||
_logger.Debug(link);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ public class MailMergeTaskRunner
|
||||
RequestUri = new Uri(_baseCommonLinkUtility.GetFullAbsolutePath(apiUrlAttach)),
|
||||
Method = HttpMethod.Post
|
||||
};
|
||||
request.Headers.Add("Authorization", _securityContext.AuthenticateMe(_securityContext.CurrentAccount.ID));
|
||||
request.Headers.Add("Authorization", await _securityContext.AuthenticateMeAsync(_securityContext.CurrentAccount.ID));
|
||||
request.Content.Headers.ContentType = new MediaTypeHeaderValue(mailMergeTask.AttachTitle);
|
||||
request.Content = new StreamContent(mailMergeTask.Attach);
|
||||
|
||||
|
@ -141,7 +141,6 @@ public class ThirdpartyController : ApiControllerBase
|
||||
public Task<object> DeleteThirdPartyAsync(int providerId)
|
||||
{
|
||||
return _fileStorageServiceThirdparty.DeleteThirdPartyAsync(providerId.ToString(CultureInfo.InvariantCulture));
|
||||
|
||||
}
|
||||
|
||||
/// <visible>false</visible>
|
||||
|
@ -64,10 +64,10 @@ public class Worker
|
||||
|
||||
_logger.InfoFoundUsers(activeTenantsUsers.Count);
|
||||
|
||||
await Parallel.ForEachAsync(activeTenantsUsers, cancellationToken, DeleteFilesAndFolders);
|
||||
await Parallel.ForEachAsync(activeTenantsUsers, cancellationToken, DeleteFilesAndFoldersAsync);
|
||||
}
|
||||
|
||||
private async ValueTask DeleteFilesAndFolders(TenantUserSettings tenantUser, CancellationToken cancellationToken)
|
||||
private async ValueTask DeleteFilesAndFoldersAsync(TenantUserSettings tenantUser, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
@ -94,7 +94,7 @@ public class Worker
|
||||
return;
|
||||
}
|
||||
|
||||
securityContext.AuthenticateMeWithoutCookie(userAccount);
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(userAccount);
|
||||
|
||||
var fileDao = daoFactory.GetFileDao<int>();
|
||||
var folderDao = daoFactory.GetFolderDao<int>();
|
||||
|
@ -60,13 +60,13 @@ internal class FileConverterService<T> : BackgroundService
|
||||
continue;
|
||||
}
|
||||
|
||||
await ExecuteCheckFileConverterStatus(serviceScope);
|
||||
await ExecuteCheckFileConverterStatusAsync(serviceScope);
|
||||
|
||||
await Task.Delay(_timerDelay, stoppingToken);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteCheckFileConverterStatus(IServiceScope scope)
|
||||
private async Task ExecuteCheckFileConverterStatusAsync(IServiceScope scope)
|
||||
{
|
||||
TenantManager tenantManager;
|
||||
UserManager userManager;
|
||||
@ -117,7 +117,7 @@ internal class FileConverterService<T> : BackgroundService
|
||||
|
||||
tenantManager.SetCurrentTenant(converter.TenantId);
|
||||
|
||||
securityContext.AuthenticateMeWithoutCookie(converter.Account);
|
||||
await securityContext.AuthenticateMeWithoutCookieAsync(converter.Account);
|
||||
|
||||
var file = await daoFactory.GetFileDao<T>().GetFileAsync(fileId, fileVersion);
|
||||
var fileUri = file.Id.ToString();
|
||||
|
@ -74,7 +74,7 @@ public class ThumbnailRequestedIntegrationEventHandler : IIntegrationEventHandle
|
||||
|
||||
return result.ToList().Select(r =>
|
||||
{
|
||||
var tariff = _tariffService.GetTariff(r.TenantId);
|
||||
var tariff = _tariffService.GetTariffAsync(r.TenantId).Result;
|
||||
var fileData = new FileData<int>(r.TenantId, r.Id, "", tariff.State);
|
||||
|
||||
return fileData;
|
||||
@ -82,13 +82,13 @@ public class ThumbnailRequestedIntegrationEventHandler : IIntegrationEventHandle
|
||||
}
|
||||
|
||||
|
||||
public async Task Handle(ThumbnailRequestedIntegrationEvent @event)
|
||||
public async Task HandleAsync(ThumbnailRequestedIntegrationEvent @event)
|
||||
{
|
||||
using (_logger.BeginScope(new[] { new KeyValuePair<string, object>("integrationEventContext", $"{@event.Id}-{Program.AppName}") }))
|
||||
{
|
||||
_logger.InformationHandlingIntegrationEvent(@event.Id, Program.AppName, @event);
|
||||
|
||||
var tariff = _tariffService.GetTariff(@event.TenantId);
|
||||
var tariff = await _tariffService.GetTariffAsync(@event.TenantId);
|
||||
var freezingThumbnails = await GetFreezingThumbnailsAsync();
|
||||
var data = @event.FileIds.Select(fileId => new FileData<int>(@event.TenantId, Convert.ToInt32(fileId), @event.BaseUrl, tariff.State))
|
||||
.Union(freezingThumbnails);
|
||||
|
@ -52,7 +52,7 @@ public class NotificationController : ApiControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("phone")]
|
||||
public object SendNotificationToChange(UpdateMemberRequestDto inDto)
|
||||
public async Task<object> SendNotificationToChangeAsync(UpdateMemberRequestDto inDto)
|
||||
{
|
||||
var user = _userManager.GetUsers(string.IsNullOrEmpty(inDto.UserId)
|
||||
? _securityContext.CurrentAccount.ID : new Guid(inDto.UserId));
|
||||
@ -73,7 +73,7 @@ public class NotificationController : ApiControllerBase
|
||||
return _commonLinkUtility.GetConfirmationEmailUrl(user.Email, ConfirmType.PhoneActivation);
|
||||
}
|
||||
|
||||
_studioNotifyService.SendMsgMobilePhoneChange(user);
|
||||
await _studioNotifyService.SendMsgMobilePhoneChangeAsync(user);
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class RemoveUserDataController : ApiControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("self/delete")]
|
||||
public object SendInstructionsToDelete()
|
||||
public async Task<object> SendInstructionsToDeleteAsync()
|
||||
{
|
||||
var user = _userManager.GetUsers(_securityContext.CurrentAccount.ID);
|
||||
|
||||
@ -77,7 +77,7 @@ public class RemoveUserDataController : ApiControllerBase
|
||||
throw new SecurityException();
|
||||
}
|
||||
|
||||
_studioNotifyService.SendMsgProfileDeletion(user);
|
||||
await _studioNotifyService.SendMsgProfileDeletionAsync(user);
|
||||
_messageService.Send(MessageAction.UserSentDeleteInstructions);
|
||||
|
||||
return string.Format(Resource.SuccessfullySentNotificationDeleteUserInfoMessage, "<b>" + user.Email + "</b>");
|
||||
|
@ -139,7 +139,7 @@ public class ThirdpartyController : ApiControllerBase
|
||||
{
|
||||
var profile = new LoginProfile(_signature, _instanceCrypto, inDto.SerializedProfile);
|
||||
|
||||
if (!(_coreBaseSettings.Standalone || _tenantManager.GetCurrentTenantQuota().Oauth))
|
||||
if (!(_coreBaseSettings.Standalone || (await _tenantManager.GetCurrentTenantQuotaAsync()).Oauth))
|
||||
{
|
||||
throw new Exception("ErrorNotAllowedOption");
|
||||
}
|
||||
@ -161,7 +161,7 @@ public class ThirdpartyController : ApiControllerBase
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("thirdparty/signup")]
|
||||
public async Task SignupAccount(SignupAccountRequestDto inDto)
|
||||
public async Task SignupAccountAsync(SignupAccountRequestDto inDto)
|
||||
{
|
||||
var employeeType = inDto.EmplType ?? EmployeeType.RoomAdmin;
|
||||
var passwordHash = inDto.PasswordHash;
|
||||
@ -192,7 +192,7 @@ public class ThirdpartyController : ApiControllerBase
|
||||
var userID = Guid.Empty;
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(Core.Configuration.Constants.CoreSystem);
|
||||
var newUser = await CreateNewUser(GetFirstName(inDto, thirdPartyProfile), GetLastName(inDto, thirdPartyProfile), GetEmailAddress(inDto, thirdPartyProfile), passwordHash, employeeType, false);
|
||||
var messageAction = employeeType == EmployeeType.RoomAdmin ? MessageAction.UserCreatedViaInvite : MessageAction.GuestCreatedViaInvite;
|
||||
_messageService.Send(MessageInitiator.System, messageAction, _messageTarget.Create(newUser.Id), newUser.DisplayUserName(false, _displayUserSettingsHelper));
|
||||
@ -211,13 +211,13 @@ public class ThirdpartyController : ApiControllerBase
|
||||
|
||||
var user = _userManager.GetUsers(userID);
|
||||
|
||||
_cookiesManager.AuthenticateMeAndSetCookies(user.Tenant, user.Id, MessageAction.LoginSuccess);
|
||||
await _cookiesManager.AuthenticateMeAndSetCookiesAsync(user.Tenant, user.Id, MessageAction.LoginSuccess);
|
||||
|
||||
_studioNotifyService.UserHasJoin();
|
||||
|
||||
if (mustChangePassword)
|
||||
{
|
||||
_studioNotifyService.UserPasswordChange(user);
|
||||
await _studioNotifyService.UserPasswordChangeAsync(user);
|
||||
}
|
||||
|
||||
_userHelpTourHelper.IsNewUser = true;
|
||||
@ -255,7 +255,7 @@ public class ThirdpartyController : ApiControllerBase
|
||||
userInfo.CultureName = _coreBaseSettings.CustomMode ? "ru-RU" : Thread.CurrentThread.CurrentUICulture.Name;
|
||||
}
|
||||
|
||||
return await _userManagerWrapper.AddUser(userInfo, passwordHash, true, true, employeeType, fromInviteLink);
|
||||
return await _userManagerWrapper.AddUserAsync(userInfo, passwordHash, true, true, employeeType, fromInviteLink);
|
||||
}
|
||||
|
||||
private async Task SaveContactImage(Guid userID, string url)
|
||||
|
@ -186,7 +186,7 @@ public class UserController : PeopleControllerBase
|
||||
UpdateContacts(inDto.Contacts, user);
|
||||
|
||||
_cache.Insert("REWRITE_URL" + _tenantManager.GetCurrentTenant().Id, HttpContext.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5));
|
||||
user = await _userManagerWrapper.AddUser(user, inDto.PasswordHash, true, false, inDto.Type,
|
||||
user = await _userManagerWrapper.AddUserAsync(user, inDto.PasswordHash, true, false, inDto.Type,
|
||||
false, true, true);
|
||||
|
||||
user.ActivationStatus = EmployeeActivationStatus.Activated;
|
||||
@ -205,7 +205,7 @@ public class UserController : PeopleControllerBase
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "LinkInvite,Everyone")]
|
||||
public async Task<EmployeeFullDto> AddMember(MemberRequestDto inDto)
|
||||
{
|
||||
_apiContext.AuthByClaim();
|
||||
await _apiContext.AuthByClaimAsync();
|
||||
|
||||
var options = inDto.FromInviteLink ? await _roomLinkService.GetOptionsAsync(inDto.Key, inDto.Email, inDto.Type) : null;
|
||||
if (options is { IsCorrect: false })
|
||||
@ -275,7 +275,7 @@ public class UserController : PeopleControllerBase
|
||||
|
||||
_cache.Insert("REWRITE_URL" + _tenantManager.GetCurrentTenant().Id, HttpContext.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5));
|
||||
|
||||
user = await _userManagerWrapper.AddUser(user, inDto.PasswordHash, inDto.FromInviteLink, true, inDto.Type,
|
||||
user = await _userManagerWrapper.AddUserAsync(user, inDto.PasswordHash, inDto.FromInviteLink, true, inDto.Type,
|
||||
inDto.FromInviteLink && options is { IsCorrect: true }, true, true, byEmail);
|
||||
|
||||
await UpdateDepartments(inDto.Department, user);
|
||||
@ -320,7 +320,7 @@ public class UserController : PeopleControllerBase
|
||||
var user = await _userManagerWrapper.AddInvitedUserAsync(invite.Email, invite.Type);
|
||||
var link = _roomLinkService.GetInvitationLink(user.Email, invite.Type, _authContext.CurrentAccount.ID);
|
||||
|
||||
_studioNotifyService.SendDocSpaceInvite(user.Email, link);
|
||||
await _studioNotifyService.SendDocSpaceInviteAsync(user.Email, link);
|
||||
_logger.Debug(link);
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ public class UserController : PeopleControllerBase
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "PasswordChange,EmailChange,Activation,EmailActivation,Everyone")]
|
||||
public async Task<EmployeeFullDto> ChangeUserPassword(Guid userid, MemberRequestDto inDto)
|
||||
{
|
||||
_apiContext.AuthByClaim();
|
||||
await _apiContext.AuthByClaimAsync();
|
||||
_permissionContext.DemandPermissions(new UserSecurityProvider(userid), Constants.Action_EditUser);
|
||||
|
||||
var user = _userManager.GetUsers(userid);
|
||||
@ -423,7 +423,7 @@ public class UserController : PeopleControllerBase
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "ProfileRemove")]
|
||||
public async Task<EmployeeFullDto> DeleteProfile()
|
||||
{
|
||||
_apiContext.AuthByClaim();
|
||||
await _apiContext.AuthByClaimAsync();
|
||||
|
||||
if (_userManager.IsSystemUser(_securityContext.CurrentAccount.ID))
|
||||
{
|
||||
@ -442,7 +442,7 @@ public class UserController : PeopleControllerBase
|
||||
throw new SecurityException();
|
||||
}
|
||||
|
||||
_securityContext.AuthenticateMeWithoutCookie(Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(Core.Configuration.Constants.CoreSystem);
|
||||
user.Status = EmployeeStatus.Terminated;
|
||||
|
||||
_userManager.UpdateUserInfo(user);
|
||||
@ -531,7 +531,7 @@ public class UserController : PeopleControllerBase
|
||||
var isInvite = _httpContextAccessor.HttpContext.User.Claims
|
||||
.Any(role => role.Type == ClaimTypes.Role && ConfirmTypeExtensions.TryParse(role.Value, out var confirmType) && confirmType == ConfirmType.LinkInvite);
|
||||
|
||||
_apiContext.AuthByClaim();
|
||||
await _apiContext.AuthByClaimAsync();
|
||||
|
||||
var user = _userManager.GetUserByUserName(username);
|
||||
if (user.Id == Constants.LostUser.Id)
|
||||
@ -682,7 +682,7 @@ public class UserController : PeopleControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("invite")]
|
||||
public async IAsyncEnumerable<EmployeeFullDto> ResendUserInvites(UpdateMembersRequestDto inDto)
|
||||
public async IAsyncEnumerable<EmployeeFullDto> ResendUserInvitesAsync(UpdateMembersRequestDto inDto)
|
||||
{
|
||||
_permissionContext.DemandPermissions(new UserSecurityProvider(Guid.Empty, EmployeeType.User), Constants.Action_AddRemoveUser);
|
||||
|
||||
@ -737,11 +737,11 @@ public class UserController : PeopleControllerBase
|
||||
}
|
||||
|
||||
var link = _roomLinkService.GetInvitationLink(user.Email, type, _authContext.CurrentAccount.ID);
|
||||
_studioNotifyService.SendDocSpaceInvite(user.Email, link);
|
||||
await _studioNotifyService.SendDocSpaceInviteAsync(user.Email, link);
|
||||
}
|
||||
else
|
||||
{
|
||||
_studioNotifyService.SendEmailActivationInstructions(user, user.Email);
|
||||
await _studioNotifyService.SendEmailActivationInstructionsAsync(user, user.Email);
|
||||
}
|
||||
}
|
||||
|
||||
@ -787,7 +787,7 @@ public class UserController : PeopleControllerBase
|
||||
|
||||
[AllowNotPayment]
|
||||
[HttpPost("email")]
|
||||
public async Task<object> SendEmailChangeInstructions(UpdateMemberRequestDto inDto)
|
||||
public async Task<object> SendEmailChangeInstructionsAsync(UpdateMemberRequestDto inDto)
|
||||
{
|
||||
Guid.TryParse(inDto.UserId, out var userid);
|
||||
|
||||
@ -830,7 +830,7 @@ public class UserController : PeopleControllerBase
|
||||
|
||||
if (!_userManager.IsDocSpaceAdmin(viewer))
|
||||
{
|
||||
_studioNotifyService.SendEmailChangeInstructions(user, email);
|
||||
await _studioNotifyService.SendEmailChangeInstructionsAsync(user, email);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -842,7 +842,7 @@ public class UserController : PeopleControllerBase
|
||||
user.Email = email;
|
||||
user.ActivationStatus = EmployeeActivationStatus.NotActivated;
|
||||
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
||||
_studioNotifyService.SendEmailActivationInstructions(user, email);
|
||||
await _studioNotifyService.SendEmailActivationInstructionsAsync(user, email);
|
||||
}
|
||||
|
||||
_messageService.Send(MessageAction.UserSentEmailChangeInstructions, user.DisplayUserName(false, _displayUserSettingsHelper));
|
||||
@ -853,9 +853,9 @@ public class UserController : PeopleControllerBase
|
||||
[AllowNotPayment]
|
||||
[AllowAnonymous]
|
||||
[HttpPost("password")]
|
||||
public object SendUserPassword(MemberRequestDto inDto)
|
||||
public async Task<object> SendUserPasswordAsync(MemberRequestDto inDto)
|
||||
{
|
||||
var error = _userManagerWrapper.SendUserPassword(inDto.Email);
|
||||
var error = await _userManagerWrapper.SendUserPasswordAsync(inDto.Email);
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
_logger.ErrorPasswordRecovery(inDto.Email, error);
|
||||
@ -868,7 +868,7 @@ public class UserController : PeopleControllerBase
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "Activation,Everyone")]
|
||||
public async IAsyncEnumerable<EmployeeFullDto> UpdateEmployeeActivationStatus(EmployeeActivationStatus activationstatus, UpdateMembersRequestDto inDto)
|
||||
{
|
||||
_apiContext.AuthByClaim();
|
||||
await _apiContext.AuthByClaimAsync();
|
||||
|
||||
foreach (var id in inDto.UserIds.Where(userId => !_userManager.IsSystemUser(userId)))
|
||||
{
|
||||
@ -1126,7 +1126,7 @@ public class UserController : PeopleControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("quota")]
|
||||
public async IAsyncEnumerable<EmployeeFullDto> UpdateUserQuota(UpdateMembersQuotaRequestDto inDto)
|
||||
public async IAsyncEnumerable<EmployeeFullDto> UpdateUserQuotaAsync(UpdateMembersQuotaRequestDto inDto)
|
||||
{
|
||||
var users = inDto.UserIds
|
||||
.Where(userId => !_userManager.IsSystemUser(userId))
|
||||
@ -1138,13 +1138,13 @@ public class UserController : PeopleControllerBase
|
||||
if (inDto.Quota != -1)
|
||||
{
|
||||
var usedSpace = Math.Max(0,
|
||||
_quotaService.FindUserQuotaRows(
|
||||
(await _quotaService.FindUserQuotaRowsAsync(
|
||||
_tenantManager.GetCurrentTenant().Id,
|
||||
user.Id
|
||||
)
|
||||
))
|
||||
.Where(r => !string.IsNullOrEmpty(r.Tag)).Sum(r => r.Counter));
|
||||
|
||||
var tenanSpaceQuota = _quotaService.GetTenantQuota(Tenant.Id).MaxTotalSize;
|
||||
var tenanSpaceQuota = (await _quotaService.GetTenantQuotaAsync(Tenant.Id)).MaxTotalSize;
|
||||
|
||||
if (tenanSpaceQuota < inDto.Quota || usedSpace > inDto.Quota)
|
||||
{
|
||||
@ -1256,13 +1256,13 @@ public class UserController : PeopleControllerBase
|
||||
{
|
||||
if (!SetupInfo.IsSecretEmail(inDto.Email) || _securityContext.IsAuthenticated)
|
||||
{
|
||||
_studioNotifyService.SendAlreadyExist(inDto.Email);
|
||||
await _studioNotifyService.SendAlreadyExistAsync(inDto.Email);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeAsync(Core.Configuration.Constants.CoreSystem);
|
||||
await _userManager.DeleteUser(newUserInfo.Id);
|
||||
}
|
||||
finally
|
||||
@ -1291,7 +1291,7 @@ public class UserController : PeopleControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
_studioNotifyService.SendInvitePersonal(inDto.Email);
|
||||
await _studioNotifyService.SendInvitePersonalAsync(inDto.Email);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -162,14 +162,14 @@ public class AuthenticationController : ControllerBase
|
||||
|
||||
try
|
||||
{
|
||||
if (_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
|
||||
if (await _studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettingsAsync() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
|
||||
{
|
||||
sms = true;
|
||||
_smsManager.ValidateSmsCode(user, inDto.Code, true);
|
||||
await _smsManager.ValidateSmsCodeAsync(user, inDto.Code, true);
|
||||
}
|
||||
else if (_tfaAppAuthSettingsHelper.IsVisibleSettings && _tfaAppAuthSettingsHelper.TfaEnabledForUser(user.Id))
|
||||
{
|
||||
if (_tfaManager.ValidateAuthCode(user, inDto.Code, true, true))
|
||||
if (await _tfaManager.ValidateAuthCodeAsync(user, inDto.Code, true, true))
|
||||
{
|
||||
_messageService.Send(MessageAction.UserConnectedTfaApp, _messageTarget.Create(user.Id));
|
||||
}
|
||||
@ -179,7 +179,7 @@ public class AuthenticationController : ControllerBase
|
||||
throw new SecurityException("Auth code is not available");
|
||||
}
|
||||
|
||||
var token = _cookiesManager.AuthenticateMeAndSetCookies(user.Tenant, user.Id, MessageAction.LoginSuccess);
|
||||
var token = await _cookiesManager.AuthenticateMeAndSetCookiesAsync(user.Tenant, user.Id, MessageAction.LoginSuccess);
|
||||
var expires = _tenantCookieSettingsHelper.GetExpiresTime(tenant);
|
||||
|
||||
var result = new AuthenticationTokenDto
|
||||
@ -228,7 +228,7 @@ public class AuthenticationController : ControllerBase
|
||||
throw new Exception(Resource.ErrorUserNotFound);
|
||||
}
|
||||
|
||||
if (_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
|
||||
if (await _studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettingsAsync() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.MobilePhone) || user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated)
|
||||
{
|
||||
@ -272,7 +272,7 @@ public class AuthenticationController : ControllerBase
|
||||
try
|
||||
{
|
||||
var action = viaEmail ? MessageAction.LoginSuccessViaApi : MessageAction.LoginSuccessViaApiSocialAccount;
|
||||
var token = _cookiesManager.AuthenticateMeAndSetCookies(user.Tenant, user.Id, action);
|
||||
var token = await _cookiesManager.AuthenticateMeAndSetCookiesAsync(user.Tenant, user.Id, action);
|
||||
|
||||
var tenant = _tenantManager.GetCurrentTenant().Id;
|
||||
var expires = _tenantCookieSettingsHelper.GetExpiresTime(tenant);
|
||||
@ -326,7 +326,7 @@ public class AuthenticationController : ControllerBase
|
||||
[HttpPost("setphone")]
|
||||
public async Task<AuthenticationTokenDto> SaveMobilePhoneAsync(MobileRequestsDto inDto)
|
||||
{
|
||||
_apiContext.AuthByClaim();
|
||||
await _apiContext.AuthByClaimAsync();
|
||||
var user = _userManager.GetUsers(_authContext.CurrentAccount.ID);
|
||||
inDto.MobilePhone = await _smsManager.SaveMobilePhoneAsync(user, inDto.MobilePhone);
|
||||
_messageService.Send(MessageAction.UserUpdatedMobileNumber, _messageTarget.Create(user.Id), user.DisplayUserName(false, _displayUserSettingsHelper), inDto.MobilePhone);
|
||||
@ -416,7 +416,7 @@ public class AuthenticationController : ControllerBase
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(_coreBaseSettings.Standalone || _tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).Oauth))
|
||||
if (!(_coreBaseSettings.Standalone || (await _tenantManager.GetTenantQuotaAsync(_tenantManager.GetCurrentTenant().Id)).Oauth))
|
||||
{
|
||||
throw new Exception(Resource.ErrorNotAllowedOption);
|
||||
}
|
||||
@ -481,7 +481,7 @@ public class AuthenticationController : ControllerBase
|
||||
{
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
await _userManager.DeleteUser(userInfo.Id);
|
||||
userInfo = Constants.LostUser;
|
||||
}
|
||||
@ -553,8 +553,8 @@ public class AuthenticationController : ControllerBase
|
||||
|
||||
try
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
userInfo = await _userManagerWrapper.AddUser(newUserInfo, UserManagerWrapper.GeneratePassword());
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
userInfo = await _userManagerWrapper.AddUserAsync(newUserInfo, UserManagerWrapper.GeneratePassword());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -61,12 +61,13 @@ public class CapabilitiesController : ControllerBase
|
||||
///<returns>CapabilitiesData</returns>
|
||||
[HttpGet] //NOTE: this method doesn't requires auth!!! //NOTE: this method doesn't check payment!!!
|
||||
[AllowNotPayment]
|
||||
public CapabilitiesDto GetPortalCapabilities()
|
||||
{
|
||||
public async Task<CapabilitiesDto> GetPortalCapabilitiesAsync()
|
||||
{
|
||||
var quota = await _tenantManager.GetTenantQuotaAsync(_tenantManager.GetCurrentTenant().Id);
|
||||
var result = new CapabilitiesDto
|
||||
{
|
||||
LdapEnabled = false,
|
||||
OauthEnabled = _coreBaseSettings.Standalone || _tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).Oauth,
|
||||
OauthEnabled = _coreBaseSettings.Standalone || quota.Oauth,
|
||||
Providers = new List<string>(0),
|
||||
SsoLabel = string.Empty,
|
||||
SsoUrl = string.Empty
|
||||
@ -76,7 +77,7 @@ public class CapabilitiesController : ControllerBase
|
||||
{
|
||||
if (_coreBaseSettings.Standalone
|
||||
|| SetupInfo.IsVisibleSettings(ManagementType.LdapSettings.ToString())
|
||||
&& _tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).Ldap)
|
||||
&& quota.Ldap)
|
||||
{
|
||||
//var settings = SettingsManager.Load<LdapSettings>();
|
||||
|
||||
@ -115,7 +116,7 @@ public class CapabilitiesController : ControllerBase
|
||||
{
|
||||
if (_coreBaseSettings.Standalone
|
||||
|| SetupInfo.IsVisibleSettings(ManagementType.SingleSignOnSettings.ToString())
|
||||
&& _tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).Sso)
|
||||
&& quota.Sso)
|
||||
{
|
||||
var settings = _settingsManager.Load<SsoSettingsV2>();
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class PaymentController : ControllerBase
|
||||
[HttpPut("payment/url")]
|
||||
public async Task<Uri> GetPaymentUrl(PaymentUrlRequestsDto inDto)
|
||||
{
|
||||
if (_tariffService.GetPayments(Tenant.Id).Any() ||
|
||||
if ((await _tariffService.GetPaymentsAsync(Tenant.Id)).Any() ||
|
||||
!_userManager.IsDocSpaceAdmin(_securityContext.CurrentAccount.ID))
|
||||
{
|
||||
return null;
|
||||
@ -85,7 +85,7 @@ public class PaymentController : ControllerBase
|
||||
|
||||
var currency = _regionHelper.GetCurrencyFromRequest();
|
||||
|
||||
return await _tariffService.GetShoppingUri(Tenant.Id, currency,
|
||||
return await _tariffService.GetShoppingUriAsync(Tenant.Id, currency,
|
||||
Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName,
|
||||
_userManager.GetUsers(_securityContext.CurrentAccount.ID).Email,
|
||||
inDto.Quantity,
|
||||
@ -93,24 +93,24 @@ public class PaymentController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPut("payment/update")]
|
||||
public async Task<bool> PaymentUpdate(PaymentUrlRequestsDto inDto)
|
||||
public async Task<bool> PaymentUpdateAsync(PaymentUrlRequestsDto inDto)
|
||||
{
|
||||
var payerId = _tariffService.GetTariff(Tenant.Id).CustomerId;
|
||||
var payerId = (await _tariffService.GetTariffAsync(Tenant.Id)).CustomerId;
|
||||
var payer = _userManager.GetUserByEmail(payerId);
|
||||
|
||||
if (!_tariffService.GetPayments(Tenant.Id).Any() ||
|
||||
if (!(await _tariffService.GetPaymentsAsync(Tenant.Id)).Any() ||
|
||||
_securityContext.CurrentAccount.ID != payer.Id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return await _tariffService.PaymentChange(Tenant.Id, inDto.Quantity);
|
||||
return await _tariffService.PaymentChangeAsync(Tenant.Id, inDto.Quantity);
|
||||
}
|
||||
|
||||
[HttpGet("payment/account")]
|
||||
public Uri GetPaymentAccount(string backUrl)
|
||||
public async Task<Uri> GetPaymentAccountAsync(string backUrl)
|
||||
{
|
||||
var payerId = _tariffService.GetTariff(Tenant.Id).CustomerId;
|
||||
var payerId = (await _tariffService.GetTariffAsync(Tenant.Id)).CustomerId;
|
||||
var payer = _userManager.GetUserByEmail(payerId);
|
||||
|
||||
if (_securityContext.CurrentAccount.ID != payer.Id &&
|
||||
@ -123,20 +123,20 @@ public class PaymentController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("payment/prices")]
|
||||
public object GetPrices()
|
||||
public async Task<object> GetPricesAsync()
|
||||
{
|
||||
var currency = _regionHelper.GetCurrencyFromRequest();
|
||||
var result = _tenantManager.GetProductPriceInfo()
|
||||
var result = (await _tenantManager.GetProductPriceInfoAsync())
|
||||
.ToDictionary(pr => pr.Key, pr => pr.Value.ContainsKey(currency) ? pr.Value[currency] : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("payment/currencies")]
|
||||
public IEnumerable<CurrenciesDto> GetCurrencies()
|
||||
public async IAsyncEnumerable<CurrenciesDto> GetCurrenciesAsync()
|
||||
{
|
||||
var defaultRegion = _regionHelper.GetDefaultRegionInfo();
|
||||
var currentRegion = _regionHelper.GetCurrentRegionInfo();
|
||||
var currentRegion = await _regionHelper.GetCurrentRegionInfoAsync();
|
||||
|
||||
yield return new CurrenciesDto(defaultRegion);
|
||||
|
||||
@ -147,19 +147,19 @@ public class PaymentController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("payment/quotas")]
|
||||
public IEnumerable<QuotaDto> GetQuotas()
|
||||
public Task<IEnumerable<QuotaDto>> GetQuotas()
|
||||
{
|
||||
return _quotaHelper.GetQuotas();
|
||||
return _quotaHelper.GetQuotasAsync();
|
||||
}
|
||||
|
||||
[HttpGet("payment/quota")]
|
||||
public QuotaDto GetQuota()
|
||||
public Task<QuotaDto> GetQuotaAsync()
|
||||
{
|
||||
return _quotaHelper.GetCurrentQuota();
|
||||
return _quotaHelper.GetCurrentQuotaAsync();
|
||||
}
|
||||
|
||||
[HttpPost("payment/request")]
|
||||
public void SendSalesRequest(SalesRequestsDto inDto)
|
||||
public async Task SendSalesRequestAsync(SalesRequestsDto inDto)
|
||||
{
|
||||
if (!inDto.Email.TestEmailRegex())
|
||||
{
|
||||
@ -173,7 +173,7 @@ public class PaymentController : ControllerBase
|
||||
|
||||
CheckCache("salesrequest");
|
||||
|
||||
_studioNotifyService.SendMsgToSales(inDto.Email, inDto.UserName, inDto.Message);
|
||||
await _studioNotifyService.SendMsgToSalesAsync(inDto.Email, inDto.UserName, inDto.Message);
|
||||
_messageService.Send(MessageAction.ContactSalesMailSent);
|
||||
}
|
||||
|
||||
|
@ -174,9 +174,9 @@ public class PortalController : ControllerBase
|
||||
customMode = _coreBaseSettings.CustomMode,
|
||||
opensource = _tenantExtra.Opensource,
|
||||
enterprise = _tenantExtra.Enterprise,
|
||||
tariff = _tenantExtra.GetCurrentTariff(),
|
||||
quota = _tenantManager.GetCurrentTenantQuota(),
|
||||
notPaid = _tenantExtra.IsNotPaid(),
|
||||
tariff = await _tenantExtra.GetCurrentTariffAsync(),
|
||||
quota = await _tenantManager.GetCurrentTenantQuotaAsync(),
|
||||
notPaid = await _tenantExtra.IsNotPaidAsync(),
|
||||
licenseAccept = _settingsManager.LoadForCurrentUser<TariffSettings>().LicenseAcceptSetting,
|
||||
enableTariffPage = //TenantExtra.EnableTarrifSettings - think about hide-settings for opensource
|
||||
(!_coreBaseSettings.Standalone || !string.IsNullOrEmpty(_licenseReader.LicensePath))
|
||||
@ -189,10 +189,10 @@ public class PortalController : ControllerBase
|
||||
|
||||
|
||||
[HttpGet("usedspace")]
|
||||
public double GetUsedSpace()
|
||||
public async Task<double> GetUsedSpaceAsync()
|
||||
{
|
||||
return Math.Round(
|
||||
_tenantManager.FindTenantQuotaRows(Tenant.Id)
|
||||
(await _tenantManager.FindTenantQuotaRowsAsync(Tenant.Id))
|
||||
.Where(q => !string.IsNullOrEmpty(q.Tag) && new Guid(q.Tag) != Guid.Empty)
|
||||
.Sum(q => q.Counter) / 1024f / 1024f / 1024f, 2);
|
||||
}
|
||||
@ -206,25 +206,25 @@ public class PortalController : ControllerBase
|
||||
|
||||
[AllowNotPayment]
|
||||
[HttpGet("tariff")]
|
||||
public Tariff GetTariff()
|
||||
public Task<Tariff> GetTariffAsync()
|
||||
{
|
||||
return _tariffService.GetTariff(Tenant.Id);
|
||||
return _tariffService.GetTariffAsync(Tenant.Id);
|
||||
}
|
||||
|
||||
[AllowNotPayment]
|
||||
[HttpGet("quota")]
|
||||
public TenantQuota GetQuota()
|
||||
public Task<TenantQuota> GetQuotaAsync()
|
||||
{
|
||||
return _tenantManager.GetTenantQuota(Tenant.Id);
|
||||
return _tenantManager.GetTenantQuotaAsync(Tenant.Id);
|
||||
}
|
||||
|
||||
[HttpGet("quota/right")]
|
||||
public TenantQuota GetRightQuota()
|
||||
public async Task<TenantQuota> GetRightQuotaAsync()
|
||||
{
|
||||
var usedSpace = GetUsedSpace();
|
||||
var usedSpace = await GetUsedSpaceAsync();
|
||||
var needUsersCount = GetUsersCount();
|
||||
|
||||
return _tenantManager.GetTenantQuotas().OrderBy(r => r.Price)
|
||||
return (await _tenantManager.GetTenantQuotasAsync()).OrderBy(r => r.Price)
|
||||
.FirstOrDefault(quota =>
|
||||
quota.CountUser > needUsersCount
|
||||
&& quota.MaxTotalSize > usedSpace);
|
||||
@ -398,7 +398,7 @@ public class PortalController : ControllerBase
|
||||
{
|
||||
if (!_securityContext.IsAuthenticated)
|
||||
{
|
||||
_securityContext.AuthenticateMeWithoutCookie(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeWithoutCookieAsync(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
}
|
||||
|
||||
_messageService.Send(MessageAction.PortalDeleted);
|
||||
@ -431,7 +431,7 @@ public class PortalController : ControllerBase
|
||||
|
||||
[AllowNotPayment]
|
||||
[HttpPost("delete")]
|
||||
public void SendDeleteInstructions()
|
||||
public async Task SendDeleteInstructionsAsync()
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
@ -443,8 +443,8 @@ public class PortalController : ControllerBase
|
||||
var owner = _userManager.GetUsers(Tenant.OwnerId);
|
||||
|
||||
var showAutoRenewText = !_coreBaseSettings.Standalone &&
|
||||
_tariffService.GetPayments(Tenant.Id).Any() &&
|
||||
!_tenantManager.GetCurrentTenantQuota().Trial;
|
||||
(await _tariffService.GetPaymentsAsync(Tenant.Id)).Any() &&
|
||||
!(await _tenantManager.GetCurrentTenantQuotaAsync()).Trial;
|
||||
|
||||
_studioNotifyService.SendMsgPortalDeletion(Tenant, _commonLinkUtility.GetConfirmationEmailUrl(owner.Email, ConfirmType.PortalRemove), showAutoRenewText);
|
||||
|
||||
@ -500,7 +500,7 @@ public class PortalController : ControllerBase
|
||||
{
|
||||
if (!_securityContext.IsAuthenticated)
|
||||
{
|
||||
_securityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
await _securityContext.AuthenticateMeAsync(ASC.Core.Configuration.Constants.CoreSystem);
|
||||
authed = true;
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ public class PortalController : ControllerBase
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("sendcongratulations")]
|
||||
public void SendCongratulations([FromQuery] SendCongratulationsDto inDto)
|
||||
public async Task SendCongratulationsAsync([FromQuery] SendCongratulationsDto inDto)
|
||||
{
|
||||
var authInterval = TimeSpan.FromHours(1);
|
||||
var checkKeyResult = _emailValidationKeyProvider.ValidateEmailKey(inDto.Userid.ToString() + ConfirmType.Auth, inDto.Key, authInterval);
|
||||
@ -532,7 +532,7 @@ public class PortalController : ControllerBase
|
||||
case ValidationResult.Ok:
|
||||
var currentUser = _userManager.GetUsers(inDto.Userid);
|
||||
|
||||
_studioNotifyService.SendCongratulations(currentUser);
|
||||
await _studioNotifyService.SendCongratulationsAsync(currentUser);
|
||||
_studioNotifyService.SendRegData(currentUser);
|
||||
|
||||
if (!SetupInfo.IsSecretEmail(currentUser.Email))
|
||||
|
@ -93,7 +93,7 @@ public class SecurityController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("/audit/login/filter")]
|
||||
public IEnumerable<LoginEventDto> GetLoginEventsByFilter(Guid userId,
|
||||
public async Task<IEnumerable<LoginEventDto>> GetLoginEventsByFilterAsync(Guid userId,
|
||||
MessageAction action,
|
||||
ApiDateTime from,
|
||||
ApiDateTime to)
|
||||
@ -106,20 +106,20 @@ public class SecurityController : ControllerBase
|
||||
|
||||
action = action == 0 ? MessageAction.None : action;
|
||||
|
||||
if (!_tenantManager.GetCurrentTenantQuota().Audit || !SetupInfo.IsVisibleSettings(ManagementType.LoginHistory.ToString()))
|
||||
if (!(await _tenantManager.GetCurrentTenantQuotaAsync()).Audit || !SetupInfo.IsVisibleSettings(ManagementType.LoginHistory.ToString()))
|
||||
{
|
||||
return GetLastLoginEvents();
|
||||
}
|
||||
else
|
||||
{
|
||||
DemandAuditPermission();
|
||||
await DemandAuditPermissionAsync();
|
||||
|
||||
return _loginEventsRepository.GetByFilter(userId, action, from, to, startIndex, limit).Select(x => new LoginEventDto(x));
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("/audit/events/filter")]
|
||||
public IEnumerable<AuditEventDto> GetAuditEventsByFilter(Guid userId,
|
||||
public async Task<IEnumerable<AuditEventDto>> GetAuditEventsByFilterAsync(Guid userId,
|
||||
ProductType productType,
|
||||
ModuleType moduleType,
|
||||
ActionType actionType,
|
||||
@ -137,13 +137,13 @@ public class SecurityController : ControllerBase
|
||||
|
||||
action = action == 0 ? MessageAction.None : action;
|
||||
|
||||
if (!_tenantManager.GetCurrentTenantQuota().Audit || !SetupInfo.IsVisibleSettings(ManagementType.LoginHistory.ToString()))
|
||||
if (!(await _tenantManager.GetCurrentTenantQuotaAsync()).Audit || !SetupInfo.IsVisibleSettings(ManagementType.LoginHistory.ToString()))
|
||||
{
|
||||
return GetLastAuditEvents();
|
||||
}
|
||||
else
|
||||
{
|
||||
DemandAuditPermission();
|
||||
await DemandAuditPermissionAsync();
|
||||
|
||||
return _auditEventsRepository.GetByFilter(userId, productType, moduleType, actionType, action, entryType, target, from, to, startIndex, limit).Select(x => new AuditEventDto(x, _auditActionMapper));
|
||||
}
|
||||
@ -192,7 +192,7 @@ public class SecurityController : ControllerBase
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
DemandAuditPermission();
|
||||
await DemandAuditPermissionAsync();
|
||||
|
||||
var settings = _settingsManager.Load<TenantAuditSettings>(_tenantManager.GetCurrentTenant().Id);
|
||||
|
||||
@ -214,7 +214,7 @@ public class SecurityController : ControllerBase
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
DemandAuditPermission();
|
||||
await DemandAuditPermissionAsync();
|
||||
|
||||
var tenantId = _tenantManager.GetCurrentTenant().Id;
|
||||
|
||||
@ -245,11 +245,11 @@ public class SecurityController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpPost("audit/settings/lifetime")]
|
||||
public TenantAuditSettings SetAuditSettings(TenantAuditSettingsWrapper wrapper)
|
||||
public async Task<TenantAuditSettings> SetAuditSettings(TenantAuditSettingsWrapper wrapper)
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
DemandAuditPermission();
|
||||
await DemandAuditPermissionAsync();
|
||||
|
||||
if (wrapper.Settings.LoginHistoryLifeTime <= 0 || wrapper.Settings.LoginHistoryLifeTime > TenantAuditSettings.MaxLifeTime)
|
||||
{
|
||||
@ -267,11 +267,11 @@ public class SecurityController : ControllerBase
|
||||
return wrapper.Settings;
|
||||
}
|
||||
|
||||
private void DemandAuditPermission()
|
||||
private async Task DemandAuditPermissionAsync()
|
||||
{
|
||||
if (!_coreBaseSettings.Standalone
|
||||
&& (!SetupInfo.IsVisibleSettings(ManagementType.LoginHistory.ToString())
|
||||
|| !_tenantManager.GetCurrentTenantQuota().Audit))
|
||||
|| !(await _tenantManager.GetCurrentTenantQuotaAsync()).Audit))
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "Audit");
|
||||
}
|
||||
|
@ -72,9 +72,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <category>LDAP</category>
|
||||
/// <returns>LDAP settings</returns>
|
||||
[HttpGet("ldap")]
|
||||
public LdapSettingsDto GetLdapSettings()
|
||||
public async Task<LdapSettingsDto> GetLdapSettingsAsync()
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var settings = _settingsManager.Load<LdapSettings>();
|
||||
|
||||
@ -90,7 +90,7 @@ public class LdapController : BaseSettingsController
|
||||
settings.PasswordBytes = null;
|
||||
|
||||
if (settings.IsDefault)
|
||||
return _mapper.Map<LdapSettings, LdapSettingsDto>(settings); ;
|
||||
return _mapper.Map<LdapSettings, LdapSettingsDto>(settings);
|
||||
|
||||
var defaultSettings = settings.GetDefault();
|
||||
|
||||
@ -109,9 +109,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <category>LDAP</category>
|
||||
/// <returns>Cron expression or null</returns>
|
||||
[HttpGet("ldap/cron")]
|
||||
public LdapCronSettingsDto GetLdapCronSettings()
|
||||
public async Task<LdapCronSettingsDto> GetLdapCronSettingsAsync()
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var settings = _settingsManager.Load<LdapCronSettings>();
|
||||
|
||||
@ -134,14 +134,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <param name="cron">Cron expression</param>
|
||||
///
|
||||
[HttpPost("ldap/cron")]
|
||||
public void SetLdapCronSettingsFromBody(LdapCronRequestDto ldapCronRequest)
|
||||
public async Task SetLdapCronSettingsAsync(LdapCronRequestDto ldapCronRequest)
|
||||
{
|
||||
SetLdapCronSettings(ldapCronRequest);
|
||||
}
|
||||
|
||||
private void SetLdapCronSettings(LdapCronRequestDto ldapCronRequest)
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var cron = ldapCronRequest.Cron;
|
||||
|
||||
@ -184,9 +179,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <category>LDAP</category>
|
||||
/// <returns>Operation status</returns>
|
||||
[HttpGet("ldap/sync")]
|
||||
public LdapStatusDto SyncLdap()
|
||||
public async Task<LdapStatusDto> SyncLdapAsync()
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var ldapSettings = _settingsManager.Load<LdapSettings>();
|
||||
|
||||
@ -206,9 +201,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <category>LDAP</category>
|
||||
/// <returns>Operation status</returns>
|
||||
[HttpGet("ldap/sync/test")]
|
||||
public LdapStatusDto TestLdapSync()
|
||||
public async Task<LdapStatusDto> TestLdapSync()
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var ldapSettings = _settingsManager.Load<LdapSettings>();
|
||||
|
||||
@ -228,15 +223,15 @@ public class LdapController : BaseSettingsController
|
||||
/// <param name="acceptCertificate">Specifies if the errors of checking certificates are allowed (true) or not (false)</param>
|
||||
/// <returns>Operation status</returns>
|
||||
[HttpPost("ldap")]
|
||||
public LdapStatusDto SaveLdapSettings(LdapRequestsDto ldapRequestsDto)
|
||||
public async Task<LdapStatusDto> SaveLdapSettingsAsync(LdapRequestsDto ldapRequestsDto)
|
||||
{
|
||||
var ldapSettings = _mapper.Map<LdapRequestsDto, LdapSettings>(ldapRequestsDto);
|
||||
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
if (!ldapSettings.EnableLdapAuthentication)
|
||||
{
|
||||
SetLdapCronSettings(null);
|
||||
await SetLdapCronSettingsAsync(null);
|
||||
}
|
||||
|
||||
var userId = _authContext.CurrentAccount.ID.ToString();
|
||||
@ -257,9 +252,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <param name="acceptCertificate">Specifies if the errors of checking certificates are allowed (true) or not (false)</param>
|
||||
/// <returns>Operation status</returns>
|
||||
[HttpPost("ldap/save/test")]
|
||||
public LdapStatusDto TestLdapSave(LdapSettings ldapSettings)
|
||||
public async Task<LdapStatusDto> TestLdapSaveAsync(LdapSettings ldapSettings)
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var userId = _authContext.CurrentAccount.ID.ToString();
|
||||
|
||||
@ -277,9 +272,9 @@ public class LdapController : BaseSettingsController
|
||||
/// <category>LDAP</category>
|
||||
/// <returns>Operation status</returns>
|
||||
[HttpGet("ldap/status")]
|
||||
public LdapStatusDto GetLdapOperationStatus()
|
||||
public async Task<LdapStatusDto> GetLdapOperationStatusAsync()
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var result = _ldapSaveSyncOperation.ToLdapOperationStatus(Tenant.Id);
|
||||
|
||||
@ -295,22 +290,22 @@ public class LdapController : BaseSettingsController
|
||||
/// <category>LDAP</category>
|
||||
/// <returns>LDAP default settings</returns>
|
||||
[HttpGet("ldap/default")]
|
||||
public LdapSettingsDto GetDefaultLdapSettings()
|
||||
public async Task<LdapSettingsDto> GetDefaultLdapSettingsAsync()
|
||||
{
|
||||
CheckLdapPermissions();
|
||||
await CheckLdapPermissionsAsync();
|
||||
|
||||
var settings = new LdapSettings().GetDefault();
|
||||
|
||||
return _mapper.Map<LdapSettings, LdapSettingsDto>(settings);
|
||||
}
|
||||
|
||||
private void CheckLdapPermissions()
|
||||
private async Task CheckLdapPermissionsAsync()
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
if (!_coreBaseSettings.Standalone
|
||||
&& (!SetupInfo.IsVisibleSettings(ManagementType.LdapSettings.ToString())
|
||||
|| !_tenantManager.GetCurrentTenantQuota().Ldap))
|
||||
|| !(await _tenantManager.GetCurrentTenantQuotaAsync()).Ldap))
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "Ldap");
|
||||
}
|
||||
|
@ -74,20 +74,20 @@ public class LicenseController : BaseSettingsController
|
||||
|
||||
[HttpGet("license/refresh")]
|
||||
[AllowNotPayment]
|
||||
public bool RefreshLicense()
|
||||
public async Task<bool> RefreshLicenseAsync()
|
||||
{
|
||||
if (!_coreBaseSettings.Standalone)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_licenseReader.RefreshLicense();
|
||||
await _licenseReader.RefreshLicenseAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
[AllowNotPayment]
|
||||
[HttpPost("license/accept")]
|
||||
public object AcceptLicense()
|
||||
public async Task<object> AcceptLicenseAsync()
|
||||
{
|
||||
if (!_coreBaseSettings.Standalone)
|
||||
{
|
||||
@ -99,7 +99,7 @@ public class LicenseController : BaseSettingsController
|
||||
|
||||
try
|
||||
{
|
||||
_licenseReader.RefreshLicense();
|
||||
await _licenseReader.RefreshLicenseAsync();
|
||||
}
|
||||
catch (BillingNotFoundException)
|
||||
{
|
||||
@ -123,7 +123,7 @@ public class LicenseController : BaseSettingsController
|
||||
|
||||
///<visible>false</visible>
|
||||
[HttpPost("license/trial")]
|
||||
public bool ActivateTrial()
|
||||
public async Task<bool> ActivateTrialAsync()
|
||||
{
|
||||
if (!_coreBaseSettings.Standalone)
|
||||
{
|
||||
@ -135,7 +135,7 @@ public class LicenseController : BaseSettingsController
|
||||
throw new SecurityException();
|
||||
}
|
||||
|
||||
var curQuota = _tenantManager.GetCurrentTenantQuota();
|
||||
var curQuota = await _tenantManager.GetCurrentTenantQuotaAsync();
|
||||
if (curQuota.Tenant != Tenant.DefaultTenant)
|
||||
{
|
||||
return false;
|
||||
@ -146,7 +146,7 @@ public class LicenseController : BaseSettingsController
|
||||
return false;
|
||||
}
|
||||
|
||||
var curTariff = _tenantExtra.GetCurrentTariff();
|
||||
var curTariff = await _tenantExtra.GetCurrentTariffAsync();
|
||||
if (curTariff.DueDate.Date != DateTime.MaxValue.Date)
|
||||
{
|
||||
return false;
|
||||
@ -162,7 +162,7 @@ public class LicenseController : BaseSettingsController
|
||||
};
|
||||
quota.Trial = true;
|
||||
|
||||
_tenantManager.SaveTenantQuota(quota);
|
||||
await _tenantManager.SaveTenantQuotaAsync(quota);
|
||||
|
||||
const int DEFAULT_TRIAL_PERIOD = 30;
|
||||
|
||||
@ -172,7 +172,7 @@ public class LicenseController : BaseSettingsController
|
||||
DueDate = DateTime.Today.AddDays(DEFAULT_TRIAL_PERIOD)
|
||||
};
|
||||
|
||||
_tariffService.SetTariff(-1, tariff);
|
||||
await _tariffService.SetTariffAsync(-1, tariff);
|
||||
|
||||
_messageService.Send(MessageAction.LicenseKeyUploaded);
|
||||
|
||||
@ -191,11 +191,11 @@ public class LicenseController : BaseSettingsController
|
||||
[AllowNotPayment]
|
||||
[HttpPost("license")]
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "Wizard, Administrators")]
|
||||
public object UploadLicense([FromForm] UploadLicenseRequestsDto inDto)
|
||||
public async Task<object> UploadLicenseAsync([FromForm] UploadLicenseRequestsDto inDto)
|
||||
{
|
||||
try
|
||||
{
|
||||
ApiContext.AuthByClaim();
|
||||
await ApiContext.AuthByClaimAsync();
|
||||
if (!_authContext.IsAuthenticated && _settingsManager.Load<WizardSettings>().Completed)
|
||||
{
|
||||
throw new SecurityException(Resource.PortalSecurity);
|
||||
@ -212,7 +212,7 @@ public class LicenseController : BaseSettingsController
|
||||
return dueDate >= DateTime.UtcNow.Date
|
||||
? Resource.LicenseUploaded
|
||||
: string.Format(
|
||||
_tenantManager.GetCurrentTenantQuota().Update
|
||||
(await _tenantManager.GetCurrentTenantQuotaAsync()).Update
|
||||
? Resource.LicenseUploadedOverdueSupport
|
||||
: Resource.LicenseUploadedOverdue,
|
||||
"",
|
||||
|
@ -114,10 +114,10 @@ public class MessageSettingsController : BaseSettingsController
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("sendadmmail")]
|
||||
public object SendAdmMail(AdminMessageSettingsRequestsDto inDto)
|
||||
public async Task<object> SendAdmMailAsync(AdminMessageSettingsRequestsDto inDto)
|
||||
{
|
||||
var studioAdminMessageSettings = _settingsManager.Load<StudioAdminMessageSettings>();
|
||||
var enableAdmMess = studioAdminMessageSettings.Enable || _tenantExtra.IsNotPaid();
|
||||
var enableAdmMess = studioAdminMessageSettings.Enable || (await _tenantExtra.IsNotPaidAsync());
|
||||
|
||||
if (!enableAdmMess)
|
||||
{
|
||||
@ -204,7 +204,7 @@ public class MessageSettingsController : BaseSettingsController
|
||||
var address = new MailAddress(email);
|
||||
if (Tenant.TrustedDomains.Any(d => address.Address.EndsWith("@" + d.Replace("*", ""), StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
_studioNotifyService.SendJoinMsg(email, emplType);
|
||||
await _studioNotifyService.SendJoinMsgAsync(email, emplType);
|
||||
_messageService.Send(MessageInitiator.System, MessageAction.SentInviteInstructions, email);
|
||||
return Resource.FinishInviteJoinEmailMessage;
|
||||
}
|
||||
@ -213,7 +213,7 @@ public class MessageSettingsController : BaseSettingsController
|
||||
}
|
||||
case TenantTrustedDomainsType.All:
|
||||
{
|
||||
_studioNotifyService.SendJoinMsg(email, emplType);
|
||||
await _studioNotifyService.SendJoinMsgAsync(email, emplType);
|
||||
_messageService.Send(MessageInitiator.System, MessageAction.SentInviteInstructions, email);
|
||||
return Resource.FinishInviteJoinEmailMessage;
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ public class SecurityController : BaseSettingsController
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
var isStartup = !_coreBaseSettings.CustomMode && _tenantExtra.Saas && _tenantManager.GetCurrentTenantQuota().Free;
|
||||
var isStartup = !_coreBaseSettings.CustomMode && _tenantExtra.Saas && (await _tenantManager.GetCurrentTenantQuotaAsync()).Free;
|
||||
if (isStartup)
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "Administrator");
|
||||
|
@ -133,7 +133,7 @@ public class SettingsController : BaseSettingsController
|
||||
|
||||
[HttpGet("")]
|
||||
[AllowNotPayment, AllowSuspended, AllowAnonymous]
|
||||
public SettingsDto GetSettings(bool? withpassword)
|
||||
public async Task<SettingsDto> GetSettingsAsync(bool? withpassword)
|
||||
{
|
||||
var studioAdminMessageSettings = _settingsManager.Load<StudioAdminMessageSettings>();
|
||||
|
||||
@ -147,7 +147,7 @@ public class SettingsController : BaseSettingsController
|
||||
Version = _configuration["version:number"] ?? "",
|
||||
TenantStatus = _tenantManager.GetCurrentTenant().Status,
|
||||
TenantAlias = Tenant.Alias,
|
||||
EnableAdmMess = studioAdminMessageSettings.Enable || _tenantExtra.IsNotPaid()
|
||||
EnableAdmMess = studioAdminMessageSettings.Enable || await _tenantExtra.IsNotPaidAsync()
|
||||
};
|
||||
|
||||
if (_authContext.IsAuthenticated)
|
||||
@ -286,9 +286,9 @@ public class SettingsController : BaseSettingsController
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "Wizard,Administrators")]
|
||||
[HttpGet("timezones")]
|
||||
[AllowNotPayment]
|
||||
public List<TimezonesRequestsDto> GetTimeZones()
|
||||
public async Task<List<TimezonesRequestsDto>> GetTimeZonesAsyncAsync()
|
||||
{
|
||||
ApiContext.AuthByClaim();
|
||||
await ApiContext.AuthByClaimAsync();
|
||||
var timeZones = TimeZoneInfo.GetSystemTimeZones().ToList();
|
||||
|
||||
if (timeZones.All(tz => tz.Id != "UTC"))
|
||||
@ -347,13 +347,13 @@ public class SettingsController : BaseSettingsController
|
||||
[AllowNotPayment]
|
||||
[HttpPut("wizard/complete")]
|
||||
[Authorize(AuthenticationSchemes = "confirm", Roles = "Wizard")]
|
||||
public WizardSettings CompleteWizard(WizardRequestsDto inDto)
|
||||
public async Task<WizardSettings> CompleteWizardAsync(WizardRequestsDto inDto)
|
||||
{
|
||||
ApiContext.AuthByClaim();
|
||||
await ApiContext.AuthByClaimAsync();
|
||||
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
return _firstTimeTenantSettings.SaveData(inDto);
|
||||
return await _firstTimeTenantSettings.SaveDataAsync(inDto);
|
||||
}
|
||||
|
||||
///<visible>false</visible>
|
||||
@ -668,11 +668,11 @@ public class SettingsController : BaseSettingsController
|
||||
}
|
||||
|
||||
[HttpPost("authservice")]
|
||||
public bool SaveAuthKeys(AuthServiceRequestsDto inDto)
|
||||
public async Task<bool> SaveAuthKeys(AuthServiceRequestsDto inDto)
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
var saveAvailable = _coreBaseSettings.Standalone || _tenantManager.GetTenantQuota(_tenantManager.GetCurrentTenant().Id).ThirdParty;
|
||||
var saveAvailable = _coreBaseSettings.Standalone || (await _tenantManager.GetTenantQuotaAsync(_tenantManager.GetCurrentTenant().Id)).ThirdParty;
|
||||
if (!SetupInfo.IsVisibleSettings(nameof(ManagementType.ThirdPartyAuthorization))
|
||||
|| !saveAvailable)
|
||||
{
|
||||
@ -734,11 +734,11 @@ public class SettingsController : BaseSettingsController
|
||||
|
||||
[AllowNotPayment]
|
||||
[HttpGet("payment")]
|
||||
public object PaymentSettings()
|
||||
public async Task<object> PaymentSettingsAsync()
|
||||
{
|
||||
var settings = _settingsManager.LoadForDefaultTenant<AdditionalWhiteLabelSettings>();
|
||||
var currentQuota = _tenantManager.GetCurrentTenantQuota();
|
||||
var currentTariff = _tenantExtra.GetCurrentTariff();
|
||||
var currentQuota = await _tenantManager.GetCurrentTenantQuotaAsync();
|
||||
var currentTariff = await _tenantExtra.GetCurrentTariffAsync();
|
||||
|
||||
if (!int.TryParse(_configuration["core:payment:max-quantity"], out var maxQuotaQuantity))
|
||||
{
|
||||
|
@ -64,9 +64,9 @@ public class SsoController : BaseSettingsController
|
||||
/// <category>SSO</category>
|
||||
/// <returns>SSO settings</returns>
|
||||
[HttpGet("ssov2")]
|
||||
public SsoSettingsV2 GetSsoSettingsV2()
|
||||
public async Task<SsoSettingsV2> GetSsoSettingsV2()
|
||||
{
|
||||
CheckSsoPermissions();
|
||||
await CheckSsoPermissionsAsync();
|
||||
|
||||
var settings = _settingsManager.Load<SsoSettingsV2>();
|
||||
|
||||
@ -87,9 +87,9 @@ public class SsoController : BaseSettingsController
|
||||
/// <category>SSO</category>
|
||||
/// <returns>Default SSO settings</returns>
|
||||
[HttpGet("ssov2/default")]
|
||||
public SsoSettingsV2 GetDefaultSsoSettingsV2()
|
||||
public async Task<SsoSettingsV2> GetDefaultSsoSettingsV2Async()
|
||||
{
|
||||
CheckSsoPermissions();
|
||||
await CheckSsoPermissionsAsync();
|
||||
return _settingsManager.GetDefault<SsoSettingsV2>();
|
||||
}
|
||||
|
||||
@ -125,9 +125,9 @@ public class SsoController : BaseSettingsController
|
||||
/// <param name="serializeSettings">Serialized SSO settings</param>
|
||||
/// <returns>SSO settings</returns>
|
||||
[HttpPost("ssov2")]
|
||||
public SsoSettingsV2 SaveSsoSettingsV2(SsoSettingsRequestsDto model)
|
||||
public async Task<SsoSettingsV2> SaveSsoSettingsV2Async(SsoSettingsRequestsDto model)
|
||||
{
|
||||
CheckSsoPermissions();
|
||||
await CheckSsoPermissionsAsync();
|
||||
|
||||
var serializeSettings = model.SerializeSettings;
|
||||
|
||||
@ -206,9 +206,9 @@ public class SsoController : BaseSettingsController
|
||||
/// <category>SSO</category>
|
||||
/// <returns>Default SSO settings</returns>
|
||||
[HttpDelete("ssov2")]
|
||||
public SsoSettingsV2 ResetSsoSettingsV2()
|
||||
public async Task<SsoSettingsV2> ResetSsoSettingsV2Async()
|
||||
{
|
||||
CheckSsoPermissions();
|
||||
await CheckSsoPermissionsAsync();
|
||||
|
||||
var defaultSettings = _settingsManager.GetDefault<SsoSettingsV2>();
|
||||
|
||||
@ -249,13 +249,13 @@ public class SsoController : BaseSettingsController
|
||||
return Uri.TryCreate(uriName, UriKind.Absolute, out var uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
|
||||
}
|
||||
|
||||
private void CheckSsoPermissions()
|
||||
private async Task CheckSsoPermissionsAsync()
|
||||
{
|
||||
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
if (!_coreBaseSettings.Standalone
|
||||
&& (!SetupInfo.IsVisibleSettings(ManagementType.SingleSignOnSettings.ToString())
|
||||
|| !_tenantManager.GetCurrentTenantQuota().Sso))
|
||||
|| !(await _tenantManager.GetCurrentTenantQuotaAsync()).Sso))
|
||||
{
|
||||
throw new BillingException(Resource.ErrorNotAllowedOption, "Sso");
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user