diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2022-02-03 09:36:34 -0600 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2022-02-03 09:36:34 -0600 |
| commit | 40b858f4710a3762390cfa0eb9415caeaa6ed39e (patch) | |
| tree | 20fddfd9a52aea4e752616000fca745341e2a9ec | |
| parent | 75cd4f807eedd018f5c4e49f00973a5a20aaeb6c (diff) | |
| download | slskd-40b858f4710a3762390cfa0eb9415caeaa6ed39e.tar.gz | |
validate group overlap
| -rw-r--r-- | src/slskd/Options.cs | 28 |
1 files changed, 27 insertions, 1 deletions
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,21 +461,47 @@ namespace slskd /// <summary> /// User groups. /// </summary> - public class GroupsOptions + public class GroupsOptions : IValidatableObject { /// <summary> /// Gets options for the default user group. /// </summary> + /// <remarks> + /// 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. + /// </remarks> [Validate] public BuiltInOptions Default { get; init; } = new BuiltInOptions(); /// <summary> + /// Gets options for the leecher user group. + /// </summary> + /// <remarks> + /// These options apply to users that have been identified as leechers, and have not been added as a member of any group. + /// </remarks> + [Validate] + public BuiltInOptions Leechers { get; init; } = new BuiltInOptions(); + + /// <summary> /// Gets user defined groups and options. /// </summary> [Validate] public Dictionary<string, UserDefinedOptions> UserDefined { get; init; } = new Dictionary<string, UserDefinedOptions>(); /// <summary> + /// Extended validation. + /// </summary> + /// <param name="validationContext"></param> + /// <returns></returns> + public IEnumerable<ValidationResult> 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.")); + } + + /// <summary> /// Built in user group options. /// </summary> public class BuiltInOptions |
