Skip to content

Commit

Permalink
Merge pull request 'feature/vdr-lifetime-correction' (#79) from featu…
Browse files Browse the repository at this point in the history
…re/vdr-lifetime-correction into release/v3.0.0
  • Loading branch information
pavelbannov committed Nov 13, 2024
2 parents 01affcb + f410b1e commit d1da085
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 deletions.
1 change: 1 addition & 0 deletions products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ Task<int> GetFoldersCountAsync(T parentId, FilterType filterType, bool subjectGr
Task<T> SetWatermarkSettings(WatermarkSettings waterMarks, Folder<T> folder);
Task<WatermarkSettings> GetWatermarkSettings(Folder<T> room);
Task<Folder<T>> DeleteWatermarkSettings(Folder<T> room);
Task<Folder<T>> DeleteLifetimeSettings(Folder<T> room);
#endregion
}

Expand Down
47 changes: 38 additions & 9 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,29 +568,58 @@ private async Task<int> InternalSaveFolderToDbAsync(FilesDbContext filesDbContex

public async Task<int> SetWatermarkSettings(WatermarkSettings watermarkSettings, Folder<int> room)
{
ArgumentNullException.ThrowIfNull(room);

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);

var toUpdate = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);

toUpdate.Watermark = mapper.Map<WatermarkSettings, DbRoomWatermark>(watermarkSettings);
filesDbContext.Update(toUpdate);

await filesDbContext.SaveChangesAsync();
if (roomSettings != null)
{
roomSettings.Watermark = mapper.Map<WatermarkSettings, DbRoomWatermark>(watermarkSettings);
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();
}

return room.Id;
}

public async Task<Folder<int>> DeleteWatermarkSettings(Folder<int> room)
{
ArgumentNullException.ThrowIfNull(room);

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);
roomSettings.Watermark = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();

if (roomSettings != null)
{
roomSettings.Watermark = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();
}

return room;
}

public async Task<Folder<int>> DeleteLifetimeSettings(Folder<int> room)
{
ArgumentNullException.ThrowIfNull(room);

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync();
var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id);

if (roomSettings != null)
{
roomSettings.Lifetime = null;
filesDbContext.Update(roomSettings);
await filesDbContext.SaveChangesAsync();
}

return room;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,12 @@ public Task<Folder<string>> DeleteWatermarkSettings(Folder<string> room)

return folderDao.DeleteWatermarkSettings(room);
}
public Task<Folder<string>> DeleteLifetimeSettings(Folder<string> room)
{
ArgumentNullException.ThrowIfNull(room);
var selector = _selectorFactory.GetSelector(room.Id);
var folderDao = selector.GetFolderDao(room.Id);

return folderDao.DeleteLifetimeSettings(room);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ public Task<Folder<string>> DeleteWatermarkSettings(Folder<string> room)
{
throw new NotImplementedException();
}

public Task<Folder<string>> DeleteLifetimeSettings(Folder<string> room)
{
throw new NotImplementedException();
}
}

static file class Queries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ public Task<Folder<string>> DeleteWatermarkSettings(Folder<string> room)
{
throw new NotImplementedException();
}

public Task<Folder<string>> DeleteLifetimeSettings(Folder<string> room)
{
throw new NotImplementedException();
}
}

internal abstract class BaseFolderDao
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private async Task DeleteFilesAsync(IEnumerable<T> fileIds, IServiceScope scope,
await folderDao.ChangeTreeFolderSizeAsync(_trashId, (-1) * file.ContentLength);
}

if (_headers != null)
if (_headers != null && _headers.Count > 0)
{
if (isNeedSendActions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ await socketManager.DeleteFolder(folder, action: async () =>
await TagDao.RemoveTagsAsync(pins);
}

await FolderDao.DeleteLifetimeSettings(folder);

await filesMessageService.SendAsync(MessageAction.RoomArchived, folder, _headers, folder.Title);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static readonly Func<FilesDbContext, int, int, DateTime, IAsyncEnumerable
(FilesDbContext ctx, int tenantId, int roomId, DateTime expiration) =>
ctx.Tree
.Join(ctx.Files, a => a.FolderId, b => b.ParentId, (tree, file) => new { tree, file })
.Where(x => x.tree.ParentId == roomId && x.file.TenantId == tenantId && x.file.ModifiedOn < expiration)
.Where(x => x.tree.ParentId == roomId && x.file.TenantId == tenantId && x.file.Version == 1 && x.file.ModifiedOn < expiration)
.Select(r => r.file.Id));
}

Expand Down

0 comments on commit d1da085

Please sign in to comment.