Skip to content

Commit

Permalink
Files: additional logging
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayRechkin committed Oct 3, 2024
1 parent 7c1bbdc commit a54ae9d
Showing 1 changed file with 57 additions and 5 deletions.
62 changes: 57 additions & 5 deletions products/ASC.Files/Core/Core/Security/FileSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
action == FilesSecurityActions.Edit &&
fileUtility.CanWebRestrictedEditing(file.Title))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("1. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, file.Id);
return false;
}

Expand All @@ -857,22 +859,30 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
action == FilesSecurityActions.FillForms) &&
!file.IsForm)
{
logger.LogDebug("1. FilterEntryAsync. IsForm: {IsForm} userId: {userId} fileId:{fileId}", file.IsForm, userId, file.Id);
logger.LogDebug("2. FilterEntryAsync. IsForm: {IsForm} userId: {userId} fileId:{fileId}", file.IsForm, userId, file.Id);
if (action == FilesSecurityActions.Edit)
logger.LogDebug("3. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, file.Id);
return false;
}

if (action is FilesSecurityActions.ReadHistory or FilesSecurityActions.EditHistory && e.ProviderEntry)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("4. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (file != null && action == FilesSecurityActions.SubmitToFormGallery && !file.IsForm)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("5. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action == FilesSecurityActions.Duplicate && folder is { FolderType: FolderType.FillingFormsRoom})
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("6. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

Expand All @@ -896,16 +906,22 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
{
if (e.RootFolderType != FolderType.VirtualRooms)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("7. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (folder != null && !(isRoom && folder.Shared))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("8. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (file != null && !(file.Shared && fileUtility.CanWebView(file.Title)))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("9. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}
}
Expand All @@ -914,11 +930,15 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
{
if (folder == null)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("10. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (folder.FolderType == FolderType.Recent && isUser)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("11. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

Expand All @@ -927,6 +947,8 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
folder.FolderType == FolderType.FormFillingFolderDone ||
folder.FolderType == FolderType.FormFillingFolderInProgress))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("12. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

Expand All @@ -936,6 +958,8 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
(folder.FolderType == FolderType.ReadyFormFolder ||
folder.FolderType == FolderType.InProcessFormFolder))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("13. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}
if (action is FilesSecurityActions.Duplicate or
Expand All @@ -950,37 +974,51 @@ FilesSecurityActions.Rename or
folder.FolderType == FolderType.FormFillingFolderDone ||
folder.FolderType == FolderType.FormFillingFolderInProgress))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("14. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action is FilesSecurityActions.Pin or FilesSecurityActions.EditAccess or FilesSecurityActions.Mute &&
!isRoom)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("15. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action == FilesSecurityActions.Mute && isRoom && await IsAllGeneralNotificationSettingsOffAsync())
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("16. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action == FilesSecurityActions.CopySharedLink && folder.FolderType is not (FolderType.CustomRoom or FolderType.PublicRoom or FolderType.FillingFormsRoom))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("17. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action == FilesSecurityActions.CopyLink && DocSpaceHelper.IsFormsFillingSystemFolder(folder.FolderType))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("18. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action is FilesSecurityActions.Copy or FilesSecurityActions.Duplicate && isRoom && folder.ProviderEntry)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("19. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (folder.FolderType == FolderType.Recent)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("20. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

Expand Down Expand Up @@ -1034,6 +1072,8 @@ FilesSecurityActions.Rename or
case FolderType.TRASH:
if (action != FilesSecurityActions.Read && action != FilesSecurityActions.Delete && action != FilesSecurityActions.Move)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("21. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

Expand All @@ -1046,6 +1086,8 @@ FilesSecurityActions.Rename or
case FolderType.USER:
if (isOutsider || action == FilesSecurityActions.Lock || (isUser && !e.Shared))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("22. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}
if (e.RootCreateBy == userId)
Expand All @@ -1057,6 +1099,8 @@ FilesSecurityActions.Rename or
case FolderType.VirtualRooms:
if (action == FilesSecurityActions.Delete && isRoom)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("23. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}
if (action == FilesSecurityActions.FillForms && file != null)
Expand All @@ -1067,7 +1111,7 @@ FilesSecurityActions.Rename or
var fileFolder = parentFolders.LastOrDefault();
if ((fileFolder.FolderType == FolderType.FormFillingFolderInProgress && file.CreateBy != userId) || fileFolder.FolderType == FolderType.FormFillingFolderDone)
{
logger.LogDebug("2. FilterEntryAsync. userId: {userId} fileId:{fileId} folderType:{folderType}", userId, file.Id, fileFolder.FolderType);
logger.LogDebug("24. FilterEntryAsync. userId: {userId} fileId:{fileId} folderType:{folderType}", userId, file.Id, fileFolder.FolderType);
return false;
}
}
Expand All @@ -1086,6 +1130,8 @@ FilesSecurityActions.Rename or
var fileFolder = parentFolders.LastOrDefault();
if ((fileFolder.FolderType == FolderType.FormFillingFolderInProgress) || fileFolder.FolderType == FolderType.FormFillingFolderDone)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("25. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}
}
Expand All @@ -1096,6 +1142,8 @@ FilesSecurityActions.Rename or

if (parentFolders.Exists(parent => DocSpaceHelper.IsFormsFillingSystemFolder(parent.FolderType)))
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("26. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
};
}
Expand All @@ -1114,12 +1162,16 @@ FilesSecurityActions.Rename or
action != FilesSecurityActions.ReadLinks
)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("27. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

if (action is FilesSecurityActions.Delete or FilesSecurityActions.Move &&
!isRoom)
{
if (action == FilesSecurityActions.Edit)
logger.LogDebug("28. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;
}

Expand Down Expand Up @@ -1213,7 +1265,7 @@ FilesSecurityActions.Rename or
{
if (ace is { Share: FileShare.FillForms } && userId != file.CreateBy)
{
logger.LogDebug("3. FilterEntryAsync. userId: {userId} fileId:{fileId} createBy:{createBy}", userId, file.Id, file.CreateBy);
logger.LogDebug("29. FilterEntryAsync. userId: {userId} fileId:{fileId} createBy:{createBy}", userId, file.Id, file.CreateBy);
return false;
}
}
Expand All @@ -1223,7 +1275,7 @@ FilesSecurityActions.Rename or
if (ace is { SubjectType: SubjectType.ExternalLink or SubjectType.PrimaryExternalLink } && ace.Subject != userId &&
await externalShare.ValidateRecordAsync(ace, null, isAuthenticated, e) != Status.Ok)
{
logger.LogDebug("4. FilterEntryAsync. subject:{subject} userId: {userId} fileId:{fileId} isAuthenticated:{isAuthenticated} ValidateRecord: {ValidateRecord}",
logger.LogDebug("30. FilterEntryAsync. subject:{subject} userId: {userId} fileId:{fileId} isAuthenticated:{isAuthenticated} ValidateRecord: {ValidateRecord}",
ace.Subject,
userId,
file.Id,
Expand Down Expand Up @@ -1599,7 +1651,7 @@ await externalShare.ValidateRecordAsync(ace, null, isAuthenticated, e) != Status
{
e.Access = FileShare.None; //HACK: for client
}

logger.LogDebug("31. FilterEntryAsync. userId: {userId} fileId:{fileId}", userId, e.Id);
return false;

bool MustConvert(FileEntry entry)
Expand Down

0 comments on commit a54ae9d

Please sign in to comment.