Files: fix file lock

This commit is contained in:
Maksim Chegulov 2022-10-17 18:30:51 +03:00
parent a1ee600ae6
commit 6c476010fd
3 changed files with 22 additions and 6 deletions

View File

@ -1237,7 +1237,7 @@ public class FileStorageService<T> //: IFileStorageService
var file = await fileDao.GetFileAsync(fileId);
ErrorIf(file == null, FilesCommonResource.ErrorMassage_FileNotFound);
ErrorIf(!await _fileSecurity.CanEditAsync(file) || lockfile && _userManager.IsVisitor(_authContext.CurrentAccount.ID), FilesCommonResource.ErrorMassage_SecurityException_EditFile);
ErrorIf(!await _fileSecurity.CanLockAsync(file) || lockfile && _userManager.IsVisitor(_authContext.CurrentAccount.ID), FilesCommonResource.ErrorMassage_SecurityException_EditFile);
ErrorIf(file.RootFolderType == FolderType.TRASH, FilesCommonResource.ErrorMassage_ViewTrashItem);
var tags = tagDao.GetTagsAsync(file.Id, FileEntryType.File, TagType.Locked);

View File

@ -231,11 +231,22 @@ public class FileSecurity : IFileSecurity
{
return CanEditRoomAsync(entry, _authContext.CurrentAccount.ID);
}
public Task<bool> CanShare<T>(FileEntry<T> entry)
public Task<bool> CanShareAsync<T>(FileEntry<T> entry)
{
return CanShareAsync(entry, _authContext.CurrentAccount.ID);
}
public Task<bool> CanLockAsync<T>(FileEntry<T> entry)
{
return CanLockAsync<T>(entry, _authContext.CurrentAccount.ID);
}
public Task<bool> CanLockAsync<T>(FileEntry<T> entry, Guid userId)
{
return CanAsync(entry, userId, FilesSecurityActions.Lock);
}
public Task<IEnumerable<Guid>> WhoCanReadAsync<T>(FileEntry<T> entry)
{
return WhoCanAsync(entry, FilesSecurityActions.Read);
@ -812,6 +823,10 @@ public class FileSecurity : IFileSecurity
{
return true;
}
else if (action == FilesSecurityActions.Lock && e.Access == FileShare.RoomAdmin)
{
return true;
}
else if (e.Access != FileShare.Restrict && e.CreateBy == userId && (e.FileEntryType == FileEntryType.File || folder.FolderType != FolderType.COMMON))
{
return true;
@ -1534,6 +1549,7 @@ public class FileSecurity : IFileSecurity
CustomFilter,
RoomEdit,
Rename,
ReadHistory
ReadHistory,
Lock
}
}

View File

@ -331,7 +331,7 @@ public class FileSharingHelper
return true;
}
if (entry.RootFolderType == FolderType.VirtualRooms && (_global.IsAdministrator || await _fileSecurity.CanShare(entry)))
if (entry.RootFolderType == FolderType.VirtualRooms && (_global.IsAdministrator || await _fileSecurity.CanShareAsync(entry)))
{
return true;
}
@ -348,7 +348,7 @@ public class FileSharingHelper
if (_coreBaseSettings.DisableDocSpace)
{
if (entry.RootFolderType == FolderType.USER && Equals(entry.RootId, _globalFolderHelper.FolderMy) || await _fileSecurity.CanShare(entry))
if (entry.RootFolderType == FolderType.USER && Equals(entry.RootId, _globalFolderHelper.FolderMy) || await _fileSecurity.CanShareAsync(entry))
{
return true;
}
@ -364,7 +364,7 @@ public class FileSharingHelper
return entry.RootFolderType == FolderType.Privacy
&& entry is File<T>
&& (Equals(entry.RootId, await _globalFolderHelper.FolderPrivacyAsync) || await _fileSecurity.CanShare(entry));
&& (Equals(entry.RootId, await _globalFolderHelper.FolderPrivacyAsync) || await _fileSecurity.CanShareAsync(entry));
}
}