Merge branch 'feature/elastic' of github.com:ONLYOFFICE/AppServer into feature/elastic

This commit is contained in:
Alexey Safronov 2020-02-26 11:06:55 +03:00
commit a192178156
12 changed files with 1119 additions and 22 deletions

View File

@ -28,8 +28,11 @@ using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
using ASC.Common;
using ASC.Common.Utils;
using ASC.Core;
using Newtonsoft.Json;
namespace ASC.Api.Core
@ -360,4 +363,29 @@ namespace ASC.Api.Core
return typeof(ApiDateTime).IsAssignableFrom(objectType);
}
}
public class ApiDateTimeHelper
{
public TenantManager TenantManager { get; }
public TimeZoneConverter TimeZoneConverter { get; }
public ApiDateTimeHelper(TenantManager tenantManager, TimeZoneConverter timeZoneConverter)
{
TenantManager = tenantManager;
TimeZoneConverter = timeZoneConverter;
}
public ApiDateTime Get(DateTime? from) => ApiDateTime.FromDate(TenantManager, TimeZoneConverter, from);
}
public static class ApiDateTimeHelperExtension
{
public static DIHelper AddApiDateTimeHelper(this DIHelper services)
{
services.TryAddScoped<ApiDateTimeHelper>();
return services
.AddTenantManagerService();
}
}
}

View File

@ -29,6 +29,7 @@ using System.Runtime.Serialization;
using ASC.Api.Core;
using ASC.Common;
using ASC.Core;
using ASC.Core.Users;
using ASC.Web.Core.Users;
using ASC.Web.Studio.Utility;
@ -67,18 +68,24 @@ namespace ASC.Web.Api.Models
public class EmployeeWraperHelper
{
public UserInfo UserInfo { get; set; }
public ApiContext HttpContext { get; }
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
public UserPhotoManager UserPhotoManager { get; }
public CommonLinkUtility CommonLinkUtility { get; }
private ApiContext HttpContext { get; }
private DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
protected UserPhotoManager UserPhotoManager { get; }
private CommonLinkUtility CommonLinkUtility { get; }
protected UserManager UserManager { get; }
public EmployeeWraperHelper(ApiContext httpContext, DisplayUserSettingsHelper displayUserSettingsHelper, UserPhotoManager userPhotoManager, CommonLinkUtility commonLinkUtility)
public EmployeeWraperHelper(
ApiContext httpContext,
DisplayUserSettingsHelper displayUserSettingsHelper,
UserPhotoManager userPhotoManager,
CommonLinkUtility commonLinkUtility,
UserManager userManager)
{
HttpContext = httpContext;
DisplayUserSettingsHelper = displayUserSettingsHelper;
UserPhotoManager = userPhotoManager;
CommonLinkUtility = commonLinkUtility;
UserManager = userManager;
}
public EmployeeWraper Get(UserInfo userInfo)
@ -86,6 +93,18 @@ namespace ASC.Web.Api.Models
return Init(new EmployeeWraper(), userInfo);
}
public EmployeeWraper Get(Guid userId)
{
try
{
return Get(UserManager.GetUsers(userId));
}
catch (Exception)
{
return Get(Constants.LostUser);
}
}
protected EmployeeWraper Init(EmployeeWraper result, UserInfo userInfo)
{
result.Id = userInfo.ID;

View File

@ -31,7 +31,6 @@ using System.Runtime.Serialization;
using ASC.Api.Core;
using ASC.Common;
using ASC.Common.Utils;
using ASC.Core;
using ASC.Core.Users;
using ASC.Web.Core;
@ -160,28 +159,23 @@ namespace ASC.Web.Api.Models
public class EmployeeWraperFullHelper : EmployeeWraperHelper
{
public ApiContext Context { get; }
public UserManager UserManager { get; }
public WebItemSecurity WebItemSecurity { get; }
public TenantManager TenantManager { get; }
public TimeZoneConverter TimeZoneConverter { get; }
private ApiContext Context { get; }
private WebItemSecurity WebItemSecurity { get; }
private ApiDateTimeHelper ApiDateTimeHelper { get; }
public EmployeeWraperFullHelper(
ApiContext context,
UserManager userManager,
UserPhotoManager userPhotoManager,
WebItemSecurity webItemSecurity,
TenantManager tenantManager,
CommonLinkUtility commonLinkUtility,
DisplayUserSettingsHelper displayUserSettingsHelper,
TimeZoneConverter timeZoneConverter)
: base(context, displayUserSettingsHelper, userPhotoManager, commonLinkUtility)
ApiDateTimeHelper apiDateTimeHelper)
: base(context, displayUserSettingsHelper, userPhotoManager, commonLinkUtility, userManager)
{
Context = context;
UserManager = userManager;
WebItemSecurity = webItemSecurity;
TenantManager = tenantManager;
TimeZoneConverter = timeZoneConverter;
ApiDateTimeHelper = apiDateTimeHelper;
}
public EmployeeWraperFull GetFull(UserInfo userInfo)
@ -191,11 +185,11 @@ namespace ASC.Web.Api.Models
UserName = userInfo.UserName,
FirstName = userInfo.FirstName,
LastName = userInfo.LastName,
Birthday = ApiDateTime.FromDate(TenantManager, TimeZoneConverter, userInfo.BirthDate),
Birthday = ApiDateTimeHelper.Get(userInfo.BirthDate),
Status = userInfo.Status,
ActivationStatus = userInfo.ActivationStatus & ~EmployeeActivationStatus.AutoGenerated,
Terminated = ApiDateTime.FromDate(TenantManager, TimeZoneConverter, userInfo.TerminatedDate),
WorkFrom = ApiDateTime.FromDate(TenantManager, TimeZoneConverter, userInfo.WorkFromDate),
Terminated = ApiDateTimeHelper.Get(userInfo.TerminatedDate),
WorkFrom = ApiDateTimeHelper.Get(userInfo.WorkFromDate),
Email = userInfo.Email,
IsVisitor = userInfo.IsVisitor(UserManager),
IsAdmin = userInfo.IsAdmin(UserManager),
@ -311,7 +305,8 @@ namespace ASC.Web.Api.Models
.AddTenantManagerService()
.AddWebItemSecurity()
.AddUserManagerService()
.AddEmployeeWraper();
.AddEmployeeWraper()
.AddApiDateTimeHelper();
}
}
}

