DocSpace-client/web/ASC.Web.Core/Notify/StudioNotifyService.cs

900 lines
43 KiB
C#
Raw Normal View History

/*
*
* (c) Copyright Ascensio System Limited 2010-2018
*
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
* In accordance with Section 7(a) of the GNU GPL 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 more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
*
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
*
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
*
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
* relevant author attributions when distributing the software. If the display of the logo in its graphic
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
* in every copy of the program you distribute.
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
*
*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
2019-08-01 08:47:15 +00:00
using ASC.Common.Logging;
using ASC.Core;
using ASC.Core.Tenants;
using ASC.Core.Users;
using ASC.Notify.Model;
using ASC.Notify.Patterns;
using ASC.Notify.Recipients;
using ASC.Security.Cryptography;
using ASC.Web.Core.Notify;
using ASC.Web.Core.PublicResources;
using ASC.Web.Core.Users;
using ASC.Web.Core.WhiteLabel;
using ASC.Web.Studio.Utility;
namespace ASC.Web.Studio.Core.Notify
{
public class StudioNotifyService
{
private readonly StudioNotifyServiceHelper client;
private static string EMailSenderName { get { return ASC.Core.Configuration.Constants.NotifyEMailSenderSysName; } }
2019-09-09 12:56:33 +00:00
public UserManager UserManager { get; }
public StudioNotifyHelper StudioNotifyHelper { get; }
public TenantExtra TenantExtra { get; }
public AuthManager Authentication { get; }
public AuthContext AuthContext { get; }
2019-09-13 11:18:27 +00:00
public MailWhiteLabelSettings MailWhiteLabelSettings { get; }
public AdditionalWhiteLabelSettings AdditionalWhiteLabelSettings { get; }
2019-09-09 12:56:33 +00:00
public StudioNotifyService(
UserManager userManager,
StudioNotifyHelper studioNotifyHelper,
StudioNotifyServiceHelper studioNotifyServiceHelper,
TenantExtra tenantExtra,
AuthManager authentication,
2019-09-13 11:18:27 +00:00
AuthContext authContext,
MailWhiteLabelSettings mailWhiteLabelSettings,
AdditionalWhiteLabelSettings additionalWhiteLabelSettings)
2019-09-09 12:56:33 +00:00
{
client = studioNotifyServiceHelper;
TenantExtra = tenantExtra;
Authentication = authentication;
AuthContext = authContext;
2019-09-13 11:18:27 +00:00
MailWhiteLabelSettings = mailWhiteLabelSettings;
AdditionalWhiteLabelSettings = additionalWhiteLabelSettings;
2019-09-09 12:56:33 +00:00
UserManager = userManager;
StudioNotifyHelper = studioNotifyHelper;
}
public void SendMsgToAdminAboutProfileUpdated()
{
client.SendNoticeAsync(Actions.SelfProfileUpdated, null);
}
public void SendMsgToAdminFromNotAuthUser(string email, string message)
{
client.SendNoticeAsync(Actions.UserMessageToAdmin, null, new TagValue(Tags.Body, message), new TagValue(Tags.UserEmail, email));
}
public void SendRequestTariff(bool license, string fname, string lname, string title, string email, string phone, string ctitle, string csize, string site, string message)
{
fname = (fname ?? "").Trim();
if (string.IsNullOrEmpty(fname)) throw new ArgumentNullException("fname");
lname = (lname ?? "").Trim();
if (string.IsNullOrEmpty(lname)) throw new ArgumentNullException("lname");
title = (title ?? "").Trim();
email = (email ?? "").Trim();
if (string.IsNullOrEmpty(email)) throw new ArgumentNullException("email");
phone = (phone ?? "").Trim();
if (string.IsNullOrEmpty(phone)) throw new ArgumentNullException("phone");
ctitle = (ctitle ?? "").Trim();
if (string.IsNullOrEmpty(ctitle)) throw new ArgumentNullException("ctitle");
csize = (csize ?? "").Trim();
if (string.IsNullOrEmpty(csize)) throw new ArgumentNullException("csize");
site = (site ?? "").Trim();
if (string.IsNullOrEmpty(site)) throw new ArgumentNullException("site");
message = (message ?? "").Trim();
var salesEmail = AdditionalWhiteLabelSettings.Instance.SalesEmail ?? SetupInfo.SalesEmail;
2019-09-09 12:56:33 +00:00
var recipient = (IRecipient)(new DirectRecipient(AuthContext.CurrentAccount.ID.ToString(), string.Empty, new[] { salesEmail }, false));
client.SendNoticeToAsync(license ? Actions.RequestLicense : Actions.RequestTariff,
new[] { recipient },
new[] { "email.sender" },
new TagValue(Tags.UserName, fname),
new TagValue(Tags.UserLastName, lname),
new TagValue(Tags.UserPosition, title),
new TagValue(Tags.UserEmail, email),
new TagValue(Tags.Phone, phone),
new TagValue(Tags.Website, site),
new TagValue(Tags.CompanyTitle, ctitle),
new TagValue(Tags.CompanySize, csize),
new TagValue(Tags.Body, message));
}
#region Voip
public void SendToAdminVoipWarning(double balance)
{
client.SendNoticeAsync(Actions.VoipWarning, null, new TagValue(Tags.Body, balance));
}
public void SendToAdminVoipBlocked()
{
client.SendNoticeAsync(Actions.VoipBlocked, null);
}
#endregion
#region User Password
2019-08-09 12:28:19 +00:00
public void UserPasswordChange(int tenantId, UserInfo userInfo)
{
2019-09-09 12:56:33 +00:00
var hash = Hasher.Base64Hash(Authentication.GetUserPasswordHash(tenantId, userInfo.ID));
2019-09-03 12:23:58 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, userInfo.Email, ConfirmType.PasswordChange, hash);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangePassword;
var action = CoreContext.Configuration.Personal
? (CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModePasswordChange : Actions.PersonalPasswordChange)
: Actions.PasswordChange;
client.SendNoticeToAsync(
action,
StudioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl));
}
#endregion
#region User Email
2019-09-03 12:23:58 +00:00
public void SendEmailChangeInstructions(int tenantId, UserInfo user, string email)
{
2019-09-09 12:56:33 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, email, ConfirmType.EmailChange, AuthContext.CurrentAccount.ID);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangeEmail;
var action = CoreContext.Configuration.Personal
? (CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModeEmailChange : Actions.PersonalEmailChange)
: Actions.EmailChange;
client.SendNoticeToAsync(
action,
StudioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(CommonTags.Culture, user.GetCulture().Name));
}
2019-09-03 12:23:58 +00:00
public void SendEmailActivationInstructions(int tenantId, UserInfo user, string email)
{
2019-09-03 12:23:58 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, email, ConfirmType.EmailActivation);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonActivateEmail;
client.SendNoticeToAsync(
Actions.ActivateEmail,
StudioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, confirmationUrl),
TagValues.GreenButton(greenButtonText, confirmationUrl),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.UserDisplayName, (user.DisplayUserName(UserManager) ?? string.Empty).Trim()));
}
#endregion
#region MailServer
public void SendMailboxCreated(List<string> toEmails, string username, string address)
{
SendMailboxCreated(toEmails, username, address, null, null, -1, -1, null);
}
public void SendMailboxCreated(List<string> toEmails, string username, string address, string server,
string encyption, int portImap, int portSmtp, string login)
{
var tags = new List<ITagValue>
{
new TagValue(Tags.UserName, username ?? string.Empty),
new TagValue(Tags.Address, address ?? string.Empty)
};
var skipSettings = string.IsNullOrEmpty(server);
if (!skipSettings)
{
var link = string.Format("{0}/addons/mail/#accounts/changepwd={1}",
CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/'), address);
tags.Add(new TagValue(Tags.MyStaffLink, link));
tags.Add(new TagValue(Tags.Server, server));
tags.Add(new TagValue(Tags.Encryption, encyption ?? string.Empty));
tags.Add(new TagValue(Tags.ImapPort, portImap.ToString(CultureInfo.InvariantCulture)));
tags.Add(new TagValue(Tags.SmtpPort, portSmtp.ToString(CultureInfo.InvariantCulture)));
tags.Add(new TagValue(Tags.Login, login));
}
foreach (var email in toEmails)
{
client.SendNoticeToAsync(
skipSettings
? Actions.MailboxWithoutSettingsCreated
: Actions.MailboxCreated,
StudioNotifyHelper.RecipientFromEmail(email, false),
2019-08-15 12:04:42 +00:00
new[] { EMailSenderName },
tags.ToArray());
}
}
public void SendMailboxPasswordChanged(List<string> toEmails, string username, string address)
{
foreach (var email in toEmails)
{
client.SendNoticeToAsync(
Actions.MailboxPasswordChanged,
StudioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, username ?? string.Empty),
new TagValue(Tags.Address, address ?? string.Empty));
}
}
#endregion
2019-09-03 12:23:58 +00:00
public void SendMsgMobilePhoneChange(int tenantId, UserInfo userInfo)
{
2019-09-03 12:23:58 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, userInfo.Email.ToLower(), ConfirmType.PhoneActivation);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangePhone;
client.SendNoticeToAsync(
Actions.PhoneChange,
StudioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl));
}
2019-09-03 12:23:58 +00:00
public void SendMsgTfaReset(int tenantId, UserInfo userInfo)
{
2019-09-03 12:23:58 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, userInfo.Email.ToLower(), ConfirmType.TfaActivation);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonChangeTfa;
client.SendNoticeToAsync(
Actions.TfaChange,
StudioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl));
}
public void UserHasJoin()
{
client.SendNoticeAsync(Actions.UserHasJoin, null);
}
2019-08-09 12:28:19 +00:00
public void SendJoinMsg(int tenantId, string email, EmployeeType emplType)
{
2019-09-09 12:56:33 +00:00
var inviteUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, email, ConfirmType.EmpInvite, (int)emplType, AuthContext.CurrentAccount.ID)
2019-08-15 13:16:39 +00:00
+ string.Format("&emplType={0}", emplType);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonJoin;
client.SendNoticeToAsync(
Actions.JoinUsers,
StudioNotifyHelper.RecipientFromEmail(email, true),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, inviteUrl),
TagValues.GreenButton(greenButtonText, inviteUrl),
2019-09-09 12:56:33 +00:00
TagValues.SendFrom(tenantId, UserManager, AuthContext));
}
2019-08-08 09:26:58 +00:00
public void UserInfoAddedAfterInvite(int tenantId, UserInfo newUserInfo)
{
2019-09-09 12:56:33 +00:00
if (!UserManager.UserExists(newUserInfo)) return;
INotifyAction notifyAction;
var footer = "social";
var analytics = string.Empty;
if (CoreContext.Configuration.Personal)
{
if (CoreContext.Configuration.CustomMode)
{
notifyAction = Actions.PersonalCustomModeAfterRegistration1;
footer = "personalCustomMode";
}
else
{
notifyAction = Actions.PersonalAfterRegistration1;
footer = "personal";
}
}
else if (TenantExtra.Enterprise)
{
var defaultRebranding = MailWhiteLabelSettings.Instance.IsDefault;
notifyAction = defaultRebranding
? Actions.EnterpriseUserWelcomeV10
: CoreContext.Configuration.CustomMode
? Actions.EnterpriseWhitelabelUserWelcomeCustomMode
: Actions.EnterpriseWhitelabelUserWelcomeV10;
footer = null;
}
else
{
notifyAction = Actions.SaasUserWelcomeV10;
2019-08-09 12:28:19 +00:00
analytics = StudioNotifyHelper.GetNotifyAnalytics(tenantId, notifyAction, false, false, true, false);
}
2019-09-09 12:56:33 +00:00
string greenButtonText() => TenantExtra.Enterprise
? WebstudioNotifyPatternResource.ButtonAccessYourPortal
: WebstudioNotifyPatternResource.ButtonAccessYouWebOffice;
client.SendNoticeToAsync(
notifyAction,
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(Tags.MyStaffLink, GetMyStaffLink()),
TagValues.GreenButton(greenButtonText, CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/')),
new TagValue(CommonTags.Footer, footer),
new TagValue(CommonTags.MasterTemplate, CoreContext.Configuration.Personal ? "HtmlMasterPersonal" : "HtmlMaster"),
new TagValue(CommonTags.Analytics, analytics));
}
2019-08-30 12:40:57 +00:00
public void GuestInfoAddedAfterInvite(UserInfo newUserInfo)
{
2019-09-09 12:56:33 +00:00
if (!UserManager.UserExists(newUserInfo)) return;
INotifyAction notifyAction;
var analytics = string.Empty;
var footer = "social";
if (TenantExtra.Enterprise)
{
var defaultRebranding = MailWhiteLabelSettings.Instance.IsDefault;
notifyAction = defaultRebranding ? Actions.EnterpriseGuestWelcomeV10 : Actions.EnterpriseWhitelabelGuestWelcomeV10;
footer = null;
}
else
{
notifyAction = Actions.SaasGuestWelcomeV10;
var tenant = CoreContext.TenantManager.GetCurrentTenant();
analytics = StudioNotifyHelper.GetNotifyAnalytics(tenant.TenantId, notifyAction, false, false, false, true);
}
2019-09-09 12:56:33 +00:00
string greenButtonText() => TenantExtra.Enterprise
? WebstudioNotifyPatternResource.ButtonAccessYourPortal
: WebstudioNotifyPatternResource.ButtonAccessYouWebOffice;
client.SendNoticeToAsync(
notifyAction,
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(Tags.MyStaffLink, GetMyStaffLink()),
TagValues.GreenButton(greenButtonText, CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/')),
new TagValue(CommonTags.Footer, footer),
new TagValue(CommonTags.Analytics, analytics));
}
2019-08-09 12:28:19 +00:00
public void UserInfoActivation(int tenantId, UserInfo newUserInfo)
{
if (newUserInfo.IsActive)
throw new ArgumentException("User is already activated!");
INotifyAction notifyAction;
var analytics = string.Empty;
var footer = "social";
if (TenantExtra.Enterprise)
{
var defaultRebranding = MailWhiteLabelSettings.Instance.IsDefault;
notifyAction = defaultRebranding ? Actions.EnterpriseUserActivationV10 : Actions.EnterpriseWhitelabelUserActivationV10;
footer = null;
}
else
{
notifyAction = Actions.SaasUserActivationV10;
2019-08-09 12:28:19 +00:00
analytics = StudioNotifyHelper.GetNotifyAnalytics(tenantId, notifyAction, false, false, true, false);
}
2019-09-03 12:23:58 +00:00
var confirmationUrl = GenerateActivationConfirmUrl(tenantId, newUserInfo);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonAccept;
client.SendNoticeToAsync(
notifyAction,
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(CommonTags.Footer, footer),
2019-09-09 12:56:33 +00:00
TagValues.SendFrom(tenantId, UserManager, AuthContext),
new TagValue(CommonTags.Analytics, analytics));
}
2019-08-09 12:28:19 +00:00
public void GuestInfoActivation(int tenantId, UserInfo newUserInfo)
{
if (newUserInfo.IsActive)
throw new ArgumentException("User is already activated!");
INotifyAction notifyAction;
var analytics = string.Empty;
var footer = "social";
if (TenantExtra.Enterprise)
{
var defaultRebranding = MailWhiteLabelSettings.Instance.IsDefault;
notifyAction = defaultRebranding ? Actions.EnterpriseGuestActivationV10 : Actions.EnterpriseWhitelabelGuestActivationV10;
footer = null;
}
else
{
notifyAction = Actions.SaasGuestActivationV10;
2019-08-09 12:28:19 +00:00
analytics = StudioNotifyHelper.GetNotifyAnalytics(tenantId, notifyAction, false, false, false, true);
}
2019-09-03 12:23:58 +00:00
var confirmationUrl = GenerateActivationConfirmUrl(tenantId, newUserInfo);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonAccept;
client.SendNoticeToAsync(
notifyAction,
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
new TagValue(CommonTags.Footer, footer),
2019-09-09 12:56:33 +00:00
TagValues.SendFrom(tenantId, UserManager, AuthContext),
new TagValue(CommonTags.Analytics, analytics));
}
2019-09-03 12:23:58 +00:00
public void SendMsgProfileDeletion(int tenantId, UserInfo user)
{
2019-09-03 12:23:58 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, user.Email, ConfirmType.ProfileRemove);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => CoreContext.Configuration.Personal ? WebstudioNotifyPatternResource.ButtonConfirmTermination : WebstudioNotifyPatternResource.ButtonRemoveProfile;
var action = CoreContext.Configuration.Personal
? (CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModeProfileDelete : Actions.PersonalProfileDelete)
: Actions.ProfileDelete;
client.SendNoticeToAsync(
action,
StudioNotifyHelper.RecipientFromEmail(user.Email, false),
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(CommonTags.Culture, user.GetCulture().Name));
}
public void SendMsgReassignsCompleted(Guid recipientId, UserInfo fromUser, UserInfo toUser)
{
client.SendNoticeToAsync(
Actions.ReassignsCompleted,
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(UserManager, recipientId)),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.FromUserName, fromUser.DisplayUserName(UserManager)),
new TagValue(Tags.FromUserLink, GetUserProfileLink(fromUser, UserManager)),
new TagValue(Tags.ToUserName, toUser.DisplayUserName(UserManager)),
new TagValue(Tags.ToUserLink, GetUserProfileLink(toUser, UserManager)));
}
public void SendMsgReassignsFailed(Guid recipientId, UserInfo fromUser, UserInfo toUser, string message)
{
client.SendNoticeToAsync(
Actions.ReassignsFailed,
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(UserManager, recipientId)),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.FromUserName, fromUser.DisplayUserName(UserManager)),
new TagValue(Tags.FromUserLink, GetUserProfileLink(fromUser, UserManager)),
new TagValue(Tags.ToUserName, toUser.DisplayUserName(UserManager)),
new TagValue(Tags.ToUserLink, GetUserProfileLink(toUser, UserManager)),
new TagValue(Tags.Message, message));
}
public void SendMsgRemoveUserDataCompleted(Guid recipientId, UserInfo user, string fromUserName, long docsSpace, long crmSpace, long mailSpace, long talkSpace)
{
client.SendNoticeToAsync(
CoreContext.Configuration.CustomMode ? Actions.RemoveUserDataCompletedCustomMode : Actions.RemoveUserDataCompleted,
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(UserManager, recipientId)),
new TagValue(Tags.FromUserName, fromUserName.HtmlEncode()),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.FromUserLink, GetUserProfileLink(user, UserManager)),
new TagValue("DocsSpace", FileSizeComment.FilesSizeToString(docsSpace)),
new TagValue("CrmSpace", FileSizeComment.FilesSizeToString(crmSpace)),
new TagValue("MailSpace", FileSizeComment.FilesSizeToString(mailSpace)),
new TagValue("TalkSpace", FileSizeComment.FilesSizeToString(talkSpace)));
}
public void SendMsgRemoveUserDataFailed(Guid recipientId, UserInfo user, string fromUserName, string message)
{
client.SendNoticeToAsync(
Actions.RemoveUserDataFailed,
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
new[] { EMailSenderName },
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(UserManager, recipientId)),
new TagValue(Tags.FromUserName, fromUserName.HtmlEncode()),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.FromUserLink, GetUserProfileLink(user, UserManager)),
new TagValue(Tags.Message, message));
}
2019-08-08 09:26:58 +00:00
public void SendAdminWelcome(UserInfo newUserInfo, int tenantId)
{
2019-09-09 12:56:33 +00:00
if (!UserManager.UserExists(newUserInfo)) return;
if (!newUserInfo.IsActive)
throw new ArgumentException("User is not activated yet!");
INotifyAction notifyAction;
var tagValues = new List<ITagValue>();
if (TenantExtra.Enterprise)
{
var defaultRebranding = MailWhiteLabelSettings.Instance.IsDefault;
notifyAction = defaultRebranding ? Actions.EnterpriseAdminWelcomeV10 : Actions.EnterpriseWhitelabelAdminWelcomeV10;
tagValues.Add(TagValues.GreenButton(() => WebstudioNotifyPatternResource.ButtonAccessControlPanel, CommonLinkUtility.GetFullAbsolutePath("~" + SetupInfo.ControlPanelUrl)));
}
else
{
notifyAction = Actions.SaasAdminWelcomeV10;
tagValues.Add(TagValues.GreenButton(() => WebstudioNotifyPatternResource.ButtonConfigureRightNow, CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetAdministration(ManagementType.General))));
var tenant = CoreContext.TenantManager.GetCurrentTenant();
var analytics = StudioNotifyHelper.GetNotifyAnalytics(tenant.TenantId, notifyAction, false, true, false, false);
tagValues.Add(new TagValue(CommonTags.Analytics, analytics));
tagValues.Add(TagValues.TableTop());
tagValues.Add(TagValues.TableItem(1, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-regional-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_regional, null, null));
tagValues.Add(TagValues.TableItem(2, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-brand-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_brand, null, null));
tagValues.Add(TagValues.TableItem(3, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-customize-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_customize, null, null));
tagValues.Add(TagValues.TableItem(4, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-security-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_security, null, null));
tagValues.Add(TagValues.TableItem(5, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-usertrack-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_usertrack, null, null));
tagValues.Add(TagValues.TableItem(6, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-backup-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_backup, null, null));
tagValues.Add(TagValues.TableItem(7, null, null, "https://static.onlyoffice.com/media/newsletters/images-v10/tips-welcome-telephony-50.png", () => WebstudioNotifyPatternResource.pattern_saas_admin_welcome_v10_item_telephony, null, null));
tagValues.Add(TagValues.TableBottom());
tagValues.Add(new TagValue(CommonTags.Footer, "common"));
}
tagValues.Add(new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()));
2019-09-09 12:56:33 +00:00
tagValues.Add(TagValues.SendFrom(tenantId, UserManager, AuthContext));
client.SendNoticeToAsync(
notifyAction,
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
2019-08-15 12:04:42 +00:00
new[] { EMailSenderName },
tagValues.ToArray());
}
#region Backup & Restore
public void SendMsgBackupCompleted(Guid userId, string link)
{
client.SendNoticeToAsync(
Actions.BackupCreated,
new[] { StudioNotifyHelper.ToRecipient(userId) },
2019-08-15 12:04:42 +00:00
new[] { EMailSenderName },
new TagValue(Tags.OwnerName, UserManager.GetUsers(userId).DisplayUserName(UserManager)));
}
2019-08-08 09:26:58 +00:00
public void SendMsgRestoreStarted(Tenant tenant, bool notifyAllUsers)
{
var owner = UserManager.GetUsers(tenant.OwnerId);
var users =
notifyAllUsers
? StudioNotifyHelper.RecipientFromEmail(UserManager.GetUsers(EmployeeStatus.Active).Where(r => r.ActivationStatus == EmployeeActivationStatus.Activated).Select(u => u.Email).ToArray(), false)
: owner.ActivationStatus == EmployeeActivationStatus.Activated ? StudioNotifyHelper.RecipientFromEmail(owner.Email, false) : new IDirectRecipient[0];
client.SendNoticeToAsync(
Actions.RestoreStarted,
users,
2019-08-01 11:44:50 +00:00
new[] { EMailSenderName });
}
2019-08-08 09:26:58 +00:00
public void SendMsgRestoreCompleted(Tenant tenant, bool notifyAllUsers)
{
var owner = UserManager.GetUsers(tenant.OwnerId);
var users =
notifyAllUsers
? UserManager.GetUsers(EmployeeStatus.Active).Select(u => StudioNotifyHelper.ToRecipient(u.ID)).ToArray()
: new[] { StudioNotifyHelper.ToRecipient(owner.ID) };
client.SendNoticeToAsync(
Actions.RestoreCompleted,
users,
2019-08-15 12:04:42 +00:00
new[] { EMailSenderName },
2019-09-09 12:56:33 +00:00
new TagValue(Tags.OwnerName, owner.DisplayUserName(UserManager)));
}
#endregion
#region Portal Deactivation & Deletion
public void SendMsgPortalDeactivation(Tenant t, string deactivateUrl, string activateUrl)
{
var u = UserManager.GetUsers(t.OwnerId);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonDeactivatePortal;
client.SendNoticeToAsync(
Actions.PortalDeactivate,
new IRecipient[] { u },
new[] { EMailSenderName },
new TagValue(Tags.ActivateUrl, activateUrl),
TagValues.GreenButton(greenButtonText, deactivateUrl),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.OwnerName, u.DisplayUserName(UserManager)));
}
public void SendMsgPortalDeletion(Tenant t, string url, bool showAutoRenewText)
{
var u = UserManager.GetUsers(t.OwnerId);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonDeletePortal;
client.SendNoticeToAsync(
Actions.PortalDelete,
new IRecipient[] { u },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, url),
new TagValue(Tags.AutoRenew, showAutoRenewText.ToString()),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.OwnerName, u.DisplayUserName(UserManager)));
}
public void SendMsgPortalDeletionSuccess(UserInfo owner, string url)
{
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonLeaveFeedback;
client.SendNoticeToAsync(
Actions.PortalDeleteSuccessV10,
new IRecipient[] { owner },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, url),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.OwnerName, owner.DisplayUserName(UserManager)));
}
#endregion
public void SendMsgDnsChange(Tenant t, string confirmDnsUpdateUrl, string portalAddress, string portalDns)
{
var u = UserManager.GetUsers(t.OwnerId);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirmPortalAddressChange;
client.SendNoticeToAsync(
Actions.DnsChange,
new IRecipient[] { u },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmDnsUpdateUrl),
new TagValue("PortalAddress", AddHttpToUrl(portalAddress)),
new TagValue("PortalDns", AddHttpToUrl(portalDns ?? string.Empty)),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.OwnerName, u.DisplayUserName(UserManager)));
}
public void SendMsgConfirmChangeOwner(Tenant t, string newOwnerName, string confirmOwnerUpdateUrl)
{
var u = UserManager.GetUsers(t.OwnerId);
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirmPortalOwnerUpdate;
2019-08-15 12:04:42 +00:00
client.SendNoticeToAsync(
Actions.ConfirmOwnerChange,
new IRecipient[] { u },
new[] { EMailSenderName },
TagValues.GreenButton(greenButtonText, confirmOwnerUpdateUrl),
new TagValue(Tags.UserName, newOwnerName),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.OwnerName, u.DisplayUserName(UserManager)));
}
2019-09-03 12:23:58 +00:00
public void SendCongratulations(int tenantId, UserInfo u)
{
try
{
INotifyAction notifyAction;
var footer = "common";
var analytics = string.Empty;
if (TenantExtra.Enterprise)
{
var defaultRebranding = MailWhiteLabelSettings.Instance.IsDefault;
notifyAction = defaultRebranding ? Actions.EnterpriseAdminActivationV10 : Actions.EnterpriseWhitelabelAdminActivationV10;
footer = null;
}
else if (TenantExtra.Opensource)
{
notifyAction = Actions.OpensourceAdminActivation;
footer = "opensource";
}
else
{
notifyAction = Actions.SaasAdminActivationV10;
var tenant = CoreContext.TenantManager.GetCurrentTenant();
analytics = StudioNotifyHelper.GetNotifyAnalytics(tenant.TenantId, notifyAction, false, true, false, false);
}
2019-09-03 12:23:58 +00:00
var confirmationUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, u.Email, ConfirmType.EmailActivation);
confirmationUrl += "&first=true";
2019-08-15 14:36:08 +00:00
static string greenButtonText() => WebstudioNotifyPatternResource.ButtonConfirm;
client.SendNoticeToAsync(
notifyAction,
StudioNotifyHelper.RecipientFromEmail(u.Email, false),
new[] { EMailSenderName },
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
new TagValue(Tags.MyStaffLink, GetMyStaffLink()),
TagValues.GreenButton(greenButtonText, confirmationUrl),
new TagValue(CommonTags.Footer, footer),
new TagValue(CommonTags.Analytics, analytics));
}
catch (Exception error)
{
LogManager.GetLogger("ASC.Notify").Error(error);
}
}
#region Personal
2019-08-08 09:26:58 +00:00
public void SendInvitePersonal(int tenantId, string email, string additionalMember = "", bool analytics = true)
{
var newUserInfo = UserManager.GetUserByEmail( email);
2019-09-09 12:56:33 +00:00
if (UserManager.UserExists(newUserInfo)) return;
var lang = CoreContext.Configuration.CustomMode
? "ru-RU"
: Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
2019-09-03 12:23:58 +00:00
var confirmUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, email, ConfirmType.EmpInvite, (int)EmployeeType.User)
+ "&emplType=" + (int)EmployeeType.User
+ "&analytics=" + analytics
+ "&lang=" + lang
+ additionalMember;
client.SendNoticeToAsync(
CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModeConfirmation : Actions.PersonalConfirmation,
StudioNotifyHelper.RecipientFromEmail(email, false),
new[] { EMailSenderName },
new TagValue(Tags.InviteLink, confirmUrl),
new TagValue(CommonTags.Footer, CoreContext.Configuration.CustomMode ? "personalCustomMode" : "personal"),
new TagValue(CommonTags.Culture, Thread.CurrentThread.CurrentUICulture.Name));
}
2019-08-09 12:28:19 +00:00
public void SendUserWelcomePersonal(int tenantId, UserInfo newUserInfo)
{
client.SendNoticeToAsync(
CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModeAfterRegistration1 : Actions.PersonalAfterRegistration1,
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, true),
new[] { EMailSenderName },
new TagValue(CommonTags.Footer, CoreContext.Configuration.CustomMode ? "personalCustomMode" : "personal"),
new TagValue(CommonTags.MasterTemplate, "HtmlMasterPersonal"),
2019-09-09 12:56:33 +00:00
TagValues.SendFrom(tenantId, UserManager, AuthContext));
}
#endregion
#region Migration Portal
2019-08-08 09:26:58 +00:00
public void MigrationPortalStart(Tenant tenant, string region, bool notify)
{
2019-08-08 09:26:58 +00:00
MigrationNotify(tenant, Actions.MigrationPortalStart, region, string.Empty, notify);
}
2019-08-08 09:26:58 +00:00
public void MigrationPortalSuccess(Tenant tenant, string region, string url, bool notify)
{
2019-08-08 09:26:58 +00:00
MigrationNotify(tenant, Actions.MigrationPortalSuccess, region, url, notify);
}
2019-08-08 09:26:58 +00:00
public void MigrationPortalError(Tenant tenant, string region, string url, bool notify)
{
2019-08-08 09:26:58 +00:00
MigrationNotify(tenant, !string.IsNullOrEmpty(region) ? Actions.MigrationPortalError : Actions.MigrationPortalServerFailure, region, url, notify);
}
2019-08-08 09:26:58 +00:00
private void MigrationNotify(Tenant tenant, INotifyAction action, string region, string url, bool notify)
{
var users = UserManager.GetUsers()
2019-08-08 09:26:58 +00:00
.Where(u => notify ? u.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated) : u.IsOwner(tenant))
.Select(u => StudioNotifyHelper.ToRecipient(u.ID))
.ToArray();
if (users.Any())
{
client.SendNoticeToAsync(
action,
users,
new[] { EMailSenderName },
new TagValue(Tags.RegionName, TransferResourceHelper.GetRegionDescription(region)),
new TagValue(Tags.PortalUrl, url));
}
}
2019-08-15 13:16:39 +00:00
public void PortalRenameNotify(Tenant tenant, string oldVirtualRootPath)
{
var users = UserManager.GetUsers()
.Where(u => u.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated));
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
2019-08-15 12:04:42 +00:00
CoreContext.TenantManager.SetCurrentTenant(tenant);
foreach (var u in users)
{
var culture = string.IsNullOrEmpty(u.CultureName) ? tenant.GetCulture() : u.GetCulture();
Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
client.SendNoticeToAsync(
Actions.PortalRename,
new[] { StudioNotifyHelper.ToRecipient(u.ID) },
new[] { EMailSenderName },
new TagValue(Tags.PortalUrl, oldVirtualRootPath),
2019-09-09 12:56:33 +00:00
new TagValue(Tags.UserDisplayName, u.DisplayUserName(UserManager)));
}
}
catch (Exception ex)
{
LogManager.GetLogger("ASC.Notify").Error(ex);
}
});
}
#endregion
#region Helpers
private static string GetMyStaffLink()
{
return CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetMyStaff());
}
2019-09-09 12:56:33 +00:00
private static string GetUserProfileLink(UserInfo userInfo, UserManager userManager)
{
2019-09-09 12:56:33 +00:00
return CommonLinkUtility.GetFullAbsolutePath(CommonLinkUtility.GetUserProfile(userInfo, userManager));
}
private static string AddHttpToUrl(string url)
{
var httpPrefix = Uri.UriSchemeHttp + Uri.SchemeDelimiter;
return !string.IsNullOrEmpty(url) && !url.StartsWith(httpPrefix) ? httpPrefix + url : url;
}
2019-09-09 12:56:33 +00:00
private string GenerateActivationConfirmUrl(int tenantId, UserInfo user)
{
2019-09-03 12:23:58 +00:00
var confirmUrl = CommonLinkUtility.GetConfirmationUrl(tenantId, user.Email, ConfirmType.Activation);
2019-08-15 13:16:39 +00:00
return confirmUrl + string.Format("&uid={0}&firstname={1}&lastname={2}",
2019-09-09 12:56:33 +00:00
AuthContext.CurrentAccount.ID,
HttpUtility.UrlEncode(user.FirstName),
HttpUtility.UrlEncode(user.LastName));
}
#endregion
}
}