public void MoveUserHomeToGarbageShoulRemoveAllUserProxies() { m_treeManager.Initialize(m_database); m_treeManager.CreateNewUser("mrX"); m_treeManager.CreateNewUser("mrY"); PwGroup grp1 = new PwGroup(true, true, "testgrp", PwIcon.Archive); PwUuid grpId = grp1.Uuid; m_database.RootGroup.AddGroup(grp1, true); Assert.AreEqual(4, m_database.RootGroup.Groups.UCount); //move home to a normal PwGroup PwGroup homeX = TestHelper.GetUserHomeNodeByNameFor(m_database, "mrX"); PwUuid homeXid = homeX.Uuid; //move home to the trash PwGroup trash = m_database.RootGroup.FindGroup(m_database.RecycleBinUuid, true); homeX.ParentGroup.Groups.Remove(homeX); trash.AddGroup(homeX, true); // TODO CK: Find out if the user should be deleted already at this place or later m_treeManager.CorrectStructure(); trash = m_database.RootGroup.FindGroup(m_database.RecycleBinUuid, true); Assert.AreEqual(1, trash.Groups.UCount); homeX = m_database.RootGroup.FindGroup(homeXid, true); Assert.AreEqual(trash, homeX.ParentGroup); //empty trash.. trash.DeleteAllObjects(m_database); //update should delete all references to the non existing user m_treeManager.CorrectStructure(); Assert.AreEqual(2, NumberOfEntriesIn(m_database)); Assert.NotNull(TestHelper.GetUserRootNodeByNameFor(m_database, "mrY")); }
public static void DeleteFrom(this PwGroup group, PwGroup parent, PwDatabase database) { //first remove all entries in the group group.DeleteAllObjects(database); // create the delete marker PwDeletedObject deleteMarker = new PwDeletedObject(group.Uuid, DateTime.Now); database.DeletedObjects.Add(deleteMarker); //now we can remove the empty group parent.Groups.Remove(group); }
/// <summary> /// Delete every entry in the target group. /// </summary> /// <param name="sourceGroups">Collection of groups which counterparts should be deleted in the target database.</param> /// <param name="targetDatabase">The target database in which the folder structure should be created.</param> private static void DeleteTargetGroupsInDatabase(IEnumerable <PwGroup> sourceGroups, PwDatabase targetDatabase) { foreach (PwGroup sourceGroup in sourceGroups) { // Get the target group ID based PwUuid groupId = sourceGroup.Uuid; PwGroup targetGroup = targetDatabase.RootGroup.FindGroup(groupId, false); // If group exists in target database, delete its entries, otherwise show a warning if (targetGroup != null) { targetGroup.DeleteAllObjects(targetDatabase); } } }
protected bool DoDeleteGroup(PwGroup pg, List <PwGroup> touchedGroups, List <PwGroup> permanentlyDeletedGroups) { PwGroup pgParent = pg.ParentGroup; if (pgParent == null) { return(false); } PwDatabase pd = Db.KpDatabase; PwGroup pgRecycleBin = pd.RootGroup.FindGroup(pd.RecycleBinUuid, true); if (pg.Uuid.Equals(pd.EntryTemplatesGroup)) { pd.EntryTemplatesGroup = PwUuid.Zero; pd.EntryTemplatesGroupChanged = DateTime.Now; } pgParent.Groups.Remove(pg); touchedGroups.Add(pgParent); if ((DeletePermanently) || (!CanRecycle)) { pg.DeleteAllObjects(pd); PwDeletedObject pdo = new PwDeletedObject(pg.Uuid, DateTime.Now); pd.DeletedObjects.Add(pdo); permanentlyDeletedGroups.Add(pg); } else // Recycle { bool groupListUpdateRequired = false; EnsureRecycleBinExists(ref pgRecycleBin, ref groupListUpdateRequired); pgRecycleBin.AddGroup(pg, true, true); pg.Touch(false); // Mark new parent (Recycle bin) touched touchedGroups.Add(pg.ParentGroup); // mark root touched if recycle bin was created if (groupListUpdateRequired) { touchedGroups.Add(Db.Root); } } return(true); }
/// <summary> /// Delete every entry in the target group. /// </summary> /// <param name="sourceGroups">Collection of groups which counterparts should be deleted in the target database.</param> /// <param name="targetDatabase">The target database in which the folder structure should be created.</param> private static void DeleteTargetGroupsInDatabase(IEnumerable <PwGroup> sourceGroups, PwDatabase targetDatabase) { foreach (PwGroup sourceGroup in sourceGroups) { // Get the target group ID based PwUuid groupId = sourceGroup.Uuid; PwGroup targetGroup = targetDatabase.RootGroup.FindGroup(groupId, false); // If group exists in target database, delete its entries, otherwise show a warning if (targetGroup != null) { targetGroup.DeleteAllObjects(targetDatabase); } else { MessageService.ShowWarning("Group not found in target database. OverrideEntireGroup will not work"); } } }
/// <summary> /// Delete a group. /// </summary> /// <param name="pg">Group to be added. Must not be <c>null</c>.</param> /// <param name="permanent">Permanent delete or move to recycle bin</param> public void DeleteGroup(PwGroup pg, bool permanent = false) { if (pg == null) { throw new ArgumentNullException("pg"); } PwGroup pgParent = pg.ParentGroup; if (pgParent == null) { throw new ArgumentNullException("pgParent"); // Can't remove virtual or root group } PwGroup pgRecycleBin = RootGroup.FindGroup(RecycleBinUuid, true); bool bPermanent = false; if (RecycleBinEnabled == false) { bPermanent = true; } else if (permanent) { bPermanent = true; } else if (pgRecycleBin == null) { } // if we cannot find it, we will create it later else if (pg == pgRecycleBin) { bPermanent = true; } else if (pg.IsContainedIn(pgRecycleBin)) { bPermanent = true; } else if (pgRecycleBin.IsContainedIn(pg)) { bPermanent = true; } pgParent.Groups.Remove(pg); if (bPermanent) { pg.DeleteAllObjects(this); PwDeletedObject pdo = new PwDeletedObject(pg.Uuid, DateTime.UtcNow); DeletedObjects.Add(pdo); } else // Recycle { EnsureRecycleBin(ref pgRecycleBin); try { pgRecycleBin.AddGroup(pg, true, true); } catch (Exception) { if (pgRecycleBin.Groups.IndexOf(pg) < 0) { pgParent.AddGroup(pg, true, true); // Undo removal } } pg.Touch(false); } }