2019-06-21 10:42:16 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (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.Collections.Generic;
|
|
|
|
using System.Globalization;
|
|
|
|
using System.Security.Cryptography;
|
2020-02-17 08:58:14 +00:00
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using ASC.Common;
|
2019-11-06 15:03:09 +00:00
|
|
|
using ASC.Common.Logging;
|
2020-08-06 18:07:27 +00:00
|
|
|
using ASC.Common.Threading;
|
2019-06-21 10:42:16 +00:00
|
|
|
using ASC.Core;
|
|
|
|
using ASC.Core.Users;
|
|
|
|
using ASC.Data.Storage;
|
|
|
|
//using ASC.Mail.Core.Engine;
|
|
|
|
using ASC.MessagingSystem;
|
|
|
|
//using ASC.Web.CRM.Core;
|
|
|
|
using ASC.Web.Core;
|
|
|
|
//using ASC.Web.Files.Services.WCFService;
|
|
|
|
using ASC.Web.Studio.Core.Notify;
|
|
|
|
//using CrmDaoFactory = ASC.CRM.Core.Dao.DaoFactory;
|
2019-11-06 15:03:09 +00:00
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Options;
|
2020-06-03 15:04:14 +00:00
|
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
namespace ASC.Data.Reassigns
|
2021-05-13 08:23:44 +00:00
|
|
|
{
|
|
|
|
[Transient]
|
2020-09-30 10:54:49 +00:00
|
|
|
public class RemoveProgressItem : DistributedTaskProgress
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
2020-06-03 15:04:14 +00:00
|
|
|
private readonly IDictionary<string, StringValues> _httpHeaders;
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2020-08-07 15:42:58 +00:00
|
|
|
private int _tenantId;
|
|
|
|
private Guid _currentUserId;
|
|
|
|
private bool _notify;
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
//private readonly IFileStorageService _docService;
|
|
|
|
//private readonly MailGarbageEngine _mailEraser;
|
2020-09-30 10:54:49 +00:00
|
|
|
public Guid FromUser { get; private set; }
|
2020-08-12 09:58:08 +00:00
|
|
|
private IServiceProvider ServiceProvider { get; }
|
2020-09-30 10:54:49 +00:00
|
|
|
public UserInfo User { get; private set; }
|
2019-11-06 15:03:09 +00:00
|
|
|
|
|
|
|
public RemoveProgressItem(
|
|
|
|
IServiceProvider serviceProvider,
|
2020-08-07 15:42:58 +00:00
|
|
|
IHttpContextAccessor httpContextAccessor)
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
2020-08-07 15:42:58 +00:00
|
|
|
_httpHeaders = QueueWorker.GetHttpHeaders(httpContextAccessor.HttpContext.Request);
|
|
|
|
ServiceProvider = serviceProvider;
|
|
|
|
|
|
|
|
|
|
|
|
//_docService = Web.Files.Classes.Global.FileStorageService;
|
2020-09-30 10:54:49 +00:00
|
|
|
//_mailEraser = new MailGarbageEngine();
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
2020-08-07 15:42:58 +00:00
|
|
|
|
|
|
|
public void Init(int tenantId, UserInfo user, Guid currentUserId, bool notify)
|
|
|
|
{
|
|
|
|
_tenantId = tenantId;
|
|
|
|
User = user;
|
|
|
|
FromUser = user.ID;
|
|
|
|
_currentUserId = currentUserId;
|
|
|
|
_notify = notify;
|
2020-09-30 10:54:49 +00:00
|
|
|
|
2020-10-01 07:22:08 +00:00
|
|
|
Id = QueueWorkerRemove.GetProgressItemId(tenantId, FromUser);
|
2020-09-30 10:54:49 +00:00
|
|
|
Status = DistributedTaskStatus.Created;
|
|
|
|
Exception = null;
|
|
|
|
Percentage = 0;
|
|
|
|
IsCompleted = false;
|
2020-08-07 15:42:58 +00:00
|
|
|
}
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2020-09-30 10:54:49 +00:00
|
|
|
protected override void DoJob()
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
2020-09-30 10:54:49 +00:00
|
|
|
using var scope = ServiceProvider.CreateScope();
|
2020-08-24 18:41:06 +00:00
|
|
|
var scopeClass = scope.ServiceProvider.GetService<RemoveProgressItemScope>();
|
2020-09-07 12:01:15 +00:00
|
|
|
var (tenantManager, coreBaseSettings, messageService, studioNotifyService, securityContext, userManager, messageTarget, webItemManagerSecurity, storageFactory, userFormatter, options) = scopeClass;
|
2022-02-07 14:53:58 +00:00
|
|
|
var logger = options.Get("ASC.Web");
|
|
|
|
tenantManager.SetCurrentTenant(_tenantId);
|
2019-11-06 15:03:09 +00:00
|
|
|
var userName = userFormatter.GetUserName(User, DisplayUserNameFormat.Default);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Percentage = 0;
|
2020-08-06 18:07:27 +00:00
|
|
|
Status = DistributedTaskStatus.Running;
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2021-08-18 14:04:16 +00:00
|
|
|
securityContext.AuthenticateMeWithoutCookie(_currentUserId);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2019-08-15 13:05:50 +00:00
|
|
|
long crmSpace;
|
2019-09-18 12:14:15 +00:00
|
|
|
GetUsageSpace(webItemManagerSecurity, out var docsSpace, out var mailSpace, out var talkSpace);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2019-08-15 13:56:54 +00:00
|
|
|
logger.InfoFormat("deleting user data for {0} ", FromUser);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
logger.Info("deleting of data from documents");
|
|
|
|
|
|
|
|
//_docService.DeleteStorage(_userId);
|
2020-09-30 10:54:49 +00:00
|
|
|
Percentage = 25;
|
|
|
|
PublishChanges();
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2020-08-31 08:18:07 +00:00
|
|
|
if (!coreBaseSettings.CustomMode)
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
|
|
|
logger.Info("deleting of data from crm");
|
|
|
|
|
2020-09-30 10:54:49 +00:00
|
|
|
|
2019-11-06 15:03:09 +00:00
|
|
|
//using (var scope = DIHelper.Resolve(_tenantId))
|
|
|
|
//{
|
|
|
|
// var crmDaoFactory = scope.Resolve<CrmDaoFactory>();
|
2020-09-30 10:54:49 +00:00
|
|
|
crmSpace = 0;// crmDaoFactory.ReportDao.GetFiles(_userId).Sum(file => file.ContentLength);
|
|
|
|
// crmDaoFactory.ReportDao.DeleteFiles(_userId);
|
|
|
|
//}
|
|
|
|
Percentage = 50;
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
crmSpace = 0;
|
2020-09-30 10:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PublishChanges();
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
logger.Info("deleting of data from mail");
|
|
|
|
|
|
|
|
//_mailEraser.ClearUserMail(_userId);
|
2020-09-30 10:54:49 +00:00
|
|
|
Percentage = 75;
|
|
|
|
PublishChanges();
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
logger.Info("deleting of data from talk");
|
2019-09-18 12:14:15 +00:00
|
|
|
DeleteTalkStorage(storageFactory);
|
2020-09-30 10:54:49 +00:00
|
|
|
Percentage = 99;
|
|
|
|
PublishChanges();
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2019-10-22 11:21:44 +00:00
|
|
|
SendSuccessNotify(studioNotifyService, messageService, messageTarget, userName, docsSpace, crmSpace, mailSpace, talkSpace);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
Percentage = 100;
|
2020-08-06 18:07:27 +00:00
|
|
|
Status = DistributedTaskStatus.Completed;
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.Error(ex);
|
2020-08-06 18:07:27 +00:00
|
|
|
Status = DistributedTaskStatus.Failted;
|
2020-09-30 10:54:49 +00:00
|
|
|
Exception = ex;
|
2019-09-24 10:32:12 +00:00
|
|
|
SendErrorNotify(studioNotifyService, ex.Message, userName);
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
logger.Info("data deletion is complete");
|
2020-09-30 10:54:49 +00:00
|
|
|
IsCompleted = true;
|
|
|
|
PublishChanges();
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public object Clone()
|
|
|
|
{
|
|
|
|
return MemberwiseClone();
|
|
|
|
}
|
|
|
|
|
2019-09-18 12:14:15 +00:00
|
|
|
private void GetUsageSpace(WebItemManagerSecurity webItemManagerSecurity, out long docsSpace, out long mailSpace, out long talkSpace)
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
|
|
|
docsSpace = mailSpace = talkSpace = 0;
|
|
|
|
|
2019-09-18 12:14:15 +00:00
|
|
|
var webItems = webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All);
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
foreach (var item in webItems)
|
|
|
|
{
|
|
|
|
IUserSpaceUsage manager;
|
|
|
|
|
|
|
|
if (item.ID == WebItemManager.DocumentsProductID)
|
|
|
|
{
|
|
|
|
manager = item.Context.SpaceUsageStatManager as IUserSpaceUsage;
|
|
|
|
if (manager == null) continue;
|
2022-01-18 16:50:31 +00:00
|
|
|
docsSpace = manager.GetUserSpaceUsageAsync(FromUser).Result;
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.ID == WebItemManager.MailProductID)
|
|
|
|
{
|
|
|
|
manager = item.Context.SpaceUsageStatManager as IUserSpaceUsage;
|
|
|
|
if (manager == null) continue;
|
2022-01-18 16:50:31 +00:00
|
|
|
mailSpace = manager.GetUserSpaceUsageAsync(FromUser).Result;
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.ID == WebItemManager.TalkProductID)
|
|
|
|
{
|
|
|
|
manager = item.Context.SpaceUsageStatManager as IUserSpaceUsage;
|
|
|
|
if (manager == null) continue;
|
2022-01-18 16:50:31 +00:00
|
|
|
talkSpace = manager.GetUserSpaceUsageAsync(FromUser).Result;
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-18 12:14:15 +00:00
|
|
|
private void DeleteTalkStorage(StorageFactory storageFactory)
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
2019-08-16 08:44:03 +00:00
|
|
|
using var md5 = MD5.Create();
|
|
|
|
var data = md5.ComputeHash(Encoding.Default.GetBytes(FromUser.ToString()));
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
var sBuilder = new StringBuilder();
|
|
|
|
|
|
|
|
for (int i = 0, n = data.Length; i < n; i++)
|
|
|
|
{
|
|
|
|
sBuilder.Append(data[i].ToString("x2"));
|
|
|
|
}
|
|
|
|
|
|
|
|
var md5Hash = sBuilder.ToString();
|
|
|
|
|
2019-09-18 12:14:15 +00:00
|
|
|
var storage = storageFactory.GetStorage(_tenantId.ToString(CultureInfo.InvariantCulture), "talk");
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2022-01-25 09:29:11 +00:00
|
|
|
if (storage != null && storage.IsDirectoryAsync(md5Hash).Result)
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
2022-01-25 09:29:11 +00:00
|
|
|
storage.DeleteDirectoryAsync(md5Hash).Wait();
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 11:21:44 +00:00
|
|
|
private void SendSuccessNotify(StudioNotifyService studioNotifyService, MessageService messageService, MessageTarget messageTarget, string userName, long docsSpace, long crmSpace, long mailSpace, long talkSpace)
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
|
|
|
if (_notify)
|
2019-09-24 10:32:12 +00:00
|
|
|
studioNotifyService.SendMsgRemoveUserDataCompleted(_currentUserId, User, userName,
|
2019-06-21 10:42:16 +00:00
|
|
|
docsSpace, crmSpace, mailSpace, talkSpace);
|
|
|
|
|
|
|
|
if (_httpHeaders != null)
|
2019-10-22 11:21:44 +00:00
|
|
|
messageService.Send(_httpHeaders, MessageAction.UserDataRemoving, messageTarget.Create(FromUser), new[] { userName });
|
2019-06-21 10:42:16 +00:00
|
|
|
else
|
2019-10-22 11:21:44 +00:00
|
|
|
messageService.Send(MessageAction.UserDataRemoving, messageTarget.Create(FromUser), userName);
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 10:32:12 +00:00
|
|
|
private void SendErrorNotify(StudioNotifyService studioNotifyService, string errorMessage, string userName)
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
|
|
|
if (!_notify) return;
|
|
|
|
|
2019-09-24 10:32:12 +00:00
|
|
|
studioNotifyService.SendMsgRemoveUserDataFailed(_currentUserId, User, userName, errorMessage);
|
2020-08-07 15:42:58 +00:00
|
|
|
}
|
2019-11-06 15:03:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 15:34:22 +00:00
|
|
|
[Scope]
|
2020-08-24 18:41:06 +00:00
|
|
|
public class RemoveProgressItemScope
|
|
|
|
{
|
2020-08-31 08:18:07 +00:00
|
|
|
private TenantManager TenantManager { get; }
|
|
|
|
private CoreBaseSettings CoreBaseSettings { get; }
|
|
|
|
private MessageService MessageService { get; }
|
|
|
|
private StudioNotifyService StudioNotifyService { get; }
|
|
|
|
private SecurityContext SecurityContext { get; }
|
|
|
|
private UserManager UserManager { get; }
|
|
|
|
private MessageTarget MessageTarget { get; }
|
|
|
|
private WebItemManagerSecurity WebItemManagerSecurity { get; }
|
|
|
|
private StorageFactory StorageFactory { get; }
|
|
|
|
private UserFormatter UserFormatter { get; }
|
|
|
|
private IOptionsMonitor<ILog> Options { get; }
|
2020-07-29 21:57:58 +00:00
|
|
|
|
2020-08-24 18:41:06 +00:00
|
|
|
public RemoveProgressItemScope(TenantManager tenantManager,
|
|
|
|
CoreBaseSettings coreBaseSettings,
|
|
|
|
MessageService messageService,
|
|
|
|
StudioNotifyService studioNotifyService,
|
|
|
|
SecurityContext securityContext,
|
|
|
|
UserManager userManager,
|
|
|
|
MessageTarget messageTarget,
|
|
|
|
WebItemManagerSecurity webItemManagerSecurity,
|
|
|
|
StorageFactory storageFactory,
|
|
|
|
UserFormatter userFormatter,
|
|
|
|
IOptionsMonitor<ILog> options)
|
|
|
|
{
|
|
|
|
TenantManager = tenantManager;
|
|
|
|
CoreBaseSettings = coreBaseSettings;
|
|
|
|
MessageService = messageService;
|
|
|
|
StudioNotifyService = studioNotifyService;
|
|
|
|
SecurityContext = securityContext;
|
|
|
|
UserManager = userManager;
|
|
|
|
MessageTarget = messageTarget;
|
|
|
|
WebItemManagerSecurity = webItemManagerSecurity;
|
|
|
|
StorageFactory = storageFactory;
|
|
|
|
UserFormatter = userFormatter;
|
|
|
|
Options = options;
|
|
|
|
}
|
2020-08-31 08:18:07 +00:00
|
|
|
|
|
|
|
public void Deconstruct(out TenantManager tenantManager,
|
|
|
|
out CoreBaseSettings coreBaseSettings,
|
2020-09-30 10:54:49 +00:00
|
|
|
out MessageService messageService,
|
|
|
|
out StudioNotifyService studioNotifyService,
|
|
|
|
out SecurityContext securityContext,
|
|
|
|
out UserManager userManager,
|
|
|
|
out MessageTarget messageTarget,
|
2020-08-31 08:18:07 +00:00
|
|
|
out WebItemManagerSecurity webItemManagerSecurity,
|
2020-09-30 10:54:49 +00:00
|
|
|
out StorageFactory storageFactory,
|
2020-08-31 08:18:07 +00:00
|
|
|
out UserFormatter userFormatter,
|
2020-09-30 10:54:49 +00:00
|
|
|
out IOptionsMonitor<ILog> optionsMonitor)
|
2020-08-31 08:18:07 +00:00
|
|
|
{
|
|
|
|
tenantManager = TenantManager;
|
|
|
|
coreBaseSettings = CoreBaseSettings;
|
|
|
|
messageService = MessageService;
|
|
|
|
studioNotifyService = StudioNotifyService;
|
|
|
|
securityContext = SecurityContext;
|
|
|
|
userManager = UserManager;
|
|
|
|
messageTarget = MessageTarget;
|
|
|
|
webItemManagerSecurity = WebItemManagerSecurity;
|
|
|
|
storageFactory = StorageFactory;
|
|
|
|
userFormatter = UserFormatter;
|
|
|
|
optionsMonitor = Options;
|
|
|
|
}
|
2019-11-06 15:03:09 +00:00
|
|
|
}
|
|
|
|
|
2019-11-11 09:03:49 +00:00
|
|
|
public static class RemoveProgressItemExtension
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
2020-10-27 15:34:22 +00:00
|
|
|
public static void Register(DIHelper services)
|
2020-08-07 15:42:58 +00:00
|
|
|
{
|
2021-05-13 08:23:44 +00:00
|
|
|
services.TryAdd<RemoveProgressItemScope>();
|
|
|
|
services.AddDistributedTaskQueueService<RemoveProgressItem>(1);
|
2019-11-06 15:03:09 +00:00
|
|
|
}
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
}
|