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
|
|
|
|
|
2022-03-25 14:51:03 +00:00
|
|
|
using ASC.Notify.Engine;
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
namespace ASC.Data.Backup;
|
2020-05-20 15:14:44 +00:00
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
[Scope]
|
2022-04-11 11:53:29 +00:00
|
|
|
public class NotifyHelper
|
2022-04-01 16:17:21 +00:00
|
|
|
{
|
|
|
|
private readonly AuthManager _authManager;
|
|
|
|
private readonly NotifyEngineQueue _notifyEngineQueue;
|
|
|
|
private readonly WorkContext _workContext;
|
|
|
|
private readonly CommonLinkUtility _commonLinkUtility;
|
|
|
|
private readonly TenantLogoManager _tenantLogoManager;
|
|
|
|
private readonly UserManager _userManager;
|
|
|
|
private readonly StudioNotifyHelper _studioNotifyHelper;
|
|
|
|
private readonly StudioNotifySource _studioNotifySource;
|
|
|
|
private readonly DisplayUserSettingsHelper _displayUserSettingsHelper;
|
|
|
|
private readonly TenantManager _tenantManager;
|
|
|
|
|
2022-04-11 11:53:29 +00:00
|
|
|
public NotifyHelper(
|
2022-04-01 16:17:21 +00:00
|
|
|
UserManager userManager,
|
|
|
|
StudioNotifyHelper studioNotifyHelper,
|
|
|
|
StudioNotifySource studioNotifySource,
|
|
|
|
DisplayUserSettingsHelper displayUserSettingsHelper,
|
|
|
|
TenantManager tenantManager,
|
|
|
|
AuthManager authManager,
|
|
|
|
NotifyEngineQueue notifyEngineQueue,
|
|
|
|
WorkContext workContext,
|
|
|
|
CommonLinkUtility commonLinkUtility,
|
|
|
|
TenantLogoManager tenantLogoManager)
|
|
|
|
{
|
|
|
|
_userManager = userManager;
|
|
|
|
_studioNotifyHelper = studioNotifyHelper;
|
|
|
|
_studioNotifySource = studioNotifySource;
|
|
|
|
_displayUserSettingsHelper = displayUserSettingsHelper;
|
|
|
|
_tenantManager = tenantManager;
|
|
|
|
_authManager = authManager;
|
|
|
|
_notifyEngineQueue = notifyEngineQueue;
|
|
|
|
_workContext = workContext;
|
|
|
|
_commonLinkUtility = commonLinkUtility;
|
|
|
|
_tenantLogoManager = tenantLogoManager;
|
|
|
|
}
|
2022-03-28 09:53:15 +00:00
|
|
|
|
2022-04-11 11:53:29 +00:00
|
|
|
public void SendAboutTransferStart(Tenant tenant, string targetRegion, bool notifyUsers)
|
|
|
|
{
|
|
|
|
MigrationNotify(tenant, Actions.MigrationPortalStart, targetRegion, string.Empty, notifyUsers);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendAboutTransferComplete(Tenant tenant, string targetRegion, string targetAddress, bool notifyOnlyOwner, int toTenantId)
|
|
|
|
{
|
|
|
|
MigrationNotify(tenant, Actions.MigrationPortalSuccessV115, targetRegion, targetAddress, !notifyOnlyOwner, toTenantId);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SendAboutTransferError(Tenant tenant, string targetRegion, string resultAddress, bool notifyOnlyOwner)
|
|
|
|
{
|
|
|
|
MigrationNotify(tenant, !string.IsNullOrEmpty(targetRegion) ? Actions.MigrationPortalError : Actions.MigrationPortalServerFailure, targetRegion, resultAddress, !notifyOnlyOwner);
|
|
|
|
}
|
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
public void SendAboutBackupCompleted(int tenantId, Guid userId)
|
|
|
|
{
|
|
|
|
_tenantManager.SetCurrentTenant(tenantId);
|
|
|
|
|
|
|
|
var client = _workContext.NotifyContext.RegisterClient(_notifyEngineQueue, _studioNotifySource);
|
2022-02-09 18:49:52 +00:00
|
|
|
|
|
|
|
client.SendNoticeToAsync(
|
|
|
|
Actions.BackupCreated,
|
2022-04-01 16:17:21 +00:00
|
|
|
new[] { _studioNotifyHelper.ToRecipient(userId) },
|
2022-02-09 18:49:52 +00:00
|
|
|
new[] { StudioNotifyService.EMailSenderName },
|
2022-04-01 16:17:21 +00:00
|
|
|
new TagValue(Tags.OwnerName, _userManager.GetUsers(userId).DisplayUserName(_displayUserSettingsHelper)));
|
|
|
|
}
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
public void SendAboutRestoreStarted(Tenant tenant, bool notifyAllUsers)
|
2022-04-01 16:17:21 +00:00
|
|
|
{
|
|
|
|
_tenantManager.SetCurrentTenant(tenant.Id);
|
2022-03-28 09:53:15 +00:00
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
var client = _workContext.NotifyContext.RegisterClient(_notifyEngineQueue, _studioNotifySource);
|
2022-02-09 18:49:52 +00:00
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
var owner = _userManager.GetUsers(tenant.OwnerId);
|
2022-02-09 18:49:52 +00:00
|
|
|
var users =
|
|
|
|
notifyAllUsers
|
2022-04-01 16:17:21 +00:00
|
|
|
? _studioNotifyHelper.RecipientFromEmail(_userManager.GetUsers(EmployeeStatus.Active).Where(r => r.ActivationStatus == EmployeeActivationStatus.Activated).Select(u => u.Email).ToList(), false)
|
|
|
|
: owner.ActivationStatus == EmployeeActivationStatus.Activated ? _studioNotifyHelper.RecipientFromEmail(owner.Email, false) : new IDirectRecipient[0];
|
2022-02-09 18:49:52 +00:00
|
|
|
|
|
|
|
client.SendNoticeToAsync(
|
|
|
|
Actions.RestoreStarted,
|
|
|
|
users,
|
|
|
|
new[] { StudioNotifyService.EMailSenderName });
|
|
|
|
}
|
2020-05-20 15:14:44 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
public void SendAboutRestoreCompleted(Tenant tenant, bool notifyAllUsers)
|
2022-04-01 16:17:21 +00:00
|
|
|
{
|
|
|
|
_tenantManager.SetCurrentTenant(tenant);
|
|
|
|
var client = _workContext.NotifyContext.RegisterClient(_notifyEngineQueue, _studioNotifySource);
|
2021-08-31 09:40:28 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
var users = notifyAllUsers
|
2022-04-01 16:17:21 +00:00
|
|
|
? _userManager.GetUsers(EmployeeStatus.Active)
|
|
|
|
: new[] { _userManager.GetUsers(_tenantManager.GetCurrentTenant().OwnerId) };
|
2022-03-25 14:51:03 +00:00
|
|
|
|
|
|
|
foreach (var user in users)
|
|
|
|
{
|
2022-04-01 16:17:21 +00:00
|
|
|
var hash = _authManager.GetUserPasswordStamp(user.Id).ToString("s");
|
|
|
|
var confirmationUrl = _commonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.PasswordChange, hash);
|
2021-08-31 09:40:28 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
Func<string> greenButtonText = () => BackupResource.ButtonSetPassword;
|
2021-08-31 09:40:28 +00:00
|
|
|
|
|
|
|
client.SendNoticeToAsync(
|
2022-02-09 18:49:52 +00:00
|
|
|
Actions.RestoreCompletedV115,
|
|
|
|
new IRecipient[] { user },
|
2021-08-31 09:40:28 +00:00
|
|
|
new[] { StudioNotifyService.EMailSenderName },
|
2022-02-09 18:49:52 +00:00
|
|
|
null,
|
|
|
|
TagValues.GreenButton(greenButtonText, confirmationUrl));
|
2021-08-31 09:40:28 +00:00
|
|
|
}
|
2022-02-09 18:49:52 +00:00
|
|
|
}
|
2021-08-31 09:40:28 +00:00
|
|
|
|
2022-04-11 11:53:29 +00:00
|
|
|
private void MigrationNotify(Tenant tenant, INotifyAction action, string region, string url, bool notify, int? toTenantId = null)
|
2022-04-01 16:17:21 +00:00
|
|
|
{
|
|
|
|
_tenantManager.SetCurrentTenant(tenant);
|
2022-03-31 17:32:46 +00:00
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
var client = _workContext.NotifyContext.RegisterClient(_notifyEngineQueue, _studioNotifySource);
|
2021-08-31 09:40:28 +00:00
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
var users = _userManager.GetUsers()
|
2022-02-09 18:49:52 +00:00
|
|
|
.Where(u => notify ? u.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated) : u.IsOwner(tenant))
|
2022-03-25 14:51:03 +00:00
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
if (users.Length > 0)
|
2021-08-31 09:40:28 +00:00
|
|
|
{
|
2022-04-01 16:17:21 +00:00
|
|
|
var args = CreateArgs(region, url);
|
2022-02-09 18:49:52 +00:00
|
|
|
if (action == Actions.MigrationPortalSuccessV115)
|
2021-08-31 09:40:28 +00:00
|
|
|
{
|
2022-02-09 18:49:52 +00:00
|
|
|
foreach (var user in users)
|
2021-08-31 09:40:28 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
var currentArgs = new List<ITagValue>(args);
|
|
|
|
|
|
|
|
var newTenantId = toTenantId.HasValue ? toTenantId.Value : tenant.Id;
|
2022-04-01 16:17:21 +00:00
|
|
|
var hash = _authManager.GetUserPasswordStamp(user.Id).ToString("s");
|
|
|
|
var confirmationUrl = url + "/" + _commonLinkUtility.GetConfirmationUrlRelative(newTenantId, user.Email, ConfirmType.PasswordChange, hash);
|
2021-08-31 09:40:28 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
Func<string> greenButtonText = () => BackupResource.ButtonSetPassword;
|
2022-03-25 14:51:03 +00:00
|
|
|
currentArgs.Add(TagValues.GreenButton(greenButtonText, confirmationUrl));
|
|
|
|
|
|
|
|
client.SendNoticeToAsync(
|
|
|
|
action,
|
|
|
|
null,
|
|
|
|
new IRecipient[] { user },
|
|
|
|
new[] { StudioNotifyService.EMailSenderName },
|
|
|
|
currentArgs.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
client.SendNoticeToAsync(
|
|
|
|
action,
|
|
|
|
null,
|
2022-04-01 16:17:21 +00:00
|
|
|
users.Select(u => _studioNotifyHelper.ToRecipient(u.Id)).ToArray(),
|
2022-03-25 14:51:03 +00:00
|
|
|
new[] { StudioNotifyService.EMailSenderName },
|
|
|
|
args.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-31 09:40:28 +00:00
|
|
|
|
2022-04-01 16:17:21 +00:00
|
|
|
private List<ITagValue> CreateArgs(string region, string url)
|
2022-02-09 18:49:52 +00:00
|
|
|
{
|
|
|
|
var args = new List<ITagValue>()
|
2021-08-31 09:40:28 +00:00
|
|
|
{
|
|
|
|
new TagValue(Tags.RegionName, TransferResourceHelper.GetRegionDescription(region)),
|
|
|
|
new TagValue(Tags.PortalUrl, url)
|
|
|
|
};
|
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
if (!string.IsNullOrEmpty(url))
|
|
|
|
{
|
|
|
|
args.Add(new TagValue(CommonTags.VirtualRootPath, url));
|
2022-04-01 16:17:21 +00:00
|
|
|
args.Add(new TagValue(CommonTags.ProfileUrl, url + _commonLinkUtility.GetMyStaff()));
|
|
|
|
args.Add(new TagValue(CommonTags.LetterLogo, _tenantLogoManager.GetLogoDark(true)));
|
2020-08-24 18:41:06 +00:00
|
|
|
}
|
2022-02-09 18:49:52 +00:00
|
|
|
|
|
|
|
return args;
|
2020-08-24 18:41:06 +00:00
|
|
|
}
|
2022-02-09 18:49:52 +00:00
|
|
|
}
|