socket notification when archiving a room,

changed file_size id to total_size when added/deleted files,
fix notification when adding paid users,
fix notification when block/unblock users,
fix problem with change-quota-feature-value notification when updating quota
This commit is contained in:
Vashchuk Nikita 2023-04-03 16:31:14 +05:00
parent 2f8d21fc42
commit 0db7c335bf
16 changed files with 125 additions and 81 deletions

View File

@ -299,7 +299,7 @@ public class LdapOperationJob : DistributedTaskProgress
{ {
_logger.DebugTurnOffLDAP(); _logger.DebugTurnOffLDAP();
TurnOffLDAP(); await TurnOffLDAP();
var ldapCurrentUserPhotos = _settingsManager.Load<LdapCurrentUserPhotos>().GetDefault(); var ldapCurrentUserPhotos = _settingsManager.Load<LdapCurrentUserPhotos>().GetDefault();
_settingsManager.Save(ldapCurrentUserPhotos); _settingsManager.Save(ldapCurrentUserPhotos);
@ -349,7 +349,7 @@ public class LdapOperationJob : DistributedTaskProgress
: "", ""); : "", "");
} }
private void TurnOffLDAP() private async Task TurnOffLDAP()
{ {
const double percents = 48; const double percents = 48;
@ -380,7 +380,7 @@ public class LdapOperationJob : DistributedTaskProgress
_logger.DebugSaveUserInfo(existingLDAPUser.GetUserInfoString()); _logger.DebugSaveUserInfo(existingLDAPUser.GetUserInfoString());
_userManager.UpdateUserInfo(existingLDAPUser); await _userManager.UpdateUserInfo(existingLDAPUser);
break; break;
case LdapOperationType.SaveTest: case LdapOperationType.SaveTest:
case LdapOperationType.SyncTest: case LdapOperationType.SyncTest:
@ -667,7 +667,7 @@ public class LdapOperationJob : DistributedTaskProgress
SetProgress(20, Resource.LdapSettingsStatusRemovingOldUsers, ""); SetProgress(20, Resource.LdapSettingsStatusRemovingOldUsers, "");
ldapUsers = RemoveOldDbUsers(ldapUsers); ldapUsers = await RemoveOldDbUsers(ldapUsers);
SetProgress(30, SetProgress(30,
OperationType == LdapOperationType.Save || OperationType == LdapOperationType.SaveTest OperationType == LdapOperationType.Save || OperationType == LdapOperationType.SaveTest
@ -729,7 +729,7 @@ public class LdapOperationJob : DistributedTaskProgress
SetProgress(90, Resource.LdapSettingsStatusRemovingOldUsers, ""); SetProgress(90, Resource.LdapSettingsStatusRemovingOldUsers, "");
RemoveOldDbUsers(newUniqueLdapGroupUsers); await RemoveOldDbUsers(newUniqueLdapGroupUsers);
} }
private async Task SyncDbGroups(Dictionary<GroupInfo, List<UserInfo>> ldapGroupsWithUsers) private async Task SyncDbGroups(Dictionary<GroupInfo, List<UserInfo>> ldapGroupsWithUsers)
@ -1012,7 +1012,7 @@ public class LdapOperationJob : DistributedTaskProgress
/// </summary> /// </summary>
/// <param name="ldapUsers">list of actual LDAP users</param> /// <param name="ldapUsers">list of actual LDAP users</param>
/// <returns>New list of actual LDAP users</returns> /// <returns>New list of actual LDAP users</returns>
private List<UserInfo> RemoveOldDbUsers(List<UserInfo> ldapUsers) private async Task<List<UserInfo>> RemoveOldDbUsers(List<UserInfo> ldapUsers)
{ {
var dbLdapUsers = _userManager.GetUsers(EmployeeStatus.All).Where(u => u.Sid != null).ToList(); var dbLdapUsers = _userManager.GetUsers(EmployeeStatus.All).Where(u => u.Sid != null).ToList();
@ -1064,7 +1064,7 @@ public class LdapOperationJob : DistributedTaskProgress
_logger.DebugSaveUserInfo(removedUser.GetUserInfoString()); _logger.DebugSaveUserInfo(removedUser.GetUserInfoString());
_userManager.UpdateUserInfo(removedUser); await _userManager.UpdateUserInfo(removedUser);
break; break;
case LdapOperationType.SaveTest: case LdapOperationType.SaveTest:
case LdapOperationType.SyncTest: case LdapOperationType.SyncTest:

View File

@ -126,7 +126,7 @@ public class LdapUserManager
return portalUserInfo; return portalUserInfo;
} }
if (!TryChangeExistingUserName(ldapUserInfo.UserName, onlyGetChanges)) if (!await TryChangeExistingUserName(ldapUserInfo.UserName, onlyGetChanges))
{ {
_logger.DebugUserAlredyExistsForUserName(ldapUserInfo.Sid, ldapUserInfo.UserName); _logger.DebugUserAlredyExistsForUserName(ldapUserInfo.Sid, ldapUserInfo.UserName);
@ -177,7 +177,7 @@ public class LdapUserManager
return portalUserInfo; return portalUserInfo;
} }
private bool TryChangeExistingUserName(string ldapUserName, bool onlyGetChanges) private async Task<bool> TryChangeExistingUserName(string ldapUserName, bool onlyGetChanges)
{ {
try try
{ {
@ -209,7 +209,7 @@ public class LdapUserManager
_logger.DebugSaveUserInfo(otherUser.GetUserInfoString()); _logger.DebugSaveUserInfo(otherUser.GetUserInfoString());
_userManager.UpdateUserInfo(otherUser); await _userManager.UpdateUserInfo(otherUser);
return true; return true;
} }
@ -343,9 +343,11 @@ public class LdapUserManager
return wrapper; return wrapper;
} }
_logger.DebugSyncUserLdapUpdaiting(ldapUserInfo.Sid, ldapUserInfo.UserName); _logger.DebugSyncUserLdapUpdaiting(ldapUserInfo.Sid, ldapUserInfo.UserName);
UserInfo uf;
if (!TryUpdateUserWithLDAPInfo(userToUpdate, ldapUserInfo, onlyGetChanges, out uf)) var (updated, uf) = await TryUpdateUserWithLDAPInfo(userToUpdate, ldapUserInfo, onlyGetChanges);
if (!updated)
{ {
if (onlyGetChanges) if (onlyGetChanges)
{ {
@ -379,7 +381,7 @@ public class LdapUserManager
var newContacts = new List<string>(ldapUser.ContactsList); var newContacts = new List<string>(ldapUser.ContactsList);
for (int i = 0; i < portalUserContacts.Count; i += 2) for (var i = 0; i < portalUserContacts.Count; i += 2)
{ {
if (portalUserContacts[i] == EXT_MOB_PHONE || portalUserContacts[i] == EXT_MAIL if (portalUserContacts[i] == EXT_MOB_PHONE || portalUserContacts[i] == EXT_MAIL
|| portalUserContacts[i] == EXT_PHONE || portalUserContacts[i] == EXT_SKYPE) || portalUserContacts[i] == EXT_PHONE || portalUserContacts[i] == EXT_SKYPE)
@ -516,9 +518,9 @@ public class LdapUserManager
return needUpdate; return needUpdate;
} }
private bool TryUpdateUserWithLDAPInfo(UserInfo userToUpdate, UserInfo updateInfo, bool onlyGetChanges, out UserInfo portlaUserInfo) private async Task<(bool, UserInfo)> TryUpdateUserWithLDAPInfo(UserInfo userToUpdate, UserInfo updateInfo, bool onlyGetChanges)
{ {
portlaUserInfo = Constants.LostUser; var portlaUserInfo = Constants.LostUser;
try try
{ {
@ -527,11 +529,11 @@ public class LdapUserManager
var settings = _settingsManager.Load<LdapSettings>(); var settings = _settingsManager.Load<LdapSettings>();
if (!userToUpdate.UserName.Equals(updateInfo.UserName, StringComparison.InvariantCultureIgnoreCase) if (!userToUpdate.UserName.Equals(updateInfo.UserName, StringComparison.InvariantCultureIgnoreCase)
&& !TryChangeExistingUserName(updateInfo.UserName, onlyGetChanges)) && !await TryChangeExistingUserName(updateInfo.UserName, onlyGetChanges))
{ {
_logger.DebugUpdateUserUserNameAlredyExists(userToUpdate.Id, userToUpdate.UserName, updateInfo.UserName); _logger.DebugUpdateUserUserNameAlredyExists(userToUpdate.Id, userToUpdate.UserName, updateInfo.UserName);
return false; return (false, portlaUserInfo);
} }
if (!userToUpdate.Email.Equals(updateInfo.Email, StringComparison.InvariantCultureIgnoreCase) if (!userToUpdate.Email.Equals(updateInfo.Email, StringComparison.InvariantCultureIgnoreCase)
@ -539,7 +541,7 @@ public class LdapUserManager
{ {
_logger.DebugUpdateUserEmailAlreadyExists(userToUpdate.Id, userToUpdate.Email, updateInfo.Email); _logger.DebugUpdateUserEmailAlreadyExists(userToUpdate.Id, userToUpdate.Email, updateInfo.Email);
return false; return (false, portlaUserInfo);
} }
if (userToUpdate.Email != updateInfo.Email && !(updateInfo.ActivationStatus == EmployeeActivationStatus.AutoGenerated && if (userToUpdate.Email != updateInfo.Email && !(updateInfo.ActivationStatus == EmployeeActivationStatus.AutoGenerated &&
@ -589,10 +591,10 @@ public class LdapUserManager
{ {
_logger.DebugSaveUserInfo(userToUpdate.GetUserInfoString()); _logger.DebugSaveUserInfo(userToUpdate.GetUserInfoString());
portlaUserInfo = _userManager.UpdateUserInfo(userToUpdate); portlaUserInfo = await _userManager.UpdateUserInfo(userToUpdate);
} }
return true; return (true, portlaUserInfo);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -600,7 +602,7 @@ public class LdapUserManager
userToUpdate.Sid, ex); userToUpdate.Sid, ex);
} }
return false; return (false, portlaUserInfo);
} }
public async Task<UserInfo> TryGetAndSyncLdapUserInfo(string login, string password) public async Task<UserInfo> TryGetAndSyncLdapUserInfo(string login, string password)
@ -678,7 +680,7 @@ public class LdapUserManager
log.DebugTryGetAndSyncLdapUserInfoDisablingUser(login, uInfo); log.DebugTryGetAndSyncLdapUserInfoDisablingUser(login, uInfo);
uInfo.Status = EmployeeStatus.Terminated; uInfo.Status = EmployeeStatus.Terminated;
uInfo.Sid = null; uInfo.Sid = null;
userManager.UpdateUserInfo(uInfo); await userManager.UpdateUserInfo(uInfo);
await cookiesManager.ResetUserCookie(uInfo.Id); await cookiesManager.ResetUserCookie(uInfo.Id);
} }
} }
@ -730,7 +732,7 @@ public class LdapUserManager
{ {
userInfo.Sid = null; userInfo.Sid = null;
userInfo.Status = EmployeeStatus.Terminated; userInfo.Status = EmployeeStatus.Terminated;
_userManager.UpdateUserInfo(userInfo); await _userManager.UpdateUserInfo(userInfo);
throw new Exception("The user did not pass the configuration check by ldap group settings"); throw new Exception("The user did not pass the configuration check by ldap group settings");
} }

View File

@ -23,7 +23,7 @@
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing // All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // 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 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
namespace ASC.Core.Billing; namespace ASC.Core.Billing;
[Singletone] [Singletone]
@ -218,6 +218,8 @@ public class TariffService : ITariffService
asynctariff = CalculateTariff(tenantId, asynctariff); asynctariff = CalculateTariff(tenantId, asynctariff);
tariff = asynctariff; tariff = asynctariff;
tariffId = asynctariff.Id; tariffId = asynctariff.Id;
NotifyWebSocket(tariff);
} }
} }
catch (BillingNotFoundException) catch (BillingNotFoundException)
@ -245,6 +247,8 @@ public class TariffService : ITariffService
asynctariff = CalculateTariff(tenantId, asynctariff); asynctariff = CalculateTariff(tenantId, asynctariff);
tariff = asynctariff; tariff = asynctariff;
tariffId = asynctariff.Id; tariffId = asynctariff.Id;
NotifyWebSocket(tariff);
} }
} }
catch (Exception error) catch (Exception error)
@ -941,6 +945,32 @@ public class TariffService : ITariffService
} }
} }
private void NotifyWebSocket(Tariff tariff)
{
var quotaSocketManager = _serviceProvider.GetRequiredService<QuotaSocketManager>();
TenantQuota updatedQuota = null;
foreach (var tariffRow in tariff.Quotas)
{
var qty = tariffRow.Quantity;
var quota = _quotaService.GetTenantQuota(tariffRow.Id);
quota *= qty;
updatedQuota += quota;
}
var maxTotalSize = updatedQuota.MaxTotalSize;
var maxTotalSizeFeatureName = updatedQuota.GetFeature<MaxTotalSizeFeature>().Name;
_ = quotaSocketManager.ChangeQuotaFeatureValue(maxTotalSizeFeatureName, maxTotalSize);
var maxPaidUsers = updatedQuota.CountRoomAdmin;
var maxPaidUsersFeatureName = updatedQuota.GetFeature<CountPaidUserFeature>().Name;
_ = quotaSocketManager.ChangeQuotaFeatureValue(maxPaidUsersFeatureName, maxPaidUsers);
}
public int GetPaymentDelay() public int GetPaymentDelay()
{ {
return _paymentDelay; return _paymentDelay;

View File

@ -330,7 +330,7 @@ public class UserManager
return findUsers.ToArray(); return findUsers.ToArray();
} }
public UserInfo UpdateUserInfo(UserInfo u) public async Task<UserInfo> UpdateUserInfo(UserInfo u)
{ {
if (IsSystemUser(u.Id)) if (IsSystemUser(u.Id))
{ {
@ -351,14 +351,30 @@ public class UserManager
throw new InvalidOperationException("User not found."); throw new InvalidOperationException("User not found.");
} }
return _userService.SaveUser(_tenantManager.GetCurrentTenant().Id, u); var (name, value) = ("", -1);
if (!IsUserInGroup(oldUserData.Id, Constants.GroupUser.ID) &&
oldUserData.Status != u.Status)
{
(name, value) = await _tenantQuotaFeatureStatHelper.GetStat<CountPaidUserFeature, int>();
value = oldUserData.Status > u.Status ? ++value : --value;//crutch: data race
}
var newUserData = _userService.SaveUser(_tenantManager.GetCurrentTenant().Id, u);
if (value > 0)
{
await _quotaSocketManager.ChangeQuotaUsedValue(name, value);
}
return newUserData;
} }
public async Task<UserInfo> UpdateUserInfoWithSyncCardDavAsync(UserInfo u) public async Task<UserInfo> UpdateUserInfoWithSyncCardDavAsync(UserInfo u)
{ {
var oldUserData = _userService.GetUserByUserName(_tenantManager.GetCurrentTenant().Id, u.UserName); var oldUserData = _userService.GetUserByUserName(_tenantManager.GetCurrentTenant().Id, u.UserName);
var newUser = UpdateUserInfo(u); var newUser = await UpdateUserInfo(u);
if (_coreBaseSettings.DisableDocSpace) if (_coreBaseSettings.DisableDocSpace)
{ {
@ -661,6 +677,7 @@ public class UserManager
var user = GetUsers(userId); var user = GetUsers(userId);
var isUser = IsUserInGroup(userId, Constants.GroupUser.ID); var isUser = IsUserInGroup(userId, Constants.GroupUser.ID);
var userGroups = GetUserGroups(userId);
_permissionContext.DemandPermissions(new UserGroupObject(new UserAccount(user, _tenantManager.GetCurrentTenant().Id, _userFormatter), groupId), _permissionContext.DemandPermissions(new UserGroupObject(new UserAccount(user, _tenantManager.GetCurrentTenant().Id, _userFormatter), groupId),
Constants.Action_EditGroups); Constants.Action_EditGroups);
@ -682,7 +699,8 @@ public class UserManager
} }
if (isUser && groupId != Constants.GroupUser.ID || if (isUser && groupId != Constants.GroupUser.ID ||
!isUser && groupId == Constants.GroupUser.ID) !isUser && groupId == Constants.GroupUser.ID &&
userGroups.Any())
{ {
var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<CountPaidUserFeature, int>(); var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<CountPaidUserFeature, int>();
await _quotaSocketManager.ChangeQuotaUsedValue(name, value); await _quotaSocketManager.ChangeQuotaUsedValue(name, value);
@ -697,6 +715,8 @@ public class UserManager
} }
var user = GetUsers(userId); var user = GetUsers(userId);
var isUser = IsUserInGroup(userId, Constants.GroupUser.ID);
var userGroups = GetUserGroups(userId);
_permissionContext.DemandPermissions(new UserGroupObject(new UserAccount(user, _tenantManager.GetCurrentTenant().Id, _userFormatter), groupId), _permissionContext.DemandPermissions(new UserGroupObject(new UserAccount(user, _tenantManager.GetCurrentTenant().Id, _userFormatter), groupId),
Constants.Action_EditGroups); Constants.Action_EditGroups);
@ -705,7 +725,8 @@ public class UserManager
ResetGroupCache(userId); ResetGroupCache(userId);
if (groupId != Constants.GroupUser.ID) if (groupId != Constants.GroupUser.ID &&
!isUser && userGroups.Any())
{ {
var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<CountPaidUserFeature, int>(); var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<CountPaidUserFeature, int>();
await _quotaSocketManager.ChangeQuotaUsedValue(name, value); await _quotaSocketManager.ChangeQuotaUsedValue(name, value);

View File

@ -346,7 +346,7 @@ public abstract class BaseStorage : IDataStore
if (QuotaController != null) if (QuotaController != null)
{ {
QuotaController.QuotaUsedAdd(Modulename, domain, DataList.GetData(domain), size, quotaCheckFileSize); QuotaController.QuotaUsedAdd(Modulename, domain, DataList.GetData(domain), size, quotaCheckFileSize);
var(name, value) = await _tenantQuotaFeatureStatHelper.GetStat<MaxFileSizeFeature, long>(); var(name, value) = await _tenantQuotaFeatureStatHelper.GetStat<MaxTotalSizeFeature, long>();
await _quotaSocketManager.ChangeQuotaUsedValue(name, value); await _quotaSocketManager.ChangeQuotaUsedValue(name, value);
} }
} }
@ -356,7 +356,7 @@ public abstract class BaseStorage : IDataStore
if (QuotaController != null) if (QuotaController != null)
{ {
QuotaController.QuotaUsedDelete(Modulename, domain, DataList.GetData(domain), size); QuotaController.QuotaUsedDelete(Modulename, domain, DataList.GetData(domain), size);
var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<MaxFileSizeFeature, long>(); var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<MaxTotalSizeFeature, long>();
await _quotaSocketManager.ChangeQuotaUsedValue(name, value); await _quotaSocketManager.ChangeQuotaUsedValue(name, value);
} }
} }

