fix bug 57725

This commit is contained in:
pavelbannov 2022-06-29 15:10:56 +03:00
parent be08c35421
commit 5f6851253f
3 changed files with 75 additions and 108 deletions

View File

@ -210,7 +210,7 @@ namespace ASC.Common.Caching
private string GetChannelName(CacheNotifyAction cacheNotifyAction)
{
return $"ascchannel{cacheNotifyAction}{typeof(T).FullName}".ToLower();
return $"ascchannel{cacheNotifyAction}{typeof(T).FullName}".ToLowerInvariant();
}
public void Unsubscribe(CacheNotifyAction action)

View File

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Linq;
using ASC.Common;
using ASC.Common.Caching;
@ -18,8 +17,6 @@ namespace ASC.Web.Core.Notify
[Scope]
public class StudioNotifyServiceHelper
{
private readonly ILog _log;
private ICacheNotify<NotifyItem> Cache { get; }
private StudioNotifyHelper StudioNotifyHelper { get; }
private AuthContext AuthContext { get; }
@ -39,7 +36,6 @@ namespace ASC.Web.Core.Notify
TenantManager = tenantManager;
CommonLinkUtility = commonLinkUtility;
Cache = cache;
_log = options.CurrentValue;
}
public void SendNoticeToAsync(INotifyAction action, IRecipient[] recipients, string[] senderNames, params ITagValue[] args)
@ -82,62 +78,51 @@ namespace ASC.Web.Core.Notify
public void SendNoticeToAsync(INotifyAction action, string objectID, IRecipient[] recipients, string[] senderNames, bool checkSubsciption, params ITagValue[] args)
{
try
var item = new NotifyItem
{
_log.Debug("SendNoticeToAsync begin");
var item = new NotifyItem
{
TenantId = TenantManager.GetCurrentTenant().TenantId,
UserId = AuthContext.CurrentAccount.ID.ToString(),
Action = (NotifyAction)action,
CheckSubsciption = checkSubsciption,
BaseUrl = CommonLinkUtility.GetFullAbsolutePath("")
};
TenantId = TenantManager.GetCurrentTenant().TenantId,
UserId = AuthContext.CurrentAccount.ID.ToString(),
Action = (NotifyAction)action,
CheckSubsciption = checkSubsciption,
BaseUrl = CommonLinkUtility.GetFullAbsolutePath("")
};
if (objectID != null)
{
item.ObjectId = objectID;
}
if (objectID != null)
{
item.ObjectId = objectID;
}
if (recipients != null)
if (recipients != null)
{
foreach (var r in recipients)
{
foreach (var r in recipients)
var recipient = new Recipient { Id = r.ID, Name = r.Name };
if (r is IDirectRecipient d)
{
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);
recipient.Addresses.AddRange(d.Addresses);
recipient.CheckActivation = d.CheckActivation;
}
if (r is IRecipientsGroup g)
{
recipient.IsGroup = true;
}
item.Recipients.Add(recipient);
}
_log.Debug("SendNoticeToAsync middle");
if (senderNames != null)
{
item.SenderNames.AddRange(senderNames);
}
if (args != null)
{
item.Tags.AddRange(args.Select(r => new Tag { Tag_ = r.Tag, Value = r.Value.ToString() }));
}
Cache.Publish(item, CacheNotifyAction.Any);
_log.Debug("SendNoticeToAsync end");
}
catch (Exception e)
if (senderNames != null)
{
_log.Error("SendNoticeToAsync", e);
item.SenderNames.AddRange(senderNames);
}
if (args != null)
{
item.Tags.AddRange(args.Select(r => new Tag { Tag_ = r.Tag, Value = r.Value.ToString() }));
}
Cache.Publish(item, CacheNotifyAction.Any);
}
}
}

View File

@ -31,7 +31,6 @@ using System.Threading;
using ASC.Common;
using ASC.Common.Caching;
using ASC.Common.Logging;
using ASC.Core;
using ASC.Core.Common;
using ASC.Core.Configuration;
@ -42,7 +41,6 @@ using ASC.Web.Studio.Utility;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace ASC.Web.Studio.Core.Notify
{
@ -64,65 +62,49 @@ namespace ASC.Web.Studio.Core.Notify
public void OnMessage(NotifyItem item)
{
using var scope = ServiceProvider.CreateScope();
var log = scope.ServiceProvider.GetService<IOptionsMonitor<ILog>>().CurrentValue;
try
var commonLinkUtilitySettings = scope.ServiceProvider.GetService<CommonLinkUtilitySettings>();
commonLinkUtilitySettings.ServerUri = item.BaseUrl;
var scopeClass = scope.ServiceProvider.GetService<StudioNotifyServiceSenderScope>();
var (tenantManager, userManager, securityContext, studioNotifyHelper, _, _) = scopeClass;
tenantManager.SetCurrentTenant(item.TenantId);
CultureInfo culture = null;
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
var tenant = tenantManager.GetCurrentTenant(false);
if (tenant != null)
{
log.Debug("onMessage try");//temp
var commonLinkUtilitySettings = scope.ServiceProvider.GetService<CommonLinkUtilitySettings>();
commonLinkUtilitySettings.ServerUri = item.BaseUrl;
var scopeClass = scope.ServiceProvider.GetService<StudioNotifyServiceSenderScope>();
var (tenantManager, userManager, securityContext, studioNotifyHelper, _, _) = scopeClass;
tenantManager.SetCurrentTenant(item.TenantId);
CultureInfo culture = null;
var client = WorkContext.NotifyContext.NotifyService.RegisterClient(studioNotifyHelper.NotifySource, scope);
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);
}
}
log.Debug("onMessage UserId");//temp
if (culture != null && !Equals(Thread.CurrentThread.CurrentCulture, culture))
{
Thread.CurrentThread.CurrentCulture = culture;
}
if (culture != null && !Equals(Thread.CurrentThread.CurrentUICulture, culture))
{
Thread.CurrentThread.CurrentUICulture = culture;
}
log.Debug("onMessage culture");//temp
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());
log.Debug("onMessage send");//temp
culture = tenant.GetCulture();
}
catch (Exception e)
if (Guid.TryParse(item.UserId, out var userId) && !userId.Equals(Constants.Guest.ID) && !userId.Equals(Guid.Empty))
{
log.Error("onMessage", e);
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());
}
public void RegisterSendMethod()