GDPR stuff update (#18300)
This commit is contained in:
committed by
GitHub
parent
86f33a8fa2
commit
e0c4884995
1770
Content.Server.Database/Migrations/Postgres/20230725193102_AdminNotesImprovementsForeignKeys.Designer.cs
generated
Normal file
1770
Content.Server.Database/Migrations/Postgres/20230725193102_AdminNotesImprovementsForeignKeys.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,90 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Content.Server.Database.Migrations.Postgres
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AdminNotesImprovementsForeignKeys : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
@@ -317,10 +317,6 @@ namespace Content.Server.Database.Migrations.Postgres
|
||||
.HasColumnType("character varying(4096)")
|
||||
.HasColumnName("message");
|
||||
|
||||
b.Property<int>("Severity")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("severity");
|
||||
|
||||
b.Property<Guid?>("PlayerUserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("player_user_id");
|
||||
@@ -337,6 +333,10 @@ namespace Content.Server.Database.Migrations.Postgres
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("secret");
|
||||
|
||||
b.Property<int>("Severity")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("severity");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("PK_admin_notes");
|
||||
|
||||
@@ -1364,7 +1364,7 @@ namespace Content.Server.Database.Migrations.Postgres
|
||||
.WithMany("AdminMessagesReceived")
|
||||
.HasForeignKey("PlayerUserId")
|
||||
.HasPrincipalKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.HasConstraintName("FK_admin_messages_player_player_user_id");
|
||||
|
||||
b.HasOne("Content.Server.Database.Round", "Round")
|
||||
@@ -1410,7 +1410,7 @@ namespace Content.Server.Database.Migrations.Postgres
|
||||
.WithMany("AdminNotesReceived")
|
||||
.HasForeignKey("PlayerUserId")
|
||||
.HasPrincipalKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.HasConstraintName("FK_admin_notes_player_player_user_id");
|
||||
|
||||
b.HasOne("Content.Server.Database.Round", "Round")
|
||||
@@ -1468,7 +1468,7 @@ namespace Content.Server.Database.Migrations.Postgres
|
||||
.WithMany("AdminWatchlistsReceived")
|
||||
.HasForeignKey("PlayerUserId")
|
||||
.HasPrincipalKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.HasConstraintName("FK_admin_watchlists_player_player_user_id");
|
||||
|
||||
b.HasOne("Content.Server.Database.Round", "Round")
|
||||
|
||||
1698
Content.Server.Database/Migrations/Sqlite/20230725193058_AdminNotesImprovementsForeignKeys.Designer.cs
generated
Normal file
1698
Content.Server.Database/Migrations/Sqlite/20230725193058_AdminNotesImprovementsForeignKeys.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,90 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Content.Server.Database.Migrations.Sqlite
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AdminNotesImprovementsForeignKeys : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_messages_player_player_user_id",
|
||||
table: "admin_messages",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_notes_player_player_user_id",
|
||||
table: "admin_notes",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_admin_watchlists_player_player_user_id",
|
||||
table: "admin_watchlists",
|
||||
column: "player_user_id",
|
||||
principalTable: "player",
|
||||
principalColumn: "user_id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// <auto-generated />
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Content.Server.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -295,10 +295,6 @@ namespace Content.Server.Database.Migrations.Sqlite
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("message");
|
||||
|
||||
b.Property<int>("Severity")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("severity");
|
||||
|
||||
b.Property<Guid?>("PlayerUserId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("player_user_id");
|
||||
@@ -315,6 +311,10 @@ namespace Content.Server.Database.Migrations.Sqlite
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("secret");
|
||||
|
||||
b.Property<int>("Severity")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnName("severity");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("PK_admin_notes");
|
||||
|
||||
@@ -1292,7 +1292,7 @@ namespace Content.Server.Database.Migrations.Sqlite
|
||||
.WithMany("AdminMessagesReceived")
|
||||
.HasForeignKey("PlayerUserId")
|
||||
.HasPrincipalKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.HasConstraintName("FK_admin_messages_player_player_user_id");
|
||||
|
||||
b.HasOne("Content.Server.Database.Round", "Round")
|
||||
@@ -1338,7 +1338,7 @@ namespace Content.Server.Database.Migrations.Sqlite
|
||||
.WithMany("AdminNotesReceived")
|
||||
.HasForeignKey("PlayerUserId")
|
||||
.HasPrincipalKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.HasConstraintName("FK_admin_notes_player_player_user_id");
|
||||
|
||||
b.HasOne("Content.Server.Database.Round", "Round")
|
||||
@@ -1396,7 +1396,7 @@ namespace Content.Server.Database.Migrations.Sqlite
|
||||
.WithMany("AdminWatchlistsReceived")
|
||||
.HasForeignKey("PlayerUserId")
|
||||
.HasPrincipalKey("UserId")
|
||||
.OnDelete(DeleteBehavior.SetNull)
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.HasConstraintName("FK_admin_watchlists_player_player_user_id");
|
||||
|
||||
b.HasOne("Content.Server.Database.Round", "Round")
|
||||
|
||||
@@ -162,13 +162,15 @@ namespace Content.Server.Database
|
||||
modelBuilder.Entity<ConnectionLog>()
|
||||
.HasIndex(p => p.UserId);
|
||||
|
||||
// SetNull is necessary here so you can safely delete admins (GDPR right to erasure) while keeping the notes intact
|
||||
// SetNull is necessary for created by/edited by-s here,
|
||||
// so you can safely delete admins (GDPR right to erasure) while keeping the notes intact
|
||||
|
||||
modelBuilder.Entity<AdminNote>()
|
||||
.HasOne(note => note.Player)
|
||||
.WithMany(player => player.AdminNotesReceived)
|
||||
.HasForeignKey(note => note.PlayerUserId)
|
||||
.HasPrincipalKey(player => player.UserId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<AdminNote>()
|
||||
.HasOne(version => version.CreatedBy)
|
||||
@@ -196,7 +198,7 @@ namespace Content.Server.Database
|
||||
.WithMany(player => player.AdminWatchlistsReceived)
|
||||
.HasForeignKey(note => note.PlayerUserId)
|
||||
.HasPrincipalKey(player => player.UserId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<AdminWatchlist>()
|
||||
.HasOne(version => version.CreatedBy)
|
||||
@@ -224,7 +226,7 @@ namespace Content.Server.Database
|
||||
.WithMany(player => player.AdminMessagesReceived)
|
||||
.HasForeignKey(note => note.PlayerUserId)
|
||||
.HasPrincipalKey(player => player.UserId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<AdminMessage>()
|
||||
.HasOne(version => version.CreatedBy)
|
||||
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
import psycopg2
|
||||
from uuid import UUID
|
||||
|
||||
LATEST_DB_MIGRATION = "20230402214647_BanAutoDelete"
|
||||
LATEST_DB_MIGRATION = "20230725193102_AdminNotesImprovementsForeignKeys"
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
@@ -33,7 +33,9 @@ def main():
|
||||
|
||||
dump_admin(cur, user_id, arg_output)
|
||||
dump_admin_log(cur, user_id, arg_output)
|
||||
dump_admin_messages(cur, user_id, arg_output)
|
||||
dump_admin_notes(cur, user_id, arg_output)
|
||||
dump_admin_watchlists(cur, user_id, arg_output)
|
||||
dump_connection_log(cur, user_id, arg_output)
|
||||
dump_play_time(cur, user_id, arg_output)
|
||||
dump_player(cur, user_id, arg_output)
|
||||
@@ -291,7 +293,7 @@ FROM (
|
||||
FROM
|
||||
server_ban
|
||||
WHERE
|
||||
user_id = %s
|
||||
player_user_id = %s
|
||||
) as data
|
||||
""", (user_id,))
|
||||
|
||||
@@ -339,7 +341,7 @@ FROM (
|
||||
FROM
|
||||
server_role_ban
|
||||
WHERE
|
||||
user_id = %s
|
||||
player_user_id = %s
|
||||
) as data
|
||||
""", (user_id,))
|
||||
|
||||
@@ -393,6 +395,50 @@ FROM (
|
||||
f.write(json_data)
|
||||
|
||||
|
||||
def dump_admin_messages(cur: "psycopg2.cursor", user_id: str, outdir: str):
|
||||
print("Dumping admin_messages...")
|
||||
|
||||
cur.execute("""
|
||||
SELECT
|
||||
COALESCE(json_agg(to_json(data)), '[]') #>> '{}'
|
||||
FROM (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
admin_messages
|
||||
WHERE
|
||||
player_user_id = %s
|
||||
) as data
|
||||
""", (user_id,))
|
||||
|
||||
json_data = cur.fetchall()[0][0]
|
||||
|
||||
with open(os.path.join(outdir, "admin_messages.json"), "w", encoding="utf-8") as f:
|
||||
f.write(json_data)
|
||||
|
||||
|
||||
def dump_admin_watchlists(cur: "psycopg2.cursor", user_id: str, outdir: str):
|
||||
print("Dumping admin_watchlists...")
|
||||
|
||||
cur.execute("""
|
||||
SELECT
|
||||
COALESCE(json_agg(to_json(data)), '[]') #>> '{}'
|
||||
FROM (
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
admin_watchlists
|
||||
WHERE
|
||||
player_user_id = %s
|
||||
) as data
|
||||
""", (user_id,))
|
||||
|
||||
json_data = cur.fetchall()[0][0]
|
||||
|
||||
with open(os.path.join(outdir, "admin_watchlists.json"), "w", encoding="utf-8") as f:
|
||||
f.write(json_data)
|
||||
|
||||
|
||||
main()
|
||||
|
||||
# "I'm surprised you managed to write this entire Python file without spamming the word 'sus' everywhere." - Remie
|
||||
|
||||
@@ -12,7 +12,7 @@ import os
|
||||
import psycopg2
|
||||
from uuid import UUID
|
||||
|
||||
LATEST_DB_MIGRATION = "20230402214647_BanAutoDelete"
|
||||
LATEST_DB_MIGRATION = "20230725193102_AdminNotesImprovementsForeignKeys"
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
Reference in New Issue
Block a user