Merge branch 'master' of github.com:ONLYOFFICE/CommunityServer-AspNetCore
This commit is contained in:
commit
07b10a878d
@ -56,7 +56,8 @@
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Protobuf Include="protos/AscCacheItem.proto" />
|
||||
<Protobuf Include="protos\AscCacheItem.proto" />
|
||||
<Protobuf Include="protos\NotifyItem.proto" />
|
||||
<Protobuf Include="protos\DistributedTaskCache.proto" />
|
||||
<Protobuf Include="protos\DistributedTaskCancelation.proto" />
|
||||
</ItemGroup>
|
||||
|
@ -36,7 +36,9 @@ namespace ASC.Notify
|
||||
|
||||
public interface INotifyClient
|
||||
{
|
||||
void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, params ITagValue[] args);
|
||||
void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, params ITagValue[] args);
|
||||
|
||||
void SendNoticeToAsync(INotifyAction action, IRecipient[] recipients, string[] senderNames, params ITagValue[] args);
|
||||
|
||||
void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, params ITagValue[] args);
|
||||
|
||||
@ -47,7 +49,8 @@ namespace ASC.Notify
|
||||
void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, params ITagValue[] args);
|
||||
|
||||
void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, bool checkSubscription, params ITagValue[] args);
|
||||
|
||||
|
||||
void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args);
|
||||
|
||||
INotifyClient RegisterSendMethod(Action<DateTime> method, string cron);
|
||||
|
||||
|
@ -48,6 +48,16 @@ namespace ASC.Notify.Model
|
||||
ID = id;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public static implicit operator NotifyActionItem(NotifyAction cache)
|
||||
{
|
||||
return new NotifyActionItem() { ID = cache.ID, Name = cache.Name };
|
||||
}
|
||||
|
||||
public static explicit operator NotifyAction(NotifyActionItem cache)
|
||||
{
|
||||
return new NotifyAction(cache.ID, cache.Name);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
|
@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System;
|
||||
using ASC.Notify.Engine;
|
||||
using ASC.Notify.Patterns;
|
||||
using ASC.Notify.Recipients;
|
||||
@ -39,14 +39,15 @@ namespace ASC.Notify.Model
|
||||
|
||||
|
||||
public NotifyClientImpl(Context context, INotifySource notifySource)
|
||||
{
|
||||
if (notifySource == null) throw new ArgumentNullException("notifySource");
|
||||
if (context == null) throw new ArgumentNullException("context");
|
||||
|
||||
this.notifySource = notifySource;
|
||||
ctx = context;
|
||||
}
|
||||
|
||||
{
|
||||
this.notifySource = notifySource ?? throw new ArgumentNullException("notifySource");
|
||||
ctx = context ?? throw new ArgumentNullException("context");
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, null, recipients, senderNames, false, args);
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
|
||||
{
|
||||
@ -116,9 +117,9 @@ namespace ASC.Notify.Model
|
||||
}
|
||||
|
||||
|
||||
private void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
|
||||
{
|
||||
if (recipients == null) throw new ArgumentNullException("recipients");
|
||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
|
||||
{
|
||||
if (recipients == null) throw new ArgumentNullException("recipients");
|
||||
|
||||
BeginSingleRecipientEvent("__syspreventduplicateinterceptor");
|
||||
|
||||
@ -145,6 +146,6 @@ namespace ASC.Notify.Model
|
||||
request.IsNeedCheckSubscriptions = checkSubsciption;
|
||||
if (args != null) request.Arguments.AddRange(args);
|
||||
return request;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -24,13 +24,9 @@
|
||||
*/
|
||||
|
||||
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Notify.Recipients
|
||||
{
|
||||
[Serializable]
|
||||
|
@ -24,12 +24,8 @@
|
||||
*/
|
||||
|
||||
|
||||
#region usings
|
||||
|
||||
using System;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace ASC.Notify.Recipients
|
||||
{
|
||||
[Serializable]
|
||||
|
32
common/ASC.Common/protos/NotifyItem.proto
Normal file
32
common/ASC.Common/protos/NotifyItem.proto
Normal file
@ -0,0 +1,32 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Notify.Model;
|
||||
|
||||
message NotifyItem {
|
||||
NotifyActionItem Action = 1;
|
||||
string ObjectID = 2;
|
||||
repeated Recipient Recipients = 3;
|
||||
repeated string SenderNames = 4;
|
||||
repeated Tag Tags = 5;
|
||||
bool CheckSubsciption = 6;
|
||||
int32 TenantId = 7;
|
||||
string UserId = 8;
|
||||
}
|
||||
|
||||
message NotifyActionItem {
|
||||
string ID = 1;
|
||||
string Name = 2;
|
||||
}
|
||||
|
||||
message Recipient {
|
||||
string ID = 1;
|
||||
string Name = 2;
|
||||
bool CheckActivation = 3;
|
||||
repeated string Addresses = 4;
|
||||
bool IsGroup = 5;
|
||||
}
|
||||
|
||||
message Tag {
|
||||
string Tag = 1;
|
||||
string Value = 2;
|
||||
}
|
@ -197,14 +197,20 @@ namespace ASC.Core.Data
|
||||
private IEnumerable<SubscriptionRecord> GetSubscriptions(ISqlInstruction q, int tenant)
|
||||
{
|
||||
var subs = ExecList(q)
|
||||
.ConvertAll(r => new SubscriptionRecord
|
||||
{
|
||||
Tenant = Convert.ToInt32(r[0]),
|
||||
SourceId = (string)r[1],
|
||||
ActionId = (string)r[2],
|
||||
RecipientId = (string)r[3],
|
||||
ObjectId = string.Empty.Equals(r[4]) ? null : (string)r[4],
|
||||
Subscribed = !Convert.ToBoolean(r[5]),
|
||||
.ConvertAll(r => {
|
||||
var result = new SubscriptionRecord
|
||||
{
|
||||
Tenant = Convert.ToInt32(r[0]),
|
||||
SourceId = (string)r[1],
|
||||
ActionId = (string)r[2],
|
||||
RecipientId = (string)r[3],
|
||||
Subscribed = !Convert.ToBoolean(r[5]),
|
||||
};
|
||||
if (!string.Empty.Equals(r[4]))
|
||||
{
|
||||
result.ObjectId = (string)r[4];
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
var result = subs.ToList();
|
||||
|
@ -41,7 +41,7 @@ namespace ASC.Studio.Notify
|
||||
{
|
||||
services.AddAutofac(hostContext.Configuration, hostContext.HostingEnvironment.ContentRootPath);
|
||||
services.AddWebItemManager();
|
||||
services.AddSingleton<StudioNotifyService>();
|
||||
services.AddSingleton<StudioNotifyServiceSender>();
|
||||
services.AddHostedService<ServiceLauncher>();
|
||||
services.AddHttpContextAccessor()
|
||||
.AddStorage()
|
||||
|
@ -38,12 +38,12 @@ namespace ASC.Notify
|
||||
public class ServiceLauncher : IHostedService
|
||||
{
|
||||
public WebItemManager WebItemManager { get; }
|
||||
public StudioNotifyService StudioNotifyService { get; }
|
||||
public StudioNotifyServiceSender StudioNotifyServiceSender { get; }
|
||||
|
||||
public ServiceLauncher(WebItemManager webItemManager, StudioNotifyService studioNotifyService)
|
||||
public ServiceLauncher(WebItemManager webItemManager, StudioNotifyServiceSender studioNotifyServiceSender)
|
||||
{
|
||||
WebItemManager = webItemManager;
|
||||
StudioNotifyService = studioNotifyService;
|
||||
StudioNotifyServiceSender = studioNotifyServiceSender;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
@ -52,7 +52,7 @@ namespace ASC.Notify
|
||||
NotifyConfiguration.Configure();
|
||||
WebItemManager.LoadItems();
|
||||
|
||||
StudioNotifyService.RegisterSendMethod();
|
||||
StudioNotifyServiceSender.RegisterSendMethod();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
@ -32,15 +32,14 @@ using System.Threading;
|
||||
using System.Web;
|
||||
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Notify;
|
||||
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;
|
||||
@ -50,79 +49,15 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
public class StudioNotifyService
|
||||
{
|
||||
private readonly INotifyClient client;
|
||||
private readonly StudioNotifyServiceHelper client;
|
||||
|
||||
private static string EMailSenderName { get { return ASC.Core.Configuration.Constants.NotifyEMailSenderSysName; } }
|
||||
|
||||
public StudioNotifyService()
|
||||
{
|
||||
client = WorkContext.NotifyContext.NotifyService.RegisterClient(StudioNotifyHelper.NotifySource);
|
||||
client = new StudioNotifyServiceHelper();
|
||||
}
|
||||
|
||||
|
||||
#region Periodic Notify
|
||||
|
||||
public void RegisterSendMethod()
|
||||
{
|
||||
var cron = ConfigurationManager.AppSettings["core:notify:cron"] ?? "0 0 5 ? * *"; // 5am every day
|
||||
|
||||
if (ConfigurationManager.AppSettings["core:notify:tariff"] != "false")
|
||||
{
|
||||
if (TenantExtra.Enterprise)
|
||||
{
|
||||
client.RegisterSendMethod(SendEnterpriseTariffLetters, cron);
|
||||
}
|
||||
else if (TenantExtra.Opensource)
|
||||
{
|
||||
client.RegisterSendMethod(SendOpensourceTariffLetters, cron);
|
||||
}
|
||||
else if (TenantExtra.Saas)
|
||||
{
|
||||
if (CoreContext.Configuration.Personal)
|
||||
{
|
||||
client.RegisterSendMethod(SendLettersPersonal, cron);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.RegisterSendMethod(SendSaasTariffLetters, cron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!CoreContext.Configuration.Personal)
|
||||
{
|
||||
client.RegisterSendMethod(SendMsgWhatsNew, "0 0 * ? * *"); // every hour
|
||||
}
|
||||
}
|
||||
|
||||
public void SendSaasTariffLetters(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendSaasLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendEnterpriseTariffLetters(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendEnterpriseLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendOpensourceTariffLetters(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendOpensourceLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendLettersPersonal(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendPersonalLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendMsgWhatsNew(DateTime scheduleDate)
|
||||
{
|
||||
StudioWhatsNewNotify.SendMsgWhatsNew(scheduleDate, client);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public void SendMsgToAdminAboutProfileUpdated()
|
||||
{
|
||||
client.SendNoticeAsync(Actions.SelfProfileUpdated, null);
|
||||
@ -157,7 +92,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
var recipient = (IRecipient)(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), String.Empty, new[] { salesEmail }, false));
|
||||
|
||||
client.SendNoticeToAsync(license ? Actions.RequestLicense : Actions.RequestTariff,
|
||||
null,
|
||||
new[] { recipient },
|
||||
new[] { "email.sender" },
|
||||
new TagValue(Tags.UserName, fname),
|
||||
@ -200,7 +134,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl));
|
||||
@ -222,7 +155,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl),
|
||||
@ -237,7 +169,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.ActivateEmail,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(email, false),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.InviteLink, confirmationUrl),
|
||||
@ -284,7 +215,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
skipSettings
|
||||
? Actions.MailboxWithoutSettingsCreated
|
||||
: Actions.MailboxCreated,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(email, false),
|
||||
new[] {EMailSenderName},
|
||||
tags.ToArray());
|
||||
@ -297,7 +227,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
Actions.MailboxPasswordChanged,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(email, false),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, username ?? string.Empty),
|
||||
@ -315,7 +244,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.PhoneChange,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl));
|
||||
@ -329,7 +257,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.TfaChange,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(userInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl));
|
||||
@ -350,7 +277,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.JoinUsers,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(email, true),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.InviteLink, inviteUrl),
|
||||
@ -402,7 +328,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
notifyAction,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
|
||||
@ -440,7 +365,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
notifyAction,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, newUserInfo.FirstName.HtmlEncode()),
|
||||
@ -478,7 +402,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
notifyAction,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl),
|
||||
@ -516,7 +439,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
notifyAction,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl),
|
||||
@ -538,7 +460,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(user.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmationUrl),
|
||||
@ -549,7 +470,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
Actions.ReassignsCompleted,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(recipientId)),
|
||||
@ -563,7 +483,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
Actions.ReassignsFailed,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(recipientId)),
|
||||
@ -578,7 +497,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
CoreContext.Configuration.CustomMode ? Actions.RemoveUserDataCompletedCustomMode : Actions.RemoveUserDataCompleted,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(recipientId)),
|
||||
@ -594,7 +512,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
Actions.RemoveUserDataFailed,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(recipientId) },
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, DisplayUserSettings.GetFullUserName(recipientId)),
|
||||
@ -648,7 +565,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
notifyAction,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, false),
|
||||
new[] {EMailSenderName},
|
||||
tagValues.ToArray());
|
||||
@ -660,7 +576,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
Actions.BackupCreated,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(userId) },
|
||||
new[] {EMailSenderName},
|
||||
new TagValue(Tags.OwnerName, CoreContext.UserManager.GetUsers(userId).DisplayUserName()));
|
||||
@ -676,7 +591,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.RestoreStarted,
|
||||
null,
|
||||
users,
|
||||
new[] { EMailSenderName });
|
||||
}
|
||||
@ -692,7 +606,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.RestoreCompleted,
|
||||
null,
|
||||
users,
|
||||
new[] {EMailSenderName},
|
||||
new TagValue(Tags.OwnerName, owner.DisplayUserName()));
|
||||
@ -710,7 +623,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.PortalDeactivate,
|
||||
null,
|
||||
new IRecipient[] { u },
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.ActivateUrl, activateUrl),
|
||||
@ -726,7 +638,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.PortalDelete,
|
||||
null,
|
||||
new IRecipient[] { u },
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, url),
|
||||
@ -740,7 +651,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.PortalDeleteSuccessV10,
|
||||
null,
|
||||
new IRecipient[] { owner },
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, url),
|
||||
@ -757,7 +667,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.DnsChange,
|
||||
null,
|
||||
new IRecipient[] { u },
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmDnsUpdateUrl),
|
||||
@ -775,7 +684,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.ConfirmOwnerChange,
|
||||
null,
|
||||
new IRecipient[] { u },
|
||||
new[] { EMailSenderName },
|
||||
TagValues.GreenButton(greenButtonText, confirmOwnerUpdateUrl),
|
||||
@ -817,7 +725,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
notifyAction,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(u.Email, false),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
|
||||
@ -851,7 +758,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModeConfirmation : Actions.PersonalConfirmation,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(email, false),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.InviteLink, confirmUrl),
|
||||
@ -863,7 +769,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
CoreContext.Configuration.CustomMode ? Actions.PersonalCustomModeAfterRegistration1 : Actions.PersonalAfterRegistration1,
|
||||
null,
|
||||
StudioNotifyHelper.RecipientFromEmail(newUserInfo.Email, true),
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(CommonTags.Footer, CoreContext.Configuration.CustomMode ? "personalCustomMode" : "personal"),
|
||||
@ -901,7 +806,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
users,
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.RegionName, TransferResourceHelper.GetRegionDescription(region)),
|
||||
@ -930,7 +834,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
Actions.PortalRename,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(u.ID) },
|
||||
new[] { EMailSenderName },
|
||||
new TagValue(Tags.PortalUrl, oldVirtualRootPath),
|
||||
|
104
web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs
Normal file
104
web/ASC.Web.Core/Notify/StudioNotifyServiceHelper.cs
Normal file
@ -0,0 +1,104 @@
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Core;
|
||||
using ASC.Notify.Model;
|
||||
using ASC.Notify.Patterns;
|
||||
using ASC.Notify.Recipients;
|
||||
using ASC.Web.Studio.Core.Notify;
|
||||
|
||||
namespace ASC.Web.Core.Notify
|
||||
{
|
||||
public class StudioNotifyServiceHelper
|
||||
{
|
||||
private readonly ICacheNotify<NotifyItem> cache;
|
||||
|
||||
public StudioNotifyServiceHelper()
|
||||
{
|
||||
cache = new KafkaCache<NotifyItem>();
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, null, recipients, senderNames, false, args);
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, objectID, recipients, senderNames, false, args);
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, objectID, recipients, null, false, args);
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, bool checkSubscription, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, objectID, recipients, null, checkSubscription, args);
|
||||
}
|
||||
|
||||
public void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, objectID, new[] { recipient }, null, false, args);
|
||||
}
|
||||
|
||||
public void SendNoticeAsync(INotifyAction action, string objectID, params ITagValue[] args)
|
||||
{
|
||||
var subscriptionSource = StudioNotifyHelper.NotifySource.GetSubscriptionProvider();
|
||||
var recipients = subscriptionSource.GetRecipients(action, objectID);
|
||||
|
||||
SendNoticeToAsync(action, objectID, recipients, null, false, args);
|
||||
}
|
||||
|
||||
public void SendNoticeAsync(INotifyAction action, string objectID, IRecipient recipient, bool checkSubscription, params ITagValue[] args)
|
||||
{
|
||||
SendNoticeToAsync(action, objectID, new[] { recipient }, null, checkSubscription, args);
|
||||
}
|
||||
|
||||
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
|
||||
{
|
||||
var item = new NotifyItem
|
||||
{
|
||||
TenantId = CoreContext.TenantManager.GetCurrentTenant().TenantId,
|
||||
UserId = SecurityContext.CurrentAccount.ID.ToString(),
|
||||
Action = (NotifyAction)action,
|
||||
CheckSubsciption = checkSubsciption
|
||||
};
|
||||
|
||||
if(objectID != null)
|
||||
{
|
||||
item.ObjectID = objectID;
|
||||
}
|
||||
|
||||
if (recipients != null)
|
||||
{
|
||||
foreach (var r in recipients)
|
||||
{
|
||||
var recipient = new Recipient { ID = r.ID, Name = r.Name };
|
||||
if (r is IDirectRecipient d)
|
||||
{
|
||||
recipient.Addresses.AddRange(d.Addresses);
|
||||
recipient.CheckActivation = d.CheckActivation;
|
||||
}
|
||||
|
||||
if (r is IRecipientsGroup g)
|
||||
{
|
||||
recipient.IsGroup = true;
|
||||
}
|
||||
|
||||
item.Recipients.Add(recipient);
|
||||
}
|
||||
}
|
||||
|
||||
if (senderNames != null)
|
||||
{
|
||||
item.SenderNames.AddRange(senderNames);
|
||||
}
|
||||
|
||||
item.Tags.AddRange(args.Select(r => new Tag { Tag_ = r.Tag, Value = r.Value.ToString() }));
|
||||
|
||||
cache.Publish(item, CacheNotifyAction.Any);
|
||||
}
|
||||
}
|
||||
}
|
150
web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs
Normal file
150
web/ASC.Web.Core/Notify/StudioNotifyServiceSender.cs
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
*
|
||||
* (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.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Core;
|
||||
using ASC.Notify;
|
||||
using ASC.Notify.Model;
|
||||
using ASC.Notify.Patterns;
|
||||
using ASC.Notify.Recipients;
|
||||
using ASC.Web.Studio.Utility;
|
||||
|
||||
namespace ASC.Web.Studio.Core.Notify
|
||||
{
|
||||
public class StudioNotifyServiceSender
|
||||
{
|
||||
private readonly INotifyClient client;
|
||||
private readonly ICacheNotify<NotifyItem> cache;
|
||||
|
||||
private static string EMailSenderName { get { return ASC.Core.Configuration.Constants.NotifyEMailSenderSysName; } }
|
||||
|
||||
public StudioNotifyServiceSender()
|
||||
{
|
||||
client = WorkContext.NotifyContext.NotifyService.RegisterClient(StudioNotifyHelper.NotifySource);
|
||||
cache = new KafkaCache<NotifyItem>();
|
||||
cache.Subscribe(OnMessage, CacheNotifyAction.Any);
|
||||
}
|
||||
|
||||
public void OnMessage(NotifyItem item)
|
||||
{
|
||||
CoreContext.TenantManager.SetCurrentTenant(item.TenantId);
|
||||
SecurityContext.AuthenticateMe(Guid.Parse(item.UserId));
|
||||
CultureInfo culture = null;
|
||||
|
||||
var tenant = CoreContext.TenantManager.GetCurrentTenant(false);
|
||||
if (tenant != null)
|
||||
{
|
||||
culture = tenant.GetCulture();
|
||||
}
|
||||
|
||||
var user = CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID);
|
||||
if (!string.IsNullOrEmpty(user.CultureName))
|
||||
{
|
||||
culture = CultureInfo.GetCultureInfo(user.CultureName);
|
||||
}
|
||||
|
||||
if (culture != null && !Equals(Thread.CurrentThread.CurrentCulture, culture))
|
||||
{
|
||||
Thread.CurrentThread.CurrentCulture = culture;
|
||||
}
|
||||
if (culture != null && !Equals(Thread.CurrentThread.CurrentUICulture, culture))
|
||||
{
|
||||
Thread.CurrentThread.CurrentUICulture = culture;
|
||||
}
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
(NotifyAction)item.Action,
|
||||
item.ObjectID,
|
||||
item.Recipients?.Select(r=> r.IsGroup ? new RecipientsGroup(r.ID, r.Name) : (IRecipient)new DirectRecipient(r.ID, r.Name, r.Addresses.ToArray(),r.CheckActivation)).ToArray(),
|
||||
item.SenderNames.Any() ? item.SenderNames.ToArray() : null,
|
||||
item.CheckSubsciption,
|
||||
item.Tags.Select(r => new TagValue(r.Tag_, r.Value)).ToArray());
|
||||
}
|
||||
|
||||
public void RegisterSendMethod()
|
||||
{
|
||||
var cron = ConfigurationManager.AppSettings["core:notify:cron"] ?? "0 0 5 ? * *"; // 5am every day
|
||||
|
||||
if (ConfigurationManager.AppSettings["core:notify:tariff"] != "false")
|
||||
{
|
||||
if (TenantExtra.Enterprise)
|
||||
{
|
||||
client.RegisterSendMethod(SendEnterpriseTariffLetters, cron);
|
||||
}
|
||||
else if (TenantExtra.Opensource)
|
||||
{
|
||||
client.RegisterSendMethod(SendOpensourceTariffLetters, cron);
|
||||
}
|
||||
else if (TenantExtra.Saas)
|
||||
{
|
||||
if (CoreContext.Configuration.Personal)
|
||||
{
|
||||
client.RegisterSendMethod(SendLettersPersonal, cron);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.RegisterSendMethod(SendSaasTariffLetters, cron);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!CoreContext.Configuration.Personal)
|
||||
{
|
||||
client.RegisterSendMethod(SendMsgWhatsNew, "0 0 * ? * *"); // every hour
|
||||
}
|
||||
}
|
||||
|
||||
public void SendSaasTariffLetters(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendSaasLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendEnterpriseTariffLetters(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendEnterpriseLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendOpensourceTariffLetters(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendOpensourceLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendLettersPersonal(DateTime scheduleDate)
|
||||
{
|
||||
StudioPeriodicNotify.SendPersonalLetters(client, EMailSenderName, scheduleDate);
|
||||
}
|
||||
|
||||
public void SendMsgWhatsNew(DateTime scheduleDate)
|
||||
{
|
||||
StudioWhatsNewNotify.SendMsgWhatsNew(scheduleDate, client);
|
||||
}
|
||||
}
|
||||
}
|
@ -462,7 +462,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(u.ID) },
|
||||
new[] { senderName },
|
||||
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
|
||||
@ -846,7 +845,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(u.ID) },
|
||||
new[] { senderName },
|
||||
new TagValue(Tags.UserName, u.FirstName.HtmlEncode()),
|
||||
@ -1026,7 +1024,6 @@ namespace ASC.Web.Studio.Core.Notify
|
||||
|
||||
client.SendNoticeToAsync(
|
||||
action,
|
||||
null,
|
||||
new[] { StudioNotifyHelper.ToRecipient(u.ID) },
|
||||
new[] { senderName },
|
||||
new TagValue(Tags.UserName, u.DisplayUserName()),
|
||||
|
Loading…
Reference in New Issue
Block a user