diff --git a/common/ASC.Core.Common/Caching/CachedUserService.cs b/common/ASC.Core.Common/Caching/CachedUserService.cs index f11fe62dc3..22343484a8 100644 --- a/common/ASC.Core.Common/Caching/CachedUserService.cs +++ b/common/ASC.Core.Common/Caching/CachedUserService.cs @@ -244,6 +244,11 @@ public class CachedUserService : IUserService, ICachedService return user; } + public IEnumerable GetTenantsWithFeeds(DateTime from) + { + return Service.GetTenantsWithFeeds(from); + } + public void RemoveUser(int tenant, Guid id) { Service.RemoveUser(tenant, id); diff --git a/common/ASC.Core.Common/Context/Impl/UserManager.cs b/common/ASC.Core.Common/Context/Impl/UserManager.cs index 4b0e622c83..1c3859adba 100644 --- a/common/ASC.Core.Common/Context/Impl/UserManager.cs +++ b/common/ASC.Core.Common/Context/Impl/UserManager.cs @@ -461,6 +461,11 @@ public class UserManager return _userService.GetDavUserEmails(_tenantManager.GetCurrentTenant().Id); } + public IEnumerable GetTenantsWithFeeds(DateTime from) + { + return _userService.GetTenantsWithFeeds(from); + } + public async Task DeleteUser(Guid id) { if (IsSystemUser(id)) diff --git a/common/ASC.Core.Common/Core/IUserService.cs b/common/ASC.Core.Common/Core/IUserService.cs index 8c5a53b7e0..75b21d455a 100644 --- a/common/ASC.Core.Common/Core/IUserService.cs +++ b/common/ASC.Core.Common/Core/IUserService.cs @@ -57,6 +57,7 @@ public interface IUserService UserInfo GetUserByPasswordHash(int tenant, string login, string passwordHash); UserInfo GetUserByUserName(int tenant, string userName); UserInfo SaveUser(int tenant, UserInfo user); + IEnumerable GetTenantsWithFeeds(DateTime from); void RemoveGroup(int tenant, Guid id); void RemoveUser(int tenant, Guid id); IEnumerable GetDavUserEmails(int tenant); diff --git a/common/ASC.Core.Common/Data/DbUserService.cs b/common/ASC.Core.Common/Data/DbUserService.cs index 812e694368..16b55f6f4f 100644 --- a/common/ASC.Core.Common/Data/DbUserService.cs +++ b/common/ASC.Core.Common/Data/DbUserService.cs @@ -262,6 +262,15 @@ public class EFUserService : IUserService .ProjectTo(_mapper.ConfigurationProvider); } + public IEnumerable GetTenantsWithFeeds(DateTime from) + { + var userDbContext = _dbContextFactory.CreateDbContext(); + + var tenants = userDbContext.Users.Where(u => u.LastModified > from).Select(u => u.Tenant).Distinct().ToList(); + + return tenants; + } + public void RemoveGroup(int tenant, Guid id) { RemoveGroup(tenant, id, false); diff --git a/common/ASC.Feed/Core/Constants.cs b/common/ASC.Feed/Core/Constants.cs index 04e54205ed..79b087ed5d 100644 --- a/common/ASC.Feed/Core/Constants.cs +++ b/common/ASC.Feed/Core/Constants.cs @@ -52,12 +52,14 @@ public static class Constants public const string FilesModule = "files"; public const string FoldersModule = "folders"; public const string RoomsModule = "rooms"; + public const string UsersModule = "users"; #endregion #region Products public const string Documents = "documents"; + public const string People = "people"; #endregion @@ -69,6 +71,7 @@ public static class Constants public const string SharedFileItem = "sharedFile"; public const string FolderItem = "folder"; public const string SharedFolderItem = "sharedFolder"; + public const string UserItem = "user"; #endregion } diff --git a/products/ASC.Files/Service/Core/FilesModule.cs b/products/ASC.Files/Service/Core/FilesModule.cs index 0fafc59678..e65217216b 100644 --- a/products/ASC.Files/Service/Core/FilesModule.cs +++ b/products/ASC.Files/Service/Core/FilesModule.cs @@ -24,6 +24,7 @@ // 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 +using Constants = ASC.Feed.Constants; using FeedModule = ASC.Feed.Aggregator.Modules.FeedModule; namespace ASC.Files.Service.Core; diff --git a/products/ASC.Files/Service/Core/FoldersModule.cs b/products/ASC.Files/Service/Core/FoldersModule.cs index cb39be1263..b66d9ea92f 100644 --- a/products/ASC.Files/Service/Core/FoldersModule.cs +++ b/products/ASC.Files/Service/Core/FoldersModule.cs @@ -24,6 +24,7 @@ // 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 +using Constants = ASC.Feed.Constants; using FeedModule = ASC.Feed.Aggregator.Modules.FeedModule; namespace ASC.Files.Service.Core; diff --git a/products/ASC.Files/Service/Core/RoomsModule.cs b/products/ASC.Files/Service/Core/RoomsModule.cs index 31794ac9a1..98c6f58d6e 100644 --- a/products/ASC.Files/Service/Core/RoomsModule.cs +++ b/products/ASC.Files/Service/Core/RoomsModule.cs @@ -24,6 +24,7 @@ // 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 +using Constants = ASC.Feed.Constants; using FeedModule = ASC.Feed.Aggregator.Modules.FeedModule; namespace ASC.Files.Service.Core; diff --git a/products/ASC.Files/Service/Core/UsersModule.cs b/products/ASC.Files/Service/Core/UsersModule.cs new file mode 100644 index 0000000000..c299d3bfed --- /dev/null +++ b/products/ASC.Files/Service/Core/UsersModule.cs @@ -0,0 +1,116 @@ +// (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 + +using Constants = ASC.Feed.Constants; +using FeedModule = ASC.Feed.Aggregator.Modules.FeedModule; + +namespace ASC.Files.Service.Core; + +public class UsersModule : FeedModule +{ + private readonly UserManager _userManager; + private readonly DisplayUserSettingsHelper _displayUserSettingsHelper; + + private const string UserItem = Constants.UserItem; + + public UsersModule( + TenantManager tenantManager, + WebItemSecurity webItemSecurity, + UserManager userManager, + DisplayUserSettingsHelper displayUserSettingsHelper) + : base(tenantManager, webItemSecurity) + { + _userManager = userManager; + _displayUserSettingsHelper = displayUserSettingsHelper; + } + + public override string Name => Constants.UsersModule; + public override string Product => Constants.People; + public override Guid ProductID => WebItemManager.PeopleProductID; + protected override string DbId => string.Empty; + + public override Task>> GetFeeds(FeedFilter filter) + { + var users = _userManager.GetUsers().Where(u => u.LastModified >= filter.Time.From && u.LastModified <= filter.Time.To); + + return Task.FromResult(users.Select(u => new Tuple(ToFeed(u), u))); + } + + public override Task> GetTenantsWithFeeds(DateTime fromTime) + { + return Task.FromResult(_userManager.GetTenantsWithFeeds(fromTime)); + } + + private Feed.Aggregator.Feed ToFeed(UserInfo u) + { + var fullName = _displayUserSettingsHelper.GetFullUserName(u); + + var feed = new Feed.Aggregator.Feed(u.Id, u.LastModified, true) + { + Item = UserItem, + ItemId = u.Id.ToString(), + Product = Product, + Module = Name, + Title = fullName, + ExtraLocation = u.Id.ToString(), + AdditionalInfo = u.Email, + AdditionalInfo2 = _userManager.GetUserType(u.Id).ToString(), + AdditionalInfo3 = u.Status.ToString(), + AdditionalInfo4 = u.ActivationStatus.ToString(), + Keywords = fullName, + Action = u.LastModified > u.CreateDate ? FeedAction.Updated : FeedAction.Created, + }; + + return feed; + } + + public override bool VisibleFor(Feed.Aggregator.Feed feed, object data, Guid userId) + { + var user = data as UserInfo; + + return user.Id != userId && !_userManager.IsUser(userId); + } + + public override Task VisibleFor(List> feed, Guid userId) + { + if (_userManager.IsUser(userId)) + { + return Task.CompletedTask; + } + + foreach (var row in feed) + { + var user = row.Item2 as UserInfo; + + if (user.Id != userId) + { + row.Item1.Users.Add(userId); + } + } + + return Task.CompletedTask; + } +} \ No newline at end of file diff --git a/products/ASC.Files/Service/GlobalUsings.cs b/products/ASC.Files/Service/GlobalUsings.cs index 911f33cbbf..504017d550 100644 --- a/products/ASC.Files/Service/GlobalUsings.cs +++ b/products/ASC.Files/Service/GlobalUsings.cs @@ -42,6 +42,7 @@ global using ASC.Core.Common.EF; global using ASC.Core.Common.Hosting; global using ASC.Core.Common.Hosting.Interfaces; global using ASC.Core.Notify.Socket; +global using ASC.Core.Users; global using ASC.Core.Tenants; global using ASC.ElasticSearch; global using ASC.ElasticSearch.Service; @@ -65,6 +66,7 @@ global using ASC.Files.Service.Log; global using ASC.Files.ThumbnailBuilder; global using ASC.Thumbnail.IntegrationEvents.EventHandling; global using ASC.Web.Core; +global using ASC.Web.Core.Users; global using ASC.Web.Files.Classes; global using ASC.Web.Files.Core.Search; global using ASC.Web.Files.Services.DocumentService; diff --git a/products/ASC.Files/Service/feed.json b/products/ASC.Files/Service/feed.json index 2f9dcf6b85..21c2a9229b 100644 --- a/products/ASC.Files/Service/feed.json +++ b/products/ASC.Files/Service/feed.json @@ -26,6 +26,15 @@ } ], "instanceScope": "perlifetimescope" + }, + { + "type": "ASC.Files.Service.Core.UsersModule, ASC.Files.Service", + "services": [ + { + "type": "ASC.Feed.Aggregator.Modules.IFeedModule, ASC.Feed.Aggregator" + } + ], + "instanceScope": "perlifetimescope" } ] } \ No newline at end of file