View File

@ -446,6 +446,9 @@ class FileMoveCopyOperation<T> : FileOperation<FileMoveCopyOperationData<T>, T>
{ {
await _semaphore.WaitAsync(); await _semaphore.WaitAsync();
newFolderId = await FolderDao.MoveFolderAsync(folder.Id, toFolderId, CancellationToken); newFolderId = await FolderDao.MoveFolderAsync(folder.Id, toFolderId, CancellationToken);
var (name, value) = await tenantQuotaFeatureStatHelper.GetStat<CountRoomFeature, int>();
await quotaSocketManager.ChangeQuotaUsedValue(name, value);
} }
else else
{ {

View File

@ -281,6 +281,6 @@ public class GroupController : ControllerBase
var user = _userManager.GetUsers(userId); var user = _userManager.GetUsers(userId);
await _userManager.RemoveUserFromGroup(user.Id, @group.ID); await _userManager.RemoveUserFromGroup(user.Id, @group.ID);
_userManager.UpdateUserInfo(user); await _userManager.UpdateUserInfo(user);
} }
} }

View File

@ -52,7 +52,7 @@ public class NotificationController : ApiControllerBase
} }
[HttpPost("phone")] [HttpPost("phone")]
public object SendNotificationToChange(UpdateMemberRequestDto inDto) public async Task<object> SendNotificationToChange(UpdateMemberRequestDto inDto)
{ {
var user = _userManager.GetUsers(string.IsNullOrEmpty(inDto.UserId) var user = _userManager.GetUsers(string.IsNullOrEmpty(inDto.UserId)
? _securityContext.CurrentAccount.ID : new Guid(inDto.UserId)); ? _securityContext.CurrentAccount.ID : new Guid(inDto.UserId));
@ -66,7 +66,7 @@ public class NotificationController : ApiControllerBase
user.MobilePhoneActivationStatus = MobilePhoneActivationStatus.NotActivated; user.MobilePhoneActivationStatus = MobilePhoneActivationStatus.NotActivated;
_userManager.UpdateUserInfo(user); await _userManager.UpdateUserInfo(user);
if (user.IsMe(_authContext)) if (user.IsMe(_authContext))
{ {

View File

@ -452,7 +452,7 @@ public class UserController : PeopleControllerBase
_securityContext.AuthenticateMeWithoutCookie(Core.Configuration.Constants.CoreSystem); _securityContext.AuthenticateMeWithoutCookie(Core.Configuration.Constants.CoreSystem);
user.Status = EmployeeStatus.Terminated; user.Status = EmployeeStatus.Terminated;
_userManager.UpdateUserInfo(user); await _userManager.UpdateUserInfo(user);
var userName = user.DisplayUserName(false, _displayUserSettingsHelper); var userName = user.DisplayUserName(false, _displayUserSettingsHelper);
_messageService.Send(MessageAction.UsersUpdatedStatus, _messageTarget.Create(user.Id), userName); _messageService.Send(MessageAction.UsersUpdatedStatus, _messageTarget.Create(user.Id), userName);
@ -887,7 +887,7 @@ public class UserController : PeopleControllerBase
} }
u.ActivationStatus = activationstatus; u.ActivationStatus = activationstatus;
_userManager.UpdateUserInfo(u); await _userManager.UpdateUserInfo(u);
yield return await _employeeFullDtoHelper.GetFull(u); yield return await _employeeFullDtoHelper.GetFull(u);
} }
} }
@ -914,7 +914,7 @@ public class UserController : PeopleControllerBase
try try
{ {
_userManager.UpdateUserInfo(user); await _userManager.UpdateUserInfo(user);
} }
catch catch
{ {

View File

@ -168,7 +168,7 @@ public class AuthenticationController : ControllerBase
if (_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id)) if (_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings() && _studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
{ {
sms = true; sms = true;
_smsManager.ValidateSmsCode(user, inDto.Code, true); await _smsManager.ValidateSmsCode(user, inDto.Code, true);
} }
else if (_tfaAppAuthSettingsHelper.IsVisibleSettings && _tfaAppAuthSettingsHelper.TfaEnabledForUser(user.Id)) else if (_tfaAppAuthSettingsHelper.IsVisibleSettings && _tfaAppAuthSettingsHelper.TfaEnabledForUser(user.Id))
{ {

View File

@ -46,7 +46,6 @@ public class PaymentController : ControllerBase
private readonly StudioNotifyService _studioNotifyService; private readonly StudioNotifyService _studioNotifyService;
private readonly int _maxCount = 10; private readonly int _maxCount = 10;
private readonly int _expirationMinutes = 2; private readonly int _expirationMinutes = 2;
private readonly QuotaSocketManager _quotaSocketManager;
protected Tenant Tenant { get { return _apiContext.Tenant; } } protected Tenant Tenant { get { return _apiContext.Tenant; } }
public PaymentController( public PaymentController(
@ -60,8 +59,7 @@ public class PaymentController : ControllerBase
IMemoryCache memoryCache, IMemoryCache memoryCache,
IHttpContextAccessor httpContextAccessor, IHttpContextAccessor httpContextAccessor,
MessageService messageService, MessageService messageService,
StudioNotifyService studioNotifyService, StudioNotifyService studioNotifyService)
QuotaSocketManager quotaSocketManager)
{ {
_apiContext = apiContext; _apiContext = apiContext;
_userManager = userManager; _userManager = userManager;
@ -74,7 +72,6 @@ public class PaymentController : ControllerBase
_httpContextAccessor = httpContextAccessor; _httpContextAccessor = httpContextAccessor;
_messageService = messageService; _messageService = messageService;
_studioNotifyService = studioNotifyService; _studioNotifyService = studioNotifyService;
_quotaSocketManager = quotaSocketManager;
} }
[HttpPut("payment/url")] [HttpPut("payment/url")]
@ -107,14 +104,7 @@ public class PaymentController : ControllerBase
return false; return false;
} }
var changed = await _tariffService.PaymentChange(Tenant.Id, inDto.Quantity); return await _tariffService.PaymentChange(Tenant.Id, inDto.Quantity);
if (changed)
{
await NotifyWebSocket();
}
return changed;
} }
[HttpGet("payment/account")] [HttpGet("payment/account")]
@ -200,19 +190,4 @@ public class PaymentController : ControllerBase
_memoryCache.Set(key, count + 1, TimeSpan.FromMinutes(_expirationMinutes)); _memoryCache.Set(key, count + 1, TimeSpan.FromMinutes(_expirationMinutes));
} }
private async Task NotifyWebSocket()
{
var updatedQuota = _tenantManager.GetCurrentTenantQuota();
var maxTotalSize = updatedQuota.MaxTotalSize;
var maxTotalSizeFeatureName = updatedQuota.GetFeature<MaxTotalSizeFeature>().Name;
await _quotaSocketManager.ChangeQuotaFeatureValue(maxTotalSizeFeatureName, maxTotalSize);
var maxPaidUsers = updatedQuota.CountRoomAdmin;
var maxPaidUsersFeatureName = updatedQuota.GetFeature<CountPaidUserFeature>().Name;
await _quotaSocketManager.ChangeQuotaFeatureValue(maxPaidUsersFeatureName, maxPaidUsers);
}
} }

