feat(admin): manual account blocking (suspensions)
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 12s
CI / ui (pull_request) Successful in 45s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m10s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 12s
CI / ui (pull_request) Successful in 45s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m10s
Operator-driven hard block, the counterpart to the soft high-rate flag: permanent or until a date, with an optional reason chosen from an editable en+ru picklist (snapshotted onto the block). A block forfeits the player's active games (opponent wins, as a resignation) and cancels their open matchmaking games. A backend gate refuses a blocked account on every /api/v1/user/* route except the block-status probe with 403 account_blocked, which threads through the gateway as the Execute result_code; the UI surfaces it as a terminal blocked screen and stops all push/poll. Temporary blocks self-expire; the operator can unblock at any time (lost games stay lost). Sessions are not revoked, so the blocked client can still reach the exempt block-status endpoint. Backend: migration 00003 (account_suspensions + suspension_reasons) + jet regen; account suspension store; game.ForfeitAllForAccount; requireNotSuspended gate + block-status endpoint; admin console block/unblock + Reasons CRUD. Wire: fbs BlockStatus + account.block_status gateway op. UI: blocked screen, app state, transport/codec, i18n. Docs: ARCHITECTURE, FUNCTIONAL(+ru), PRERELEASE (AB).
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AccountSuspensions struct {
|
||||
SuspensionID uuid.UUID `sql:"primary_key"`
|
||||
AccountID uuid.UUID
|
||||
BlockedAt time.Time
|
||||
BlockedUntil *time.Time
|
||||
ReasonEn *string
|
||||
ReasonRu *string
|
||||
ReasonID *uuid.UUID
|
||||
LiftedAt *time.Time
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SuspensionReasons struct {
|
||||
ReasonID uuid.UUID `sql:"primary_key"`
|
||||
TextEn string
|
||||
TextRu string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package table
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
var AccountSuspensions = newAccountSuspensionsTable("backend", "account_suspensions", "")
|
||||
|
||||
type accountSuspensionsTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
SuspensionID postgres.ColumnString
|
||||
AccountID postgres.ColumnString
|
||||
BlockedAt postgres.ColumnTimestampz
|
||||
BlockedUntil postgres.ColumnTimestampz
|
||||
ReasonEn postgres.ColumnString
|
||||
ReasonRu postgres.ColumnString
|
||||
ReasonID postgres.ColumnString
|
||||
LiftedAt postgres.ColumnTimestampz
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type AccountSuspensionsTable struct {
|
||||
accountSuspensionsTable
|
||||
|
||||
EXCLUDED accountSuspensionsTable
|
||||
}
|
||||
|
||||
// AS creates new AccountSuspensionsTable with assigned alias
|
||||
func (a AccountSuspensionsTable) AS(alias string) *AccountSuspensionsTable {
|
||||
return newAccountSuspensionsTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new AccountSuspensionsTable with assigned schema name
|
||||
func (a AccountSuspensionsTable) FromSchema(schemaName string) *AccountSuspensionsTable {
|
||||
return newAccountSuspensionsTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new AccountSuspensionsTable with assigned table prefix
|
||||
func (a AccountSuspensionsTable) WithPrefix(prefix string) *AccountSuspensionsTable {
|
||||
return newAccountSuspensionsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new AccountSuspensionsTable with assigned table suffix
|
||||
func (a AccountSuspensionsTable) WithSuffix(suffix string) *AccountSuspensionsTable {
|
||||
return newAccountSuspensionsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newAccountSuspensionsTable(schemaName, tableName, alias string) *AccountSuspensionsTable {
|
||||
return &AccountSuspensionsTable{
|
||||
accountSuspensionsTable: newAccountSuspensionsTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newAccountSuspensionsTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newAccountSuspensionsTableImpl(schemaName, tableName, alias string) accountSuspensionsTable {
|
||||
var (
|
||||
SuspensionIDColumn = postgres.StringColumn("suspension_id")
|
||||
AccountIDColumn = postgres.StringColumn("account_id")
|
||||
BlockedAtColumn = postgres.TimestampzColumn("blocked_at")
|
||||
BlockedUntilColumn = postgres.TimestampzColumn("blocked_until")
|
||||
ReasonEnColumn = postgres.StringColumn("reason_en")
|
||||
ReasonRuColumn = postgres.StringColumn("reason_ru")
|
||||
ReasonIDColumn = postgres.StringColumn("reason_id")
|
||||
LiftedAtColumn = postgres.TimestampzColumn("lifted_at")
|
||||
allColumns = postgres.ColumnList{SuspensionIDColumn, AccountIDColumn, BlockedAtColumn, BlockedUntilColumn, ReasonEnColumn, ReasonRuColumn, ReasonIDColumn, LiftedAtColumn}
|
||||
mutableColumns = postgres.ColumnList{AccountIDColumn, BlockedAtColumn, BlockedUntilColumn, ReasonEnColumn, ReasonRuColumn, ReasonIDColumn, LiftedAtColumn}
|
||||
defaultColumns = postgres.ColumnList{BlockedAtColumn}
|
||||
)
|
||||
|
||||
return accountSuspensionsTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
SuspensionID: SuspensionIDColumn,
|
||||
AccountID: AccountIDColumn,
|
||||
BlockedAt: BlockedAtColumn,
|
||||
BlockedUntil: BlockedUntilColumn,
|
||||
ReasonEn: ReasonEnColumn,
|
||||
ReasonRu: ReasonRuColumn,
|
||||
ReasonID: ReasonIDColumn,
|
||||
LiftedAt: LiftedAtColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Code generated by go-jet DO NOT EDIT.
|
||||
//
|
||||
// WARNING: Changes to this file may cause incorrect behavior
|
||||
// and will be lost if the code is regenerated
|
||||
//
|
||||
|
||||
package table
|
||||
|
||||
import (
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
)
|
||||
|
||||
var SuspensionReasons = newSuspensionReasonsTable("backend", "suspension_reasons", "")
|
||||
|
||||
type suspensionReasonsTable struct {
|
||||
postgres.Table
|
||||
|
||||
// Columns
|
||||
ReasonID postgres.ColumnString
|
||||
TextEn postgres.ColumnString
|
||||
TextRu postgres.ColumnString
|
||||
CreatedAt postgres.ColumnTimestampz
|
||||
UpdatedAt postgres.ColumnTimestampz
|
||||
|
||||
AllColumns postgres.ColumnList
|
||||
MutableColumns postgres.ColumnList
|
||||
DefaultColumns postgres.ColumnList
|
||||
}
|
||||
|
||||
type SuspensionReasonsTable struct {
|
||||
suspensionReasonsTable
|
||||
|
||||
EXCLUDED suspensionReasonsTable
|
||||
}
|
||||
|
||||
// AS creates new SuspensionReasonsTable with assigned alias
|
||||
func (a SuspensionReasonsTable) AS(alias string) *SuspensionReasonsTable {
|
||||
return newSuspensionReasonsTable(a.SchemaName(), a.TableName(), alias)
|
||||
}
|
||||
|
||||
// Schema creates new SuspensionReasonsTable with assigned schema name
|
||||
func (a SuspensionReasonsTable) FromSchema(schemaName string) *SuspensionReasonsTable {
|
||||
return newSuspensionReasonsTable(schemaName, a.TableName(), a.Alias())
|
||||
}
|
||||
|
||||
// WithPrefix creates new SuspensionReasonsTable with assigned table prefix
|
||||
func (a SuspensionReasonsTable) WithPrefix(prefix string) *SuspensionReasonsTable {
|
||||
return newSuspensionReasonsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
|
||||
}
|
||||
|
||||
// WithSuffix creates new SuspensionReasonsTable with assigned table suffix
|
||||
func (a SuspensionReasonsTable) WithSuffix(suffix string) *SuspensionReasonsTable {
|
||||
return newSuspensionReasonsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
|
||||
}
|
||||
|
||||
func newSuspensionReasonsTable(schemaName, tableName, alias string) *SuspensionReasonsTable {
|
||||
return &SuspensionReasonsTable{
|
||||
suspensionReasonsTable: newSuspensionReasonsTableImpl(schemaName, tableName, alias),
|
||||
EXCLUDED: newSuspensionReasonsTableImpl("", "excluded", ""),
|
||||
}
|
||||
}
|
||||
|
||||
func newSuspensionReasonsTableImpl(schemaName, tableName, alias string) suspensionReasonsTable {
|
||||
var (
|
||||
ReasonIDColumn = postgres.StringColumn("reason_id")
|
||||
TextEnColumn = postgres.StringColumn("text_en")
|
||||
TextRuColumn = postgres.StringColumn("text_ru")
|
||||
CreatedAtColumn = postgres.TimestampzColumn("created_at")
|
||||
UpdatedAtColumn = postgres.TimestampzColumn("updated_at")
|
||||
allColumns = postgres.ColumnList{ReasonIDColumn, TextEnColumn, TextRuColumn, CreatedAtColumn, UpdatedAtColumn}
|
||||
mutableColumns = postgres.ColumnList{TextEnColumn, TextRuColumn, CreatedAtColumn, UpdatedAtColumn}
|
||||
defaultColumns = postgres.ColumnList{CreatedAtColumn, UpdatedAtColumn}
|
||||
)
|
||||
|
||||
return suspensionReasonsTable{
|
||||
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
|
||||
|
||||
//Columns
|
||||
ReasonID: ReasonIDColumn,
|
||||
TextEn: TextEnColumn,
|
||||
TextRu: TextRuColumn,
|
||||
CreatedAt: CreatedAtColumn,
|
||||
UpdatedAt: UpdatedAtColumn,
|
||||
|
||||
AllColumns: allColumns,
|
||||
MutableColumns: mutableColumns,
|
||||
DefaultColumns: defaultColumns,
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ package table
|
||||
// this method only once at the beginning of the program.
|
||||
func UseSchema(schema string) {
|
||||
AccountStats = AccountStats.FromSchema(schema)
|
||||
AccountSuspensions = AccountSuspensions.FromSchema(schema)
|
||||
Accounts = Accounts.FromSchema(schema)
|
||||
Blocks = Blocks.FromSchema(schema)
|
||||
ChatMessages = ChatMessages.FromSchema(schema)
|
||||
@@ -28,4 +29,5 @@ func UseSchema(schema string) {
|
||||
Games = Games.FromSchema(schema)
|
||||
Identities = Identities.FromSchema(schema)
|
||||
Sessions = Sessions.FromSchema(schema)
|
||||
SuspensionReasons = SuspensionReasons.FromSchema(schema)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
-- +goose Up
|
||||
-- Manual account blocking ("suspension"), the operator's hard counterpart to the soft,
|
||||
-- reversible accounts.flagged_high_rate_at marker. Named "suspension" throughout the schema
|
||||
-- and Go to stay distinct from the peer-to-peer `blocks` table (one player muting another);
|
||||
-- the wire/UI vocabulary the player sees is "blocked". A suspension forces the player to
|
||||
-- forfeit every active game and replaces their whole UI with a terminal "blocked" screen until
|
||||
-- it is lifted or (for a temporary one) expires. See docs/ARCHITECTURE.md §12.
|
||||
SET search_path = backend, pg_catalog;
|
||||
|
||||
-- The operator-editable reason picklist, one row per reason with its English and Russian text.
|
||||
-- A suspension snapshots the chosen text (account_suspensions.reason_en/ru), so editing or
|
||||
-- deleting a reason here never changes or breaks a reason already shown to a blocked player.
|
||||
CREATE TABLE suspension_reasons (
|
||||
reason_id uuid PRIMARY KEY,
|
||||
text_en text NOT NULL,
|
||||
text_ru text NOT NULL,
|
||||
created_at timestamptz NOT NULL DEFAULT now(),
|
||||
updated_at timestamptz NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
-- The block history: one row per block. blocked_until is NULL for a permanent block and the
|
||||
-- expiry instant for a temporary one; lifted_at is stamped when an operator unblocks early.
|
||||
-- reason_en/reason_ru are the text snapshot taken at block time (NULL when no reason was
|
||||
-- cited); reason_id keeps a loose link to the picklist entry for later analytics and is nulled
|
||||
-- if that entry is deleted (the snapshot remains the source of truth shown to the player). An
|
||||
-- account is currently blocked when its newest row has lifted_at IS NULL AND (blocked_until IS
|
||||
-- NULL OR blocked_until > now()).
|
||||
CREATE TABLE account_suspensions (
|
||||
suspension_id uuid PRIMARY KEY,
|
||||
account_id uuid NOT NULL REFERENCES accounts (account_id) ON DELETE CASCADE,
|
||||
blocked_at timestamptz NOT NULL DEFAULT now(),
|
||||
blocked_until timestamptz,
|
||||
reason_en text,
|
||||
reason_ru text,
|
||||
reason_id uuid REFERENCES suspension_reasons (reason_id) ON DELETE SET NULL,
|
||||
lifted_at timestamptz
|
||||
);
|
||||
-- The enforcement gate looks up the newest suspension for an account on every authenticated
|
||||
-- request; this index serves that "latest by account" probe.
|
||||
CREATE INDEX account_suspensions_account_idx ON account_suspensions (account_id, blocked_at DESC);
|
||||
|
||||
-- +goose Down
|
||||
SET search_path = backend, pg_catalog;
|
||||
DROP TABLE IF EXISTS account_suspensions;
|
||||
DROP TABLE IF EXISTS suspension_reasons;
|
||||
Reference in New Issue
Block a user