Merge branch 'develop' of github.com:ONLYOFFICE/DocSpace into feature/branding

This commit is contained in:
Viktor Fomin 2022-08-24 20:04:37 +03:00
commit ceedc9a187
27 changed files with 327 additions and 270 deletions

View File

@ -95,8 +95,7 @@
"viewed-media": [ ".aac", ".flac", ".m4a", ".mp3", ".oga", ".ogg", ".wav", ".f4v", ".m4v", ".mov", ".mp4", ".ogv", ".webm" ],
"index": [ ".pptx", ".xlsx", ".docx" ],
"oform": {
"url": "https://cmsoforms.onlyoffice.com/api/oforms?populate=*&locale=all",
"period": 60,
"url": "https://cmsoforms.onlyoffice.com/api/oforms/",
"ext": ".oform"
}
},

View File

@ -76,10 +76,10 @@
"domain": [
{
"name": "logos_temp",
"visible": false,
"data": "00000000-0000-0000-0000-000000000000",
"type": "disc",
"path": "$STORAGE_ROOT\\Products\\Files\\logos\\{0}\\temp",
"expires": "0:10:0"
"path": "$STORAGE_ROOT\\Products\\Files\\logos\\{0}\\temp"
}
]
},

View File

@ -66,6 +66,7 @@
"i18next-express-middleware": "^2.0.0",
"i18next-fs-backend": "^1.1.4",
"morgan": "^1.10.0",
"nconf": "^0.12.0",
"utf-8-validate": "^5.0.9",
"winston": "^3.8.1",
"winston-daily-rotate-file": "^4.7.1"

View File

@ -1,3 +1,6 @@
{
"PORT": "5013"
"PORT": "5013",
"app": {
"appsettings": "../../../config"
}
}

View File

@ -0,0 +1,35 @@
import nconf from "nconf";
import path from "path";
import fs from "fs";
nconf.argv().env().file("config", path.join(__dirname, "config.json"));
getAndSaveAppsettings();
function getAndSaveAppsettings() {
let appsettings = nconf.get("app").appsettings;
if (!path.isAbsolute(appsettings)) {
appsettings = path.join(__dirname, appsettings);
}
const env = nconf.get("app").environment;
const valueEnv = nconf.get(env);
const fileWithEnv = path.join(
appsettings,
"appsettings." + valueEnv + ".json"
);
if (fs.existsSync(fileWithEnv)) {
nconf.file("appsettings", fileWithEnv);
} else {
nconf.file("appsettings", path.join(appsettings, "appsettings.json"));
}
nconf.file(
"appsettingsServices",
path.join(appsettings, "appsettings.services.json")
);
}
export default nconf;

View File