View File

@ -347,7 +347,7 @@ public class SettingsController : BaseSettingsController
[AllowNotPayment] [AllowNotPayment]
[HttpPut("wizard/complete")] [HttpPut("wizard/complete")]
[Authorize(AuthenticationSchemes = "confirm", Roles = "Wizard")] [Authorize(AuthenticationSchemes = "confirm", Roles = "Wizard")]
public WizardSettings CompleteWizard(WizardRequestsDto inDto) public Task<WizardSettings> CompleteWizard(WizardRequestsDto inDto)
{ {
ApiContext.AuthByClaim(); ApiContext.AuthByClaim();

View File

@ -125,7 +125,7 @@ public class SsoController : BaseSettingsController
/// <param name="serializeSettings">Serialized SSO settings</param> /// <param name="serializeSettings">Serialized SSO settings</param>
/// <returns>SSO settings</returns> /// <returns>SSO settings</returns>
[HttpPost("ssov2")] [HttpPost("ssov2")]
public SsoSettingsV2 SaveSsoSettingsV2(SsoSettingsRequestsDto model) public async Task<SsoSettingsV2> SaveSsoSettingsV2(SsoSettingsRequestsDto model)
{ {
CheckSsoPermissions(); CheckSsoPermissions();
@ -187,7 +187,7 @@ public class SsoController : BaseSettingsController
if (!settings.EnableSso) if (!settings.EnableSso)
{ {
ConverSsoUsersToOrdinary(); await ConverSsoUsersToOrdinary();
} }
var messageAction = settings.EnableSso ? MessageAction.SSOEnabled : MessageAction.SSODisabled; var messageAction = settings.EnableSso ? MessageAction.SSOEnabled : MessageAction.SSODisabled;
@ -206,7 +206,7 @@ public class SsoController : BaseSettingsController
/// <category>SSO</category> /// <category>SSO</category>
/// <returns>Default SSO settings</returns> /// <returns>Default SSO settings</returns>
[HttpDelete("ssov2")] [HttpDelete("ssov2")]
public SsoSettingsV2 ResetSsoSettingsV2() public async Task<SsoSettingsV2> ResetSsoSettingsV2()
{ {
CheckSsoPermissions(); CheckSsoPermissions();
@ -217,14 +217,14 @@ public class SsoController : BaseSettingsController
throw new Exception(Resource.SsoSettingsCantSaveSettings); throw new Exception(Resource.SsoSettingsCantSaveSettings);
} }
ConverSsoUsersToOrdinary(); await ConverSsoUsersToOrdinary();
_messageService.Send(MessageAction.SSODisabled); _messageService.Send(MessageAction.SSODisabled);
return defaultSettings; return defaultSettings;
} }
private void ConverSsoUsersToOrdinary() private async Task ConverSsoUsersToOrdinary()
{ {
var ssoUsers = _userManager.GetUsers().Where(u => u.IsSSO()).ToList(); var ssoUsers = _userManager.GetUsers().Where(u => u.IsSSO()).ToList();
@ -240,7 +240,7 @@ public class SsoController : BaseSettingsController
existingSsoUser.ConvertExternalContactsToOrdinary(); existingSsoUser.ConvertExternalContactsToOrdinary();
_userManager.UpdateUserInfo(existingSsoUser); await _userManager.UpdateUserInfo(existingSsoUser);
} }
} }

