public void IsParentTest()
        {
            PwDatabase db = new PwDatabase();

            db.RootGroup = new PwGroup();
            TreeManager um = new TreeManager();

            userManager.Initialize(db);
            rootGroup = db.RootGroup;

            //groups are named like g<# of group>_<level in tree> level 0 is the copyRootGroup
            PwGroup g1_1 = new PwGroup(true, true, "g1_1", PwIcon.Apple);
            PwGroup g2_1 = new PwGroup(true, true, "g2_1", PwIcon.Apple);
            PwGroup g3_2 = new PwGroup(true, true, "g3_2", PwIcon.Apple);
            PwGroup g4_3 = new PwGroup(true, true, "g4_3", PwIcon.Apple);

            rootGroup.AddGroup(g1_1, true);
            rootGroup.AddGroup(g2_1, true);
            g2_1.AddGroup(g3_2, true);
            g3_2.AddGroup(g4_3, true);

            PwEntry pe1_0 = new PwEntry(true, true);
            PwEntry pe2_1 = new PwEntry(true, true);
            PwEntry pe3_2 = new PwEntry(true, true);
            PwEntry pe4_3 = new PwEntry(true, true);

            rootGroup.AddEntry(pe1_0, true);
            g2_1.AddEntry(pe2_1, true);
            g3_2.AddEntry(pe3_2, true);
            g4_3.AddEntry(pe4_3, true);

            Assert.IsTrue(pe1_0.IsInsideParent(rootGroup));
            Assert.IsTrue(pe4_3.IsInsideParent(rootGroup));
            Assert.IsTrue(pe4_3.IsInsideParent(g2_1));
            Assert.IsTrue(g4_3.IsInsideParent(g2_1));
            Assert.IsTrue(g4_3.IsInsideParent(rootGroup));

            Assert.IsFalse(pe1_0.IsInsideParent(g2_1));
            Assert.IsFalse(pe4_3.IsInsideParent(g1_1));
            Assert.IsFalse(pe2_1.IsInsideParent(g3_2));
            Assert.IsFalse(g2_1.IsInsideParent(g4_3));
        }
Ejemplo n.º 2
0
        private Changes FixSharingNodesFor(PwEntry userNode)
        {
            PwGroup userHome   = m_database.GetUserHomeFor(userNode, false);
            PwGroup usersGroup = m_database.GetUsersGroup();
            PwGroup recycleBin = m_database.RootGroup.FindGroup(m_database.RecycleBinUuid, false);

            if (m_database.RecycleBinEnabled && userNode.IsInsideParent(recycleBin))
            {
                return(RemoveDeletedSharingNodes(userNode, userHome, usersGroup));
            }
            if (userNode.ParentGroup.IsHome() && !userNode.IsInsideParent(usersGroup))
            {
                return(RestoreMovedUsersHome(userNode, userHome, usersGroup));
            }
            if (userNode.ParentGroup != userHome)
            {
                return(RestoreMovedUserNode(userNode, userHome, usersGroup));
            }
            return(EnsureMatchingNamingAndIcons(userNode, userHome, usersGroup));
        }
Ejemplo n.º 3
0
        private Changes RemoveDeletedSharingNodes(PwEntry userNode, PwGroup userHome, PwGroup usersGroup)
        {
            PwGroup recycleBin = m_database.RootGroup.FindGroup(m_database.RecycleBinUuid, false);

            Debug.Assert(userNode.IsInsideParent(recycleBin));
            //we delete the user completely
            userNode.DeleteFrom(userNode.ParentGroup, m_database);

            RemoveBrokenProxies();

            //if only the rootNode was moved to trash, we have to delete the users Home too!
            if (null != userHome)
            {
                userHome.DeleteFrom(usersGroup, m_database);
            }
            return(Changes.GroupDeleted | Changes.EntryDeleted);
        }
Ejemplo n.º 4
0
        private Changes RestoreMovedUserNode(PwEntry userNode, PwGroup userHome, PwGroup usersGroup)
        {
            //only the userNode was moved..
            //are we located anywhere in the "users"group => here we have to be careful!
            if (userNode.IsInsideParent(usersGroup))
            {
                //do we have a applicable homeFolder?
                if (null != userHome)
                {
                    //then we should only move back!
                    userNode.ParentGroup.Entries.Remove(userNode);
                    userNode.SetParent(userHome);
                    //and we are done here...
                    return(Changes.EntryMoved);
                }
            }
            else
            {
                //else userNode was moved intentionally to share a folder, so move the rootNode back
                //and create a proxy at the new location
                PwGroup parentGroup = userNode.ParentGroup;
                parentGroup.Entries.Remove(userNode);
                //ensure that the original rootNode is located in his homefolder
                //move the original userRootNode back to his homefolder
                userNode.SetParent(m_database.GetUserHomeFor(userNode));

                //create proxyNode in the folder
                if (!GroupIsSharedToUser(parentGroup, userNode))
                {
                    PwEntry proxy = userNode.CreateProxyNode();
                    proxy.SetParent(parentGroup);
                    return(Changes.EntryMoved | Changes.EntryCreated);
                }
                return(Changes.EntryMoved);
            }
            return(Changes.None);
        }
        public void IsParentTest()
        {
            PwDatabase db = new PwDatabase();
            db.RootGroup = new PwGroup();
            TreeManager um = new TreeManager();
            userManager.Initialize( db );
            rootGroup = db.RootGroup;

            //groups are named like g<# of group>_<level in tree> level 0 is the copyRootGroup
            PwGroup g1_1 = new PwGroup( true, true, "g1_1", PwIcon.Apple );
            PwGroup g2_1 = new PwGroup( true, true, "g2_1", PwIcon.Apple );
            PwGroup g3_2 = new PwGroup( true, true, "g3_2", PwIcon.Apple );
            PwGroup g4_3 = new PwGroup( true, true, "g4_3", PwIcon.Apple );

            rootGroup.AddGroup( g1_1, true );
            rootGroup.AddGroup( g2_1, true );
            g2_1.AddGroup( g3_2, true );
            g3_2.AddGroup( g4_3, true );

            PwEntry pe1_0 = new PwEntry( true, true );
            PwEntry pe2_1 = new PwEntry( true, true );
            PwEntry pe3_2 = new PwEntry( true, true );
            PwEntry pe4_3 = new PwEntry( true, true );

            rootGroup.AddEntry( pe1_0, true );
            g2_1.AddEntry( pe2_1, true );
            g3_2.AddEntry( pe3_2, true );
            g4_3.AddEntry( pe4_3, true );

            Assert.IsTrue( pe1_0.IsInsideParent( rootGroup ) );
            Assert.IsTrue( pe4_3.IsInsideParent( rootGroup ) );
            Assert.IsTrue( pe4_3.IsInsideParent( g2_1 ) );
            Assert.IsTrue( g4_3.IsInsideParent( g2_1 ) );
            Assert.IsTrue( g4_3.IsInsideParent( rootGroup ) );

            Assert.IsFalse( pe1_0.IsInsideParent( g2_1 ) );
            Assert.IsFalse( pe4_3.IsInsideParent( g1_1 ) );
            Assert.IsFalse( pe2_1.IsInsideParent( g3_2 ) );
            Assert.IsFalse( g2_1.IsInsideParent( g4_3 ) );
        }