@ -2,19 +2,18 @@ import winston from "winston";
import "winston-daily-rotate-file";
import path from "path";
import fs from "fs";
import config from "../config";
let logpath = process.env.logpath || null;
let logPath = config.get("logPath");
if (logpath != null) {
if (!path.isAbsolute(logpath)) {
logpath = path.join(__dirname, "..", logpath);
if (logPath != null) {
if (!path.isAbsolute(logPath)) {
logPath = path.join(__dirname, "..", logPath);
}
}
const fileName = IS_DEVELOPMENT
? path.join(__dirname, "..", "..", "..", "Logs", "editor.%DATE%.log")
: logpath
? path.join(logpath, "editor.%DATE%.log")
const fileName = logPath
? path.join(logPath, "editor.%DATE%.log")
: path.join(__dirname, "..", "..", "..", "Logs", "editor.%DATE%.log");
const dirName = path.dirname(fileName);

View File

@ -67,7 +67,7 @@ public class FileShareDtoHelper
_employeeWraperFullHelper = employeeWraperFullHelper;
}
public FileShareDto Get(AceWrapper aceWrapper)
public async Task<FileShareDto> Get(AceWrapper aceWrapper)
{
var result = new FileShareDto
{
@ -93,7 +93,7 @@ public class FileShareDtoHelper
}
else
{
result.SharedTo = _employeeWraperFullHelper.GetFull(_userManager.GetUsers(aceWrapper.SubjectId));
result.SharedTo = await _employeeWraperFullHelper.GetFull(_userManager.GetUsers(aceWrapper.SubjectId));
}
result.Access = aceWrapper.Share;

View File

@ -109,7 +109,7 @@ public class FolderDtoHelper : FileEntryDtoHelper
result.Tags = folder.Tags.Select(t => t.Name);
}
result.Logo = await _roomLogoManager.GetLogo(folder.Id);
result.Logo = await _roomLogoManager.GetLogo(folder);
result.RoomType = folder.FolderType switch
{
FolderType.FillingFormsRoom => RoomType.FillingFormsRoom,

View File

@ -36,7 +36,7 @@ public interface IProviderInfo : IDisposable
DateTime CreateOn { get; }
string CustomerTitle { get; }
string RootFolderId { get; }
string FolderId { get; }
string FolderId { get; set; }
Task<bool> CheckAccessAsync();
Task InvalidateStorageAsync();

View File

@ -157,6 +157,7 @@ public class AbstractDao
{
using var filesDbContext = _dbContextFactory.CreateDbContext();
result = await Query(filesDbContext.ThirdpartyIdMapping)
.AsNoTracking()
.Where(r => r.HashId == id.ToString())
.Select(r => r.Id)
.FirstOrDefaultAsync();
@ -173,6 +174,7 @@ public class AbstractDao
using var filesDbContext = _dbContextFactory.CreateDbContext();
await filesDbContext.AddOrUpdateAsync(r => r.ThirdpartyIdMapping, newItem);
await filesDbContext.SaveChangesAsync();
}
return result;

View File

@ -739,6 +739,10 @@ public class FileSecurity : IFileSecurity
{
return true;
}
else if (e.Access != FileShare.Restrict && e.CreateBy == userId && (e.FileEntryType == FileEntryType.File || folder.FolderType != FolderType.COMMON))
{
return true;
}
else if (action == FilesSecurityActions.Delete && (e.Access == FileShare.RoomManager || e.Access == FileShare.ReadWrite))
{
if (file != null && (file.RootFolderType == FolderType.VirtualRooms || file.RootFolderType == FolderType.Archive))
@ -751,10 +755,6 @@ public class FileSecurity : IFileSecurity
return true;
}
}
else if (e.Access != FileShare.Restrict && e.CreateBy == userId && (e.FileEntryType == FileEntryType.File || folder.FolderType != FolderType.COMMON))
{
return true;
}
if (e.CreateBy == userId)
{

View File

@ -229,7 +229,7 @@ internal class ProviderAccountDao : IProviderDao
return true;
}
public async Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType)
public async Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType roomType)
{
using var filesDbContext = _dbContextFactory.CreateDbContext();
var forUpdate = await filesDbContext.ThirdpartyAccount
@ -242,8 +242,9 @@ internal class ProviderAccountDao : IProviderDao
return false;
}
forUpdate.RoomType = folderType;
forUpdate.RoomType = roomType;
forUpdate.FolderId = folderId;
forUpdate.FolderType = FolderType.VirtualRooms;
await filesDbContext.SaveChangesAsync();

View File

@ -153,6 +153,13 @@ internal abstract class RegexDaoSelectorBase<T> : IDaoSelector<T> where T : clas
provider.UpdateTitle(newTitle); //This will update cached version too
}
public async Task UpdateProviderFolderId(T provider, string id)
{
var dbDao = _serviceProvider.GetService<ProviderAccountDao>();
await dbDao.UpdateProviderInfoAsync(provider.ID, id, provider.FolderType);
provider.FolderId = id;
}
protected virtual T GetProviderInfo(int linkId)
{
var dbDao = _daoFactory.ProviderDao;

View File

@ -143,38 +143,52 @@ internal class SharePointDaoBase : ThirdPartyProviderDao<SharePointProviderInfo>
var newID = oldID.Replace(oldValue, newValue);
var newHashID = await MappingIDAsync(newID);
var mappingForUpdate = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID)
.ToListAsync();
var mappingForDelete = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID).ToListAsync();
foreach (var m in mappingForUpdate)
var mappingForInsert = mappingForDelete.Select(m => new DbFilesThirdpartyIdMapping
{
m.Id = newID;
m.HashId = newHashID;
}
TenantId = m.TenantId,
Id = newID,
HashId = newHashID
});
await filesDbContext.SaveChangesAsync();
filesDbContext.RemoveRange(mappingForDelete);
await filesDbContext.AddRangeAsync(mappingForInsert);
var securityForUpdate = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
var securityForDelete = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID).ToListAsync();
foreach (var s in securityForUpdate)
var securityForInsert = securityForDelete.Select(s => new DbFilesSecurity
{
s.EntryId = newHashID;
s.TimeStamp = DateTime.Now;
}
TenantId = s.TenantId,
TimeStamp = DateTime.Now,
EntryId = newHashID,
Share = s.Share,
Subject = s.Subject,
EntryType = s.EntryType,
Owner = s.Owner
});
await filesDbContext.SaveChangesAsync();
filesDbContext.RemoveRange(securityForDelete);
await filesDbContext.AddRangeAsync(securityForInsert);
var linkForUpdate = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
var linkForDelete = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID).ToListAsync();
foreach (var l in linkForUpdate)
var linkForInsert = linkForDelete.Select(l => new DbFilesTagLink
{
l.EntryId = newHashID;
}
EntryId = newHashID,
Count = l.Count,
CreateBy = l.CreateBy,
CreateOn = l.CreateOn,
EntryType = l.EntryType,
TagId = l.TagId,
TenantId = l.TenantId
});
filesDbContext.RemoveRange(linkForDelete);
await filesDbContext.AddRangeAsync(linkForInsert);
await filesDbContext.SaveChangesAsync();
}

