feat: config setting to default show/hide private info

This commit is contained in:
spiral
2021-12-06 04:01:42 -05:00
parent 455830a2b5
commit 32bea51e18
14 changed files with 71 additions and 17 deletions

View File

@@ -72,6 +72,13 @@ public class Config
"disabled"
));
items.Add(new(
"show private",
"Whether private information is shown to linked accounts by default",
ctx.Config.ShowPrivateInfo.ToString().ToLower(),
"true"
));
items.Add(new(
"Member limit",
"The maximum number of registered members for your system",
@@ -345,7 +352,7 @@ public class Config
if (!ctx.HasNext())
{
if (ctx.Config.MemberDefaultPrivate) { await ctx.Reply("Newly created groups will currently have their privacy settings set to private. To change this, type `pk;config private group off`"); }
if (ctx.Config.GroupDefaultPrivate) { await ctx.Reply("Newly created groups will currently have their privacy settings set to private. To change this, type `pk;config private group off`"); }
else { await ctx.Reply("Newly created groups will currently have their privacy settings set to public. To automatically set new groups' privacy settings to private, type `pk;config private group on`"); }
}
else
@@ -364,4 +371,30 @@ public class Config
}
}
}
public async Task ShowPrivateInfo(Context ctx)
{
ctx.CheckSystem();
if (!ctx.HasNext())
{
if (ctx.Config.ShowPrivateInfo) await ctx.Reply("Private information is currently **shown** when looking up your own info. Use the `-public` flag to hide it.");
else await ctx.Reply("Private information is currently **hidden** when looking up your own info. Use the `-private` flag to show it.");
return;
}
if (ctx.Match("true"))
{
await _repo.UpdateSystemConfig(ctx.System.Id, new() { ShowPrivateInfo = true });
await ctx.Reply("Private information will now be **shown** when looking up your own info. Use the `-public` flag to hide it.");
}
else if (ctx.Match("false"))
{
await _repo.UpdateSystemConfig(ctx.System.Id, new() { ShowPrivateInfo = false });
await ctx.Reply("Private information will now be **hidden** when looking up your own info. Use the `-private` flag to show it.");
}
else throw new PKError("You must pass 'true' or 'false' to this command.");
}
}

View File

@@ -190,7 +190,7 @@ public class Groups
public async Task GroupDescription(Context ctx, PKGroup target)
{
if (!target.DescriptionPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
throw Errors.LookupNotAllowed;
throw target.System == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
var noDescriptionSetMessage = "This group does not have a description set.";
if (ctx.System?.Id == target.System)
@@ -282,7 +282,8 @@ public class Groups
async Task ShowIcon()
{
if (!target.IconPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
throw Errors.LookupNotAllowed;
throw target.System == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
if ((target.Icon?.Trim() ?? "").Length > 0)
{
var eb = new EmbedBuilder()
@@ -346,7 +347,8 @@ public class Groups
async Task ShowBannerImage()
{
if (!target.DescriptionPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
throw Errors.LookupNotAllowed;
throw target.System == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
if ((target.BannerImage?.Trim() ?? "").Length > 0)
{
var eb = new EmbedBuilder()
@@ -440,7 +442,7 @@ public class Groups
if (system.Id == ctx.System.Id)
pctx = LookupContext.ByOwner;
else
throw new PKError("You do not have permission to access this information.");
throw system.Id == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
}
var groups = (await _db.Execute(conn => conn.QueryGroupList(system.Id)))

View File

@@ -54,8 +54,7 @@ public static class ContextListExt
// Privacy filter (default is public only)
if (ctx.MatchFlag("a", "all")) p.PrivacyFilter = null;
if (ctx.MatchFlag("private-only", "private", "priv")) p.PrivacyFilter = PrivacyLevel.Private;
if (ctx.MatchFlag("public-only", "public", "pub")) p.PrivacyFilter = PrivacyLevel.Public;
if (ctx.MatchFlag("private-only", "po")) p.PrivacyFilter = PrivacyLevel.Private;
// PERM CHECK: If we're trying to access non-public members of another system, error
if (p.PrivacyFilter != PrivacyLevel.Public && lookupCtx != LookupContext.ByOwner)

View File

@@ -69,7 +69,7 @@ public class MemberEdit
$" To set one, type `pk;member {target.Reference()} description <description>`.";
if (!target.DescriptionPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
throw Errors.LookupNotAllowed;
throw target.System == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
if (ctx.MatchRaw())
{
@@ -125,7 +125,7 @@ public class MemberEdit
noPronounsSetMessage += $"To set some, type `pk;member {target.Reference()} pronouns <pronouns>`.";
if (!target.PronounPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
throw Errors.LookupNotAllowed;
throw target.System == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
if (ctx.MatchRaw())
{
@@ -293,7 +293,7 @@ public class MemberEdit
else if (!ctx.HasNext())
{
if (!target.BirthdayPrivacy.CanAccess(ctx.LookupContextFor(target.System)))
throw Errors.LookupNotAllowed;
throw target.System == ctx.System?.Id ? Errors.LookupHidden : Errors.LookupNotAllowed;
if (target.Birthday == null)
await ctx.Reply("This member does not have a birthdate set."