View File

@ -65,4 +65,7 @@
<LastGenOutput>FilesUCResource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Model\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,173 @@
/*
*
* (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.Runtime.Serialization;
using ASC.Api.Core;
using ASC.Files.Core;
using ASC.Files.Core.Security;
using ASC.Web.Api.Models;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
[DataContract(Namespace = "")]
public abstract class FileEntryWrapper
{
/// <summary>
/// </summary>
[DataMember]
public object Id { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = true)]
public string Title { get; set; }
/// <summary>
/// </summary>
[DataMember]
public FileShare Access { get; set; }
/// <summary>
/// </summary>
[DataMember]
public bool Shared { get; set; }
/// <summary>
/// </summary>
[DataMember(Order = 50)]
public ApiDateTime Created { get; set; }
/// <summary>
/// </summary>
[DataMember(Order = 51, EmitDefaultValue = false)]
public EmployeeWraper CreatedBy { get; set; }
private ApiDateTime _updated;
/// <summary>
/// </summary>
[DataMember(Order = 52, EmitDefaultValue = false)]
public ApiDateTime Updated
{
get
{
return _updated < Created ? Created : _updated;
}
set { _updated = value; }
}
/// <summary>
/// </summary>
[DataMember(Order = 41, EmitDefaultValue = false)]
public FolderType RootFolderType { get; set; }
/// <summary>
/// </summary>
[DataMember(Order = 41, EmitDefaultValue = false)]
public EmployeeWraper UpdatedBy { get; set; }
/// <summary>
/// </summary>
[DataMember(Order = 55, EmitDefaultValue = false)]
public bool ProviderItem { get; set; }
/// <summary>
/// </summary>
[DataMember(Order = 56, EmitDefaultValue = false)]
public string ProviderKey { get; set; }
/// <summary>
/// </summary>
[DataMember(Order = 57, EmitDefaultValue = false)]
public int ProviderId { get; set; }
/// <summary>
///
/// </summary>
/// <param name="entry"></param>
protected FileEntryWrapper(FileEntry entry, EmployeeWraperHelper employeeWraperHelper, ApiDateTimeHelper apiDateTimeHelper)
{
Id = entry.ID;
Title = entry.Title;
Access = entry.Access;
Shared = entry.Shared;
Created = apiDateTimeHelper.Get(entry.CreateOn);
CreatedBy = employeeWraperHelper.Get(entry.CreateBy);
Updated = apiDateTimeHelper.Get(entry.ModifiedOn);
UpdatedBy = employeeWraperHelper.Get(entry.ModifiedBy);
RootFolderType = entry.RootFolderType;
ProviderItem = entry.ProviderEntry;
ProviderKey = entry.ProviderKey;
ProviderId = entry.ProviderId;
}
/// <summary>
///
/// </summary>
protected FileEntryWrapper()
{
}
}
public class FileEntryWrapperHelper
{
public ApiDateTimeHelper ApiDateTimeHelper { get; }
public EmployeeWraperHelper EmployeeWraperHelper { get; }
public FileEntryWrapperHelper(
ApiDateTimeHelper apiDateTimeHelper,
EmployeeWraperHelper employeeWraperHelper
)
{
ApiDateTimeHelper = apiDateTimeHelper;
EmployeeWraperHelper = employeeWraperHelper;
}
public T Get<T>(FileEntry entry) where T : FileEntryWrapper, new()
{
return new T
{
Id = entry.ID,
Title = entry.Title,
Access = entry.Access,
Shared = entry.Shared,
Created = ApiDateTimeHelper.Get(entry.CreateOn),
CreatedBy = EmployeeWraperHelper.Get(entry.CreateBy),
Updated = ApiDateTimeHelper.Get(entry.ModifiedOn),
UpdatedBy = EmployeeWraperHelper.Get(entry.ModifiedBy),
RootFolderType = entry.RootFolderType,
ProviderItem = entry.ProviderEntry,
ProviderKey = entry.ProviderKey,
ProviderId = entry.ProviderId
};
}
}
}

View File

@ -0,0 +1,170 @@
/*
*
* (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.Linq;
using System.Runtime.Serialization;
using ASC.Files.Core;
using ASC.Web.Files.Services.WCFService.FileOperations;
using ASC.Web.Studio.Utility;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
[DataContract(Name = "operation_result", Namespace = "")]
public class FileOperationWraper
{
/// <summary>
/// </summary>
[DataMember(Name = "id", IsRequired = false)]
public string Id { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "operation", IsRequired = false)]
public FileOperationType OperationType { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "progress", IsRequired = false)]
public int Progress { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "error", IsRequired = false)]
public string Error { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "processed", IsRequired = false)]
public string Processed { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "finished", IsRequired = false)]
public bool Finished { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "url", IsRequired = false)]
public string Url { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "files", IsRequired = true, EmitDefaultValue = true)]
public List<FileWrapper> Files { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "folders", IsRequired = true, EmitDefaultValue = true)]
public List<FolderWrapper> Folders { get; set; }
/// <summary>
/// </summary>
public FileOperationWraper()
{
}
/// <summary>
/// </summary>
/// <returns></returns>
public static FileOperationWraper GetSample()
{
return new FileOperationWraper
{
Id = Guid.NewGuid().ToString(),
OperationType = FileOperationType.Move,
Progress = 100,
//Source = "folder_1,file_1",
//Result = "folder_1,file_1",
Error = "",
Processed = "1",
Files = new List<FileWrapper> { FileWrapper.GetSample() },
Folders = new List<FolderWrapper> { FolderWrapper.GetSample() }
};
}
}
public class FileOperationWraperHelper
{
public FolderWrapperHelper FolderWrapperHelper { get; }
public FileWrapperHelper FilesWrapperHelper { get; }
public IDaoFactory DaoFactory { get; }
public CommonLinkUtility CommonLinkUtility { get; }
public FileOperationWraperHelper(
FolderWrapperHelper folderWrapperHelper,
FileWrapperHelper filesWrapperHelper,
IDaoFactory daoFactory,
CommonLinkUtility commonLinkUtility)
{
FolderWrapperHelper = folderWrapperHelper;
FilesWrapperHelper = filesWrapperHelper;
DaoFactory = daoFactory;
CommonLinkUtility = commonLinkUtility;
}
public FileOperationWraper Get(FileOperationResult o)
{
var result = new FileOperationWraper
{
Id = o.Id,
OperationType = o.OperationType,
Progress = o.Progress,
Error = o.Error,
Processed = o.Processed,
Finished = o.Finished
};
if (!string.IsNullOrEmpty(o.Result) && result.OperationType != FileOperationType.Delete)
{
var arr = o.Result.Split(':');
var folders = arr.Where(s => s.StartsWith("folder_")).Select(s => s.Substring(7));
if (folders.Any())
{
var folderDao = DaoFactory.FolderDao;
result.Folders = folderDao.GetFolders(folders.ToArray()).Select(FolderWrapperHelper.Get<FolderWrapper>).ToList();
}
var files = arr.Where(s => s.StartsWith("file_")).Select(s => s.Substring(5));
if (files.Any())
{
var fileDao = DaoFactory.FileDao;
result.Files = fileDao.GetFiles(files.ToArray()).Select(FolderWrapperHelper.Get<FileWrapper>).ToList();
}
if (result.OperationType == FileOperationType.Download)
{
result.Url = CommonLinkUtility.GetFullAbsolutePath(o.Result);
}
}
return result;
}
}
}

View File

@ -0,0 +1,75 @@
/*
*
* (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.Runtime.Serialization;
using ASC.Core;
using ASC.Files.Core.Security;
using ASC.Web.Files.Services.WCFService;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
[DataContract(Name = "share", Namespace = "")]
public class FileShareParams
{
/// <summary>
/// </summary>
[DataMember(Name = "shareTo", Order = 0)]
public Guid ShareTo { get; set; }
/// <summary>
/// </summary>
[DataMember(Name = "access", Order = 1)]
public FileShare Access { get; set; }
/// <summary>
/// </summary>
/// <returns></returns>
}
public class FileShareParamsHelper
{
public UserManager UserManager { get; }
public FileShareParamsHelper(UserManager userManager)
{
UserManager = userManager;
}
public AceWrapper ToAceObject(FileShareParams fileShareParams)
{
return new AceWrapper
{
Share = fileShareParams.Access,
SubjectId = fileShareParams.ShareTo,
SubjectGroup = !UserManager.UserExists(fileShareParams.ShareTo)
};
}
}
}

View File

@ -0,0 +1,140 @@
/*
*
* (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 ASC.Core;
using ASC.Files.Core;
using ASC.Files.Core.Security;
using ASC.Web.Api.Models;
using ASC.Web.Files.Services.WCFService;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
public class FileShareWrapper
{
/// <summary>
/// </summary>
/// <param name="aceWrapper"></param>
public FileShareWrapper()
{
}
/// <summary>
/// </summary>
public FileShare Access { get; set; }
/// <summary>
/// </summary>
public object SharedTo { get; set; }
/// <summary>
/// </summary>
public bool IsLocked { get; set; }
/// <summary>
/// </summary>
public bool IsOwner { get; set; }
/// <summary>
/// </summary>
/// <returns></returns>
public static FileShareWrapper GetSample()
{
return new FileShareWrapper
{
Access = FileShare.ReadWrite,
IsLocked = false,
IsOwner = true,
//SharedTo = EmployeeWraper.GetSample()
};
}
}
/// <summary>
/// </summary>
public class FileShareLink
{
/// <summary>
/// </summary>
public Guid Id;
/// <summary>
/// </summary>
public string ShareLink;
}
public class FileShareWrapperHelper
{
private UserManager UserManager { get; }
private EmployeeWraperFullHelper EmployeeWraperFullHelper { get; }
public FileShareWrapperHelper(
UserManager userManager,
EmployeeWraperFullHelper employeeWraperFullHelper)
{
UserManager = userManager;
EmployeeWraperFullHelper = employeeWraperFullHelper;
}
public FileShareWrapper Get(AceWrapper aceWrapper)
{
var result = new FileShareWrapper
{
IsOwner = aceWrapper.Owner,
IsLocked = aceWrapper.LockedRights
};
if (aceWrapper.SubjectGroup)
{
if (aceWrapper.SubjectId == FileConstant.ShareLinkId)
{
result.SharedTo = new FileShareLink
{
Id = aceWrapper.SubjectId,
ShareLink = aceWrapper.Link
};
}
else
{
//Shared to group
result.SharedTo = new GroupWrapperSummary(UserManager.GetGroupInfo(aceWrapper.SubjectId), UserManager);
}
}
else
{
result.SharedTo = EmployeeWraperFullHelper.GetFull(UserManager.GetUsers(aceWrapper.SubjectId));
}
result.Access = aceWrapper.Share;
return result;
}
}
}

View File

@ -0,0 +1,217 @@
/*
*
* (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.Globalization;
using System.Runtime.Serialization;
using ASC.Api.Core;
using ASC.Core;
using ASC.Files.Core;
using ASC.Files.Core.Security;
using ASC.Web.Api.Models;
using ASC.Web.Core.Files;
using ASC.Web.Files.Classes;
using ASC.Web.Studio.Utility;
using File = ASC.Files.Core.File;
using FileShare = ASC.Files.Core.Security.FileShare;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
[DataContract(Name = "file", Namespace = "")]
public class FileWrapper : FileEntryWrapper
{
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public object FolderId { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = true, IsRequired = false)]
public int Version { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = true, IsRequired = false)]
public int VersionGroup { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = true)]
public string ContentLength { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = true)]
public long PureContentLength { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = true, IsRequired = false)]
public FileStatus FileStatus { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public string ViewUrl { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public string WebUrl { get; set; }
/// <summary>
///
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public FileType FileType { get; set; }
/// <summary>
///
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public string FileExst { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = true, IsRequired = false)]
public string Comment { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false)]
public bool Encrypted { get; set; }
/// <summary>
/// </summary>
/// <param name="file"></param>
public FileWrapper()
{
}
/// <summary>
/// </summary>
/// <returns></returns>
public static FileWrapper GetSample()
{
return new FileWrapper
{
Access = FileShare.ReadWrite,
//Updated = ApiDateTime.GetSample(),
//Created = ApiDateTime.GetSample(),
//CreatedBy = EmployeeWraper.GetSample(),
Id = new Random().Next(),
RootFolderType = FolderType.BUNCH,
Shared = false,
Title = "Some titile.txt",
FileExst = ".txt",
FileType = FileType.Document,
//UpdatedBy = EmployeeWraper.GetSample(),
ContentLength = 12345.ToString(CultureInfo.InvariantCulture),
FileStatus = FileStatus.IsNew,
FolderId = 12334,
Version = 3,
VersionGroup = 1,
ViewUrl = "http://www.onlyoffice.com/viewfile?fileid=2221"
};
}
}
public class FileWrapperHelper : FileEntryWrapperHelper
{
public AuthContext AuthContext { get; }
public IDaoFactory DaoFactory { get; }
public FileSecurity FileSecurity { get; }
public GlobalFolderHelper GlobalFolderHelper { get; }
public CommonLinkUtility CommonLinkUtility { get; }
public FilesLinkUtility FilesLinkUtility { get; }
public FileUtility FileUtility { get; }
public FileWrapperHelper(
ApiDateTimeHelper apiDateTimeHelper,
EmployeeWraperHelper employeeWrapperHelper,
AuthContext authContext,
IDaoFactory daoFactory,
FileSecurity fileSecurity,
GlobalFolderHelper globalFolderHelper,
CommonLinkUtility commonLinkUtility,
FilesLinkUtility filesLinkUtility,
FileUtility fileUtility)
: base(apiDateTimeHelper, employeeWrapperHelper)
{
AuthContext = authContext;
DaoFactory = daoFactory;
FileSecurity = fileSecurity;
GlobalFolderHelper = globalFolderHelper;
CommonLinkUtility = commonLinkUtility;
FilesLinkUtility = filesLinkUtility;
FileUtility = fileUtility;
}
public FileWrapper Get(File file)
{
var result = Get<FileWrapper>(file);
result.FolderId = file.FolderID;
if (file.RootFolderType == FolderType.USER
&& !Equals(file.RootFolderCreator, AuthContext.CurrentAccount.ID))
{
result.RootFolderType = FolderType.SHARE;
var folderDao = DaoFactory.FolderDao;
var parentFolder = folderDao.GetFolder(file.FolderID);
if (!FileSecurity.CanRead(parentFolder))
{
result.FolderId = GlobalFolderHelper.FolderShare;
}
}
result.FileExst = FileUtility.GetFileExtension(file.Title);
result.FileType = FileUtility.GetFileTypeByExtention(result.FileExst);
result.Version = file.Version;
result.VersionGroup = file.VersionGroup;
result.ContentLength = file.ContentLengthString;
result.FileStatus = file.FileStatus;
result.PureContentLength = file.ContentLength;
result.Comment = file.Comment;
result.Encrypted = file.Encrypted;
try
{
result.ViewUrl = CommonLinkUtility.GetFullAbsolutePath(file.DownloadUrl);
result.WebUrl = CommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.GetFileWebPreviewUrl(FileUtility, file.Title, file.ID));
}
catch (Exception)
{
//Don't catch anything here because of httpcontext
}
return result;
}
}
}

View File

@ -0,0 +1,138 @@
/*
*
* (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.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using ASC.Files.Core;
using ASC.Web.Files.Services.WCFService;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
[DataContract(Name = "content", Namespace = "")]
public class FolderContentWrapper
{
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public List<FileWrapper> Files { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = false)]
public List<FolderWrapper> Folders { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public FolderWrapper Current { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public object PathParts { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public int StartIndex { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public int Count { get; set; }
/// <summary>
/// </summary>
[DataMember(IsRequired = false, EmitDefaultValue = true)]
public int Total { get; set; }
/// <summary>
/// </summary>
/// <param name="folderItems"></param>
/// <param name="startIndex"></param>
public FolderContentWrapper()
{
}
/// <summary>
/// </summary>
/// <returns></returns>
public static FolderContentWrapper GetSample()
{
return new FolderContentWrapper
{
Current = FolderWrapper.GetSample(),
Files = new List<FileWrapper>(new[] { FileWrapper.GetSample(), FileWrapper.GetSample() }),
Folders = new List<FolderWrapper>(new[] { FolderWrapper.GetSample(), FolderWrapper.GetSample() }),
PathParts = new
{
key = "Key",
path = "//path//to//folder"
},
StartIndex = 0,
Count = 4,
Total = 4,
};
}
}
public class FolderContentWrapperHelper
{
public FileWrapperHelper FileWrapperHelper { get; }
public FolderWrapperHelper FolderWrapperHelper { get; }
public FolderContentWrapperHelper(
FileWrapperHelper fileWrapperHelper,
FolderWrapperHelper folderWrapperHelper)
{
FileWrapperHelper = fileWrapperHelper;
FolderWrapperHelper = folderWrapperHelper;
}
public FolderContentWrapper Get(DataWrapper folderItems, int startIndex)
{
var result = new FolderContentWrapper
{
Files = folderItems.Entries.OfType<File>().Select(FileWrapperHelper.Get<FileWrapper>).ToList(),
Folders = folderItems.Entries.OfType<Folder>().Select(FileWrapperHelper.Get<FolderWrapper>).ToList(),
Current = FileWrapperHelper.Get<FolderWrapper>(folderItems.FolderInfo),
PathParts = folderItems.FolderPathParts,
StartIndex = startIndex
};
result.Count = result.Files.Count + result.Folders.Count;
result.Total = folderItems.Total;
return result;
}
}
}

View File

@ -0,0 +1,139 @@
/*
*
* (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.Runtime.Serialization;
using ASC.Api.Core;
using ASC.Core;
using ASC.Files.Core;
using ASC.Files.Core.Security;
using ASC.Web.Api.Models;
using ASC.Web.Files.Classes;
namespace ASC.Api.Documents
{
/// <summary>
/// </summary>
[DataContract(Name = "folder", Namespace = "")]
public class FolderWrapper : FileEntryWrapper
{
/// <summary>
/// </summary>
[DataMember(IsRequired = true, EmitDefaultValue = true)]
public object ParentId { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = true, IsRequired = false)]
public int FilesCount { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = true, IsRequired = false)]
public int FoldersCount { get; set; }
/// <summary>
/// </summary>
[DataMember(EmitDefaultValue = false, IsRequired = false)]
public bool IsShareable { get; set; }
/// <summary>
/// </summary>
/// <param name="folder"></param>
public FolderWrapper()
{
}
/// <summary>
/// </summary>
/// <returns></returns>
public static FolderWrapper GetSample()
{
return new FolderWrapper
{
Access = FileShare.ReadWrite,
//Updated = ApiDateTime.GetSample(),
//Created = ApiDateTime.GetSample(),
//CreatedBy = EmployeeWraper.GetSample(),
Id = new Random().Next(),
RootFolderType = FolderType.BUNCH,
Shared = false,
Title = "Some titile",
//UpdatedBy = EmployeeWraper.GetSample(),
FilesCount = new Random().Next(),
FoldersCount = new Random().Next(),
ParentId = new Random().Next(),
IsShareable = false
};
}
}
public class FolderWrapperHelper : FileEntryWrapperHelper
{
public AuthContext AuthContext { get; }
public IDaoFactory DaoFactory { get; }
public FileSecurity FileSecurity { get; }
public GlobalFolderHelper GlobalFolderHelper { get; }
public FolderWrapperHelper(
ApiDateTimeHelper apiDateTimeHelper,
EmployeeWraperHelper employeeWrapperHelper,
AuthContext authContext,
IDaoFactory daoFactory,
FileSecurity fileSecurity,
GlobalFolderHelper globalFolderHelper)
: base(apiDateTimeHelper, employeeWrapperHelper)
{
AuthContext = authContext;
DaoFactory = daoFactory;
FileSecurity = fileSecurity;
GlobalFolderHelper = globalFolderHelper;
}
public FolderWrapper Get(Folder folder)
{
var result = Get<FolderWrapper>(folder);
result.ParentId = folder.ParentFolderID;
if (folder.RootFolderType == FolderType.USER
&& !Equals(folder.RootFolderCreator, AuthContext.CurrentAccount.ID))
{
result.RootFolderType = FolderType.SHARE;
var folderDao = DaoFactory.FolderDao;
var parentFolder = folderDao.GetFolder(folder.ParentFolderID);
if (!FileSecurity.CanRead(parentFolder))
result.ParentId = GlobalFolderHelper.FolderShare;
}
result.FilesCount = folder.TotalFiles;
result.FoldersCount = folder.TotalSubFolders;
result.IsShareable = folder.Shareable;
return result;
}
}
}