View File

@ -403,7 +403,13 @@ internal class SharePointFolderDao : SharePointDaoBase, IFolderDao<string>
else
{
newFolderId = (string)await ProviderInfo.RenameFolderAsync(folder.Id, newTitle);
if (DocSpaceHelper.IsRoom(ProviderInfo.FolderType) && ProviderInfo.FolderId != null && ProviderInfo.FolderId == oldId)
{
await DaoSelector.UpdateProviderFolderId(ProviderInfo, newFolderId);
}
}
await UpdatePathInDBAsync(oldId, newFolderId);
return newFolderId;

View File

@ -163,38 +163,52 @@ internal abstract class SharpBoxDaoBase : ThirdPartyProviderDao<SharpBoxProvider
var newID = oldID.Replace(oldValue, newValue);
var newHashID = await MappingIDAsync(newID);
var mappingForUpdate = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID)
.ToListAsync();
var mappingForDelete = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID).ToListAsync();
foreach (var m in mappingForUpdate)
var mappingForInsert = mappingForDelete.Select(m => new DbFilesThirdpartyIdMapping
{
m.Id = newID;
m.HashId = newHashID;
}
TenantId = m.TenantId,
Id = newID,
HashId = newHashID
});
await filesDbContext.SaveChangesAsync();
filesDbContext.RemoveRange(mappingForDelete);
await filesDbContext.AddRangeAsync(mappingForInsert);
var securityForUpdate = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
var securityForDelete = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID).ToListAsync();
foreach (var s in securityForUpdate)
var securityForInsert = securityForDelete.Select(s => new DbFilesSecurity
{
s.EntryId = newHashID;
s.TimeStamp = DateTime.Now;
}
TenantId = s.TenantId,
TimeStamp = DateTime.Now,
EntryId = newHashID,
Share = s.Share,
Subject = s.Subject,
EntryType = s.EntryType,
Owner = s.Owner
});
await filesDbContext.SaveChangesAsync();
filesDbContext.RemoveRange(securityForDelete);
await filesDbContext.AddRangeAsync(securityForInsert);
var linkForUpdate = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
var linkForDelete = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID).ToListAsync();
foreach (var l in linkForUpdate)
var linkForInsert = linkForDelete.Select(l => new DbFilesTagLink
{
l.EntryId = newHashID;
}
EntryId = newHashID,
Count = l.Count,
CreateBy = l.CreateBy,
CreateOn = l.CreateOn,
EntryType = l.EntryType,
TagId = l.TagId,
TenantId = l.TenantId
});
filesDbContext.RemoveRange(linkForDelete);
await filesDbContext.AddRangeAsync(linkForInsert);
await filesDbContext.SaveChangesAsync();
}

View File

@ -461,6 +461,11 @@ internal class SharpBoxFolderDao : SharpBoxDaoBase, IFolderDao<string>
//We can't search google folders by title because root can have multiple folders with the same name
//var newFolder = SharpBoxProviderInfo.Storage.GetFileSystemObject(newTitle, folder.Parent);
newId = MakeId(entry);
if (DocSpaceHelper.IsRoom(ProviderInfo.FolderType) && ProviderInfo.FolderId != null && ProviderInfo.FolderId == oldId)
{
await DaoSelector.UpdateProviderFolderId(ProviderInfo, newId);
}
}
}

