/// <summary> /// Propagates possible changes of a rootNode to all of his proxyNodes /// </summary> /// <param name="root">The rootNode we want to propagate</param> /// <returns>True if the function has made changes to the database.</returns> private Changes UpdateProxyInformation(PwEntry root) { Changes changeFlag = Changes.None; //get all relevant proxies //copy new information from root to proxies PwObjectList <PwEntry> allProxies = m_database.GetAllProxyNodes(); foreach (PwEntry proxy in allProxies) { //check if the proxy matches to the root and has changes! if not we are done here if (proxy.IsProxyOf(root) && !proxy.IsSimilarTo(root, true)) { PwGroup parent = proxy.ParentGroup; bool success = parent.Entries.Remove(proxy); Debug.Assert(success); PwEntry duplicate = root.CloneDeep(); duplicate.Uuid = proxy.Uuid; //if the rootNode was a userRoot, the StringFiledUidLink is set automatically in a clone //but if not we have to set it manually if (!root.IsUserRootNode()) { duplicate.MakeToProxyOf(root); } duplicate.SetParent(parent); changeFlag |= Changes.EntryCreated; } } return(changeFlag); }
/// <summary> /// The function checks if thelast made change has to be propageted to /// some referenced PwEntries /// </summary> /// <returns>True if the function has made changes to the database.</returns> private Changes CheckReferences() { PwEntry lastModifiedEntry = GetLastModifiedEntry(); //if there are no changes, then we have nothing to do if (lastModifiedEntry == null) { return(Changes.None); } //was it a proxy or not? Changes changeFlag = Changes.None; if (lastModifiedEntry.IsProxyNode()) { //lets update the root so we later can update all proxies PwEntry root = m_database.GetProxyTargetFor(lastModifiedEntry); //check if there are real changes! if not we are done here if (lastModifiedEntry.IsSimilarTo(root, true)) { return(Changes.None); } PwGroup parent = root.ParentGroup; root.CreateBackup(m_database); //rootNode_X should save all modifications in history parent.Entries.Remove(root); PwEntry updatedRoot = lastModifiedEntry.CloneDeep(); updatedRoot.Uuid = root.Uuid; updatedRoot.SetParent(parent); //special handling for userRootNodes because they have a homefolder if (root.IsUserRootNode()) { //maybe the oldUserName has changed to => the homefolder should have the new name also //we also want to have the same icons everywhere parent.Name = updatedRoot.GetTitle(); parent.IconId = updatedRoot.IconId; } else { updatedRoot.Strings.Remove(KeeShare.UuidLinkField); } changeFlag |= UpdateProxyInformation(updatedRoot); changeFlag |= Changes.GroupDeleted; } else { changeFlag |= UpdateProxyInformation(lastModifiedEntry); } pe_lastModedEntry = GetLastModifiedEntry(); return(changeFlag); }
public void IsUserRootNodeTest() { //should all be false: Assert.IsFalse(normalEntry1.IsUserRootNode()); Assert.IsFalse(normalEntry2.IsUserRootNode()); Assert.IsFalse(normalEntry3.IsUserRootNode()); Assert.IsFalse(pwdProxyTo1.IsUserRootNode()); Assert.IsFalse(pwdProxyTo3.IsUserRootNode()); Assert.IsFalse(pwdProxyTo3_1.IsUserRootNode()); Assert.IsFalse(proxyToRoot1.IsUserRootNode()); Assert.IsFalse(brokenProxy1.IsUserRootNode()); Assert.IsFalse(brokenProxy2.IsUserRootNode()); //should all be true: Assert.IsTrue(root1.IsUserRootNode()); Assert.IsTrue(root2.IsUserRootNode()); }
public void RespectProxiesOfDifferentUsersWithSameName() { m_treeManager.Initialize(m_database); m_treeManager.CreateNewUser("mrX"); m_treeManager.CreateNewUser("mrX"); PwEntry mrX1 = TestHelper.GetUserRootNodeFor(m_database, 0); PwEntry mrX2 = TestHelper.GetUserRootNodeFor(m_database, 1); Assert.IsTrue(mrX1.IsUserRootNode()); Assert.IsTrue(mrX2.IsUserRootNode()); PwEntry proxyX1 = mrX1.CreateProxyNode(); PwEntry proxyX2 = mrX2.CreateProxyNode(); m_database.RootGroup.AddEntry(proxyX1, true); m_database.RootGroup.AddEntry(proxyX2, true); m_treeManager.CorrectStructure(); Assert.AreEqual(6, NumberOfEntriesIn(m_database)); }