From 40b858f4710a3762390cfa0eb9415caeaa6ed39e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 3 Feb 2022 09:36:34 -0600 Subject: validate group overlap --- src/slskd/Options.cs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index b97c40d1..f7e1266d 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -461,20 +461,46 @@ namespace slskd /// /// User groups. /// - public class GroupsOptions + public class GroupsOptions : IValidatableObject { /// /// Gets options for the default user group. /// + /// + /// These options apply to users that are not priviledged, have not been identified as leechers, + /// and have not been added as a member of any group. + /// [Validate] public BuiltInOptions Default { get; init; } = new BuiltInOptions(); + /// + /// Gets options for the leecher user group. + /// + /// + /// These options apply to users that have been identified as leechers, and have not been added as a member of any group. + /// + [Validate] + public BuiltInOptions Leechers { get; init; } = new BuiltInOptions(); + /// /// Gets user defined groups and options. /// [Validate] public Dictionary UserDefined { get; init; } = new Dictionary(); + /// + /// Extended validation. + /// + /// + /// + public IEnumerable Validate(ValidationContext validationContext) + { + var builtInGroups = new[] { Application.PriviledgedGroup, Application.DefaultGroup, Application.LeecherGroup }; + var intersection = UserDefined.Keys.Intersect(builtInGroups); + + return intersection.Select(group => new ValidationResult($"User defined group '{group}' collides with a built in group. Choose a different name.")); + } + /// /// Built in user group options. /// -- cgit v1.2.3