View File

@ -90,6 +90,9 @@ public class RoomLogoManager
var fileName = Path.GetFileName(tempFile);
var data = await GetTempAsync(fileName);
id = GetId(room);
await DeleteLogo(id);
await SaveWithProcessAsync(id, data, -1, new Point(x, y), new Size(width, height));
if (EnableAudit)
@ -110,17 +113,16 @@ public class RoomLogoManager
throw new InvalidOperationException("You don't have permission to edit the room");
}
id = GetId(room);
try
{
await DataStore.DeleteFilesAsync(string.Empty, $"{ProcessFolderId(id)}*.*", false);
await DeleteLogo(id);
if (EnableAudit)
{
_filesMessageService.Send(room, Headers, MessageAction.RoomLogoDeleted);
}
_cache.Remove(_cachePattern);
_cache.Remove(GetKey(id));
}
catch (DirectoryNotFoundException e)
{
@ -130,8 +132,10 @@ public class RoomLogoManager
return room;
}
public async Task<Logo> GetLogo<T>(T id)
public async Task<Logo> GetLogo<T>(Folder<T> room)
{
var id = GetId(room);
return new Logo
{
Original = await GetOriginalLogoPath(id),
@ -294,6 +298,14 @@ public class RoomLogoManager
}
}
private async Task DeleteLogo<T>(T id)
{
await DataStore.DeleteFilesAsync(string.Empty, $"{ProcessFolderId(id)}*.*", false);
_cache.Remove(_cachePattern);
_cache.Remove(GetKey(id));
}
private string ProcessFolderId<T>(T id)
{
ArgumentNullException.ThrowIfNull(id, nameof(id));
@ -312,4 +324,10 @@ public class RoomLogoManager
{
return $"{TenantId}/{id}/orig";
}
private T GetId<T>(Folder<T> room)
{
return room.ProviderEntry && (room.RootId.ToString().Contains("sbox")
|| room.RootId.ToString().Contains("spoint")) ? room.RootId : room.Id;
}
}

View File

@ -166,6 +166,8 @@ global using DocuSign.eSign.Model;
global using Dropbox.Api;
global using Dropbox.Api.Files;
global using Flurl;
global using Google;
global using Google.Apis.Auth.OAuth2;
global using Google.Apis.Auth.OAuth2.Flows;

View File

@ -24,104 +24,51 @@
// 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 File = System.IO.File;
namespace ASC.Files.Core.Services.OFormService;
[Singletone]
public class OFormRequestManager : IDisposable
public class OFormRequestManager
{
private readonly OFormSettings _configuration;
private readonly ILogger<OFormRequestManager> _logger;
private readonly IHttpClientFactory _httpClientFactory;
private readonly TempPath _tempPath;
private readonly SemaphoreSlim _semaphoreSlim;
private OFromRequestData _data;
private readonly JsonSerializerOptions _options;
public OFormRequestManager(
ILogger<OFormRequestManager> logger,
ConfigurationExtension configuration,
IHttpClientFactory httpClientFactory,
TempPath tempPath)
{
_semaphoreSlim = new SemaphoreSlim(1);
_configuration = configuration.GetSetting<OFormSettings>("files:oform");
_logger = logger;
_httpClientFactory = httpClientFactory;
_tempPath = tempPath;
}
public async Task Init(CancellationToken cancellationToken)
{
await _semaphoreSlim.WaitAsync();
try
{
using var httpClient = _httpClientFactory.CreateClient();
using var response = await httpClient.GetAsync(_configuration.Url);
if (response.StatusCode != HttpStatusCode.OK)
{
return;
}
var options = new JsonSerializerOptions
_options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
using var combined = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, cts.Token);
_data = JsonSerializer.Deserialize<OFromRequestData>(await response.Content.ReadAsStringAsync(combined.Token), options);
}
catch (Exception)
public async Task<Stream> Get(int id)
{
}
finally
{
_semaphoreSlim.Release();
}
}
public async Task<FileStream> Get(int id)
{
await _semaphoreSlim.WaitAsync(TimeSpan.FromSeconds(_configuration.Period));
try
{
if (_data == null) throw new Exception("not found");
var item = _data.Data.FirstOrDefault(r => r.Id == id);
if (item == null) throw new Exception("not found");
var file = item.Attributes.File.Data.FirstOrDefault(f => f.Attributes.Ext == _configuration.Ext);
if (file == null) throw new Exception("not found");
using var httpClient = _httpClientFactory.CreateClient();
using var response = await httpClient.GetAsync($"{_configuration.Url}{id}?populate[file_oform][fields]=url&populate[file_oform][fields]=name&populate[file_oform][fields]=ext&populate[file_oform][filters][url][$endsWith]={_configuration.Ext}");
var data = JsonSerializer.Deserialize<OFromRequestData>(await response.Content.ReadAsStringAsync(), _options);
var file = data.Data.Attributes.File.Data.FirstOrDefault(f => f.Attributes.Ext == _configuration.Ext);
var filePath = Path.Combine(_tempPath.GetTempPath(), file.Attributes.Name);
if (!File.Exists(filePath))
var streamResponse = await httpClient.GetAsync(file.Attributes.Url);
return await streamResponse.Content.ReadAsStreamAsync();
}
catch (Exception e)
{
await DownloadAndSave(file, filePath);
_logger.ErrorWithException(e);
throw;
}
return File.OpenRead(filePath);
}
finally
{
_semaphoreSlim.Release();
}
}
private async Task DownloadAndSave(OFromFileData fileData, string filePath)
{
using var httpClient = _httpClientFactory.CreateClient();
using var response = await httpClient.GetAsync(fileData.Attributes.Url);
using var stream = await response.Content.ReadAsStreamAsync();
using var fileStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.ReadWrite, System.IO.FileShare.Read);
await stream.CopyToAsync(fileStream);
}
public void Dispose()
{
_semaphoreSlim?.Dispose();
}
}

