Match saved bookmarks against existing collections and remove missing
This commit is contained in:
@@ -44,6 +44,38 @@ public class PasswordStoreService : IPasswordStoreService
|
|||||||
|
|
||||||
public IEnumerable<PasswordStore> GetAll()
|
public IEnumerable<PasswordStore> GetAll()
|
||||||
{
|
{
|
||||||
return repository.GetAll();
|
List<PasswordStore> jsonResults = repository.GetAll();
|
||||||
|
|
||||||
|
//Validate against actual secret collections
|
||||||
|
var collections = secretService.GetCollections() ?? Enumerable.Empty<Secret.Collection>();
|
||||||
|
|
||||||
|
// Identify bookmarks that do NOT match any existing Secret collection.
|
||||||
|
var toDelete = new List<uint>();
|
||||||
|
|
||||||
|
foreach (var ps in jsonResults)
|
||||||
|
{
|
||||||
|
var key = string.IsNullOrWhiteSpace(ps.DisplayName) ? ps.Path : ps.DisplayName;
|
||||||
|
if (string.IsNullOrWhiteSpace(key))
|
||||||
|
{
|
||||||
|
// No reasonable key to match — schedule for deletion
|
||||||
|
toDelete.Add(ps.ID);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var exists = collections.Any(c => string.Equals(c.Label, key, StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (!exists)
|
||||||
|
{
|
||||||
|
toDelete.Add(ps.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform deletions from repository for all missing bookmarks
|
||||||
|
foreach (var id in toDelete)
|
||||||
|
{
|
||||||
|
repository.Delete(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
var remaining = jsonResults.Where(ps => !toDelete.Contains(ps.ID)).ToList();
|
||||||
|
return remaining;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user