public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true)) { yield return(new ValidationResult("You must select at least one collection.", new string[] { nameof(CollectionIds) })); } }
} = " (1 = 1) "; // Default is effectively NO filter. public Rule(string ruleId, string rulesetId, ISchemaProvider schemaProvider, IEnumerable <string> collectionIds = null, string sql = null, IEnumerable <string> components = null) { _schemaProvider = schemaProvider; RuleId = ruleId; RulesetId = rulesetId; CollectionIds.AddRange(collectionIds ?? new List <string>()); Components.AddRange(components ?? new List <string>()); Sql = sql; }
public CipherData ToCipherData(string userId) { var c = new CipherData { Id = Id, OrganizationId = OrganizationId, FolderId = FolderId, UserId = OrganizationId != null ? userId : null, Edit = Edit, OrganizationUseTotp = OrganizationUseTotp, Favorite = Favorite, RevisionDate = RevisionDate, Type = Type, CollectionIds = CollectionIds.ToList(), DeletedDate = DeletedDate, Reprompt = Reprompt, }; BuildDataModel(this, c, new HashSet <string> { "Name", "Notes" }); switch (c.Type) { case Enums.CipherType.Login: c.Login = Login.ToLoginData(); break; case Enums.CipherType.SecureNote: c.SecureNote = SecureNote.ToSecureNoteData(); break; case Enums.CipherType.Card: c.Card = Card.ToCardData(); break; case Enums.CipherType.Identity: c.Identity = Identity.ToIdentityData(); break; default: break; } c.Fields = Fields?.Select(f => f.ToFieldData()).ToList(); c.Attachments = Attachments?.Select(a => a.ToAttachmentData()).ToList(); c.PasswordHistory = PasswordHistory?.Select(ph => ph.ToPasswordHistoryData()).ToList(); return(c); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (!Ciphers?.Any() ?? true) { yield return(new ValidationResult("You must select at least one cipher.", new string[] { nameof(Ciphers) })); } else { var allHaveIds = true; var organizationIds = new HashSet <string>(); foreach (var c in Ciphers) { organizationIds.Add(c.OrganizationId); if (allHaveIds) { allHaveIds = !(string.IsNullOrWhiteSpace(c.Id) || string.IsNullOrWhiteSpace(c.OrganizationId)); } } if (!allHaveIds) { yield return(new ValidationResult("All Ciphers must have an Id and OrganizationId.", new string[] { nameof(Ciphers) })); } else if (organizationIds.Count != 1) { yield return(new ValidationResult("All ciphers must be for the same organization.")); } } if (!CollectionIds?.Any() ?? true) { yield return(new ValidationResult("You must select at least one collection.", new string[] { nameof(CollectionIds) })); } }
public void AddCollectionId(string collectionId) => CollectionIds.Add(collectionId);