View File

@ -1,49 +0,0 @@
// (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
namespace ASC.Files.Core.Services.OFormService;
[Singletone]
public sealed class OFormService : BackgroundService
{
private readonly TimeSpan _formPeriod;
private readonly OFormRequestManager _oFormRequestManager;
public OFormService(OFormRequestManager oFormRequestManager, ConfigurationExtension configurationExtension)
{
_oFormRequestManager = oFormRequestManager;
_formPeriod = TimeSpan.FromSeconds(configurationExtension.GetSetting<OFormSettings>("files:oform").Period);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await _oFormRequestManager.Init(stoppingToken);
await Task.Delay(_formPeriod, stoppingToken);
}
}
}

View File

@ -28,5 +28,5 @@ namespace ASC.Files.Core.Services.OFormService;
public class OFromRequestData
{
public IEnumerable<OFromData> Data { get; set; }
public OFromData Data { get; set; }
}

View File

@ -88,9 +88,12 @@ public abstract class SecutiryController<T> : ApiControllerBase
/// <param name="fileId">File ID</param>
/// <returns>Shared file information</returns>
[HttpGet("file/{fileId}/share")]
public Task<IEnumerable<FileShareDto>> GetFileSecurityInfoAsync(T fileId)
public async IAsyncEnumerable<FileShareDto> GetFileSecurityInfoAsync(T fileId)
{
return _securityControllerHelper.GetFileSecurityInfoAsync(fileId);
await foreach (var s in _securityControllerHelper.GetFileSecurityInfoAsync(fileId))
{
yield return s;
}
}
/// <summary>
@ -101,9 +104,12 @@ public abstract class SecutiryController<T> : ApiControllerBase
/// <category>Sharing</category>
/// <returns>Shared folder information</returns>
[HttpGet("folder/{folderId}/share")]
public Task<IEnumerable<FileShareDto>> GetFolderSecurityInfoAsync(T folderId)
public async IAsyncEnumerable<FileShareDto> GetFolderSecurityInfoAsync(T folderId)
{
return _securityControllerHelper.GetFolderSecurityInfoAsync(folderId);
await foreach (var s in _securityControllerHelper.GetFolderSecurityInfoAsync(folderId))
{
yield return s;
}
}
[HttpPut("{fileId}/setacelink")]
@ -126,9 +132,12 @@ public abstract class SecutiryController<T> : ApiControllerBase
/// </remarks>
/// <returns>Shared file information</returns>
[HttpPut("file/{fileId}/share")]
public Task<IEnumerable<FileShareDto>> SetFileSecurityInfoAsync(T fileId, SecurityInfoRequestDto inDto)
public async IAsyncEnumerable<FileShareDto> SetFileSecurityInfoAsync(T fileId, SecurityInfoRequestDto inDto)
{
return _securityControllerHelper.SetFileSecurityInfoAsync(fileId, inDto.Share, inDto.Notify, inDto.SharingMessage);
await foreach (var s in _securityControllerHelper.SetSecurityInfoAsync(new List<T> { fileId }, new List<T>(), inDto.Share, inDto.Notify, inDto.SharingMessage))
{
yield return s;
}
}
/// <summary>
@ -145,9 +154,12 @@ public abstract class SecutiryController<T> : ApiControllerBase
/// <category>Sharing</category>
/// <returns>Shared folder information</returns>
[HttpPut("folder/{folderId}/share")]
public Task<IEnumerable<FileShareDto>> SetFolderSecurityInfoAsync(T folderId, SecurityInfoRequestDto inDto)
public async IAsyncEnumerable<FileShareDto> SetFolderSecurityInfoAsync(T folderId, SecurityInfoRequestDto inDto)
{
return _securityControllerHelper.SetFolderSecurityInfoAsync(folderId, inDto.Share, inDto.Notify, inDto.SharingMessage);
await foreach (var s in _securityControllerHelper.SetSecurityInfoAsync(new List<T>(), new List<T> { folderId }, inDto.Share, inDto.Notify, inDto.SharingMessage))
{
yield return s;
}
}
[HttpGet("file/{fileId}/publickeys")]
@ -201,16 +213,18 @@ public class SecutiryControllerCommon : ApiControllerBase
}
[HttpPost("share")]
public async Task<IEnumerable<FileShareDto>> GetSecurityInfoAsync(BaseBatchRequestDto inDto)
public async IAsyncEnumerable<FileShareDto> GetSecurityInfoAsync(BaseBatchRequestDto inDto)
{
var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds);
var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds);
var result = new List<FileShareDto>();
result.AddRange(await _securityControllerHelperInt.GetSecurityInfoAsync(fileIntIds, folderIntIds));
result.AddRange(await _securityControllerHelperString.GetSecurityInfoAsync(fileStringIds, folderStringIds));
var internalIds = _securityControllerHelperInt.GetSecurityInfoAsync(fileIntIds, folderIntIds);
var thirdpartyIds = _securityControllerHelperString.GetSecurityInfoAsync(fileStringIds, folderStringIds);
return result;
await foreach (var r in internalIds.Concat(thirdpartyIds))
{
yield return r;
}
}
/// <summary>
@ -235,15 +249,17 @@ public class SecutiryControllerCommon : ApiControllerBase
[HttpPut("share")]
public async Task<IEnumerable<FileShareDto>> SetSecurityInfoAsync(SecurityInfoRequestDto inDto)
public async IAsyncEnumerable<FileShareDto> SetSecurityInfoAsync(SecurityInfoRequestDto inDto)
{
var (folderIntIds, folderStringIds) = FileOperationsManager.GetIds(inDto.FolderIds);
var (fileIntIds, fileStringIds) = FileOperationsManager.GetIds(inDto.FileIds);
var result = new List<FileShareDto>();
result.AddRange(await _securityControllerHelperInt.SetSecurityInfoAsync(fileIntIds, folderIntIds, inDto.Share, inDto.Notify, inDto.SharingMessage));
result.AddRange(await _securityControllerHelperString.SetSecurityInfoAsync(fileStringIds, folderStringIds, inDto.Share, inDto.Notify, inDto.SharingMessage));
var internalIds = _securityControllerHelperInt.SetSecurityInfoAsync(fileIntIds, folderIntIds, inDto.Share, inDto.Notify, inDto.SharingMessage);
var thirdpartyIds = _securityControllerHelperString.SetSecurityInfoAsync(fileStringIds, folderStringIds, inDto.Share, inDto.Notify, inDto.SharingMessage);
return result;
await foreach (var s in internalIds.Concat(thirdpartyIds))
{
yield return s;
}
}
}