View File

@ -73,7 +73,7 @@ public class FirstTimeTenantSettings
_clientFactory = clientFactory; _clientFactory = clientFactory;
} }
public WizardSettings SaveData(WizardRequestsDto inDto) public async Task<WizardSettings> SaveData(WizardRequestsDto inDto)
{ {
try try
{ {
@ -122,7 +122,7 @@ public class FirstTimeTenantSettings
currentUser.ActivationStatus = EmployeeActivationStatus.NotActivated; currentUser.ActivationStatus = EmployeeActivationStatus.NotActivated;
} }
_userManager.UpdateUserInfo(currentUser); await _userManager.UpdateUserInfo(currentUser);
if (RequestLicense) if (RequestLicense)
{ {

View File

@ -143,7 +143,7 @@ public class SmsManager
} }
} }
public void ValidateSmsCode(UserInfo user, string code, bool isEntryPoint = false) public async Task ValidateSmsCode(UserInfo user, string code, bool isEntryPoint = false)
{ {
if (!_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings() if (!_studioSmsNotificationSettingsHelper.IsVisibleAndAvailableSettings()
|| !_studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id)) || !_studioSmsNotificationSettingsHelper.TfaEnabledForUser(user.Id))
@ -182,7 +182,7 @@ public class SmsManager
if (user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated) if (user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated)
{ {
user.MobilePhoneActivationStatus = MobilePhoneActivationStatus.Activated; user.MobilePhoneActivationStatus = MobilePhoneActivationStatus.Activated;
_userManager.UpdateUserInfo(user); await _userManager.UpdateUserInfo(user);
} }
} }
} }

