feat: pk;config
This commit is contained in:
@@ -46,18 +46,11 @@ public class PKSystem
|
||||
public string WebhookUrl { get; }
|
||||
public string WebhookToken { get; }
|
||||
public Instant Created { get; }
|
||||
public string UiTz { get; set; }
|
||||
public bool PingsEnabled { get; }
|
||||
public int? LatchTimeout { get; }
|
||||
public PrivacyLevel DescriptionPrivacy { get; }
|
||||
public PrivacyLevel MemberListPrivacy { get; }
|
||||
public PrivacyLevel FrontPrivacy { get; }
|
||||
public PrivacyLevel FrontHistoryPrivacy { get; }
|
||||
public PrivacyLevel GroupListPrivacy { get; }
|
||||
public int? MemberLimitOverride { get; }
|
||||
public int? GroupLimitOverride { get; }
|
||||
|
||||
[JsonIgnore] public DateTimeZone Zone => DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz);
|
||||
}
|
||||
|
||||
public static class PKSystemExt
|
||||
@@ -84,7 +77,7 @@ public static class PKSystemExt
|
||||
{
|
||||
case APIVersion.V1:
|
||||
{
|
||||
o.Add("tz", system.UiTz);
|
||||
o.Add("tz", null);
|
||||
|
||||
o.Add("description_privacy",
|
||||
ctx == LookupContext.ByOwner ? system.DescriptionPrivacy.ToJsonString() : null);
|
||||
@@ -98,7 +91,8 @@ public static class PKSystemExt
|
||||
}
|
||||
case APIVersion.V2:
|
||||
{
|
||||
o.Add("timezone", system.UiTz);
|
||||
// todo: remove this
|
||||
o.Add("timezone", null);
|
||||
|
||||
if (ctx == LookupContext.ByOwner)
|
||||
{
|
||||
|
68
PluralKit.Core/Models/Patch/SystemConfigPatch.cs
Normal file
68
PluralKit.Core/Models/Patch/SystemConfigPatch.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using SqlKata;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class SystemConfigPatch: PatchObject
|
||||
{
|
||||
public Partial<string> UiTz { get; set; }
|
||||
public Partial<bool> PingsEnabled { get; set; }
|
||||
public Partial<int?> LatchTimeout { get; set; }
|
||||
public Partial<int?> MemberLimitOverride { get; set; }
|
||||
public Partial<int?> GroupLimitOverride { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("ui_tz", UiTz)
|
||||
.With("pings_enabled", PingsEnabled)
|
||||
.With("latch_timeout", LatchTimeout)
|
||||
.With("member_limit_override", MemberLimitOverride)
|
||||
.With("group_limit_override", GroupLimitOverride)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
{
|
||||
if (UiTz.IsPresent && DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz.Value) == null)
|
||||
Errors.Add(new ValidationError("timezone"));
|
||||
}
|
||||
|
||||
public JObject ToJson()
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
if (UiTz.IsPresent)
|
||||
o.Add("timezone", UiTz.Value);
|
||||
|
||||
if (PingsEnabled.IsPresent)
|
||||
o.Add("pings_enabled", PingsEnabled.Value);
|
||||
|
||||
if (LatchTimeout.IsPresent)
|
||||
o.Add("latch_timeout", LatchTimeout.Value);
|
||||
|
||||
if (MemberLimitOverride.IsPresent)
|
||||
o.Add("member_limit", MemberLimitOverride.Value);
|
||||
|
||||
if (GroupLimitOverride.IsPresent)
|
||||
o.Add("group_limit", GroupLimitOverride.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
public static SystemConfigPatch FromJson(JObject o)
|
||||
{
|
||||
var patch = new SystemConfigPatch();
|
||||
|
||||
if (o.ContainsKey("timezone"))
|
||||
patch.UiTz = o.Value<string>("timezone");
|
||||
|
||||
if (o.ContainsKey("pings_enabled"))
|
||||
patch.PingsEnabled = o.Value<bool>("pings_enabled");
|
||||
|
||||
if (o.ContainsKey("latch_timeout"))
|
||||
patch.LatchTimeout = o.Value<int>("latch_timeout");
|
||||
|
||||
return patch;
|
||||
}
|
||||
}
|
@@ -19,16 +19,11 @@ public class SystemPatch: PatchObject
|
||||
public Partial<string?> Token { get; set; }
|
||||
public Partial<string?> WebhookUrl { get; set; }
|
||||
public Partial<string?> WebhookToken { get; set; }
|
||||
public Partial<string> UiTz { get; set; }
|
||||
public Partial<PrivacyLevel> DescriptionPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> MemberListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> GroupListPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontPrivacy { get; set; }
|
||||
public Partial<PrivacyLevel> FrontHistoryPrivacy { get; set; }
|
||||
public Partial<bool> PingsEnabled { get; set; }
|
||||
public Partial<int?> LatchTimeout { get; set; }
|
||||
public Partial<int?> MemberLimitOverride { get; set; }
|
||||
public Partial<int?> GroupLimitOverride { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("name", Name)
|
||||
@@ -41,16 +36,11 @@ public class SystemPatch: PatchObject
|
||||
.With("token", Token)
|
||||
.With("webhook_url", WebhookUrl)
|
||||
.With("webhook_token", WebhookToken)
|
||||
.With("ui_tz", UiTz)
|
||||
.With("description_privacy", DescriptionPrivacy)
|
||||
.With("member_list_privacy", MemberListPrivacy)
|
||||
.With("group_list_privacy", GroupListPrivacy)
|
||||
.With("front_privacy", FrontPrivacy)
|
||||
.With("front_history_privacy", FrontHistoryPrivacy)
|
||||
.With("pings_enabled", PingsEnabled)
|
||||
.With("latch_timeout", LatchTimeout)
|
||||
.With("member_limit_override", MemberLimitOverride)
|
||||
.With("group_limit_override", GroupLimitOverride)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
@@ -69,8 +59,6 @@ public class SystemPatch: PatchObject
|
||||
s => MiscUtils.TryMatchUri(s, out var bannerUri));
|
||||
if (Color.Value != null)
|
||||
AssertValid(Color.Value, "color", "^[0-9a-fA-F]{6}$");
|
||||
if (UiTz.IsPresent && DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz.Value) == null)
|
||||
Errors.Add(new ValidationError("timezone"));
|
||||
}
|
||||
|
||||
#nullable disable
|
||||
@@ -84,14 +72,11 @@ public class SystemPatch: PatchObject
|
||||
if (o.ContainsKey("avatar_url")) patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
|
||||
if (o.ContainsKey("banner")) patch.BannerImage = o.Value<string>("banner").NullIfEmpty();
|
||||
if (o.ContainsKey("color")) patch.Color = o.Value<string>("color").NullIfEmpty();
|
||||
if (o.ContainsKey("timezone")) patch.UiTz = o.Value<string>("timezone") ?? "UTC";
|
||||
|
||||
switch (v)
|
||||
{
|
||||
case APIVersion.V1:
|
||||
{
|
||||
if (o.ContainsKey("tz")) patch.UiTz = o.Value<string>("tz") ?? "UTC";
|
||||
|
||||
if (o.ContainsKey("description_privacy"))
|
||||
patch.DescriptionPrivacy = patch.ParsePrivacy(o, "description_privacy");
|
||||
if (o.ContainsKey("member_list_privacy"))
|
||||
@@ -149,8 +134,6 @@ public class SystemPatch: PatchObject
|
||||
o.Add("banner", BannerImage.Value);
|
||||
if (Color.IsPresent)
|
||||
o.Add("color", Color.Value);
|
||||
if (UiTz.IsPresent)
|
||||
o.Add("timezone", UiTz.Value);
|
||||
|
||||
if (
|
||||
DescriptionPrivacy.IsPresent
|
||||
|
33
PluralKit.Core/Models/SystemConfig.cs
Normal file
33
PluralKit.Core/Models/SystemConfig.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
namespace PluralKit.Core;
|
||||
|
||||
public class SystemConfig
|
||||
{
|
||||
public SystemId Id { get; }
|
||||
public string UiTz { get; set; }
|
||||
public bool PingsEnabled { get; }
|
||||
public int? LatchTimeout { get; }
|
||||
public int? MemberLimitOverride { get; }
|
||||
public int? GroupLimitOverride { get; }
|
||||
|
||||
public DateTimeZone Zone => DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz);
|
||||
}
|
||||
|
||||
public static class SystemConfigExt
|
||||
{
|
||||
public static JObject ToJson(this SystemConfig cfg)
|
||||
{
|
||||
var o = new JObject();
|
||||
|
||||
o.Add("timezone", cfg.UiTz);
|
||||
o.Add("pings_enabled", cfg.PingsEnabled);
|
||||
o.Add("latch_timeout", cfg.LatchTimeout);
|
||||
o.Add("member_limit", cfg.MemberLimitOverride ?? Limits.MaxMemberCount);
|
||||
o.Add("group_limit", cfg.GroupLimitOverride ?? Limits.MaxGroupCount);
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user