View File

@ -320,16 +320,24 @@ public abstract class VirtualRoomsController<T> : ApiControllerBase
/// Room security info
/// </returns>
[HttpPut("rooms/{id}/share")]
public Task<IEnumerable<FileShareDto>> SetRoomSecurityAsync(T id, SecurityInfoRequestDto inDto)
public async IAsyncEnumerable<FileShareDto> SetRoomSecurityAsync(T id, SecurityInfoRequestDto inDto)
{
ErrorIfNotDocSpace();
IAsyncEnumerable<FileShareDto> result;
if (!string.IsNullOrEmpty(inDto.Key))
{
return SetRoomSecurityByLinkAsync(id, _authContext.CurrentAccount.ID, inDto.Access, inDto.Key);
result = SetRoomSecurityByLinkAsync(id, _authContext.CurrentAccount.ID, inDto.Access, inDto.Key);
}
else
{
result = _securityControllerHelper.SetFolderSecurityInfoAsync(id, inDto.Share, inDto.Notify, inDto.SharingMessage);
}
return _securityControllerHelper.SetFolderSecurityInfoAsync(id, inDto.Share, inDto.Notify, inDto.SharingMessage);
await foreach (var r in result)
{
yield return r;
}
}
/// <summary>
@ -568,7 +576,7 @@ public abstract class VirtualRoomsController<T> : ApiControllerBase
}
}
private async Task<IEnumerable<FileShareDto>> SetRoomSecurityByLinkAsync(T id, Guid userId, FileShare access, string key)
private async IAsyncEnumerable<FileShareDto> SetRoomSecurityByLinkAsync(T id, Guid userId, FileShare access, string key)
{
var result = _emailValidationKeyProvider.ValidateEmailKey(string.Empty + ConfirmType.LinkInvite + ((int)EmployeeType.User + (int)access + id.ToString()), key,
_emailValidationKeyProvider.ValidEmailKeyInterval);
@ -584,7 +592,10 @@ public abstract class VirtualRoomsController<T> : ApiControllerBase
Access = access
};
return await _securityControllerHelper.SetFolderSecurityInfoAsync(id, new[] { share }, false, null, true);
await foreach (var s in _securityControllerHelper.SetFolderSecurityInfoAsync(id, new[] { share }, false, null, true))
{
yield return s;
}
}
private async Task ErrorIfNotRights(T id, FileShare share)

