DocSpace-buildtools/common/services/ASC.Feed.Aggregator/Modules/FeedModule.cs

93 lines
2.9 KiB
C#
Raw Normal View History

2022-03-15 16:59:24 +00:00
namespace ASC.Feed.Aggregator.Modules;
public abstract class FeedModule : IFeedModule
2020-06-03 14:53:58 +00:00
{
public abstract string Name { get; }
public abstract string Product { get; }
public abstract Guid ProductID { get; }
protected abstract string DbId { get; }
protected int Tenant => TenantManager.GetCurrentTenant().Id;
2020-06-03 14:53:58 +00:00
protected readonly TenantManager TenantManager;
protected readonly WebItemSecurity WebItemSecurity;
2020-06-03 14:53:58 +00:00
protected FeedModule(TenantManager tenantManager, WebItemSecurity webItemSecurity)
{
TenantManager = tenantManager;
WebItemSecurity = webItemSecurity;
}
2020-06-03 14:53:58 +00:00
public abstract IEnumerable<Tuple<Feed, object>> GetFeeds(FeedFilter filter);
2020-06-03 14:53:58 +00:00
public abstract IEnumerable<int> GetTenantsWithFeeds(DateTime fromTime);
2022-02-11 14:59:18 +00:00
public virtual void VisibleFor(List<Tuple<FeedRow, object>> feed, Guid userId)
{
if (!WebItemSecurity.IsAvailableForUser(ProductID, userId))
2020-06-03 14:53:58 +00:00
{
return;
2020-06-03 14:53:58 +00:00
}
foreach (var tuple in feed)
2020-06-03 14:53:58 +00:00
{
if (VisibleFor(tuple.Item1.Feed, tuple.Item2, userId))
2020-06-03 14:53:58 +00:00
{
tuple.Item1.Users.Add(userId);
2020-06-03 14:53:58 +00:00
}
}
}
2020-06-03 14:53:58 +00:00
public virtual bool VisibleFor(Feed feed, object data, Guid userId)
{
return WebItemSecurity.IsAvailableForUser(ProductID, userId);
}
2020-06-03 14:53:58 +00:00
protected static Guid ToGuid(object guid)
{
try
2020-06-03 14:53:58 +00:00
{
var str = guid as string;
return !string.IsNullOrEmpty(str) ? new Guid(str) : Guid.Empty;
2020-06-03 14:53:58 +00:00
}
catch (Exception)
2020-06-03 14:53:58 +00:00
{
return Guid.Empty;
2020-06-03 14:53:58 +00:00
}
}
2020-06-03 14:53:58 +00:00
protected string GetGroupId(string item, Guid author, string rootId = null, int action = -1)
{
const int interval = 2;
2020-06-03 14:53:58 +00:00
var now = DateTime.UtcNow;
var hours = now.Hour;
var groupIdHours = hours - (hours % interval);
2020-06-03 14:53:58 +00:00
if (rootId == null)
{
// groupId = {item}_{author}_{date}
return string.Format("{0}_{1}_{2}",
item,
author,
now.ToString("yyyy.MM.dd.") + groupIdHours);
2020-06-03 14:53:58 +00:00
}
if (action == -1)
{
2020-06-03 14:53:58 +00:00
// groupId = {item}_{author}_{date}_{rootId}_{action}
return string.Format("{0}_{1}_{2}_{3}",
2020-06-03 14:53:58 +00:00
item,
author,
now.ToString("yyyy.MM.dd.") + groupIdHours,
rootId);
2020-06-03 14:53:58 +00:00
}
// groupId = {item}_{author}_{date}_{rootId}_{action}
return string.Format("{0}_{1}_{2}_{3}_{4}",
item,
author,
now.ToString("yyyy.MM.dd.") + groupIdHours,
rootId,
action);
2020-06-03 14:53:58 +00:00
}
}