Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check message attachment's permission. #3645

Merged
merged 2 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
using DotNetNuke.Framework;
using DotNetNuke.Security;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Social.Messaging.Data;
using DotNetNuke.Services.Social.Messaging.Exceptions;
using DotNetNuke.Services.Social.Messaging.Internal;
Expand Down Expand Up @@ -209,7 +211,10 @@ public virtual void SendMessage(Message message, IList<RoleInfo> roles, IList<Us
{
foreach (var attachment in fileIDs.Select(fileId => new MessageAttachment { MessageAttachmentID = Null.NullInteger, FileID = fileId, MessageID = message.MessageID }))
{
_dataService.SaveMessageAttachment(attachment, UserController.Instance.GetCurrentUserInfo().UserID);
if (CanViewFile(attachment.FileID))
{
_dataService.SaveMessageAttachment(attachment, UserController.Instance.GetCurrentUserInfo().UserID);
}
}
}

Expand Down Expand Up @@ -290,5 +295,17 @@ internal virtual bool IsAdminOrHost(UserInfo userInfo)
}

#endregion

private bool CanViewFile(int fileId)
{
var file = FileManager.Instance.GetFile(fileId);
if (file == null)
{
return false;
}

var folder = FolderManager.Instance.GetFolder(file.FolderId);
return folder != null && FolderPermissionController.Instance.CanViewFolder(folder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Portals.Internal;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Cache;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Social.Messaging.Data;
using DotNetNuke.Services.Social.Messaging;
Expand Down Expand Up @@ -66,6 +68,9 @@ public class MessagingControllerTests
private Mock<RoleProvider> _mockRoleProvider;
private Mock<CachingProvider> _mockCacheProvider;
private Mock<ILocalizationProvider> _mockLocalizationProvider;
private Mock<IFolderManager> _folderManager;
private Mock<IFileManager> _fileManager;
private Mock<IFolderPermissionController> _folderPermissionController;

private DataTable _dtMessages;
private DataTable _dtMessageAttachment;
Expand Down Expand Up @@ -108,12 +113,21 @@ public void SetUp()

DataService.RegisterInstance(_mockDataService.Object);

_folderManager = new Mock<IFolderManager>();
_fileManager = new Mock<IFileManager>();
_folderPermissionController = new Mock<IFolderPermissionController>();

FolderManager.RegisterInstance(_folderManager.Object);
FileManager.RegisterInstance(_fileManager.Object);
FolderPermissionController.SetTestableInstance(_folderPermissionController.Object);

SetupDataProvider();
SetupRoleProvider();
SetupDataTables();
SetupUsers();
SetupPortalSettings();
SetupCachingProvider();
SetupFileControllers();

_mockInternalMessagingController.Setup(m => m.GetLastSentMessage(It.IsAny<UserInfo>())).Returns((Message)null);
}
Expand Down Expand Up @@ -195,6 +209,13 @@ private void SetupRoleProvider()
_mockRoleProvider.Setup(rp => rp.GetUserRoles(It.Is<UserInfo>(u => u.UserID == Constants.UserID_FirstSocialGroupOwner), It.IsAny<bool>())).Returns(new List<UserRoleInfo> { userFirstSocialGroupOwner });
}

private void SetupFileControllers()
{
_folderManager.Setup(f => f.GetFolder(It.IsAny<int>())).Returns(new FolderInfo());
_fileManager.Setup(f => f.GetFile(It.IsAny<int>())).Returns(new FileInfo());
_folderPermissionController.Setup(f => f.CanViewFolder(It.IsAny<IFolderInfo>())).Returns(true);
}

#endregion

#region Constructor Tests
Expand Down Expand Up @@ -785,6 +806,8 @@ public void MessagingController_CreateMessage_Calls_DataService_SaveSocialMessag
[Test]
public void MessagingController_CreateMessage_Calls_DataService_CreateSocialMessageRecipientsForRole_On_Passing_Role_ByAdmin()
{
InternalMessagingController.SetTestableInstance(_mockInternalMessagingController.Object);

//Arrange
var message = new Message { Subject = "subject", Body = "body" };
var role = new RoleInfo { RoleName = Constants.RoleName_RegisteredUsers, RoleID = Constants.RoleID_RegisteredUsers };
Expand Down