Merge branch 'feature/create-room' of github.com:ONLYOFFICE/AppServer into feature/create-room

This commit is contained in:
mushka 2022-08-23 14:48:33 +03:00
commit 9264bf2c56
13 changed files with 164 additions and 94 deletions

View File

@ -10,26 +10,31 @@ if %errorlevel% == 0 (
call start\stop.bat nopause
dotnet build ..\asc.web.slnf /fl1 /flp1:logfile=asc.web.log;verbosity=normal
echo.
)
if %errorlevel% == 0 (
echo install nodejs projects dependencies...
echo.
for /R "scripts\" %%f in (*.bat) do (
echo Run script %%~nxf...
echo.
call scripts\%%~nxf
)
)
echo.
if %errorlevel% == 0 (
call start\start.bat nopause
)
echo.
if "%1"=="nopause" goto end
pause
)
:end

View File

@ -1,9 +1,11 @@
@echo off
PUSHD %~dp0..\..
setlocal EnableDelayedExpansion
PUSHD %~dp0..
call runasadmin.bat "%~dpnx0"
if %errorlevel% == 0 (
PUSHD %~dp0..\..
setlocal EnableDelayedExpansion
for /R "build\run\" %%f in (*.bat) do (
call build\run\%%~nxf
echo service create "Onlyoffice%%~nf"

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

@ -137,49 +137,63 @@ internal class SharePointDaoBase : ThirdPartyProviderDao<SharePointProviderInfo>
.Select(r => r.Id)
.ToListAsync();
foreach (var oldID in oldIDs)
{
var oldHashID = await MappingIDAsync(oldID);
var newID = oldID.Replace(oldValue, newValue);
var newHashID = await MappingIDAsync(newID);
var mappingForUpdate = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID)
.ToListAsync();
foreach (var m in mappingForUpdate)
foreach (var oldID in oldIDs)
{
m.Id = newID;
m.HashId = newHashID;
}
var oldHashID = await MappingIDAsync(oldID);
var newID = oldID.Replace(oldValue, newValue);
var newHashID = await MappingIDAsync(newID);
var mappingForDelete = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID).ToListAsync();
var mappingForInsert = mappingForDelete.Select(m => new DbFilesThirdpartyIdMapping
{
TenantId = m.TenantId,
Id = newID,
HashId = newHashID
});
filesDbContext.RemoveRange(mappingForDelete);
await filesDbContext.AddRangeAsync(mappingForInsert);
var securityForDelete = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID).ToListAsync();
var securityForInsert = securityForDelete.Select(s => new DbFilesSecurity
{
TenantId = s.TenantId,
TimeStamp = DateTime.Now,
EntryId = newHashID,
Share = s.Share,
Subject = s.Subject,
EntryType = s.EntryType,
Owner = s.Owner
});
filesDbContext.RemoveRange(securityForDelete);
await filesDbContext.AddRangeAsync(securityForInsert);
var linkForDelete = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID).ToListAsync();
var linkForInsert = linkForDelete.Select(l => new DbFilesTagLink
{
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();
var securityForUpdate = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
foreach (var s in securityForUpdate)
{
s.EntryId = newHashID;
s.TimeStamp = DateTime.Now;
}
await filesDbContext.SaveChangesAsync();
var linkForUpdate = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
foreach (var l in linkForUpdate)
{
l.EntryId = newHashID;
}
await filesDbContext.SaveChangesAsync();
}
await tx.CommitAsync();
await tx.CommitAsync();
});
}

View File

@ -157,49 +157,63 @@ internal abstract class SharpBoxDaoBase : ThirdPartyProviderDao<SharpBoxProvider
.Select(r => r.Id)
.ToListAsync();
foreach (var oldID in oldIDs)
{
var oldHashID = await MappingIDAsync(oldID);
var newID = oldID.Replace(oldValue, newValue);
var newHashID = await MappingIDAsync(newID);
var mappingForUpdate = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID)
.ToListAsync();
foreach (var m in mappingForUpdate)
foreach (var oldID in oldIDs)
{
m.Id = newID;
m.HashId = newHashID;
}
var oldHashID = await MappingIDAsync(oldID);
var newID = oldID.Replace(oldValue, newValue);
var newHashID = await MappingIDAsync(newID);
var mappingForDelete = await Query(filesDbContext.ThirdpartyIdMapping)
.Where(r => r.HashId == oldHashID).ToListAsync();
var mappingForInsert = mappingForDelete.Select(m => new DbFilesThirdpartyIdMapping
{
TenantId = m.TenantId,
Id = newID,
HashId = newHashID
});
filesDbContext.RemoveRange(mappingForDelete);
await filesDbContext.AddRangeAsync(mappingForInsert);
var securityForDelete = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID).ToListAsync();
var securityForInsert = securityForDelete.Select(s => new DbFilesSecurity
{
TenantId = s.TenantId,
TimeStamp = DateTime.Now,
EntryId = newHashID,
Share = s.Share,
Subject = s.Subject,
EntryType = s.EntryType,
Owner = s.Owner
});
filesDbContext.RemoveRange(securityForDelete);
await filesDbContext.AddRangeAsync(securityForInsert);
var linkForDelete = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID).ToListAsync();
var linkForInsert = linkForDelete.Select(l => new DbFilesTagLink
{
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();
var securityForUpdate = await Query(filesDbContext.Security)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
foreach (var s in securityForUpdate)
{
s.EntryId = newHashID;
s.TimeStamp = DateTime.Now;
}
await filesDbContext.SaveChangesAsync();
var linkForUpdate = await Query(filesDbContext.TagLink)
.Where(r => r.EntryId == oldHashID)
.ToListAsync();
foreach (var l in linkForUpdate)
{
l.EntryId = newHashID;
}
await filesDbContext.SaveChangesAsync();
}
await tx.CommitAsync();
await tx.CommitAsync();
});
}

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))
{
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),
@ -169,7 +173,7 @@ public class RoomLogoManager
using var stream = new MemoryStream(data);
var path = await DataStore.SaveAsync(TempDomainPath, fileName, stream);
return path.ToString();
return path.RemoveQueryParams("auth", "expire").ToString();
}
public async Task<string> SaveWithProcessAsync<T>(T id, byte[] imageData, long maxFileSize, Point position, Size cropSize)
@ -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;