View File

@ -95,21 +95,24 @@ public class SecurityControllerHelper<T> : FilesHelperBase<T>
return sharedInfo.Link;
}
public Task<IEnumerable<FileShareDto>> GetFileSecurityInfoAsync(T fileId)
public IAsyncEnumerable<FileShareDto> GetFileSecurityInfoAsync(T fileId)
{
return GetSecurityInfoAsync(new List<T> { fileId }, new List<T> { });
}
public Task<IEnumerable<FileShareDto>> GetFolderSecurityInfoAsync(T folderId)
public IAsyncEnumerable<FileShareDto> GetFolderSecurityInfoAsync(T folderId)
{
return GetSecurityInfoAsync(new List<T> { }, new List<T> { folderId });
}
public async Task<IEnumerable<FileShareDto>> GetSecurityInfoAsync(IEnumerable<T> fileIds, IEnumerable<T> folderIds, bool invite = false)
public async IAsyncEnumerable<FileShareDto> GetSecurityInfoAsync(IEnumerable<T> fileIds, IEnumerable<T> folderIds, bool invite = false)
{
var fileShares = await _fileStorageService.GetSharedInfoAsync(fileIds, folderIds, invite);
return fileShares.Select(_fileShareDtoHelper.Get).ToList();
foreach (var fileShareDto in fileShares)
{
yield return await _fileShareDtoHelper.Get(fileShareDto);
}
}
public async Task<bool> RemoveSecurityInfoAsync(List<T> fileIds, List<T> folderIds)
@ -119,17 +122,12 @@ public class SecurityControllerHelper<T> : FilesHelperBase<T>
return true;
}
public Task<IEnumerable<FileShareDto>> SetFileSecurityInfoAsync(T fileId, IEnumerable<FileShareParams> share, bool notify, string sharingMessage)
{
return SetSecurityInfoAsync(new List<T> { fileId }, new List<T>(), share, notify, sharingMessage);
}
public Task<IEnumerable<FileShareDto>> SetFolderSecurityInfoAsync(T folderId, IEnumerable<FileShareParams> share, bool notify, string sharingMessage, bool invite = false)
public IAsyncEnumerable<FileShareDto> SetFolderSecurityInfoAsync(T folderId, IEnumerable<FileShareParams> share, bool notify, string sharingMessage, bool invite = false)
{
return SetSecurityInfoAsync(new List<T>(), new List<T> { folderId }, share, notify, sharingMessage, invite);
}
public async Task<IEnumerable<FileShareDto>> SetSecurityInfoAsync(IEnumerable<T> fileIds, IEnumerable<T> folderIds, IEnumerable<FileShareParams> share, bool notify, string sharingMessage, bool invite = false)
public async IAsyncEnumerable<FileShareDto> SetSecurityInfoAsync(IEnumerable<T> fileIds, IEnumerable<T> folderIds, IEnumerable<FileShareParams> share, bool notify, string sharingMessage, bool invite = false)
{
if (share != null && share.Any())
{
@ -146,6 +144,9 @@ public class SecurityControllerHelper<T> : FilesHelperBase<T>
await _fileStorageService.SetAceObjectAsync(aceCollection, notify, invite);
}
return await GetSecurityInfoAsync(fileIds, folderIds, invite);
await foreach (var s in GetSecurityInfoAsync(fileIds, folderIds, invite))
{
yield return s;
}
}
}

