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, FolderType rootFolderType);
Task<bool> UpdateProviderInfoAsync(int linkId, string folderId, FolderType folderType); 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> 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); Task RemoveProviderInfoAsync(int linkId);
} }

View File

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

View File

@ -422,17 +422,29 @@ internal abstract class ThirdPartyProviderDao<T> : ThirdPartyProviderDao, IDispo
{ {
if (filterTypes.Any() && !filterTypes.Contains(FilterType.None)) 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, switch (f)
FilterType.EditingRooms => FolderType.EditingRoom, {
FilterType.ReviewRooms => FolderType.ReviewRoom, case FilterType.FillingFormsRooms:
FilterType.ReadOnlyRooms => FolderType.ReadOnlyRoom, filter.Add(FolderType.FillingFormsRoom);
FilterType.CustomRooms => FolderType.CustomRoom, break;
_ => FolderType.CustomRoom case FilterType.EditingRooms:
}).ToHashSet(); filter.Add(FolderType.EditingRoom);
break;
return folders.Where(f => filter.Contains(f.FolderType)); 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; return folders;

View File

@ -348,6 +348,64 @@ internal class ProviderAccountDao : IProviderDao
return toUpdate.Count == 1 ? linkId : default; 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) public virtual async Task RemoveProviderInfoAsync(int linkId)
{ {
var strategy = FilesDbContext.Database.CreateExecutionStrategy(); var strategy = FilesDbContext.Database.CreateExecutionStrategy();

View File

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