View File

@ -26,6 +26,8 @@
using ASC.Core.Common.Quota;
using Constants = ASC.Core.Users.Constants; using Constants = ASC.Core.Users.Constants;
namespace ASC.Web.Core.Users; namespace ASC.Web.Core.Users;
@ -51,6 +53,8 @@ public sealed class UserManagerWrapper
private readonly CountPaidUserChecker _countPaidUserChecker; private readonly CountPaidUserChecker _countPaidUserChecker;
private readonly TenantManager _tenantManager; private readonly TenantManager _tenantManager;
private readonly WebItemSecurityCache _webItemSecurityCache; private readonly WebItemSecurityCache _webItemSecurityCache;
private readonly QuotaSocketManager _quotaSocketManager;
private readonly TenantQuotaFeatureStatHelper _tenantQuotaFeatureStatHelper;
public UserManagerWrapper( public UserManagerWrapper(
StudioNotifyService studioNotifyService, StudioNotifyService studioNotifyService,
@ -64,7 +68,9 @@ public sealed class UserManagerWrapper
UserFormatter userFormatter, UserFormatter userFormatter,
CountPaidUserChecker countPaidUserChecker, CountPaidUserChecker countPaidUserChecker,
TenantManager tenantManager, TenantManager tenantManager,
WebItemSecurityCache webItemSecurityCache) WebItemSecurityCache webItemSecurityCache,
QuotaSocketManager quotaSocketManager,
TenantQuotaFeatureStatHelper tenantQuotaFeatureStatHelper)
{ {
_studioNotifyService = studioNotifyService; _studioNotifyService = studioNotifyService;
_userManager = userManager; _userManager = userManager;
@ -78,6 +84,8 @@ public sealed class UserManagerWrapper
_countPaidUserChecker = countPaidUserChecker; _countPaidUserChecker = countPaidUserChecker;
_tenantManager = tenantManager; _tenantManager = tenantManager;
_webItemSecurityCache = webItemSecurityCache; _webItemSecurityCache = webItemSecurityCache;
_quotaSocketManager = quotaSocketManager;
_tenantQuotaFeatureStatHelper = tenantQuotaFeatureStatHelper;
} }
private bool TestUniqueUserName(string uniqueName) private bool TestUniqueUserName(string uniqueName)
@ -148,6 +156,11 @@ public sealed class UserManagerWrapper
{ {
await _userManager.AddUserIntoGroup(newUser.Id, groupId, true); await _userManager.AddUserIntoGroup(newUser.Id, groupId, true);
} }
else if(type == EmployeeType.RoomAdmin)
{
var (name, value) = await _tenantQuotaFeatureStatHelper.GetStat<CountPaidUserFeature, int>();
await _quotaSocketManager.ChangeQuotaUsedValue(name, value);
}
return newUser; return newUser;
} }
@ -269,16 +282,16 @@ public sealed class UserManagerWrapper
} }
else if (currentType is EmployeeType.Collaborator) else if (currentType is EmployeeType.Collaborator)
{ {
await _userManager.RemoveUserFromGroup(user.Id, Constants.GroupCollaborator.ID);
await _userManager.AddUserIntoGroup(user.Id, Constants.GroupAdmin.ID); await _userManager.AddUserIntoGroup(user.Id, Constants.GroupAdmin.ID);
await _userManager.RemoveUserFromGroup(user.Id, Constants.GroupCollaborator.ID);
_webItemSecurityCache.ClearCache(Tenant.Id); _webItemSecurityCache.ClearCache(Tenant.Id);
changed = true; changed = true;
} }
else if (currentType is EmployeeType.User) else if (currentType is EmployeeType.User)
{ {
await _countPaidUserChecker.CheckAppend(); await _countPaidUserChecker.CheckAppend();
await _userManager.RemoveUserFromGroup(user.Id, Constants.GroupUser.ID);
await _userManager.AddUserIntoGroup(user.Id, Constants.GroupAdmin.ID); await _userManager.AddUserIntoGroup(user.Id, Constants.GroupAdmin.ID);
await _userManager.RemoveUserFromGroup(user.Id, Constants.GroupUser.ID);
_webItemSecurityCache.ClearCache(Tenant.Id); _webItemSecurityCache.ClearCache(Tenant.Id);
changed = true; changed = true;
} }
@ -308,8 +321,8 @@ public sealed class UserManagerWrapper
else if (type is EmployeeType.Collaborator && currentType is EmployeeType.User) else if (type is EmployeeType.Collaborator && currentType is EmployeeType.User)
{ {
await _countPaidUserChecker.CheckAppend(); await _countPaidUserChecker.CheckAppend();
await _userManager.RemoveUserFromGroup(user.Id, Constants.GroupUser.ID);
await _userManager.AddUserIntoGroup(user.Id, Constants.GroupCollaborator.ID); await _userManager.AddUserIntoGroup(user.Id, Constants.GroupCollaborator.ID);
await _userManager.RemoveUserFromGroup(user.Id, Constants.GroupUser.ID);
_webItemSecurityCache.ClearCache(Tenant.Id); _webItemSecurityCache.ClearCache(Tenant.Id);
changed = true; changed = true;
} }