Skip to content

Commit

Permalink
models: add blacklist model
Browse files Browse the repository at this point in the history
  • Loading branch information
laggron42 committed Sep 25, 2022
1 parent f470b58 commit bc00ba7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ballsdex/core/admin/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi_admin.resources import Field, Link, Model, Action
from fastapi_admin.widgets import displays, filters, inputs
from starlette.requests import Request
from ballsdex.core.models import BallInstance, User, Ball, Player, GuildConfig
from ballsdex.core.models import BallInstance, User, Ball, Player, GuildConfig, BlacklistedID
from typing import List


Expand Down Expand Up @@ -205,3 +205,12 @@ class GuildConfigResource(Model):
),
]
fields = ["guild_id", "spawn_channel", "enabled"]


@app.register
class BlacklistedIDResource(Model):
label = "Blacklisted user ID"
model = BlacklistedID
icon = "fas fa-lock"
page_title = "Blacklisted user IDs"
fields = ["discord_id"]
9 changes: 9 additions & 0 deletions ballsdex/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,12 @@ class Player(models.Model):

def __str__(self) -> str:
return str(self.discord_id)


class BlacklistedID(models.Model):
discord_id = fields.BigIntField(
description="Discord user ID", unique=True, validators=[DiscordSnowflakeValidator()]
)

def __str__(self) -> str:
return str(self.discord_id)
7 changes: 7 additions & 0 deletions migrations/models/7_20220926000044_update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- upgrade --
CREATE TABLE IF NOT EXISTS "blacklistedid" (
"discord_id" BIGSERIAL NOT NULL PRIMARY KEY
);
COMMENT ON COLUMN "blacklistedid"."discord_id" IS 'Discord user ID';
-- downgrade --
DROP TABLE IF EXISTS "blacklistedid";
6 changes: 6 additions & 0 deletions migrations/models/8_20220926000601_update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- upgrade --
ALTER TABLE "blacklistedid" RENAME COLUMN "discord_id" TO "id";
ALTER TABLE "blacklistedid" ADD "discord_id" BIGINT NOT NULL UNIQUE;
-- downgrade --
ALTER TABLE "blacklistedid" RENAME COLUMN "id" TO "discord_id";
ALTER TABLE "blacklistedid" DROP COLUMN "discord_id";

0 comments on commit bc00ba7

Please sign in to comment.