diff --git a/src/Logic/PasswordStoreService.cs b/src/Logic/PasswordStoreService.cs index a70546c..7a832be 100644 --- a/src/Logic/PasswordStoreService.cs +++ b/src/Logic/PasswordStoreService.cs @@ -44,6 +44,38 @@ public class PasswordStoreService : IPasswordStoreService public IEnumerable GetAll() { - return repository.GetAll(); + List jsonResults = repository.GetAll(); + + //Validate against actual secret collections + var collections = secretService.GetCollections() ?? Enumerable.Empty(); + + // Identify bookmarks that do NOT match any existing Secret collection. + var toDelete = new List(); + + 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; } }