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
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-01-31 08:30:08 +00:00
|
|
|
using Constants = ASC.Core.Configuration.Constants;
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
namespace ASC.Web.Studio.Core.Notify;
|
|
|
|
|
|
|
|
[Singletone(Additional = typeof(ServiceLauncherExtension))]
|
|
|
|
public class StudioNotifyServiceSender
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
private static string EMailSenderName { get { return Constants.NotifyEMailSenderSysName; } }
|
|
|
|
|
2022-03-31 17:32:46 +00:00
|
|
|
private readonly IServiceScopeFactory _serviceProvider;
|
|
|
|
private readonly IConfiguration _configuration;
|
2022-03-25 14:51:03 +00:00
|
|
|
private readonly WorkContext _workContext;
|
2022-03-31 17:32:46 +00:00
|
|
|
private readonly TenantExtraConfig _tenantExtraConfig;
|
|
|
|
private readonly CoreBaseSettings _coreBaseSettings;
|
|
|
|
|
|
|
|
public StudioNotifyServiceSender(
|
|
|
|
IServiceScopeFactory serviceProvider,
|
|
|
|
IConfiguration configuration,
|
|
|
|
ICacheNotify<NotifyItem> cache,
|
|
|
|
WorkContext workContext,
|
|
|
|
TenantExtraConfig tenantExtraConfig,
|
|
|
|
CoreBaseSettings coreBaseSettings)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
cache.Subscribe(OnMessage, CacheNotifyAction.Any);
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
_configuration = configuration;
|
2022-03-25 14:51:03 +00:00
|
|
|
_workContext = workContext;
|
2022-03-31 17:32:46 +00:00
|
|
|
_tenantExtraConfig = tenantExtraConfig;
|
|
|
|
_coreBaseSettings = coreBaseSettings;
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void OnMessage(NotifyItem item)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
using var scope = _serviceProvider.CreateScope();
|
|
|
|
var scopeClass = scope.ServiceProvider.GetRequiredService<StudioNotifyWorker>();
|
|
|
|
scopeClass.OnMessage(item);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void RegisterSendMethod()
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
var cron = _configuration["core:notify:cron"] ?? "0 0 5 ? * *"; // 5am every day
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-31 17:32:46 +00:00
|
|
|
if (_configuration["core:notify:tariff"] != "false")
|
2022-03-17 15:13:38 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
if (_tenantExtraConfig.Enterprise)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
_workContext.RegisterSendMethod(SendEnterpriseTariffLetters, cron);
|
2019-08-02 10:25:33 +00:00
|
|
|
}
|
2022-03-31 17:32:46 +00:00
|
|
|
else if (_tenantExtraConfig.Opensource)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
_workContext.RegisterSendMethod(SendOpensourceTariffLetters, cron);
|
2019-08-02 10:25:33 +00:00
|
|
|
}
|
2022-03-31 17:32:46 +00:00
|
|
|
else if (_tenantExtraConfig.Saas)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
if (_coreBaseSettings.Personal)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
if (!_coreBaseSettings.CustomMode)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
_workContext.RegisterSendMethod(SendLettersPersonal, cron);
|
2019-08-02 10:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
else
|
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
_workContext.RegisterSendMethod(SendSaasTariffLetters, cron);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 17:32:46 +00:00
|
|
|
if (!_coreBaseSettings.Personal)
|
2019-08-02 10:25:33 +00:00
|
|
|
{
|
2022-03-25 14:51:03 +00:00
|
|
|
_workContext.RegisterSendMethod(SendMsgWhatsNew, "0 0 * ? * *"); // every hour
|
2019-08-02 10:25:33 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void SendSaasTariffLetters(DateTime scheduleDate)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
using var scope = _serviceProvider.CreateScope();
|
2022-03-17 15:13:38 +00:00
|
|
|
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendSaasLettersAsync(EMailSenderName, scheduleDate).Wait();
|
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void SendEnterpriseTariffLetters(DateTime scheduleDate)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
using var scope = _serviceProvider.CreateScope();
|
2022-03-17 15:13:38 +00:00
|
|
|
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendEnterpriseLetters(EMailSenderName, scheduleDate);
|
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void SendOpensourceTariffLetters(DateTime scheduleDate)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
using var scope = _serviceProvider.CreateScope();
|
2022-03-17 15:13:38 +00:00
|
|
|
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendOpensourceLetters(EMailSenderName, scheduleDate);
|
|
|
|
}
|
2019-08-02 10:25:33 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void SendLettersPersonal(DateTime scheduleDate)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
using var scope = _serviceProvider.CreateScope();
|
2022-03-17 15:13:38 +00:00
|
|
|
scope.ServiceProvider.GetService<StudioPeriodicNotify>().SendPersonalLetters(EMailSenderName, scheduleDate);
|
2020-08-24 18:41:06 +00:00
|
|
|
}
|
2020-07-30 13:33:54 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public void SendMsgWhatsNew(DateTime scheduleDate)
|
2020-08-24 18:41:06 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
using var scope = _serviceProvider.CreateScope();
|
2022-03-29 10:53:05 +00:00
|
|
|
scope.ServiceProvider.GetRequiredService<StudioWhatsNewNotify>().SendMsgWhatsNew(scheduleDate);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-31 08:18:07 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
[Scope]
|
2022-03-31 17:32:46 +00:00
|
|
|
public class StudioNotifyWorker
|
2022-03-17 15:13:38 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
private readonly CommonLinkUtilitySettings _commonLinkUtilitySettings;
|
|
|
|
private readonly NotifyEngineQueue _notifyEngineQueue;
|
|
|
|
private readonly WorkContext _workContext;
|
|
|
|
private readonly TenantManager _tenantManager;
|
|
|
|
private readonly UserManager _userManager;
|
|
|
|
private readonly SecurityContext _securityContext;
|
|
|
|
private readonly StudioNotifyHelper _studioNotifyHelper;
|
|
|
|
|
|
|
|
public StudioNotifyWorker(
|
|
|
|
TenantManager tenantManager,
|
2022-03-17 15:13:38 +00:00
|
|
|
UserManager userManager,
|
|
|
|
SecurityContext securityContext,
|
|
|
|
StudioNotifyHelper studioNotifyHelper,
|
2022-03-31 17:32:46 +00:00
|
|
|
CommonLinkUtilitySettings commonLinkUtilitySettings,
|
|
|
|
NotifyEngineQueue notifyEngineQueue,
|
|
|
|
WorkContext workContext)
|
2022-03-17 15:13:38 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
_tenantManager = tenantManager;
|
|
|
|
_userManager = userManager;
|
|
|
|
_securityContext = securityContext;
|
|
|
|
_studioNotifyHelper = studioNotifyHelper;
|
|
|
|
_commonLinkUtilitySettings = commonLinkUtilitySettings;
|
|
|
|
_notifyEngineQueue = notifyEngineQueue;
|
|
|
|
_workContext = workContext;
|
2019-08-02 10:25:33 +00:00
|
|
|
}
|
2019-11-01 08:49:08 +00:00
|
|
|
|
2022-03-31 17:32:46 +00:00
|
|
|
public void OnMessage(NotifyItem item)
|
2019-11-01 08:49:08 +00:00
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
_commonLinkUtilitySettings.ServerUri = item.BaseUrl;
|
|
|
|
_tenantManager.SetCurrentTenant(item.TenantId);
|
|
|
|
|
|
|
|
CultureInfo culture = null;
|
|
|
|
|
|
|
|
var client = _workContext.NotifyContext.RegisterClient(_notifyEngineQueue, _studioNotifyHelper.NotifySource);
|
|
|
|
|
|
|
|
var tenant = _tenantManager.GetCurrentTenant(false);
|
|
|
|
|
|
|
|
if (tenant != null)
|
|
|
|
{
|
|
|
|
culture = tenant.GetCulture();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Guid.TryParse(item.UserId, out var userId) && !userId.Equals(Constants.Guest.ID) && !userId.Equals(Guid.Empty))
|
|
|
|
{
|
|
|
|
_securityContext.AuthenticateMeWithoutCookie(Guid.Parse(item.UserId));
|
|
|
|
var user = _userManager.GetUsers(userId);
|
|
|
|
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.Count > 0 ? item.SenderNames.ToArray() : null,
|
|
|
|
item.CheckSubsciption,
|
|
|
|
item.Tags.Select(r => new TagValue(r.Tag_, r.Value)).ToArray());
|
2020-08-31 08:18:07 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static class ServiceLauncherExtension
|
|
|
|
{
|
|
|
|
public static void Register(DIHelper services)
|
|
|
|
{
|
2022-03-31 17:32:46 +00:00
|
|
|
services.TryAdd<StudioNotifyWorker>();
|
2022-03-17 15:13:38 +00:00
|
|
|
services.TryAdd<StudioPeriodicNotify>();
|
|
|
|
services.TryAdd<StudioWhatsNewNotify>();
|
2019-11-01 08:49:08 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|