From 787a1ba1720967dad7135811e3119c353e0bb1b0 Mon Sep 17 00:00:00 2001 From: Nikita Date: Fri, 13 May 2022 12:20:28 +0300 Subject: [PATCH] fix --- .../Data/LdapCertificateConfirmRequest.cs | 5 ++++ .../ComplexOperations/LdapOperationJob.cs | 25 +++++++++++++------ .../ComplexOperations/LdapOperationStatus.cs | 12 +-------- .../LdapSaveSyncOperation.cs | 11 +++----- common/ASC.ActiveDirectory/LdapUserManager.cs | 6 ++--- common/ASC.ActiveDirectory/LdapUtils.cs | 2 +- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/common/ASC.ActiveDirectory/Base/Data/LdapCertificateConfirmRequest.cs b/common/ASC.ActiveDirectory/Base/Data/LdapCertificateConfirmRequest.cs index ea1f85e936..4324362a20 100644 --- a/common/ASC.ActiveDirectory/Base/Data/LdapCertificateConfirmRequest.cs +++ b/common/ASC.ActiveDirectory/Base/Data/LdapCertificateConfirmRequest.cs @@ -161,4 +161,9 @@ public class LdapCertificateConfirmRequest return null; } } + + public override string ToString() + { + return JsonSerializer.Serialize(this); + } } diff --git a/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationJob.cs b/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationJob.cs index b6db2a642d..0c929cf60d 100644 --- a/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationJob.cs +++ b/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationJob.cs @@ -34,7 +34,6 @@ public class LdapOperationJob : DistributedTaskProgress private string _culture; public LdapSettings LDAPSettings { get; private set; } - protected DistributedTask TaskInfo { get; private set; } protected string Source { get; private set; } protected new string Status { get; set; } protected string Error { get; set; } @@ -47,7 +46,7 @@ public class LdapOperationJob : DistributedTaskProgress { return _tenantId ?? this[nameof(_tenantId)]; } - set + private set { _tenantId = value; this[nameof(_tenantId)] = value; @@ -116,7 +115,7 @@ public class LdapOperationJob : DistributedTaskProgress { _currentUser = userId != null ? _userManager.GetUsers(Guid.Parse(userId)) : null; - _tenantId = tenant.Id; + TenantId = tenant.Id; _tenantManager.SetCurrentTenant(tenant); _ldapChanges.Tenant = tenant; @@ -131,17 +130,17 @@ public class LdapOperationJob : DistributedTaskProgress Status = ""; Error = ""; Warning = ""; - Source = ""; Resource = resource ?? new LdapLocalization(); _lDAPUserManager.Init(Resource); + + InitDisturbedTask(); } protected override void DoJob() { try - { - FillDistributedTask(); + { _securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(_culture); @@ -241,7 +240,7 @@ public class LdapOperationJob : DistributedTaskProgress try { this[LdapTaskProperty.FINISHED] = true; - PublishChanges(); + PublishTaskInfo(); _securityContext.Logout(); } catch (Exception ex) @@ -1217,9 +1216,21 @@ public class LdapOperationJob : DistributedTaskProgress _log.InfoFormat(PROGRESS_STRING, Percentage, Status, Source); + PublishTaskInfo(); + } + private void PublishTaskInfo() + { + FillDistributedTask(); PublishChanges(); } + private void InitDisturbedTask() + { + this[LdapTaskProperty.FINISHED] = false; + this[LdapTaskProperty.CERT_REQUEST] = null; + FillDistributedTask(); + } + private void FillDistributedTask() { this[LdapTaskProperty.SOURCE] = Source; diff --git a/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationStatus.cs b/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationStatus.cs index 26a5157916..6b3f48af1a 100644 --- a/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationStatus.cs +++ b/common/ASC.ActiveDirectory/ComplexOperations/LdapOperationStatus.cs @@ -26,33 +26,23 @@ namespace ASC.ActiveDirectory.ComplexOperations; -[DataContract] public class LdapOperationStatus { - [DataMember] public bool Completed { get; set; } - [DataMember] public string Id { get; set; } - [DataMember] public string Status { get; set; } - [DataMember] public string Error { get; set; } - [DataMember] public string Warning { get; set; } - [DataMember] public int Percents { get; set; } - [DataMember] - public LdapCertificateConfirmRequest CertificateConfirmRequest { get; set; } + public string CertificateConfirmRequest { get; set; } - [DataMember] public string Source { get; set; } - [DataMember] public string OperationType { get; set; } } diff --git a/common/ASC.ActiveDirectory/ComplexOperations/LdapSaveSyncOperation.cs b/common/ASC.ActiveDirectory/ComplexOperations/LdapSaveSyncOperation.cs index 44bdf78e4e..c35949ffaa 100644 --- a/common/ASC.ActiveDirectory/ComplexOperations/LdapSaveSyncOperation.cs +++ b/common/ASC.ActiveDirectory/ComplexOperations/LdapSaveSyncOperation.cs @@ -63,7 +63,7 @@ public class LdapSaveSyncOperation public LdapOperationStatus TestLdapSave(LdapSettings ldapSettings, Tenant tenant, string userId) { - var operations = _progressQueue.GetAllTasks() + var operations = _progressQueue.GetAllTasks() .Where(t => t[LdapTaskProperty.OWNER] == tenant.Id) .ToList(); @@ -183,7 +183,7 @@ public class LdapSaveSyncOperation public LdapOperationStatus ToLdapOperationStatus(int tenantId) { - var operations = _progressQueue.GetAllTasks().ToList(); + var operations = _progressQueue.GetAllTasks().ToList(); foreach (var o in operations) { @@ -209,8 +209,6 @@ public class LdapSaveSyncOperation _progressQueue.DequeueTask(operation.Id); } - var certificateConfirmRequest = operation[LdapTaskProperty.CERT_REQUEST]; - var result = new LdapOperationStatus { Id = operation.Id, @@ -218,10 +216,9 @@ public class LdapSaveSyncOperation Percents = operation[LdapTaskProperty.PROGRESS], Status = operation[LdapTaskProperty.RESULT], Error = operation[LdapTaskProperty.ERROR], - CertificateConfirmRequest = certificateConfirmRequest, + CertificateConfirmRequest = operation[LdapTaskProperty.CERT_REQUEST] != "" ? operation[LdapTaskProperty.CERT_REQUEST] : null, Source = operation[LdapTaskProperty.SOURCE], - OperationType = Enum.GetName(typeof(LdapOperationType), - (LdapOperationType)operation[LdapTaskProperty.OPERATION_TYPE]), + OperationType = operation[LdapTaskProperty.OPERATION_TYPE], Warning = operation[LdapTaskProperty.WARNING] }; diff --git a/common/ASC.ActiveDirectory/LdapUserManager.cs b/common/ASC.ActiveDirectory/LdapUserManager.cs index fc7dc5a319..2f1ffe0195 100644 --- a/common/ASC.ActiveDirectory/LdapUserManager.cs +++ b/common/ASC.ActiveDirectory/LdapUserManager.cs @@ -347,7 +347,7 @@ public class LdapUserManager private static void UpdateLdapUserContacts(UserInfo ldapUser, List portalUserContacts) { - if (!portalUserContacts.Any()) + if (portalUserContacts == null || !portalUserContacts.Any()) return; var ldapUserContacts = ldapUser.Contacts; @@ -458,8 +458,8 @@ public class LdapUserManager needUpdate = true; } - if (ldapUser.ContactsList.Count != portalUser.ContactsList.Count || - !ldapUser.Contacts.All(portalUser.Contacts.Contains)) + if (portalUser.ContactsList == null && ldapUser.ContactsList.Count != 0 || portalUser.ContactsList != null && (ldapUser.ContactsList.Count != portalUser.ContactsList.Count || + !ldapUser.Contacts.All(portalUser.Contacts.Contains))) { _log.DebugFormat("NeedUpdateUser by Contacts -> portal: '{0}', ldap: '{1}'", string.Join("|", portalUser.Contacts), diff --git a/common/ASC.ActiveDirectory/LdapUtils.cs b/common/ASC.ActiveDirectory/LdapUtils.cs index b1520eed1b..9e55b046df 100644 --- a/common/ASC.ActiveDirectory/LdapUtils.cs +++ b/common/ASC.ActiveDirectory/LdapUtils.cs @@ -149,7 +149,7 @@ public static class LdapUtils public static string GetContactsString(this UserInfo userInfo) { - if (userInfo.ContactsList.Count == 0) return null; + if (userInfo.ContactsList == null || userInfo.ContactsList.Count == 0) return null; var sBuilder = new StringBuilder(); foreach (var contact in userInfo.Contacts) {