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;
|
2020-08-12 09:58:08 +00:00
|
|
|
|
|
|
|
using ASC.Common;
|
2019-11-06 15:03:09 +00:00
|
|
|
using ASC.Common.Logging;
|
2019-06-21 10:42:16 +00:00
|
|
|
using ASC.Common.Threading.Progress;
|
|
|
|
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-08-12 09:58:08 +00:00
|
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
|
2019-06-21 10:42:16 +00:00
|
|
|
namespace ASC.Data.Reassigns
|
|
|
|
{
|
|
|
|
public class RemoveProgressItem : IProgressItem
|
|
|
|
{
|
2020-06-03 15:04:14 +00:00
|
|
|
private readonly IDictionary<string, StringValues> _httpHeaders;
|
2019-06-21 10:42:16 +00:00
|
|
|
|
|
|
|
private readonly int _tenantId;
|
|
|
|
private readonly Guid _currentUserId;
|
|
|
|
private readonly bool _notify;
|
|
|
|
|
|
|
|
//private readonly IFileStorageService _docService;
|
|
|
|
//private readonly MailGarbageEngine _mailEraser;
|
|
|
|
|
|
|
|
public object Id { get; set; }
|
|
|
|
public object Status { get; set; }
|
|
|
|
public object Error { get; set; }
|
|
|
|
public double Percentage { get; set; }
|
|
|
|
public bool IsCompleted { get; set; }
|
2019-11-06 15:03:09 +00:00
|
|
|
public Guid FromUser { get; }
|
2020-08-12 09:58:08 +00:00
|
|
|
private IServiceProvider ServiceProvider { get; }
|
2019-11-06 15:03:09 +00:00
|
|
|
public UserInfo User { get; }
|
|
|
|
|
|
|
|
public RemoveProgressItem(
|
|
|
|
IServiceProvider serviceProvider,
|
|
|
|
HttpContext context,
|
|
|
|
QueueWorkerRemove queueWorkerRemove,
|
2019-09-09 12:56:33 +00:00
|
|
|
int tenantId, UserInfo user, Guid currentUserId, bool notify)
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
|
|
|
_httpHeaders = QueueWorker.GetHttpHeaders(context.Request);
|
2019-09-18 12:14:15 +00:00
|
|
|
ServiceProvider = serviceProvider;
|
2019-06-21 10:42:16 +00:00
|
|
|
_tenantId = tenantId;
|
2019-11-06 15:03:09 +00:00
|
|
|
User = user;
|
2019-08-15 13:56:54 +00:00
|
|
|
FromUser = user.ID;
|
2019-06-21 10:42:16 +00:00
|
|
|
_currentUserId = currentUserId;
|
|
|
|
_notify = notify;
|
|
|
|
|
|
|
|
//_docService = Web.Files.Classes.Global.FileStorageService;
|
|
|
|
//_mailEraser = new MailGarbageEngine();
|
|
|
|
|
2019-08-15 13:56:54 +00:00
|
|
|
Id = queueWorkerRemove.GetProgressItemId(tenantId, FromUser);
|
2019-06-21 10:42:16 +00:00
|
|
|
Status = ProgressStatus.Queued;
|
|
|
|
Error = null;
|
|
|
|
Percentage = 0;
|
|
|
|
IsCompleted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RunJob()
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
|
|
|
using var scope = ServiceProvider.CreateScope();
|
|
|
|
var logger = ServiceProvider.GetService<IOptionsMonitor<ILog>>().Get("ASC.Web");
|
|
|
|
var tenantManager = scope.ServiceProvider.GetService<TenantManager>();
|
|
|
|
var tenant = tenantManager.SetCurrentTenant(_tenantId);
|
|
|
|
|
|
|
|
var messageService = scope.ServiceProvider.GetService<MessageService>();
|
|
|
|
var studioNotifyService = scope.ServiceProvider.GetService<StudioNotifyService>();
|
|
|
|
var securityContext = scope.ServiceProvider.GetService<SecurityContext>();
|
|
|
|
var webItemManagerSecurity = scope.ServiceProvider.GetService<WebItemManagerSecurity>();
|
|
|
|
var storageFactory = scope.ServiceProvider.GetService<StorageFactory>();
|
|
|
|
var coreSettings = scope.ServiceProvider.GetService<CoreBaseSettings>();
|
|
|
|
var userFormatter = scope.ServiceProvider.GetService<UserFormatter>();
|
2019-10-22 11:21:44 +00:00
|
|
|
var messageTarget = scope.ServiceProvider.GetService<MessageTarget>();
|
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;
|
2019-11-06 15:03:09 +00:00
|
|
|
Status = ProgressStatus.Started;
|
2019-06-21 10:42:16 +00:00
|
|
|
|
2019-09-20 15:53:27 +00:00
|
|
|
securityContext.AuthenticateMe(_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");
|
|
|
|
|
|
|
|
Percentage = 25;
|
|
|
|
//_docService.DeleteStorage(_userId);
|
|
|
|
|
2019-09-18 15:19:30 +00:00
|
|
|
if (!coreSettings.CustomMode)
|
2019-06-21 10:42:16 +00:00
|
|
|
{
|
|
|
|
logger.Info("deleting of data from crm");
|
|
|
|
|
2019-11-06 15:03:09 +00:00
|
|
|
Percentage = 50;
|
|
|
|
//using (var scope = DIHelper.Resolve(_tenantId))
|
|
|
|
//{
|
|
|
|
// var crmDaoFactory = scope.Resolve<CrmDaoFactory>();
|
2019-06-21 10:42:16 +00:00
|
|
|
crmSpace = 0;// crmDaoFactory.ReportDao.GetFiles(_userId).Sum(file => file.ContentLength);
|
|
|
|
// crmDaoFactory.ReportDao.DeleteFiles(_userId);
|
|
|
|
//}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
crmSpace = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Info("deleting of data from mail");
|
|
|
|
|
|
|
|
Percentage = 75;
|
|
|
|
//_mailEraser.ClearUserMail(_userId);
|
|
|
|
|
|
|
|
logger.Info("deleting of data from talk");
|
|
|
|
|
|
|
|
Percentage = 99;
|
2019-09-18 12:14:15 +00:00
|
|
|
DeleteTalkStorage(storageFactory);
|
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;
|
|
|
|
Status = ProgressStatus.Done;
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
logger.Error(ex);
|
|
|
|
Status = ProgressStatus.Failed;
|
|
|
|
Error = ex.Message;
|
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");
|
|
|
|
IsCompleted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2019-08-15 13:56:54 +00:00
|
|
|
docsSpace = manager.GetUserSpaceUsage(FromUser);
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.ID == WebItemManager.MailProductID)
|
|
|
|
{
|
|
|
|
manager = item.Context.SpaceUsageStatManager as IUserSpaceUsage;
|
|
|
|
if (manager == null) continue;
|
2019-08-15 13:56:54 +00:00
|
|
|
mailSpace = manager.GetUserSpaceUsage(FromUser);
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.ID == WebItemManager.TalkProductID)
|
|
|
|
{
|
|
|
|
manager = item.Context.SpaceUsageStatManager as IUserSpaceUsage;
|
|
|
|
if (manager == null) continue;
|
2019-08-15 13:56:54 +00:00
|
|
|
talkSpace = manager.GetUserSpaceUsage(FromUser);
|
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
|
|
|
|
|
|
|
if (storage != null && storage.IsDirectory(md5Hash))
|
|
|
|
{
|
|
|
|
storage.DeleteDirectory(md5Hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
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-02-17 08:58:14 +00:00
|
|
|
public static DIHelper AddRemoveProgressItemService(this DIHelper services)
|
2019-11-06 15:03:09 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
services.TryAddSingleton<ProgressQueueOptionsManager<RemoveProgressItem>>();
|
|
|
|
services.TryAddSingleton<ProgressQueue<RemoveProgressItem>>();
|
2020-06-08 09:44:01 +00:00
|
|
|
services.AddSingleton<IPostConfigureOptions<ProgressQueue<RemoveProgressItem>>, ConfigureProgressQueue<RemoveProgressItem>>();
|
2019-11-06 15:03:09 +00:00
|
|
|
return services;
|
|
|
|
}
|
2019-06-21 10:42:16 +00:00
|
|
|
}
|
|
|
|
}
|