Files: fixed ProlongEditing

This commit is contained in:
pavelbannov 2023-09-25 11:41:01 +03:00
parent be0dfa8441
commit 991babc0ee
4 changed files with 22 additions and 20 deletions

View File

@ -1010,7 +1010,7 @@ public class FileStorageService //: IFileStorageService
}
else
{
await _entryManager.TrackEditingAsync(id, tabId, _authContext.CurrentAccount.ID, doc);
await _entryManager.TrackEditingAsync(id, tabId, _authContext.CurrentAccount.ID, doc, await _tenantManager.GetCurrentTenantIdAsync());
}
return new KeyValuePair<bool, string>(true, string.Empty);
@ -1118,7 +1118,7 @@ public class FileStorageService //: IFileStorageService
app = _thirdPartySelector.GetAppByFileId(fileId.ToString());
if (app == null)
{
await _entryManager.TrackEditingAsync(fileId, Guid.Empty, _authContext.CurrentAccount.ID, doc, true);
await _entryManager.TrackEditingAsync(fileId, Guid.Empty, _authContext.CurrentAccount.ID, doc, await _tenantManager.GetCurrentTenantIdAsync(), true);
}
//without StartTrack, track via old scheme

View File

@ -300,7 +300,7 @@ public class DocumentServiceTrackerHelper
try
{
var doc = await _fileShareLink.CreateKeyAsync(fileId);
await _entryManager.TrackEditingAsync(fileId, userId, userId, doc);
await _entryManager.TrackEditingAsync(fileId, userId, userId, doc, await _tenantManager.GetCurrentTenantIdAsync());
}
catch (Exception e)
{

View File

@ -1544,12 +1544,12 @@ public class EntryManager
return file;
}
public async Task TrackEditingAsync<T>(T fileId, Guid tabId, Guid userId, string doc, bool editingAlone = false)
public async Task TrackEditingAsync<T>(T fileId, Guid tabId, Guid userId, string doc, int tenantId, bool editingAlone = false)
{
bool checkRight;
if (_fileTracker.GetEditingBy(fileId).Contains(userId))
{
checkRight = _fileTracker.ProlongEditing(fileId, tabId, userId, editingAlone);
checkRight = _fileTracker.ProlongEditing(fileId, tabId, userId, tenantId, editingAlone);
if (!checkRight)
{
return;
@ -1588,7 +1588,7 @@ public class EntryManager
throw new Exception(FilesCommonResource.ErrorMassage_ViewTrashItem);
}
checkRight = _fileTracker.ProlongEditing(fileId, tabId, userId, editingAlone);
checkRight = _fileTracker.ProlongEditing(fileId, tabId, userId, tenantId, editingAlone);
if (checkRight)
{
_fileTracker.ChangeRight(fileId, userId, false);

View File

@ -44,15 +44,8 @@ public class FileTrackerHelper
_logger = logger;
}
public Guid Add<T>(Guid userId, T fileId)
{
var tabId = Guid.NewGuid();
ProlongEditing(fileId, tabId, userId);
return tabId;
}
public bool ProlongEditing<T>(T fileId, Guid tabId, Guid userId, bool editingAlone = false)
public bool ProlongEditing<T>(T fileId, Guid tabId, Guid userId, int tenantId, bool editingAlone = false)
{
var checkRight = true;
var tracker = GetTracker(fileId);
@ -65,12 +58,12 @@ public class FileTrackerHelper
}
else
{
tracker.EditingBy.Add(tabId, new TrackInfo(userId, tabId == userId, editingAlone));
tracker.EditingBy.Add(tabId, new TrackInfo(userId, tabId == userId, editingAlone, tenantId));
}
}
else
{
tracker = new FileTracker(tabId, userId, tabId == userId, editingAlone);
tracker = new FileTracker(tabId, userId, tabId == userId, editingAlone, tenantId);
}
SetTracker(fileId, tracker);
@ -233,7 +226,15 @@ public class FileTrackerHelper
try
{
if (fileTracker.EditingBy == null || !fileTracker.EditingBy.Any())
{
return;
}
var editedBy = fileTracker.EditingBy.FirstOrDefault();
await using var scope = _serviceScopeFactory.CreateAsyncScope();
var tenantManager = scope.ServiceProvider.GetRequiredService<TenantManager>();
await tenantManager.SetCurrentTenantAsync(editedBy.Value.TenantId);
var helper = scope.ServiceProvider.GetRequiredService<DocumentServiceHelper>();
var tracker = scope.ServiceProvider.GetRequiredService<DocumentServiceTrackerHelper>();
@ -245,7 +246,6 @@ public class FileTrackerHelper
if (await tracker.StartTrackAsync(fileId.ToString(), docKey))
{
_cache.Insert(Tracker + fileId, fileTracker, CacheTimeout, EvictionCallback(fileId, fileTracker));
await socketManager.StartEditAsync(fileId);
}
}
catch (Exception e)
@ -261,9 +261,9 @@ public class FileTracker
internal Dictionary<Guid, TrackInfo> EditingBy { get; private set; }
internal FileTracker(Guid tabId, Guid userId, bool newScheme, bool editingAlone)
internal FileTracker(Guid tabId, Guid userId, bool newScheme, bool editingAlone, int tenantId)
{
EditingBy = new Dictionary<Guid, TrackInfo> { { tabId, new TrackInfo(userId, newScheme, editingAlone) } };
EditingBy = new Dictionary<Guid, TrackInfo> { { tabId, new TrackInfo(userId, newScheme, editingAlone, tenantId) } };
}
@ -272,18 +272,20 @@ public class FileTracker
public DateTime CheckRightTime { get; set; }
public DateTime TrackTime { get; set; }
public Guid UserId { get; set; }
public int TenantId { get; set; }
public bool NewScheme { get; set; }
public bool EditingAlone { get; set; }
public TrackInfo() { }
public TrackInfo(Guid userId, bool newScheme, bool editingAlone)
public TrackInfo(Guid userId, bool newScheme, bool editingAlone, int tenantId)
{
CheckRightTime = DateTime.UtcNow;
TrackTime = DateTime.UtcNow;
NewScheme = newScheme;
UserId = userId;
EditingAlone = editingAlone;
TenantId = tenantId;
}
}
}