From 574c348bc10d988f039fdee860ff456465f9b066 Mon Sep 17 00:00:00 2001 From: Owen Date: Wed, 18 Jan 2023 10:25:34 +0000 Subject: [PATCH] feat(portal/pool): adds rdr domain field to the pool table --- app/models/base.py | 1 + app/portal/pool.py | 7 +++- .../09b5f4bd75b8_adding_redirector_domain.py | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/09b5f4bd75b8_adding_redirector_domain.py diff --git a/app/models/base.py b/app/models/base.py index d5f8b49..a504204 100644 --- a/app/models/base.py +++ b/app/models/base.py @@ -26,6 +26,7 @@ class Group(AbstractConfiguration): class Pool(AbstractConfiguration): pool_name = db.Column(db.String(80), unique=True, nullable=False) api_key = db.Column(db.String(80), nullable=False) + redirector_domain = db.Column(db.String(128), nullable=True) @classmethod def csv_header(cls) -> List[str]: diff --git a/app/portal/pool.py b/app/portal/pool.py index a0c9207..a5c5347 100644 --- a/app/portal/pool.py +++ b/app/portal/pool.py @@ -18,11 +18,13 @@ bp = Blueprint("pool", __name__) class NewPoolForm(FlaskForm): # type: ignore[misc] group_name = StringField("Short Name", validators=[DataRequired()]) description = StringField("Description", validators=[DataRequired()]) + redirector_domain = StringField("Redirector Domain") submit = SubmitField('Save Changes', render_kw={"class": "btn btn-success"}) class EditPoolForm(FlaskForm): # type: ignore[misc] description = StringField("Description", validators=[DataRequired()]) + redirector_domain = StringField("Redirector Domain") api_key = StringField("API Key", description=("Any change to this field (e.g. clearing it) will result in the " "API key being regenerated.")) submit = SubmitField('Save Changes', render_kw={"class": "btn btn-success"}) @@ -51,6 +53,7 @@ def pool_new() -> ResponseReturnValue: pool = Pool() pool.pool_name = form.group_name.data pool.description = form.description.data + pool.redirector_domain = form.redirector_domain.data if form.redirector_domain.data != "" else None pool.api_key = secrets.token_urlsafe(nbytes=32) pool.created = datetime.utcnow() pool.updated = datetime.utcnow() @@ -75,9 +78,11 @@ def pool_edit(pool_id: int) -> ResponseReturnValue: message="The requested pool could not be found."), status=404) form = EditPoolForm(description=pool.description, - api_key=pool.api_key) + api_key=pool.api_key, + redirector_domain=pool.redirector_domain) if form.validate_on_submit(): pool.description = form.description.data + pool.redirector_domain = form.redirector_domain.data if form.redirector_domain.data != "" else None if form.api_key.data != pool.api_key: pool.api_key = secrets.token_urlsafe(nbytes=32) form.api_key.data = pool.api_key diff --git a/migrations/versions/09b5f4bd75b8_adding_redirector_domain.py b/migrations/versions/09b5f4bd75b8_adding_redirector_domain.py new file mode 100644 index 0000000..9bf173f --- /dev/null +++ b/migrations/versions/09b5f4bd75b8_adding_redirector_domain.py @@ -0,0 +1,32 @@ +"""Adding redirector domain + +Revision ID: 09b5f4bd75b8 +Revises: a08ce5e7246a +Create Date: 2023-01-17 10:48:59.742946 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '09b5f4bd75b8' +down_revision = 'a08ce5e7246a' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('pool', schema=None) as batch_op: + batch_op.add_column(sa.Column('redirector_domain', sa.String(length=128), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('pool', schema=None) as batch_op: + batch_op.drop_column('redirector_domain') + + # ### end Alembic commands ###