Add disabling autoproxy per-account

This commit is contained in:
spiral
2020-11-20 18:34:08 -05:00
parent 41247c68a6
commit 37294b68da
8 changed files with 98 additions and 5 deletions

View File

@@ -24,5 +24,6 @@ namespace PluralKit.Core
public Instant? LastSwitchTimestamp { get; }
public string? SystemTag { get; }
public string? SystemAvatar { get; }
public bool AllowAutoproxy { get; }
}
}

View File

@@ -14,12 +14,13 @@
last_switch_members int[],
last_switch_timestamp timestamp,
system_tag text,
system_avatar text
system_avatar text,
allow_autoproxy bool
)
as $$
-- CTEs to query "static" (accessible only through args) data
with
system as (select systems.* from accounts inner join systems on systems.id = accounts.system where accounts.uid = account_id),
system as (select systems.*, allow_autoproxy as account_autoproxy from accounts inner join systems on systems.id = accounts.system where accounts.uid = account_id),
guild as (select * from servers where id = guild_id),
last_message as (select * from messages where messages.guild = guild_id and messages.sender = account_id order by mid desc limit 1)
select
@@ -37,7 +38,8 @@ as $$
system_last_switch.members as last_switch_members,
system_last_switch.timestamp as last_switch_timestamp,
system.tag as system_tag,
system.avatar_url as system_avatar
system.avatar_url as system_avatar,
system.account_autoproxy as allow_autoproxy
-- We need a "from" clause, so we just use some bogus data that's always present
-- This ensure we always have exactly one row going forward, so we can left join afterwards and still get data
from (select 1) as _placeholder

View File

@@ -1,5 +1,7 @@
-- SCHEMA VERSION 12: <insert date> --
-- Add disabling front/latch autoproxy per-member --
-- Add disabling autoproxy per-account --
alter table members add column allow_autoproxy bool not null default true;
alter table accounts add column allow_autoproxy bool not null default true;
update info set schema_version = 12;

View File

@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;
using Dapper;
namespace PluralKit.Core
{
public partial class ModelRepository
{
public async Task UpdateAccount(IPKConnection conn, ulong id, AccountPatch patch)
{
_logger.Information("Updated account {accountId}: {@AccountPatch}", id, patch);
var (query, pms) = patch.Apply(UpdateQueryBuilder.Update("accounts", "uid = @uid"))
.WithConstant("uid", id)
.Build();
await conn.ExecuteAsync(query, pms);
}
}
}