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
|
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
|
|
|
|
|
|
|
|
|
using Constants = ASC.Core.Users.Constants;
|
2022-03-01 10:58:02 +00:00
|
|
|
|
|
|
|
|
|
namespace ASC.Web.Api.Controllers.Settings;
|
|
|
|
|
|
2022-03-02 08:08:59 +00:00
|
|
|
|
public class OwnerController : BaseSettingsController
|
2022-03-01 10:58:02 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly MessageService _messageService;
|
|
|
|
|
private readonly StudioNotifyService _studioNotifyService;
|
|
|
|
|
private readonly UserManager _userManager;
|
|
|
|
|
private readonly TenantManager _tenantManager;
|
|
|
|
|
private readonly AuthContext _authContext;
|
|
|
|
|
private readonly PermissionContext _permissionContext;
|
|
|
|
|
private readonly CommonLinkUtility _commonLinkUtility;
|
|
|
|
|
private readonly DisplayUserSettingsHelper _displayUserSettingsHelper;
|
|
|
|
|
private readonly MessageTarget _messageTarget;
|
|
|
|
|
|
|
|
|
|
public OwnerController(
|
2022-03-02 08:08:59 +00:00
|
|
|
|
MessageService messageService,
|
|
|
|
|
CommonLinkUtility commonLinkUtility,
|
2022-03-01 10:58:02 +00:00
|
|
|
|
StudioNotifyService studioNotifyService,
|
|
|
|
|
ApiContext apiContext,
|
|
|
|
|
UserManager userManager,
|
|
|
|
|
TenantManager tenantManager,
|
|
|
|
|
AuthContext authContext,
|
|
|
|
|
PermissionContext permissionContext,
|
|
|
|
|
WebItemManager webItemManager,
|
2022-03-02 08:08:59 +00:00
|
|
|
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
|
|
|
|
MessageTarget messageTarget,
|
2022-04-15 10:27:48 +00:00
|
|
|
|
IMemoryCache memoryCache,
|
|
|
|
|
IHttpContextAccessor httpContextAccessor) : base(apiContext, memoryCache, webItemManager, httpContextAccessor)
|
2022-03-01 10:58:02 +00:00
|
|
|
|
{
|
2022-03-02 08:08:59 +00:00
|
|
|
|
_messageService = messageService;
|
|
|
|
|
_commonLinkUtility = commonLinkUtility;
|
2022-03-01 10:58:02 +00:00
|
|
|
|
_studioNotifyService = studioNotifyService;
|
|
|
|
|
_userManager = userManager;
|
|
|
|
|
_tenantManager = tenantManager;
|
|
|
|
|
_authContext = authContext;
|
|
|
|
|
_permissionContext = permissionContext;
|
2022-03-02 08:08:59 +00:00
|
|
|
|
_displayUserSettingsHelper = displayUserSettingsHelper;
|
|
|
|
|
_messageTarget = messageTarget;
|
2022-03-01 10:58:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPost("owner")]
|
2022-05-17 09:29:24 +00:00
|
|
|
|
public object SendOwnerChangeInstructions(SettingsRequestsDto inDto)
|
2022-03-01 10:58:02 +00:00
|
|
|
|
{
|
|
|
|
|
_permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
|
|
|
|
|
|
|
|
|
var curTenant = _tenantManager.GetCurrentTenant();
|
|
|
|
|
var owner = _userManager.GetUsers(curTenant.OwnerId);
|
2022-03-15 10:56:22 +00:00
|
|
|
|
var newOwner = _userManager.GetUsers(inDto.OwnerId);
|
2022-03-01 10:58:02 +00:00
|
|
|
|
|
2022-03-17 15:01:39 +00:00
|
|
|
|
if (newOwner.IsVisitor(_userManager))
|
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
|
throw new SecurityException("Collaborator can not be an owner");
|
2022-03-17 15:01:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 10:58:02 +00:00
|
|
|
|
if (!owner.Id.Equals(_authContext.CurrentAccount.ID) || Guid.Empty.Equals(newOwner.Id))
|
|
|
|
|
{
|
|
|
|
|
return new { Status = 0, Message = Resource.ErrorAccessDenied };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var confirmLink = _commonLinkUtility.GetConfirmationUrl(owner.Email, ConfirmType.PortalOwnerChange, newOwner.Id, newOwner.Id);
|
|
|
|
|
_studioNotifyService.SendMsgConfirmChangeOwner(owner, newOwner, confirmLink);
|
|
|
|
|
|
|
|
|
|
_messageService.Send(MessageAction.OwnerSentChangeOwnerInstructions, _messageTarget.Create(owner.Id), owner.DisplayUserName(false, _displayUserSettingsHelper));
|
|
|
|
|
|
|
|
|
|
var emailLink = $"<a href=\"mailto:{owner.Email}\">{owner.Email}</a>";
|
|
|
|
|
return new { Status = 1, Message = Resource.ChangePortalOwnerMsg.Replace(":email", emailLink) };
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-23 15:48:23 +00:00
|
|
|
|
[HttpPut("owner")]
|
2022-03-01 10:58:02 +00:00
|
|
|
|
[Authorize(AuthenticationSchemes = "confirm", Roles = "PortalOwnerChange")]
|
2022-05-17 09:29:24 +00:00
|
|
|
|
public void Owner(SettingsRequestsDto inDto)
|
2022-03-01 10:58:02 +00:00
|
|
|
|
{
|
|
|
|
|
var newOwner = Constants.LostUser;
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-03-15 10:56:22 +00:00
|
|
|
|
newOwner = _userManager.GetUsers(inDto.OwnerId);
|
2022-03-01 10:58:02 +00:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
if (Constants.LostUser.Equals(newOwner))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorUserNotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_userManager.IsUserInGroup(newOwner.Id, Constants.GroupVisitor.ID))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Resource.ErrorUserNotFound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var curTenant = _tenantManager.GetCurrentTenant();
|
|
|
|
|
curTenant.OwnerId = newOwner.Id;
|
|
|
|
|
_tenantManager.SaveTenant(curTenant);
|
|
|
|
|
|
|
|
|
|
_messageService.Send(MessageAction.OwnerUpdated, newOwner.DisplayUserName(false, _displayUserSettingsHelper));
|
|
|
|
|
}
|
|
|
|
|
}
|