Merge branch 'feature/docspace-backup' of github.com:ONLYOFFICE/AppServer into feature/docspace-backup

This commit is contained in:
Tatiana Lopaeva 2022-07-26 15:53:56 +03:00
commit 8833c89a5a
5 changed files with 85 additions and 12 deletions

View File

@ -37,5 +37,6 @@ public interface IProviderDao
Task<bool> UpdateProviderInfoAsync(int linkId, FolderType rootFolderType);
Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType);
Task<int> UpdateProviderInfoAsync(int linkId, string customerTitle, AuthData authData, FolderType folderType, Guid? userId = null);
Task<int> UpdateBackupProviderInfoAsync(string providerKey, string customerTitle, AuthData authData);
Task RemoveProviderInfoAsync(int linkId);
}

View File

@ -1768,8 +1768,7 @@ public class FileStorageService<T> //: IFileStorageService
}
else
{
curProviderId = Convert.ToInt32(thirdparty.ProviderId);
curProviderId = await providerDao.UpdateProviderInfoAsync(curProviderId, thirdPartyParams.CustomerTitle, thirdPartyParams.AuthData, folderType);
curProviderId = await providerDao.UpdateBackupProviderInfoAsync(thirdPartyParams.ProviderKey, thirdPartyParams.CustomerTitle, thirdPartyParams.AuthData);
messageAction = MessageAction.ThirdPartyUpdated;
}

View File

@ -422,17 +422,29 @@ internal abstract class ThirdPartyProviderDao<T> : ThirdPartyProviderDao, IDispo
{
if (filterTypes.Any() && !filterTypes.Contains(FilterType.None))
{
var filter = filterTypes.Select(f => f switch
var filter = new HashSet<FolderType>();
foreach(var f in filterTypes)
{
FilterType.FillingFormsRooms => FolderType.FillingFormsRoom,
FilterType.EditingRooms => FolderType.EditingRoom,
FilterType.ReviewRooms => FolderType.ReviewRoom,
FilterType.ReadOnlyRooms => FolderType.ReadOnlyRoom,
FilterType.CustomRooms => FolderType.CustomRoom,
_ => FolderType.CustomRoom
}).ToHashSet();
return folders.Where(f => filter.Contains(f.FolderType));
switch (f)
{
case FilterType.FillingFormsRooms:
filter.Add(FolderType.FillingFormsRoom);
break;
case FilterType.EditingRooms:
filter.Add(FolderType.EditingRoom);
break;
case FilterType.ReviewRooms:
filter.Add(FolderType.ReviewRoom);
break;
case FilterType.ReadOnlyRooms:
filter.Add(FolderType.ReadOnlyRoom);
break;
case FilterType.CustomRooms:
filter.Add(FolderType.CustomRoom);
break;
}
}
return filter.Count == 0 ? folders : folders.Where(f => filter.Contains(f.FolderType));
}
return folders;

View File

@ -347,6 +347,64 @@ internal class ProviderAccountDao : IProviderDao
return toUpdate.Count == 1 ? linkId : default;
}
public virtual async Task<int> UpdateBackupProviderInfoAsync(string providerKey, string customerTitle, AuthData newAuthData)
{
var querySelect =
FilesDbContext.ThirdpartyAccount
.AsQueryable()
.Where(r => r.TenantId == TenantID)
.Where(r => r.FolderType == FolderType.ThirdpartyBackup);
DbFilesThirdpartyAccount thirdparty;
try
{
thirdparty = await querySelect.SingleAsync().ConfigureAwait(false);
}
catch (Exception e)
{
_logger.ErrorUpdateBackupProviderInfo(_securityContext.CurrentAccount.ID, e);
throw;
}
if (!ProviderTypesExtensions.TryParse(providerKey, true, out var key))
{
throw new ArgumentException("Unrecognize ProviderType");
}
if (newAuthData != null && !newAuthData.IsEmpty())
{
if (!string.IsNullOrEmpty(newAuthData.Token))
{
newAuthData = GetEncodedAccesToken(newAuthData, key);
}
if (!await CheckProviderInfoAsync(ToProviderInfo(0, key, customerTitle, newAuthData, _securityContext.CurrentAccount.ID, FolderType.ThirdpartyBackup, _tenantUtil.DateTimeToUtc(_tenantUtil.DateTimeNow()))).ConfigureAwait(false))
{
throw new UnauthorizedAccessException(string.Format(FilesCommonResource.ErrorMassage_SecurityException_Auth, key));
}
}
if (!string.IsNullOrEmpty(customerTitle))
{
thirdparty.Title = customerTitle;
}
thirdparty.UserId = _securityContext.CurrentAccount.ID;
thirdparty.Provider = providerKey;
if (!newAuthData.IsEmpty())
{
thirdparty.UserName = newAuthData.Login ?? "";
thirdparty.Password = EncryptPassword(newAuthData.Password);
thirdparty.Token = EncryptPassword(newAuthData.Token ?? "");
thirdparty.Url = newAuthData.Url ?? "";
}
await FilesDbContext.SaveChangesAsync().ConfigureAwait(false);
return thirdparty.Id;
}
public virtual async Task RemoveProviderInfoAsync(int linkId)
{

View File

@ -36,6 +36,9 @@ internal static partial class ProviderAccountDaoLogger
[LoggerMessage(Level = LogLevel.Error, Message = "UpdateProviderInfo: linkId = {linkId} , user = {userId}")]
public static partial void ErrorUpdateProviderInfo(this ILogger logger, int linkId, Guid userId, Exception exception);
[LoggerMessage(Level = LogLevel.Error, Message = "UpdateProviderInfo: user = {userId}")]
public static partial void ErrorUpdateBackupProviderInfo(this ILogger logger, Guid userId, Exception exception);
[LoggerMessage(Level = LogLevel.Error, Message = "DecryptPassword error: linkId = {linkId} , user = {userId}")]
public static partial void ErrorDecryptPassword(this ILogger logger, int linkId, Guid userId, Exception exception);
}