View File

@ -53,9 +53,7 @@ public class Startup : BaseStartup
DIHelper.TryAdd<ChunkedUploaderHandlerService>();
DIHelper.TryAdd<DocuSignHandlerService>();
DIHelper.TryAdd<ThirdPartyAppHandlerService>();
DIHelper.TryAdd<OFormService>();
services.AddHostedService<OFormService>();
NotifyConfigurationExtension.Register(DIHelper);
}

View File

@ -2194,6 +2194,7 @@ __metadata:
i18next-fs-backend: ^1.1.4
json-loader: ^0.5.7
morgan: ^1.10.0
nconf: ^0.12.0
nodemon: ^2.0.7
npm-run-all: ^4.1.5
sass: ^1.53.0
@ -7238,7 +7239,7 @@ __metadata:
languageName: node
linkType: hard
"async@npm:^3.2.3":
"async@npm:^3.0.0, async@npm:^3.2.3":
version: 3.2.4
resolution: "async@npm:3.2.4"
checksum: 43d07459a4e1d09b84a20772414aa684ff4de085cbcaec6eea3c7a8f8150e8c62aa6cd4e699fe8ee93c3a5b324e777d34642531875a0817a35697522c1b02e89
@ -14087,6 +14088,13 @@ __metadata:
languageName: node
linkType: hard
"ini@npm:^2.0.0":
version: 2.0.0
resolution: "ini@npm:2.0.0"
checksum: e7aadc5fb2e4aefc666d74ee2160c073995a4061556b1b5b4241ecb19ad609243b9cceafe91bae49c219519394bbd31512516cb22a3b1ca6e66d869e0447e84e
languageName: node
linkType: hard
"inline-style-parser@npm:0.1.1":
version: 0.1.1
resolution: "inline-style-parser@npm:0.1.1"
@ -17717,6 +17725,18 @@ __metadata:
languageName: node
linkType: hard
"nconf@npm:^0.12.0":
version: 0.12.0
resolution: "nconf@npm:0.12.0"
dependencies:
async: ^3.0.0
ini: ^2.0.0
secure-keys: ^1.0.0
yargs: ^16.1.1
checksum: 70c1ce82d91149940dbe57555372c99282a9625a961915b302093b34e04ab308d978d1885224b9738a0873c064a0aa48914a7260e67ba312441fc4917221dbd8
languageName: node
linkType: hard
"nearley@npm:^2.7.10":
version: 2.20.1
resolution: "nearley@npm:2.20.1"
@ -21810,6 +21830,13 @@ __metadata:
languageName: node
linkType: hard
"secure-keys@npm:^1.0.0":
version: 1.0.0
resolution: "secure-keys@npm:1.0.0"
checksum: 3dd4e64e6717fe6e2dc4c70e172982fcbad87b853e96566ab1cfaec540587f737bac106853ae469cb32d4a6413cfe80a28176cfe7dfcf7ddd35c9f92e58dffed
languageName: node
linkType: hard
"select-hose@npm:^2.0.0":
version: 2.0.0
resolution: "select-hose@npm:2.0.0"
@ -25697,7 +25724,7 @@ __metadata:
languageName: node
linkType: hard
"yargs@npm:16.2.0, yargs@npm:^16.2.0":
"yargs@npm:16.2.0, yargs@npm:^16.1.1, yargs@npm:^16.2.0":
version: 16.2.0
resolution: "yargs@npm:16.2.0"
dependencies: