상속: IFolder
        private void Synchronize(object sender, EventArgs e)
        {
            var tmp = new InMemoryPermissionManager();

            // FolderGet has to return folders ordered by ID, otherwise the parent won't be 
            foreach (var folder in McmRepository.FolderGet())
            {
                var permissionFolder = new Folder
                                           {
                                               ID          = folder.ID,
                                               Name        = folder.Name,
                                               DateCreated = folder.DateCreated
                                           };

                if(folder.ParentID.HasValue)
                    permissionFolder.ParentFolder = tmp.GetFolders((uint) folder.ParentID);

                tmp.AddFolder(permissionFolder);
            }

            foreach (var permission in McmRepository.FolderPermissionGet())
            {
                foreach(var entityPermission in permission.UserPermissions)
                    tmp.GetFolders(permission.FolderID).AddUser(entityPermission);

                foreach (var entityPermission in permission.GroupPermissions)
                    tmp.GetFolders(permission.FolderID).AddGroup(entityPermission);
            }

            _folders = tmp._folders;
        }
        public void Should_assocociate_subfolders_with_parent_on_addfolder()
        {
            var permissionManager = new InMemoryPermissionManager();
            var folder1 = new Folder {ID = 1};
            var folder2 = new Folder {ID = 2, ParentFolder = folder1};

            permissionManager.AddFolder(folder1);
            permissionManager.AddFolder(folder2);

            Assert.AreEqual(1, folder1.GetSubFolders().Count());
        }
 public void Should_Add_User_to_folder_with_permission()
 {
     var permissionManager = new InMemoryPermissionManager();
     var folder1 = new Folder{ID = 1};
     var user    = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("39f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                .SetupProperty(f => f.Permission, FolderPermission.Max);
     
     permissionManager.AddFolder(folder1);
     permissionManager.GetFolders(folder1.ID).AddUser(user.Object);
     
     Assert.AreEqual(1, folder1.UserPermissions.Count);
 }
        public void Get_WithMultipleGuids_ShouldQueryViewWithIdsAndFolders()
        {
            var extension  = Make_ObjectV6Extension();
            var objectGuid = new List<Guid> { new Guid("00000000-0000-0000-0000-000000000001"), new Guid("00000000-0000-0000-0000-000000000002"), new Guid("00000000-0000-0000-0000-000000000003") };
            var folder     = new Folder{ID = 1};
            var user       = Make_User();
            PortalApplication.Setup(m => m.Log.Debug(It.IsAny<string>(), null));
            PortalRequest.SetupGet(p => p.User).Returns(user);
            PermissionManager.Setup(m => m.GetFolders(FolderPermission.Read, user.Guid, It.IsAny<IEnumerable<Guid>>())).Returns(new[] { folder });
            ViewManager.Setup(m => m.GetView("Object").Query(It.Is<IQuery>(q => q.Query == "(Id:00000000-0000-0000-0000-000000000001 00000000-0000-0000-0000-000000000002 00000000-0000-0000-0000-000000000003)AND((FolderAncestors:1))"))).Returns(new PagedResult<IResult>(0, 0, new IResult[0]));

            extension.Get(objectGuid);

            ViewManager.Verify(m => m.GetView("Object").Query(It.Is<IQuery>(q => q.Query == "(Id:00000000-0000-0000-0000-000000000001 00000000-0000-0000-0000-000000000002 00000000-0000-0000-0000-000000000003)AND((FolderAncestors:1))")));
        }
        public void Should_assocociate_inherit_userpermissions_when_adding_subfolder()
        {
            var permissionManager = new InMemoryPermissionManager();
            var folder1 = new Folder { ID = 1, Name = "folder 1" };
            var folder2 = new Folder { ID = 2, Name = "folder 2", ParentFolder = folder1};
            var user    = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("39f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                       .SetupProperty(f => f.Permission, FolderPermission.Max);

            permissionManager.AddFolder(folder1);
            permissionManager.GetFolders(folder1.ID).AddUser(user.Object);
            permissionManager.AddFolder(folder2);

            var result = permissionManager.GetFolders(folder2.ID);

            Assert.AreEqual("folder 2", result.Name);
            Assert.AreEqual(1, result.UserPermissions.Count);
            Assert.AreEqual("39f26c89-5e6c-46d5-af3a-bc14a7e1486b", result.UserPermissions.First().Key.ToString());          
        }
        public void Should_propagate_userpermissions_to_subfolders_when_adding_a_user()
        {
            var permissionManager = new InMemoryPermissionManager();
            var folder1 = new Folder { ID = 1 };
            var folder2 = new Folder { ID = 1, ParentFolder = folder1 };
            var user    = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("39f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                       .SetupProperty(f => f.Permission, FolderPermission.Max);

            permissionManager.AddFolder(folder1);
            permissionManager.AddFolder(folder2);
            permissionManager.GetFolders(folder1.ID).AddUser(user.Object);

            Assert.AreEqual(user.Object.Guid, folder2.UserPermissions.First().Key);
            Assert.AreEqual(user.Object.Permission, folder2.UserPermissions.First().Value);
        }
        public void Should_Get_SubFolders_With_Permission_Through_Group()
        {
            var permissionManager = new InMemoryPermissionManager();
            var folder1 = new Folder { ID = 1 };
            var folder2 = new Folder { ID = 2, ParentFolder = folder1 };
            var folder3 = new Folder { ID = 3, ParentFolder = folder2 };
            var folder4 = new Folder { ID = 4 };
            var perm1   = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("39f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                       .SetupProperty(f => f.Permission, FolderPermission.Max);
            var perm2   = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("40f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                       .SetupProperty(f => f.Permission, FolderPermission.Read);

            permissionManager.AddFolder(folder1);
            permissionManager.AddFolder(folder2);
            permissionManager.AddFolder(folder3);
            permissionManager.AddFolder(folder4);
            permissionManager.GetFolders(folder1.ID).AddGroup(perm2.Object);

            var hasPermissions = permissionManager.GetFolders(folder1.ID).DoesUserOrGroupHavePermission(perm1.Object.Guid, new[] { perm2.Object.Guid }, FolderPermission.Read );
            var folders        = permissionManager.GetFolders(folder1.ID).GetSubFolders().Where(item => item.DoesUserOrGroupHavePermission(perm1.Object.Guid, new[] { perm2.Object.Guid }, FolderPermission.Read));

            Assert.IsTrue(hasPermissions);
            Assert.AreEqual(2, folders.First().ID);
        }
        public void Should_Get_TopFolders_With_Group_Permission()
        {
            var permissionManager = new InMemoryPermissionManager();
            var folder1 = new Folder { ID = 1 };
            var folder2 = new Folder { ID = 2 };
            var folder3 = new Folder { ID = 3, ParentFolder = folder1 };
            var folder4 = new Folder { ID = 4, ParentFolder = folder2 };
            var folder5 = new Folder { ID = 5, ParentFolder = folder3};
            var folder6 = new Folder { ID = 6, ParentFolder = folder4};
            var perm1   = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("39f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                       .SetupProperty(f => f.Permission, FolderPermission.Max);
            var perm2   = new Mock<IEntityPermission>().SetupProperty(f => f.Guid, new Guid("40f26c89-5e6c-46d5-af3a-bc14a7e1486b"))
                                                       .SetupProperty(f => f.Permission, FolderPermission.Max);

            permissionManager.AddFolder(folder1);
            permissionManager.AddFolder(folder2);
            permissionManager.AddFolder(folder3);
            permissionManager.AddFolder(folder4);
            permissionManager.AddFolder(folder5);
            permissionManager.AddFolder(folder6);
            permissionManager.GetFolders(folder1.ID).AddGroup(perm1.Object);
            permissionManager.GetFolders(folder4.ID).AddUser(perm1.Object);

            var topFolders = permissionManager.GetFolders(FolderPermission.Read, perm1.Object.Guid, new[] { perm2.Object.Guid, perm1.Object.Guid }).ToList();

            Assert.AreEqual(2, topFolders.Count());
            Assert.AreEqual(folder1.ID, topFolders[0].ID);
            Assert.AreEqual(folder4.ID, topFolders[1].ID);
        }
        public void Should_Get_Users_and_Groups_with_permission_to_a_folder()
        {
            var folder = new Folder();
            folder.AddUser(new EntityPermission
                               {
                                   Guid       = new Guid("e1678025-fbc6-4b8a-a566-b5d7d54d4279"),
                                   Permission = (FolderPermission) 5
                               });
            folder.AddGroup(new EntityPermission
                                {
                                    Guid       = new Guid("60627145-18b5-43cd-89c9-25a9c0f878be"),
                                    Permission = (FolderPermission) 2
                                });
            var module = Make_FolderExtension();
            PermissionManager.Setup(m => m.GetFolders(folder.ID)).Returns(folder);

            var result = module.GetPermission(folder.ID);

            Assert.AreEqual(1, result.UserPermissions.Count());
            Assert.AreEqual("e1678025-fbc6-4b8a-a566-b5d7d54d4279", result.UserPermissions.First().Guid.ToString());
            Assert.AreEqual(5, (uint) result.UserPermissions.First().Permission);
            Assert.AreEqual(2, (uint) result.GroupPermissions.First().Permission);
        }
 public new void SetUp()
 {
     var folder = new Folder();
     PermissionManager.Setup(m => m.GetFolders(It.IsAny<uint>())).Returns(folder);
 }