2022-03-15 18:00:53 +00:00
|
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
|
//
|
|
|
|
|
// This program is a free software product.
|
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended
|
|
|
|
|
// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of
|
|
|
|
|
// any third-party rights.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty
|
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see
|
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
|
//
|
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
|
//
|
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
|
//
|
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
|
//
|
|
|
|
|
// 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
|
2022-11-02 08:16:29 +00:00
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
|
|
|
|
|
|
using ASC.Common.Log;
|
|
|
|
|
|
2022-02-28 19:23:39 +00:00
|
|
|
|
namespace ASC.People.Api;
|
|
|
|
|
|
2022-03-05 12:57:46 +00:00
|
|
|
|
public class UserController : PeopleControllerBase
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
private Tenant Tenant => _apiContext.Tenant;
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
private readonly ICache _cache;
|
2022-06-07 18:00:08 +00:00
|
|
|
|
private readonly TenantManager _tenantManager;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
private readonly CookiesManager _cookiesManager;
|
|
|
|
|
private readonly CoreBaseSettings _coreBaseSettings;
|
|
|
|
|
private readonly CustomNamingPeople _customNamingPeople;
|
|
|
|
|
private readonly EmployeeDtoHelper _employeeDtoHelper;
|
|
|
|
|
private readonly EmployeeFullDtoHelper _employeeFullDtoHelper;
|
2022-05-26 09:01:54 +00:00
|
|
|
|
private readonly ILogger<UserController> _logger;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
private readonly PasswordHasher _passwordHasher;
|
|
|
|
|
private readonly QueueWorkerReassign _queueWorkerReassign;
|
|
|
|
|
private readonly QueueWorkerRemove _queueWorkerRemove;
|
|
|
|
|
private readonly Recaptcha _recaptcha;
|
|
|
|
|
private readonly TenantUtil _tenantUtil;
|
|
|
|
|
private readonly UserFormatter _userFormatter;
|
|
|
|
|
private readonly UserManagerWrapper _userManagerWrapper;
|
|
|
|
|
private readonly WebItemManager _webItemManager;
|
|
|
|
|
private readonly WebItemSecurity _webItemSecurity;
|
|
|
|
|
private readonly WebItemSecurityCache _webItemSecurityCache;
|
|
|
|
|
private readonly DisplayUserSettingsHelper _displayUserSettingsHelper;
|
|
|
|
|
private readonly MessageTarget _messageTarget;
|
|
|
|
|
private readonly SecurityContext _securityContext;
|
|
|
|
|
private readonly StudioNotifyService _studioNotifyService;
|
|
|
|
|
private readonly MessageService _messageService;
|
|
|
|
|
private readonly AuthContext _authContext;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
private readonly SetupInfo _setupInfo;
|
|
|
|
|
private readonly SettingsManager _settingsManager;
|
|
|
|
|
private readonly RoomLinkService _roomLinkService;
|
2022-10-12 11:23:57 +00:00
|
|
|
|
private readonly FileSecurity _fileSecurity;
|
2022-10-19 11:48:48 +00:00
|
|
|
|
private readonly IQuotaService _quotaService;
|
2022-10-18 11:43:31 +00:00
|
|
|
|
private readonly CountRoomAdminChecker _countRoomAdminChecker;
|
2022-11-02 10:40:53 +00:00
|
|
|
|
private readonly UsersQuotaSyncOperation _usersQuotaSyncOperation;
|
2022-10-10 16:16:03 +00:00
|
|
|
|
private readonly CountUserChecker _countUserChecker;
|
|
|
|
|
private readonly UsersInRoomChecker _usersInRoomChecker;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
|
2022-03-05 12:57:46 +00:00
|
|
|
|
public UserController(
|
2022-11-02 08:16:29 +00:00
|
|
|
|
ICache cache,
|
2022-06-07 18:00:08 +00:00
|
|
|
|
TenantManager tenantManager,
|
2022-03-05 12:57:46 +00:00
|
|
|
|
CookiesManager cookiesManager,
|
|
|
|
|
CoreBaseSettings coreBaseSettings,
|
|
|
|
|
CustomNamingPeople customNamingPeople,
|
|
|
|
|
EmployeeDtoHelper employeeDtoHelper,
|
|
|
|
|
EmployeeFullDtoHelper employeeFullDtoHelper,
|
2022-04-26 17:53:48 +00:00
|
|
|
|
ILogger<UserController> logger,
|
2022-03-05 12:57:46 +00:00
|
|
|
|
PasswordHasher passwordHasher,
|
|
|
|
|
QueueWorkerReassign queueWorkerReassign,
|
|
|
|
|
QueueWorkerRemove queueWorkerRemove,
|
|
|
|
|
Recaptcha recaptcha,
|
|
|
|
|
TenantUtil tenantUtil,
|
|
|
|
|
UserFormatter userFormatter,
|
|
|
|
|
UserManagerWrapper userManagerWrapper,
|
|
|
|
|
WebItemManager webItemManager,
|
|
|
|
|
WebItemSecurity webItemSecurity,
|
|
|
|
|
WebItemSecurityCache webItemSecurityCache,
|
|
|
|
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
|
|
|
|
MessageTarget messageTarget,
|
|
|
|
|
SecurityContext securityContext,
|
|
|
|
|
StudioNotifyService studioNotifyService,
|
|
|
|
|
MessageService messageService,
|
|
|
|
|
AuthContext authContext,
|
|
|
|
|
SetupInfo setupInfo,
|
|
|
|
|
UserManager userManager,
|
|
|
|
|
PermissionContext permissionContext,
|
|
|
|
|
ApiContext apiContext,
|
|
|
|
|
UserPhotoManager userPhotoManager,
|
2022-11-02 08:16:29 +00:00
|
|
|
|
IHttpClientFactory httpClientFactory,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor,
|
|
|
|
|
SettingsManager settingsManager,
|
2022-09-23 13:11:23 +00:00
|
|
|
|
RoomLinkService roomLinkService,
|
2022-10-12 11:23:57 +00:00
|
|
|
|
FileSecurity fileSecurity,
|
2022-10-19 11:48:48 +00:00
|
|
|
|
UsersQuotaSyncOperation usersQuotaSyncOperation,
|
2022-10-18 11:43:31 +00:00
|
|
|
|
CountRoomAdminChecker countRoomAdminChecker,
|
2022-09-23 13:11:23 +00:00
|
|
|
|
CountUserChecker activeUsersChecker,
|
|
|
|
|
UsersInRoomChecker usersInRoomChecker,
|
2022-10-07 13:37:57 +00:00
|
|
|
|
IQuotaService quotaService)
|
2022-04-15 10:27:48 +00:00
|
|
|
|
: base(userManager, permissionContext, apiContext, userPhotoManager, httpClientFactory, httpContextAccessor)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_cache = cache;
|
2022-09-19 15:20:21 +00:00
|
|
|
|
_tenantManager = tenantManager;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_cookiesManager = cookiesManager;
|
|
|
|
|
_coreBaseSettings = coreBaseSettings;
|
|
|
|
|
_customNamingPeople = customNamingPeople;
|
|
|
|
|
_employeeDtoHelper = employeeDtoHelper;
|
|
|
|
|
_employeeFullDtoHelper = employeeFullDtoHelper;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_passwordHasher = passwordHasher;
|
|
|
|
|
_queueWorkerReassign = queueWorkerReassign;
|
|
|
|
|
_queueWorkerRemove = queueWorkerRemove;
|
|
|
|
|
_recaptcha = recaptcha;
|
|
|
|
|
_tenantUtil = tenantUtil;
|
|
|
|
|
_userFormatter = userFormatter;
|
|
|
|
|
_userManagerWrapper = userManagerWrapper;
|
|
|
|
|
_webItemManager = webItemManager;
|
|
|
|
|
_webItemSecurity = webItemSecurity;
|
|
|
|
|
_webItemSecurityCache = webItemSecurityCache;
|
|
|
|
|
_displayUserSettingsHelper = displayUserSettingsHelper;
|
|
|
|
|
_messageTarget = messageTarget;
|
|
|
|
|
_securityContext = securityContext;
|
|
|
|
|
_studioNotifyService = studioNotifyService;
|
|
|
|
|
_messageService = messageService;
|
|
|
|
|
_authContext = authContext;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_setupInfo = setupInfo;
|
|
|
|
|
_settingsManager = settingsManager;
|
|
|
|
|
_roomLinkService = roomLinkService;
|
2022-10-12 11:23:57 +00:00
|
|
|
|
_fileSecurity = fileSecurity;
|
2022-10-18 11:43:31 +00:00
|
|
|
|
_countRoomAdminChecker = countRoomAdminChecker;
|
2022-10-10 16:16:03 +00:00
|
|
|
|
_countUserChecker = activeUsersChecker;
|
|
|
|
|
_usersInRoomChecker = usersInRoomChecker;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_quotaService = quotaService;
|
2022-10-12 11:23:57 +00:00
|
|
|
|
_usersQuotaSyncOperation = usersQuotaSyncOperation;
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPost("active")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> AddMemberAsActivated(MemberRequestDto inDto)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_permissionContext.DemandPermissions(Constants.Action_AddRemoveUser);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
var user = new UserInfo();
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
inDto.PasswordHash = (inDto.PasswordHash ?? "").Trim();
|
|
|
|
|
if (string.IsNullOrEmpty(inDto.PasswordHash))
|
|
|
|
|
{
|
|
|
|
|
inDto.Password = (inDto.Password ?? "").Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(inDto.Password))
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
inDto.Password = UserManagerWrapper.GeneratePassword();
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_userManagerWrapper.CheckPasswordPolicy(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;
|
|
|
|
|
user.Sex = "male".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
? true
|
2022-10-18 18:37:16 +00:00
|
|
|
|
: ("female".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase) ? false : null);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
|
|
|
|
user.BirthDate = inDto.Birthday != null ? _tenantUtil.DateTimeFromUtc(inDto.Birthday) : null;
|
|
|
|
|
user.WorkFromDate = inDto.Worksfrom != null ? _tenantUtil.DateTimeFromUtc(inDto.Worksfrom) : DateTime.UtcNow.Date;
|
|
|
|
|
|
|
|
|
|
UpdateContacts(inDto.Contacts, user);
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_cache.Insert("REWRITE_URL" + _tenantManager.GetCurrentTenant().Id, HttpContext.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5));
|
|
|
|
|
user = await _userManagerWrapper.AddUser(user, inDto.PasswordHash, false, false, inDto.IsUser, false, true, true);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.Activated;
|
|
|
|
|
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await UpdateDepartments(inDto.Department, user);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (inDto.Files != _userPhotoManager.GetDefaultPhotoAbsoluteWebPath())
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
await UpdatePhotoUrl(inDto.Files, user);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPost]
|
2022-02-28 19:23:39 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "LinkInvite,Everyone")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> AddMember(MemberRequestDto inDto)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_apiContext.AuthByClaim();
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-12-05 08:15:15 +00:00
|
|
|
|
var options = inDto.FromInviteLink ? await _roomLinkService.GetOptionsAsync(inDto.Key, inDto.Email, inDto.Type) : null;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (options != null && !options.IsCorrect)
|
2022-09-20 20:22:27 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
throw new SecurityException(FilesCommonResource.ErrorMessage_InvintationLink);
|
2022-09-13 20:47:35 +00:00
|
|
|
|
}
|
2022-09-20 20:22:27 +00:00
|
|
|
|
|
2022-12-05 22:57:55 +00:00
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(Guid.Empty, inDto.Type) ,Constants.Action_AddRemoveUser);
|
2022-09-20 20:22:27 +00:00
|
|
|
|
|
2022-10-26 14:40:43 +00:00
|
|
|
|
inDto.Type = options != null ? options.EmployeeType : inDto.Type;
|
2022-09-20 20:22:27 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
var user = new UserInfo();
|
|
|
|
|
|
|
|
|
|
var byEmail = options?.LinkType == LinkType.InvintationByEmail;
|
2022-09-20 20:22:27 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (byEmail)
|
2022-09-23 13:22:02 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
user = _userManager.GetUserByEmail(inDto.Email);
|
2022-09-20 20:22:27 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (user == Constants.LostUser || user.ActivationStatus != EmployeeActivationStatus.Pending)
|
2022-09-23 13:22:02 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
throw new SecurityException(FilesCommonResource.ErrorMessage_InvintationLink);
|
|
|
|
|
}
|
2022-06-08 13:38:16 +00:00
|
|
|
|
}
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
|
|
|
|
inDto.PasswordHash = (inDto.PasswordHash ?? "").Trim();
|
|
|
|
|
if (string.IsNullOrEmpty(inDto.PasswordHash))
|
|
|
|
|
{
|
|
|
|
|
inDto.Password = (inDto.Password ?? "").Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(inDto.Password))
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
inDto.Password = UserManagerWrapper.GeneratePassword();
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_userManagerWrapper.CheckPasswordPolicy(inDto.Password);
|
|
|
|
|
}
|
|
|
|
|
inDto.PasswordHash = _passwordHasher.GetClientPassword(inDto.Password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Validate email
|
|
|
|
|
var address = new MailAddress(inDto.Email);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
user.Email = address.Address;
|
|
|
|
|
//Set common fields
|
2022-07-07 14:41:41 +00:00
|
|
|
|
user.CultureName = inDto.CultureName;
|
2022-05-17 09:29:24 +00:00
|
|
|
|
user.FirstName = inDto.Firstname;
|
|
|
|
|
user.LastName = inDto.Lastname;
|
|
|
|
|
user.Title = inDto.Title;
|
|
|
|
|
user.Location = inDto.Location;
|
|
|
|
|
user.Notes = inDto.Comment;
|
|
|
|
|
user.Sex = "male".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
? true
|
2022-10-18 18:37:16 +00:00
|
|
|
|
: ("female".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase) ? false : null);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
|
|
|
|
user.BirthDate = inDto.Birthday != null && inDto.Birthday != DateTime.MinValue ? _tenantUtil.DateTimeFromUtc(inDto.Birthday) : null;
|
|
|
|
|
user.WorkFromDate = inDto.Worksfrom != null && inDto.Worksfrom != DateTime.MinValue ? _tenantUtil.DateTimeFromUtc(inDto.Worksfrom) : DateTime.UtcNow.Date;
|
|
|
|
|
|
2022-11-29 08:59:33 +00:00
|
|
|
|
UpdateContacts(inDto.Contacts, user, !inDto.FromInviteLink);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_cache.Insert("REWRITE_URL" + _tenantManager.GetCurrentTenant().Id, HttpContext.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5));
|
2022-11-29 08:59:33 +00:00
|
|
|
|
user = await _userManagerWrapper.AddUser(user, inDto.PasswordHash, inDto.FromInviteLink, true, inDto.Type == EmployeeType.User, inDto.FromInviteLink && options.IsCorrect, true, true, byEmail, inDto.Type == EmployeeType.DocSpaceAdmin);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await UpdateDepartments(inDto.Department, user);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (inDto.Files != _userPhotoManager.GetDefaultPhotoAbsoluteWebPath())
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
await UpdatePhotoUrl(inDto.Files, user);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (options != null && options.LinkType == LinkType.InvintationToRoom)
|
|
|
|
|
{
|
|
|
|
|
var success = int.TryParse(options.RoomId, out var id);
|
|
|
|
|
|
|
|
|
|
if (success)
|
2022-09-23 13:22:02 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
await _usersInRoomChecker.CheckAppend();
|
2022-10-25 20:18:07 +00:00
|
|
|
|
await _fileSecurity.ShareAsync(id, FileEntryType.Folder, user.Id, options.Share);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2022-09-23 13:22:02 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
await _usersInRoomChecker.CheckAppend();
|
2022-10-25 20:18:07 +00:00
|
|
|
|
await _fileSecurity.ShareAsync(options.RoomId, FileEntryType.Folder, user.Id, options.Share);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var messageAction = inDto.IsUser ? MessageAction.GuestCreated : MessageAction.UserCreated;
|
2022-09-07 15:23:08 +00:00
|
|
|
|
_messageService.Send(messageAction, _messageTarget.Create(user.Id), user.DisplayUserName(false, _displayUserSettingsHelper));
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
[HttpPost("invite")]
|
|
|
|
|
public async IAsyncEnumerable<EmployeeDto> InviteUsersAsync(InviteUsersRequestDto inDto)
|
2022-12-05 08:15:15 +00:00
|
|
|
|
{
|
2022-11-29 08:59:33 +00:00
|
|
|
|
foreach (var invite in inDto.Invitations)
|
2022-12-05 08:15:15 +00:00
|
|
|
|
{
|
2022-12-05 22:57:55 +00:00
|
|
|
|
if (!_permissionContext.CheckPermissions(new UserSecurityProvider(Guid.Empty, invite.Type), Constants.Action_AddRemoveUser))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
2022-11-29 08:59:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
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);
|
|
|
|
|
_logger.Debug(link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var users = _userManager.GetUsers().Where(u => u.ActivationStatus == EmployeeActivationStatus.Pending);
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeDtoHelper.Get(user);
|
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("{userid}/password")]
|
2022-02-28 19:23:39 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "PasswordChange,EmailChange,Activation,EmailActivation,Everyone")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> ChangeUserPassword(Guid userid, MemberRequestDto inDto)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_apiContext.AuthByClaim();
|
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(userid), Constants.Action_EditUser);
|
|
|
|
|
|
|
|
|
|
var user = _userManager.GetUsers(userid);
|
|
|
|
|
|
|
|
|
|
if (!_userManager.UserExists(user))
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
return null;
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (_userManager.IsSystemUser(user.Id))
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
throw new SecurityException();
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(inDto.Email))
|
|
|
|
|
{
|
|
|
|
|
var address = new MailAddress(inDto.Email);
|
|
|
|
|
if (!string.Equals(address.Address, user.Email, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
user.Email = address.Address.ToLowerInvariant();
|
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.Activated;
|
2022-10-25 15:27:56 +00:00
|
|
|
|
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inDto.PasswordHash = (inDto.PasswordHash ?? "").Trim();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(inDto.PasswordHash))
|
|
|
|
|
{
|
|
|
|
|
inDto.Password = (inDto.Password ?? "").Trim();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(inDto.Password))
|
|
|
|
|
{
|
|
|
|
|
inDto.PasswordHash = _passwordHasher.GetClientPassword(inDto.Password);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(inDto.PasswordHash))
|
|
|
|
|
{
|
|
|
|
|
_securityContext.SetUserPasswordHash(userid, inDto.PasswordHash);
|
|
|
|
|
_messageService.Send(MessageAction.UserUpdatedPassword);
|
|
|
|
|
|
2022-06-14 08:11:41 +00:00
|
|
|
|
await _cookiesManager.ResetUserCookie(userid);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_messageService.Send(MessageAction.CookieSettingsUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(GetUserInfo(userid.ToString()));
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpDelete("{userid}")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> DeleteMember(string userid)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_permissionContext.DemandPermissions(Constants.Action_AddRemoveUser);
|
|
|
|
|
|
|
|
|
|
var user = GetUserInfo(userid);
|
|
|
|
|
|
|
|
|
|
if (_userManager.IsSystemUser(user.Id) || user.IsLDAP())
|
|
|
|
|
{
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.Status != EmployeeStatus.Terminated)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("The user is not suspended");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckReassignProccess(new[] { user.Id });
|
|
|
|
|
|
|
|
|
|
var userName = user.DisplayUserName(false, _displayUserSettingsHelper);
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await _userPhotoManager.RemovePhoto(user.Id);
|
2022-10-27 11:06:37 +00:00
|
|
|
|
await _userManager.DeleteUser(user.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_queueWorkerRemove.Start(Tenant.Id, user, _securityContext.CurrentAccount.ID, false);
|
|
|
|
|
|
|
|
|
|
_messageService.Send(MessageAction.UserDeleted, _messageTarget.Create(user.Id), userName);
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpDelete("@self")]
|
2022-02-28 19:23:39 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "ProfileRemove")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> DeleteProfile()
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_apiContext.AuthByClaim();
|
|
|
|
|
|
|
|
|
|
if (_userManager.IsSystemUser(_securityContext.CurrentAccount.ID))
|
|
|
|
|
{
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = GetUserInfo(_securityContext.CurrentAccount.ID.ToString());
|
|
|
|
|
|
|
|
|
|
if (!_userManager.UserExists(user))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorUserNotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.IsLDAP())
|
|
|
|
|
{
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-15 09:08:06 +00:00
|
|
|
|
_securityContext.AuthenticateMeWithoutCookie(Core.Configuration.Constants.CoreSystem);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
user.Status = EmployeeStatus.Terminated;
|
|
|
|
|
|
2022-10-24 15:30:17 +00:00
|
|
|
|
_userManager.UpdateUserInfo(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
var userName = user.DisplayUserName(false, _displayUserSettingsHelper);
|
|
|
|
|
_messageService.Send(MessageAction.UsersUpdatedStatus, _messageTarget.Create(user.Id), userName);
|
|
|
|
|
|
2022-06-14 08:11:41 +00:00
|
|
|
|
await _cookiesManager.ResetUserCookie(user.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_messageService.Send(MessageAction.CookieSettingsUpdated);
|
|
|
|
|
|
|
|
|
|
if (_coreBaseSettings.Personal)
|
|
|
|
|
{
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await _userPhotoManager.RemovePhoto(user.Id);
|
2022-10-27 11:06:37 +00:00
|
|
|
|
await _userManager.DeleteUser(user.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_messageService.Send(MessageAction.UserDeleted, _messageTarget.Create(user.Id), userName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//StudioNotifyService.Instance.SendMsgProfileHasDeletedItself(user);
|
|
|
|
|
//StudioNotifyService.SendMsgProfileDeletion(Tenant.TenantId, user);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("status/{status}/search")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> GetAdvanced(EmployeeStatus status, [FromQuery] string query)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (_coreBaseSettings.Personal)
|
|
|
|
|
{
|
|
|
|
|
throw new MethodAccessException("Method not available");
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
var list = _userManager.GetUsers(status).AsEnumerable();
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
if ("group".Equals(_apiContext.FilterBy, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(_apiContext.FilterValue))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-08-12 13:26:57 +00:00
|
|
|
|
var groupId = new Guid(_apiContext.FilterValue);
|
|
|
|
|
//Filter by group
|
|
|
|
|
list = list.Where(x => _userManager.IsUserInGroup(x.Id, groupId));
|
|
|
|
|
_apiContext.SetDataFiltered();
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
list = list.Where(x => x.FirstName != null && x.FirstName.IndexOf(query, StringComparison.OrdinalIgnoreCase) > -1 || (x.LastName != null && x.LastName.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1) ||
|
|
|
|
|
(x.UserName != null && x.UserName.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1) || (x.Email != null && x.Email.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1) || (x.ContactsList != null && x.ContactsList.Any(y => y.IndexOf(query, StringComparison.OrdinalIgnoreCase) != -1)));
|
2022-11-02 08:16:29 +00:00
|
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(item);
|
2022-08-12 13:26:57 +00:00
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public IAsyncEnumerable<EmployeeFullDto> GetAll()
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
|
|
|
|
return GetByStatus(EmployeeStatus.Active);
|
|
|
|
|
}
|
2022-11-16 15:14:47 +00:00
|
|
|
|
|
|
|
|
|
[AllowNotPayment]
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("email")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> GetByEmail([FromQuery] string email)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (_coreBaseSettings.Personal && !_userManager.GetUsers(_securityContext.CurrentAccount.ID).IsOwner(Tenant))
|
|
|
|
|
{
|
|
|
|
|
throw new MethodAccessException("Method not available");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var user = _userManager.GetUserByEmail(email);
|
|
|
|
|
if (user.Id == Constants.LostUser.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new ItemNotFoundException("User not found");
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-09-06 09:48:09 +00:00
|
|
|
|
[AllowNotPayment]
|
2022-04-21 19:36:29 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "LinkInvite,Everyone")]
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("{username}", Order = 1)]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> GetById(string username)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (_coreBaseSettings.Personal)
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
throw new MethodAccessException("Method not available");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var isInvite = _httpContextAccessor.HttpContext.User.Claims
|
|
|
|
|
.Any(role => role.Type == ClaimTypes.Role && ConfirmTypeExtensions.TryParse(role.Value, out var confirmType) && confirmType == ConfirmType.LinkInvite);
|
|
|
|
|
|
|
|
|
|
_apiContext.AuthByClaim();
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
var user = _userManager.GetUserByUserName(username);
|
|
|
|
|
if (user.Id == Constants.LostUser.Id)
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (Guid.TryParse(username, out var userId))
|
2022-04-14 19:42:15 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
user = _userManager.GetUsers(userId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-13 11:24:01 +00:00
|
|
|
|
_logger.ErrorCouldNotGetUserByName(_securityContext.CurrentAccount.ID, username);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user.Id == Constants.LostUser.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new ItemNotFoundException("User not found");
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isInvite)
|
|
|
|
|
{
|
|
|
|
|
return await _employeeFullDtoHelper.GetSimple(user);
|
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("status/{status}")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public IAsyncEnumerable<EmployeeFullDto> GetByStatus(EmployeeStatus status)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (_coreBaseSettings.Personal)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Method not available");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Guid? groupId = null;
|
|
|
|
|
if ("group".Equals(_apiContext.FilterBy, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(_apiContext.FilterValue))
|
|
|
|
|
{
|
|
|
|
|
groupId = new Guid(_apiContext.FilterValue);
|
|
|
|
|
_apiContext.SetDataFiltered();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 14:14:03 +00:00
|
|
|
|
return GetFullByFilter(status, groupId, null, null, null, null);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("filter")]
|
2022-11-10 14:14:03 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> GetFullByFilter(EmployeeStatus? employeeStatus, Guid? groupId, EmployeeActivationStatus? activationStatus, EmployeeType? employeeType, bool? isAdministrator, Payments? payments)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-11-10 14:14:03 +00:00
|
|
|
|
var users = GetByFilter(employeeStatus, groupId, activationStatus, employeeType, isAdministrator, payments);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
2022-08-12 13:26:57 +00:00
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("info")]
|
2022-02-28 19:23:39 +00:00
|
|
|
|
public Module GetModule()
|
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
var product = new PeopleProduct();
|
|
|
|
|
product.Init();
|
|
|
|
|
|
|
|
|
|
return new Module(product);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
2022-03-01 11:52:52 +00:00
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("search")]
|
2022-08-12 13:26:57 +00:00
|
|
|
|
public IAsyncEnumerable<EmployeeDto> GetPeopleSearch([FromQuery] string query)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
|
|
|
|
return GetSearch(query);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("@search/{query}")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> GetSearch(string query)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (_coreBaseSettings.Personal)
|
|
|
|
|
{
|
|
|
|
|
throw new MethodAccessException("Method not available");
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var groupId = Guid.Empty;
|
|
|
|
|
if ("group".Equals(_apiContext.FilterBy, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(_apiContext.FilterValue))
|
|
|
|
|
{
|
|
|
|
|
groupId = new Guid(_apiContext.FilterValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var users = _userManager.Search(query, EmployeeStatus.Active, groupId);
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("simple/filter")]
|
2022-11-10 14:14:03 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeDto> GetSimpleByFilter(EmployeeStatus? employeeStatus, Guid? groupId, EmployeeActivationStatus? activationStatus, EmployeeType? employeeType, bool? isAdministrator, Payments? payments)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-11-10 14:14:03 +00:00
|
|
|
|
var users = GetByFilter(employeeStatus, groupId, activationStatus, employeeType, isAdministrator, payments);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeDtoHelper.Get(user);
|
2022-08-12 13:26:57 +00:00
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPost("register")]
|
2022-03-05 13:20:51 +00:00
|
|
|
|
public Task<string> RegisterUserOnPersonalAsync(RegisterPersonalUserRequestDto inDto)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (!_coreBaseSettings.Personal)
|
|
|
|
|
{
|
|
|
|
|
throw new MethodAccessException("Method is only available on personal.onlyoffice.com");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
return InternalRegisterUserOnPersonalAsync(inDto);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("delete", Order = -1)]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> RemoveUsers(UpdateMembersRequestDto inDto)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_permissionContext.DemandPermissions(Constants.Action_AddRemoveUser);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
CheckReassignProccess(inDto.UserIds);
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
var users = inDto.UserIds.Select(userId => _userManager.GetUsers(userId))
|
|
|
|
|
.Where(u => !_userManager.IsSystemUser(u.Id) && !u.IsLDAP())
|
|
|
|
|
.ToList();
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
var userNames = users.Select(x => x.DisplayUserName(false, _displayUserSettingsHelper)).ToList();
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (user.Status != EmployeeStatus.Terminated)
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await _userPhotoManager.RemovePhoto(user.Id);
|
2022-10-27 11:06:37 +00:00
|
|
|
|
await _userManager.DeleteUser(user.Id);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_queueWorkerRemove.Start(Tenant.Id, user, _securityContext.CurrentAccount.ID, false);
|
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_messageService.Send(MessageAction.UsersDeleted, _messageTarget.Create(users.Select(x => x.Id)), userNames);
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("invite")]
|
2022-11-02 08:16:29 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> ResendUserInvites(UpdateMembersRequestDto inDto)
|
2022-02-28 19:23:39 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
var users = inDto.UserIds
|
|
|
|
|
.Where(userId => !_userManager.IsSystemUser(userId))
|
|
|
|
|
.Select(userId => _userManager.GetUsers(userId))
|
2022-05-17 09:29:24 +00:00
|
|
|
|
.ToList();
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
foreach (var user in users)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (user.IsActive)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
continue;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
var viewer = _userManager.GetUsers(_securityContext.CurrentAccount.ID);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
if (viewer == null)
|
2022-03-17 15:01:39 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
throw new Exception(Resource.ErrorAccessDenied);
|
2022-03-17 15:01:39 +00:00
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (_userManager.IsDocSpaceAdmin(viewer) || viewer.Id == user.Id)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
if (user.ActivationStatus == EmployeeActivationStatus.Activated)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.NotActivated;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (user.ActivationStatus == (EmployeeActivationStatus.AutoGenerated | EmployeeActivationStatus.Activated))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.AutoGenerated;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (user.ActivationStatus == EmployeeActivationStatus.Pending)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
var type = _userManager.IsDocSpaceAdmin(user) ? EmployeeType.DocSpaceAdmin :
|
|
|
|
|
_userManager.IsUser(user) ? EmployeeType.User : EmployeeType.RoomAdmin;
|
|
|
|
|
|
|
|
|
|
_studioNotifyService.SendDocSpaceInvite(user.Email, _roomLinkService.GetInvitationLink(user.Email, type, _authContext.CurrentAccount.ID));
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-11-02 08:16:29 +00:00
|
|
|
|
else
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_studioNotifyService.SendEmailActivationInstructions(user, user.Email);
|
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_messageService.Send(MessageAction.UsersSentActivationInstructions, _messageTarget.Create(users.Select(x => x.Id)), users.Select(x => x.DisplayUserName(false, _displayUserSettingsHelper)));
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
[HttpGet("theme")]
|
|
|
|
|
public DarkThemeSettings GetTheme()
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
return _settingsManager.LoadForCurrentUser<DarkThemeSettings>();
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-12 17:45:12 +00:00
|
|
|
|
[HttpPut("theme")]
|
|
|
|
|
public DarkThemeSettings ChangeTheme(DarkThemeSettingsRequestDto model)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-07-12 17:45:12 +00:00
|
|
|
|
var darkThemeSettings = new DarkThemeSettings
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-07-12 17:45:12 +00:00
|
|
|
|
Theme = model.Theme
|
|
|
|
|
};
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-07-12 17:45:12 +00:00
|
|
|
|
_settingsManager.SaveForCurrentUser(darkThemeSettings);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-07-12 17:45:12 +00:00
|
|
|
|
return darkThemeSettings;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-01 11:02:04 +00:00
|
|
|
|
[AllowNotPayment]
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpGet("@self")]
|
2022-11-02 08:16:29 +00:00
|
|
|
|
public async Task<EmployeeFullDto> Self()
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
var user = _userManager.GetUser(_securityContext.CurrentAccount.ID, EmployeeFullDtoHelper.GetExpression(_apiContext));
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
var result = await _employeeFullDtoHelper.GetFull(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
result.Theme = _settingsManager.LoadForCurrentUser<DarkThemeSettings>().Theme;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
return result;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[AllowNotPayment]
|
|
|
|
|
[HttpPost("email")]
|
2022-10-25 15:27:56 +00:00
|
|
|
|
public async Task<object> SendEmailChangeInstructions(UpdateMemberRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-05 13:20:51 +00:00
|
|
|
|
Guid.TryParse(inDto.UserId, out var userid);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
if (userid == Guid.Empty)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("userid");
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
var email = (inDto.Email ?? "").Trim();
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(email))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorEmailEmpty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!email.TestEmailRegex())
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorNotCorrectEmail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var viewer = _userManager.GetUsers(_securityContext.CurrentAccount.ID);
|
|
|
|
|
var user = _userManager.GetUsers(userid);
|
|
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorUserNotFound);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
if (viewer == null || (user.IsOwner(Tenant) && viewer.Id != user.Id))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
throw new Exception(Resource.ErrorAccessDenied);
|
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
var existentUser = _userManager.GetUserByEmail(email);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
if (existentUser.Id != Constants.LostUser.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(_customNamingPeople.Substitute<Resource>("ErrorEmailAlreadyExists"));
|
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (!_userManager.IsDocSpaceAdmin(viewer))
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
_studioNotifyService.SendEmailChangeInstructions(user, email);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (email == user.Email)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-05-17 09:29:24 +00:00
|
|
|
|
throw new Exception(Resource.ErrorEmailsAreTheSame);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
user.Email = email;
|
|
|
|
|
user.ActivationStatus = EmployeeActivationStatus.NotActivated;
|
2022-10-25 15:27:56 +00:00
|
|
|
|
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_studioNotifyService.SendEmailActivationInstructions(user, email);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_messageService.Send(MessageAction.UserSentEmailChangeInstructions, user.DisplayUserName(false, _displayUserSettingsHelper));
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-05-17 09:29:24 +00:00
|
|
|
|
return string.Format(Resource.MessageEmailChangeInstuctionsSentOnEmail, email);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[AllowNotPayment]
|
2022-05-17 09:29:24 +00:00
|
|
|
|
[AllowAnonymous]
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPost("password")]
|
2022-03-05 13:20:51 +00:00
|
|
|
|
public object SendUserPassword(MemberRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-17 14:55:19 +00:00
|
|
|
|
var error = _userManagerWrapper.SendUserPassword(inDto.Email);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(error))
|
2022-11-02 08:16:29 +00:00
|
|
|
|
{
|
2022-05-13 11:24:01 +00:00
|
|
|
|
_logger.ErrorPasswordRecovery(inDto.Email, error);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
return string.Format(Resource.MessageYourPasswordSendedToEmail, inDto.Email);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("activationstatus/{activationstatus}")]
|
2022-05-17 09:29:24 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "Activation,Everyone")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> UpdateEmployeeActivationStatus(EmployeeActivationStatus activationstatus, UpdateMembersRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
_apiContext.AuthByClaim();
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
foreach (var id in inDto.UserIds.Where(userId => !_userManager.IsSystemUser(userId)))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(id), Constants.Action_EditUser);
|
|
|
|
|
var u = _userManager.GetUsers(id);
|
|
|
|
|
if (u.Id == Constants.LostUser.Id || u.IsLDAP())
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u.ActivationStatus = activationstatus;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_userManager.UpdateUserInfo(u);
|
2022-08-12 13:26:57 +00:00
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(u);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("{userid}/culture")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> UpdateMemberCulture(string userid, UpdateMemberRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
|
|
|
|
|
|
|
|
|
if (_userManager.IsSystemUser(user.Id))
|
|
|
|
|
{
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(user.Id), Constants.Action_EditUser);
|
|
|
|
|
|
|
|
|
|
var curLng = user.CultureName;
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
if (_setupInfo.EnabledCultures.Find(c => string.Equals(c.Name, inDto.CultureName, StringComparison.InvariantCultureIgnoreCase)) != null)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-05 13:20:51 +00:00
|
|
|
|
if (curLng != inDto.CultureName)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.CultureName = inDto.CultureName;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-10-24 15:30:17 +00:00
|
|
|
|
_userManager.UpdateUserInfo(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
user.CultureName = curLng;
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_messageService.Send(MessageAction.UserUpdatedLanguage, _messageTarget.Create(user.Id), user.DisplayUserName(false, _displayUserSettingsHelper));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-12 17:45:12 +00:00
|
|
|
|
[HttpPut("{userid}", Order = 1)]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async Task<EmployeeFullDto> UpdateMember(string userid, UpdateMemberRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
var user = GetUserInfo(userid);
|
|
|
|
|
|
|
|
|
|
if (_userManager.IsSystemUser(user.Id))
|
|
|
|
|
{
|
|
|
|
|
throw new SecurityException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_permissionContext.DemandPermissions(new UserSecurityProvider(user.Id), Constants.Action_EditUser);
|
|
|
|
|
var self = _securityContext.CurrentAccount.ID.Equals(user.Id);
|
|
|
|
|
var resetDate = new DateTime(1900, 01, 01);
|
|
|
|
|
|
|
|
|
|
//Update it
|
|
|
|
|
|
|
|
|
|
var isLdap = user.IsLDAP();
|
|
|
|
|
var isSso = user.IsSSO();
|
2022-10-18 11:22:02 +00:00
|
|
|
|
var isDocSpaceAdmin = _webItemSecurity.IsProductAdministrator(WebItemManager.PeopleProductID, _securityContext.CurrentAccount.ID);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
if (!isLdap && !isSso)
|
|
|
|
|
{
|
|
|
|
|
//Set common fields
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.FirstName = inDto.Firstname ?? user.FirstName;
|
|
|
|
|
user.LastName = inDto.Lastname ?? user.LastName;
|
|
|
|
|
user.Location = inDto.Location ?? user.Location;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (isDocSpaceAdmin)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.Title = inDto.Title ?? user.Title;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!_userFormatter.IsValidUserName(user.FirstName, user.LastName))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorIncorrectUserName);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.Notes = inDto.Comment ?? user.Notes;
|
|
|
|
|
user.Sex = ("male".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
? true
|
2022-03-05 13:20:51 +00:00
|
|
|
|
: ("female".Equals(inDto.Sex, StringComparison.OrdinalIgnoreCase) ? (bool?)false : null)) ?? user.Sex;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.BirthDate = inDto.Birthday != null ? _tenantUtil.DateTimeFromUtc(inDto.Birthday) : user.BirthDate;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
if (user.BirthDate == resetDate)
|
|
|
|
|
{
|
|
|
|
|
user.BirthDate = null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.WorkFromDate = inDto.Worksfrom != null ? _tenantUtil.DateTimeFromUtc(inDto.Worksfrom) : user.WorkFromDate;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
|
|
|
|
if (user.WorkFromDate == resetDate)
|
|
|
|
|
{
|
|
|
|
|
user.WorkFromDate = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Update contacts
|
2022-03-05 13:20:51 +00:00
|
|
|
|
UpdateContacts(inDto.Contacts, user);
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await UpdateDepartments(inDto.Department, user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
if (inDto.Files != await _userPhotoManager.GetPhotoAbsoluteWebPath(user.Id))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-08-15 11:30:50 +00:00
|
|
|
|
await UpdatePhotoUrl(inDto.Files, user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-03-05 13:20:51 +00:00
|
|
|
|
if (inDto.Disable.HasValue)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-05 13:20:51 +00:00
|
|
|
|
user.Status = inDto.Disable.Value ? EmployeeStatus.Terminated : EmployeeStatus.Active;
|
|
|
|
|
user.TerminatedDate = inDto.Disable.Value ? DateTime.UtcNow : null;
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (self && !isDocSpaceAdmin)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
_studioNotifyService.SendMsgToAdminAboutProfileUpdated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// change user type
|
2022-10-18 11:22:02 +00:00
|
|
|
|
var canBeGuestFlag = !user.IsOwner(Tenant) && !_userManager.IsDocSpaceAdmin(user) && user.GetListAdminModules(_webItemSecurity, _webItemManager).Count == 0 && !user.IsMe(_authContext);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (inDto.IsUser && !_userManager.IsUser(user) && canBeGuestFlag)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-10-18 18:37:16 +00:00
|
|
|
|
await _countUserChecker.CheckAppend();
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await _userManager.AddUserIntoGroup(user.Id, Constants.GroupUser.ID);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_webItemSecurityCache.ClearCache(Tenant.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (!self && !inDto.IsUser && _userManager.IsUser(user))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-10-19 12:31:14 +00:00
|
|
|
|
await _countRoomAdminChecker.CheckAppend();
|
2022-09-19 14:56:45 +00:00
|
|
|
|
_userManager.RemoveUserFromGroup(user.Id, Constants.GroupUser.ID);
|
|
|
|
|
_webItemSecurityCache.ClearCache(Tenant.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-25 15:27:56 +00:00
|
|
|
|
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_messageService.Send(MessageAction.UserUpdated, _messageTarget.Create(user.Id), user.DisplayUserName(false, _displayUserSettingsHelper));
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
if (inDto.Disable.HasValue && inDto.Disable.Value)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-06-14 08:11:41 +00:00
|
|
|
|
await _cookiesManager.ResetUserCookie(user.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_messageService.Send(MessageAction.CookieSettingsUpdated);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-12 13:26:57 +00:00
|
|
|
|
return await _employeeFullDtoHelper.GetFull(user);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("status/{status}")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> UpdateUserStatus(EmployeeStatus status, UpdateMembersRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(Constants.Action_EditUser);
|
|
|
|
|
|
2022-03-05 13:20:51 +00:00
|
|
|
|
var users = inDto.UserIds.Select(userId => _userManager.GetUsers(userId))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
.Where(u => !_userManager.IsSystemUser(u.Id) && !u.IsLDAP())
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
if (user.IsOwner(Tenant) || user.IsMe(_authContext))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (status)
|
|
|
|
|
{
|
|
|
|
|
case EmployeeStatus.Active:
|
|
|
|
|
if (user.Status == EmployeeStatus.Terminated)
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
if (!_userManager.IsUser(user))
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
await _countRoomAdminChecker.CheckAppend();
|
2022-10-17 11:20:31 +00:00
|
|
|
|
}
|
2022-11-02 08:16:29 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await _countUserChecker.CheckAppend();
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-09-19 14:56:45 +00:00
|
|
|
|
|
|
|
|
|
user.Status = EmployeeStatus.Active;
|
2022-10-25 15:27:56 +00:00
|
|
|
|
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EmployeeStatus.Terminated:
|
|
|
|
|
user.Status = EmployeeStatus.Terminated;
|
2022-10-25 15:27:56 +00:00
|
|
|
|
await _userManager.UpdateUserInfoWithSyncCardDavAsync(user);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
|
2022-06-14 08:11:41 +00:00
|
|
|
|
await _cookiesManager.ResetUserCookie(user.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
_messageService.Send(MessageAction.CookieSettingsUpdated);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_messageService.Send(MessageAction.UsersUpdatedStatus, _messageTarget.Create(users.Select(x => x.Id)), users.Select(x => x.DisplayUserName(false, _displayUserSettingsHelper)));
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
2022-08-12 13:26:57 +00:00
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("type/{type}")]
|
2022-08-15 11:30:50 +00:00
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> UpdateUserType(EmployeeType type, UpdateMembersRequestDto inDto)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
2022-03-05 13:20:51 +00:00
|
|
|
|
var users = inDto.UserIds
|
2022-03-05 12:57:46 +00:00
|
|
|
|
.Where(userId => !_userManager.IsSystemUser(userId))
|
|
|
|
|
.Select(userId => _userManager.GetUsers(userId))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (user.IsOwner(Tenant) || _userManager.IsDocSpaceAdmin(user)
|
2022-04-15 09:08:06 +00:00
|
|
|
|
|| user.IsMe(_authContext) || user.GetListAdminModules(_webItemSecurity, _webItemManager).Count > 0)
|
2022-03-05 12:57:46 +00:00
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
2022-11-02 08:16:29 +00:00
|
|
|
|
case EmployeeType.RoomAdmin:
|
|
|
|
|
await _countRoomAdminChecker.CheckAppend();
|
2022-12-05 22:57:55 +00:00
|
|
|
|
_userManager.RemoveUserFromGroup(user.Id, Constants.GroupUser.ID);
|
2022-09-19 14:56:45 +00:00
|
|
|
|
_webItemSecurityCache.ClearCache(Tenant.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
break;
|
2022-11-02 08:16:29 +00:00
|
|
|
|
case EmployeeType.User:
|
|
|
|
|
await _countUserChecker.CheckAppend();
|
2022-12-05 22:57:55 +00:00
|
|
|
|
await _userManager.AddUserIntoGroup(user.Id, Constants.GroupUser.ID);
|
2022-09-19 14:56:45 +00:00
|
|
|
|
_webItemSecurityCache.ClearCache(Tenant.Id);
|
2022-03-05 12:57:46 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_messageService.Send(MessageAction.UsersUpdatedType, _messageTarget.Create(users.Select(x => x.Id)), users.Select(x => x.DisplayUserName(false, _displayUserSettingsHelper)));
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
|
{
|
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
2022-08-12 13:26:57 +00:00
|
|
|
|
}
|
2022-03-05 12:57:46 +00:00
|
|
|
|
}
|
2022-10-12 11:23:57 +00:00
|
|
|
|
[HttpGet("recalculatequota")]
|
|
|
|
|
public void RecalculateQuota()
|
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
_usersQuotaSyncOperation.RecalculateQuota(_tenantManager.GetCurrentTenant());
|
|
|
|
|
}
|
2022-11-09 09:57:16 +00:00
|
|
|
|
|
2022-10-25 14:31:25 +00:00
|
|
|
|
[HttpGet("checkrecalculatequota")]
|
|
|
|
|
public TaskProgressDto CheckRecalculateQuota()
|
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
return _usersQuotaSyncOperation.CheckRecalculateQuota(_tenantManager.GetCurrentTenant());
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-29 12:03:36 +00:00
|
|
|
|
[HttpPut("quota")]
|
|
|
|
|
public async IAsyncEnumerable<EmployeeFullDto> UpdateUserQuota(UpdateMembersQuotaRequestDto inDto)
|
|
|
|
|
{
|
|
|
|
|
var users = inDto.UserIds
|
|
|
|
|
.Where(userId => !_userManager.IsSystemUser(userId))
|
|
|
|
|
.Select(userId => _userManager.GetUsers(userId))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var user in users)
|
2022-11-02 08:16:29 +00:00
|
|
|
|
{
|
|
|
|
|
if (inDto.Quota != -1)
|
|
|
|
|
{
|
|
|
|
|
var usedSpace = Math.Max(0,
|
2022-10-12 11:23:57 +00:00
|
|
|
|
_quotaService.FindUserQuotaRows(
|
2022-11-02 08:16:29 +00:00
|
|
|
|
_tenantManager.GetCurrentTenant().Id,
|
|
|
|
|
user.Id
|
|
|
|
|
)
|
|
|
|
|
.Where(r => !string.IsNullOrEmpty(r.Tag)).Sum(r => r.Counter));
|
|
|
|
|
|
|
|
|
|
var tenanSpaceQuota = _quotaService.GetTenantQuota(Tenant.Id).MaxTotalSize;
|
|
|
|
|
|
|
|
|
|
if (tenanSpaceQuota < inDto.Quota || usedSpace > inDto.Quota)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var quotaSettings = _settingsManager.Load<TenantUserQuotaSettings>();
|
|
|
|
|
|
|
|
|
|
_settingsManager.SaveForUser(new UserQuotaSettings { UserQuota = inDto.Quota }, user);
|
|
|
|
|
|
2022-08-30 11:16:10 +00:00
|
|
|
|
yield return await _employeeFullDtoHelper.GetFull(user);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-29 12:03:36 +00:00
|
|
|
|
|
2022-02-28 19:23:39 +00:00
|
|
|
|
|
2022-10-27 10:49:42 +00:00
|
|
|
|
private async Task UpdateDepartments(IEnumerable<Guid> department, UserInfo user)
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (!_permissionContext.CheckPermissions(Constants.Action_EditGroups))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (department == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var groups = _userManager.GetUserGroups(user.Id);
|
|
|
|
|
var managerGroups = new List<Guid>();
|
|
|
|
|
foreach (var groupInfo in groups)
|
|
|
|
|
{
|
|
|
|
|
_userManager.RemoveUserFromGroup(user.Id, groupInfo.ID);
|
|
|
|
|
var managerId = _userManager.GetDepartmentManager(groupInfo.ID);
|
|
|
|
|
if (managerId == user.Id)
|
|
|
|
|
{
|
|
|
|
|
managerGroups.Add(groupInfo.ID);
|
|
|
|
|
_userManager.SetDepartmentManager(groupInfo.ID, Guid.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach (var guid in department)
|
|
|
|
|
{
|
|
|
|
|
var userDepartment = _userManager.GetGroupInfo(guid);
|
|
|
|
|
if (userDepartment != Constants.LostGroupInfo)
|
|
|
|
|
{
|
2022-10-27 10:49:42 +00:00
|
|
|
|
await _userManager.AddUserIntoGroup(user.Id, guid);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
if (managerGroups.Contains(guid))
|
|
|
|
|
{
|
|
|
|
|
_userManager.SetDepartmentManager(guid, user.Id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckReassignProccess(IEnumerable<Guid> userIds)
|
|
|
|
|
{
|
|
|
|
|
foreach (var userId in userIds)
|
|
|
|
|
{
|
|
|
|
|
var reassignStatus = _queueWorkerReassign.GetProgressItemStatus(Tenant.Id, userId);
|
|
|
|
|
if (reassignStatus == null || reassignStatus.IsCompleted)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userName = _userManager.GetUsers(userId).DisplayUserName(_displayUserSettingsHelper);
|
|
|
|
|
|
|
|
|
|
throw new Exception(string.Format(Resource.ReassignDataRemoveUserError, userName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task<string> InternalRegisterUserOnPersonalAsync(RegisterPersonalUserRequestDto inDto)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_coreBaseSettings.CustomMode)
|
|
|
|
|
{
|
|
|
|
|
inDto.Lang = "ru-RU";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var cultureInfo = _setupInfo.GetPersonalCulture(inDto.Lang).Value;
|
|
|
|
|
|
|
|
|
|
if (cultureInfo != null)
|
|
|
|
|
{
|
|
|
|
|
Thread.CurrentThread.CurrentUICulture = cultureInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inDto.Email.ThrowIfNull(new ArgumentException(Resource.ErrorEmailEmpty, "email"));
|
|
|
|
|
|
|
|
|
|
if (!inDto.Email.TestEmailRegex())
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException(Resource.ErrorNotCorrectEmail, "email");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!SetupInfo.IsSecretEmail(inDto.Email)
|
|
|
|
|
&& !string.IsNullOrEmpty(_setupInfo.RecaptchaPublicKey) && !string.IsNullOrEmpty(_setupInfo.RecaptchaPrivateKey))
|
|
|
|
|
{
|
|
|
|
|
var ip = Request.Headers["X-Forwarded-For"].ToString() ?? Request.GetUserHostAddress();
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(inDto.RecaptchaResponse)
|
|
|
|
|
|| !await _recaptcha.ValidateRecaptchaAsync(inDto.RecaptchaResponse, ip))
|
|
|
|
|
{
|
|
|
|
|
throw new RecaptchaException(Resource.RecaptchaInvalid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var newUserInfo = _userManager.GetUserByEmail(inDto.Email);
|
|
|
|
|
|
|
|
|
|
if (_userManager.UserExists(newUserInfo.Id))
|
|
|
|
|
{
|
|
|
|
|
if (!SetupInfo.IsSecretEmail(inDto.Email) || _securityContext.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
_studioNotifyService.SendAlreadyExist(inDto.Email);
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_securityContext.AuthenticateMe(Core.Configuration.Constants.CoreSystem);
|
2022-10-27 11:06:37 +00:00
|
|
|
|
await _userManager.DeleteUser(newUserInfo.Id);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_securityContext.Logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!inDto.Spam)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//TODO
|
|
|
|
|
//const string _databaseID = "com";
|
|
|
|
|
//using (var db = DbManager.FromHttpContext(_databaseID))
|
|
|
|
|
//{
|
|
|
|
|
// db.ExecuteNonQuery(new SqlInsert("template_unsubscribe", false)
|
|
|
|
|
// .InColumnValue("email", email.ToLowerInvariant())
|
|
|
|
|
// .InColumnValue("reason", "personal")
|
|
|
|
|
// );
|
|
|
|
|
// Log.Debug(String.Format("Write to template_unsubscribe {0}", email.ToLowerInvariant()));
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2022-05-24 20:13:57 +00:00
|
|
|
|
_logger.DebugWriteToTemplateUnsubscribe(inDto.Email.ToLowerInvariant(), ex);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_studioNotifyService.SendInvitePersonal(inDto.Email);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return ex.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 14:14:03 +00:00
|
|
|
|
private IQueryable<UserInfo> GetByFilter(EmployeeStatus? employeeStatus, Guid? groupId, EmployeeActivationStatus? activationStatus, EmployeeType? employeeType, bool? isDocSpaceAdministrator, Payments? payments)
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (_coreBaseSettings.Personal)
|
|
|
|
|
{
|
|
|
|
|
throw new MethodAccessException("Method not available");
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
var isDocSpaceAdmin = _userManager.IsDocSpaceAdmin(_securityContext.CurrentAccount.ID) ||
|
2022-05-17 09:29:24 +00:00
|
|
|
|
_webItemSecurity.IsProductAdministrator(WebItemManager.PeopleProductID, _securityContext.CurrentAccount.ID);
|
|
|
|
|
|
|
|
|
|
var includeGroups = new List<List<Guid>>();
|
|
|
|
|
if (groupId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
includeGroups.Add(new List<Guid> { groupId.Value });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var excludeGroups = new List<Guid>();
|
|
|
|
|
|
|
|
|
|
if (employeeType != null)
|
|
|
|
|
{
|
|
|
|
|
switch (employeeType)
|
|
|
|
|
{
|
2022-11-10 14:14:03 +00:00
|
|
|
|
case EmployeeType.DocSpaceAdmin:
|
|
|
|
|
includeGroups.Add(new List<Guid> { Constants.GroupAdmin.ID });
|
|
|
|
|
break;
|
2022-10-18 11:22:02 +00:00
|
|
|
|
case EmployeeType.RoomAdmin:
|
2022-11-10 14:14:03 +00:00
|
|
|
|
excludeGroups.Add(Constants.GroupUser.ID);
|
|
|
|
|
excludeGroups.Add(Constants.GroupAdmin.ID);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
break;
|
2022-10-18 11:22:02 +00:00
|
|
|
|
case EmployeeType.User:
|
2022-09-19 14:56:45 +00:00
|
|
|
|
includeGroups.Add(new List<Guid> { Constants.GroupUser.ID });
|
2022-05-17 09:29:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-10 14:14:03 +00:00
|
|
|
|
if (payments != null)
|
|
|
|
|
{
|
|
|
|
|
switch (payments)
|
|
|
|
|
{
|
|
|
|
|
case Payments.Paid:
|
|
|
|
|
excludeGroups.Add(Constants.GroupUser.ID);
|
|
|
|
|
break;
|
|
|
|
|
case Payments.Free:
|
|
|
|
|
includeGroups.Add(new List<Guid> { Constants.GroupUser.ID });
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-17 09:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
if (isDocSpaceAdministrator.HasValue && isDocSpaceAdministrator.Value)
|
2022-05-17 09:29:24 +00:00
|
|
|
|
{
|
|
|
|
|
var adminGroups = new List<Guid>
|
|
|
|
|
{
|
|
|
|
|
Constants.GroupAdmin.ID
|
|
|
|
|
};
|
|
|
|
|
var products = _webItemManager.GetItemsAll().Where(i => i is IProduct || i.ID == WebItemManager.MailProductID);
|
|
|
|
|
adminGroups.AddRange(products.Select(r => r.ID));
|
|
|
|
|
|
|
|
|
|
includeGroups.Add(adminGroups);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 11:22:02 +00:00
|
|
|
|
var users = _userManager.GetUsers(isDocSpaceAdmin, employeeStatus, includeGroups, excludeGroups, activationStatus, _apiContext.FilterValue, _apiContext.SortBy, !_apiContext.SortDescending, _apiContext.Count, _apiContext.StartIndex, out var total, out var count);
|
2022-05-17 09:29:24 +00:00
|
|
|
|
|
|
|
|
|
_apiContext.SetTotalCount(total).SetCount(count);
|
|
|
|
|
|
|
|
|
|
return users;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 19:23:39 +00:00
|
|
|
|
///// <summary>
|
|
|
|
|
///// Adds a new portal user from import with the first and last name, email address
|
|
|
|
|
///// </summary>
|
|
|
|
|
///// <short>
|
|
|
|
|
///// Add new import user
|
|
|
|
|
///// </short>
|
|
|
|
|
///// <param name="userList">The list of users to add</param>
|
|
|
|
|
///// <param name="importUsersAsCollaborators" optional="true">Add users as guests (bool type: false|true)</param>
|
|
|
|
|
///// <returns>Newly created users</returns>
|
2022-05-23 15:48:23 +00:00
|
|
|
|
//[HttpPost("import/save")]
|
2022-02-28 19:23:39 +00:00
|
|
|
|
//public void SaveUsers(string userList, bool importUsersAsCollaborators)
|
|
|
|
|
//{
|
|
|
|
|
// lock (progressQueue.SynchRoot)
|
|
|
|
|
// {
|
|
|
|
|
// var task = progressQueue.GetItems().OfType<ImportUsersTask>().FirstOrDefault(t => (int)t.Id == TenantProvider.CurrentTenantID);
|
2022-11-02 08:16:29 +00:00
|
|
|
|
//var tenant = CoreContext.TenantManager.GetCurrentTenant();
|
2022-06-07 18:00:08 +00:00
|
|
|
|
//Cache.Insert("REWRITE_URL" + tenant.TenantId, HttpContext.Current.Request.GetUrlRewriter().ToString(), TimeSpan.FromMinutes(5));
|
2022-02-28 19:23:39 +00:00
|
|
|
|
// if (task != null && task.IsCompleted)
|
|
|
|
|
// {
|
|
|
|
|
// progressQueue.Remove(task);
|
|
|
|
|
// task = null;
|
|
|
|
|
// }
|
|
|
|
|
// if (task == null)
|
|
|
|
|
// {
|
|
|
|
|
// progressQueue.Add(new ImportUsersTask(userList, importUsersAsCollaborators, GetHttpHeaders(HttpContext.Current.Request))
|
|
|
|
|
// {
|
|
|
|
|
// Id = TenantProvider.CurrentTenantID,
|
|
|
|
|
// UserId = SecurityContext.CurrentAccount.ID,
|
|
|
|
|
// Percentage = 0
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
//[HttpGet("import/status")]
|
2022-02-28 19:23:39 +00:00
|
|
|
|
//public object GetStatus()
|
|
|
|
|
//{
|
|
|
|
|
// lock (progressQueue.SynchRoot)
|
|
|
|
|
// {
|
|
|
|
|
// var task = progressQueue.GetItems().OfType<ImportUsersTask>().FirstOrDefault(t => (int)t.Id == TenantProvider.CurrentTenantID);
|
|
|
|
|
// if (task == null) return null;
|
|
|
|
|
|
|
|
|
|
// return new
|
|
|
|
|
// {
|
|
|
|
|
// Completed = task.IsCompleted,
|
|
|
|
|
// Percents = (int)task.Percentage,
|
|
|
|
|
// UserCounter = task.GetUserCounter,
|
|
|
|
|
// Status = (int)task.Status,
|
|
|
|
|
// Error = (string)task.Error,
|
|
|
|
|
// task.Data
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
}
|