aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2022-02-03 09:36:34 -0600
committerJP Dillingham <jpdillingham@gmail.com>2022-02-03 09:36:34 -0600
commit40b858f4710a3762390cfa0eb9415caeaa6ed39e (patch)
tree20fddfd9a52aea4e752616000fca745341e2a9ec /src
parent75cd4f807eedd018f5c4e49f00973a5a20aaeb6c (diff)
downloadslskd-40b858f4710a3762390cfa0eb9415caeaa6ed39e.tar.gz
validate group overlap
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Options.cs28
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