Feature/granular member privacy (#174)
* Some reasons this needs to exist for it to run on my machine? I don't think it would hurt to have it in other machines so * Add options to member model * Add Privacy to member embed * Added member privacy display list * Update database settings * apparetnly this is nolonger needed? * Fix sql call * Fix more sql errors * Added in settings control * Add all subject to system privacy * Basic API Privacy * Name privacy in logs * update todo * remove CheckReadMemberPermission * Added name privacy to log embed * update todo * Update todo * Update api to handle privacy * update todo * Update systemlist full to respect privacy (as well as system list) * include colour as option for member privacy subject * move todo file (why was it there?) * Update TODO.md * Update TODO.md * Update TODO.md * Deleted to create pr * Update command usage and add to the command tree * Make api respect created privacy * Add editing privacy through the api * Fix pronoun privacy field in api * Fix info leak of display name in api * deprecate privacy field in api * Deprecate privacy diffrently * Update API * Update documentation * Update documentation * Remove comment in yml * Update userguide * Update migration (fix typo in 5.sql too) * Sanatize names * some full stops * Fix after merge * update migration * update schema version * update edit command * update privacy filter * fix a dumb mistake * clarify on what name privacy does * make it easier on someone else * Update docs * Comment out unused code * Add aliases for `member privacy all public` and `member privacy all private`
This commit is contained in:
@@ -20,7 +20,7 @@ namespace PluralKit.Core
|
||||
internal class Database: IDatabase
|
||||
{
|
||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||
private const int TargetSchemaVersion = 7;
|
||||
private const int TargetSchemaVersion = 8;
|
||||
|
||||
private readonly CoreConfig _config;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
22
PluralKit.Core/Database/Migrations/8.sql
Normal file
22
PluralKit.Core/Database/Migrations/8.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- SCHEMA VERSION 8: 2020-05-13 --
|
||||
-- Create new columns --
|
||||
alter table members add column description_privacy integer check (description_privacy in (1, 2)) not null default 1;
|
||||
alter table members add column name_privacy integer check (name_privacy in (1, 2)) not null default 1;
|
||||
alter table members add column birthday_privacy integer check (birthday_privacy in (1, 2)) not null default 1;
|
||||
alter table members add column pronoun_privacy integer check (pronoun_privacy in (1, 2)) not null default 1;
|
||||
alter table members add column metadata_privacy integer check (metadata_privacy in (1, 2)) not null default 1;
|
||||
alter table members add column color_privacy integer check (color_privacy in (1, 2)) not null default 1;
|
||||
|
||||
-- Transfer existing settings --
|
||||
update members set description_privacy = member_privacy;
|
||||
update members set name_privacy = member_privacy;
|
||||
update members set birthday_privacy = member_privacy;
|
||||
update members set pronoun_privacy = member_privacy;
|
||||
update members set metadata_privacy = member_privacy;
|
||||
update members set color_privacy = member_privacy;
|
||||
|
||||
-- Rename member_privacy to member_visibility --
|
||||
alter table members rename column member_privacy to member_visibility;
|
||||
|
||||
-- Update Schema Info --
|
||||
update info set schema_version = 8;
|
||||
@@ -17,7 +17,7 @@ namespace PluralKit.Core
|
||||
StringBuilder query = new StringBuilder("select * from member_list where system = @system");
|
||||
|
||||
if (privacyFilter != null)
|
||||
query.Append($" and member_privacy = {(int) privacyFilter}");
|
||||
query.Append($" and member_visibility = {(int) privacyFilter}");
|
||||
|
||||
if (filter != null)
|
||||
{
|
||||
|
||||
@@ -23,7 +23,13 @@ namespace PluralKit.Core {
|
||||
public Instant Created { get; }
|
||||
public int MessageCount { get; }
|
||||
|
||||
public PrivacyLevel MemberPrivacy { get; set; }
|
||||
public PrivacyLevel MemberVisibility { get; set; }
|
||||
public PrivacyLevel DescriptionPrivacy { get; set; }
|
||||
public PrivacyLevel NamePrivacy { get; set; } //ignore setting if no display name is set
|
||||
public PrivacyLevel BirthdayPrivacy { get; set; }
|
||||
public PrivacyLevel PronounPrivacy { get; set; }
|
||||
public PrivacyLevel MetadataPrivacy { get; set; }
|
||||
public PrivacyLevel ColorPrivacy { get; set; }
|
||||
|
||||
/// Returns a formatted string representing the member's birthday, taking into account that a year of "0001" or "0004" is hidden
|
||||
/// Before Feb 10 2020, the sentinel year was 0001, now it is 0004.
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace PluralKit.Core {
|
||||
|
||||
public async Task SaveMember(PKMember member) {
|
||||
using (var conn = await _conn.Obtain())
|
||||
await conn.ExecuteAsync("update members set name = @Name, display_name = @DisplayName, description = @Description, color = @Color, avatar_url = @AvatarUrl, birthday = @Birthday, pronouns = @Pronouns, proxy_tags = @ProxyTags, keep_proxy = @KeepProxy, member_privacy = @MemberPrivacy where id = @Id", member);
|
||||
await conn.ExecuteAsync("update members set name = @Name, display_name = @DisplayName, description = @Description, color = @Color, avatar_url = @AvatarUrl, birthday = @Birthday, pronouns = @Pronouns, proxy_tags = @ProxyTags, keep_proxy = @KeepProxy, member_visibility = @MemberVisibility, description_privacy = @DescriptionPrivacy, name_privacy = @NamePrivacy, birthday_privacy = @BirthdayPrivacy, pronoun_privacy = @PronounPrivacy, metadata_privacy = @MetadataPrivacy, color_privacy = @ColorPrivacy where id = @Id", member);
|
||||
|
||||
_logger.Information("Updated member {@Member}", member);
|
||||
}
|
||||
@@ -164,8 +164,8 @@ namespace PluralKit.Core {
|
||||
|
||||
public async Task<int> GetSystemMemberCount(SystemId id, bool includePrivate)
|
||||
{
|
||||
var query = "select count(*) from members where system = @id";
|
||||
if (!includePrivate) query += " and member_privacy = 1"; // 1 = public
|
||||
var query = "select count(*) from members where system = @Id";
|
||||
if (!includePrivate) query += " and member_visibility = 1"; // 1 = public
|
||||
|
||||
using (var conn = await _conn.Obtain())
|
||||
return await conn.ExecuteScalarAsync<int>(query, new { id });
|
||||
|
||||
Reference in New Issue
Block a user