From 3732161be5daddfdc37cc5f2fc943ac4a4724379 Mon Sep 17 00:00:00 2001 From: Andrey Savihin Date: Thu, 23 Nov 2023 16:07:55 +0300 Subject: [PATCH 1/3] ASC.People: UserController: removed unused method --- .../ASC.People/Server/Api/UserController.cs | 76 ------------------- 1 file changed, 76 deletions(-) diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index 2e37bd2caf9..9560e0fe960 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -146,82 +146,6 @@ public UserController( _fileSecurityCommon = fileSecurityCommon; } - /// - /// Adds an activated portal user with the first name, last name, email address, and several optional parameters specified in the request. - /// - /// - /// Add an activated user - /// - /// Profiles - /// Member request parameters - /// Newly added user with the detailed information - /// api/2.0/people/active - /// POST - /// false - [HttpPost("active")] - public async Task AddMemberAsActivatedAsync(MemberRequestDto inDto) - { - await _permissionContext.DemandPermissionsAsync(new UserSecurityProvider(inDto.Type), Constants.Action_AddRemoveUser); - - var user = new UserInfo(); - - inDto.PasswordHash = (inDto.PasswordHash ?? "").Trim(); - if (string.IsNullOrEmpty(inDto.PasswordHash)) - { - inDto.Password = (inDto.Password ?? "").Trim(); - - if (string.IsNullOrEmpty(inDto.Password)) - { - inDto.Password = UserManagerWrapper.GeneratePassword(); - } - else - { - await _userManagerWrapper.CheckPasswordPolicyAsync(inDto.Password); - } - - inDto.PasswordHash = _passwordHasher.GetClientPassword(inDto.Password); - } - - //Validate email - var address = new MailAddress(inDto.Email); - user.Email = address.Address; - //Set common fields - user.FirstName = inDto.Firstname; - user.LastName = inDto.Lastname; - user.Title = inDto.Title; - user.Location = inDto.Location; - user.Notes = inDto.Comment; - - if ("male".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)) - { - user.Sex = true; - } - else if ("female".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)) - { - user.Sex = false; - } - - user.BirthDate = inDto.Birthday != null ? _tenantUtil.DateTimeFromUtc(inDto.Birthday) : null; - user.WorkFromDate = inDto.Worksfrom != null ? _tenantUtil.DateTimeFromUtc(inDto.Worksfrom) : DateTime.UtcNow.Date; - - await UpdateContactsAsync(inDto.Contacts, user); - - _cache.Insert("REWRITE_URL" + await _tenantManager.GetCurrentTenantIdAsync(), HttpContext.Request.GetDisplayUrl(), TimeSpan.FromMinutes(5)); - user = await _userManagerWrapper.AddUserAsync(user, inDto.PasswordHash, true, false, inDto.Type, - false, true, true); - - user.ActivationStatus = EmployeeActivationStatus.Activated; - - await UpdateDepartmentsAsync(inDto.Department, user); - - if (inDto.Files != _userPhotoManager.GetDefaultPhotoAbsoluteWebPath()) - { - await UpdatePhotoUrlAsync(inDto.Files, user); - } - - return await _employeeFullDtoHelper.GetFullAsync(user); - } - /// /// Adds a new portal user with the first name, last name, email address, and several optional parameters specified in the request. /// From eaac60fb57b3d12ccce9b1921692bc8b01b089c1 Mon Sep 17 00:00:00 2001 From: Andrey Savihin Date: Thu, 23 Nov 2023 16:32:07 +0300 Subject: [PATCH 2/3] Revert "ASC.People: UserController: removed unused method" This reverts commit 3732161be5daddfdc37cc5f2fc943ac4a4724379. --- .../ASC.People/Server/Api/UserController.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index 9560e0fe960..2e37bd2caf9 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -146,6 +146,82 @@ public UserController( _fileSecurityCommon = fileSecurityCommon; } + /// + /// Adds an activated portal user with the first name, last name, email address, and several optional parameters specified in the request. + /// + /// + /// Add an activated user + /// + /// Profiles + /// Member request parameters + /// Newly added user with the detailed information + /// api/2.0/people/active + /// POST + /// false + [HttpPost("active")] + public async Task AddMemberAsActivatedAsync(MemberRequestDto inDto) + { + await _permissionContext.DemandPermissionsAsync(new UserSecurityProvider(inDto.Type), Constants.Action_AddRemoveUser); + + var user = new UserInfo(); + + inDto.PasswordHash = (inDto.PasswordHash ?? "").Trim(); + if (string.IsNullOrEmpty(inDto.PasswordHash)) + { + inDto.Password = (inDto.Password ?? "").Trim(); + + if (string.IsNullOrEmpty(inDto.Password)) + { + inDto.Password = UserManagerWrapper.GeneratePassword(); + } + else + { + await _userManagerWrapper.CheckPasswordPolicyAsync(inDto.Password); + } + + inDto.PasswordHash = _passwordHasher.GetClientPassword(inDto.Password); + } + + //Validate email + var address = new MailAddress(inDto.Email); + user.Email = address.Address; + //Set common fields + user.FirstName = inDto.Firstname; + user.LastName = inDto.Lastname; + user.Title = inDto.Title; + user.Location = inDto.Location; + user.Notes = inDto.Comment; + + if ("male".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)) + { + user.Sex = true; + } + else if ("female".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)) + { + user.Sex = false; + } + + user.BirthDate = inDto.Birthday != null ? _tenantUtil.DateTimeFromUtc(inDto.Birthday) : null; + user.WorkFromDate = inDto.Worksfrom != null ? _tenantUtil.DateTimeFromUtc(inDto.Worksfrom) : DateTime.UtcNow.Date; + + await UpdateContactsAsync(inDto.Contacts, user); + + _cache.Insert("REWRITE_URL" + await _tenantManager.GetCurrentTenantIdAsync(), HttpContext.Request.GetDisplayUrl(), TimeSpan.FromMinutes(5)); + user = await _userManagerWrapper.AddUserAsync(user, inDto.PasswordHash, true, false, inDto.Type, + false, true, true); + + user.ActivationStatus = EmployeeActivationStatus.Activated; + + await UpdateDepartmentsAsync(inDto.Department, user); + + if (inDto.Files != _userPhotoManager.GetDefaultPhotoAbsoluteWebPath()) + { + await UpdatePhotoUrlAsync(inDto.Files, user); + } + + return await _employeeFullDtoHelper.GetFullAsync(user); + } + /// /// Adds a new portal user with the first name, last name, email address, and several optional parameters specified in the request. /// From a12aafbf7ce01c716ec9140118c33fad352d75a4 Mon Sep 17 00:00:00 2001 From: Andrey Savihin Date: Thu, 23 Nov 2023 16:39:31 +0300 Subject: [PATCH 3/3] ASC.People: UserController: AddMemberAsActivated: activation status pending --- products/ASC.People/Server/Api/UserController.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index 2e37bd2caf9..15709cacdd7 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -207,11 +207,9 @@ public async Task AddMemberAsActivatedAsync(MemberRequestDto in await UpdateContactsAsync(inDto.Contacts, user); _cache.Insert("REWRITE_URL" + await _tenantManager.GetCurrentTenantIdAsync(), HttpContext.Request.GetDisplayUrl(), TimeSpan.FromMinutes(5)); - user = await _userManagerWrapper.AddUserAsync(user, inDto.PasswordHash, true, false, inDto.Type, + user = await _userManagerWrapper.AddUserAsync(user, inDto.PasswordHash, false, false, inDto.Type, false, true, true); - user.ActivationStatus = EmployeeActivationStatus.Activated; - await UpdateDepartmentsAsync(inDto.Department, user); if (inDto.Files != _userPhotoManager.GetDefaultPhotoAbsoluteWebPath())