From d5d4496cd0302dff8d05296d5785564accfa592c Mon Sep 17 00:00:00 2001 From: alicia pritchett Date: Wed, 29 Sep 2021 16:53:59 -0400 Subject: [PATCH] Admin flag on category + migration + updated test --- crc/models/study.py | 3 +- crc/models/workflow.py | 2 +- example_data.py | 5 ++-- migrations/versions/5c63a89ee7b7_.py | 43 ++++++++++++++++++++++++++++ tests/study/test_study_api.py | 1 + 5 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 migrations/versions/5c63a89ee7b7_.py diff --git a/crc/models/study.py b/crc/models/study.py index cc999720..adb61680 100644 --- a/crc/models/study.py +++ b/crc/models/study.py @@ -162,13 +162,14 @@ class Category(object): self.name = model.name self.display_name = model.display_name self.display_order = model.display_order + self.admin = model.admin class CategorySchema(ma.Schema): workflows = fields.List(fields.Nested(WorkflowMetadataSchema), dump_only=True) class Meta: model = Category - additional = ["id", "name", "display_name", "display_order"] + additional = ["id", "name", "display_name", "display_order", "admin"] unknown = INCLUDE diff --git a/crc/models/workflow.py b/crc/models/workflow.py index 1c586f05..4c2611d9 100644 --- a/crc/models/workflow.py +++ b/crc/models/workflow.py @@ -16,7 +16,7 @@ class WorkflowSpecCategoryModel(db.Model): name = db.Column(db.String) display_name = db.Column(db.String) display_order = db.Column(db.Integer) - + admin = db.Column(db.Boolean) class WorkflowSpecCategoryModelSchema(SQLAlchemyAutoSchema): class Meta: diff --git a/example_data.py b/example_data.py index 1fdfc965..2b5dc14a 100644 --- a/example_data.py +++ b/example_data.py @@ -249,7 +249,8 @@ class ExampleDataLoader: id=0, name='test_category', display_name='Test Category', - display_order=0 + display_order=0, + admin=False ) db.session.add(category) db.session.commit() @@ -394,4 +395,4 @@ for k in investigators.keys(): del investigator cnt_subs = len(subs.keys()) -del investigators \ No newline at end of file +del investigators diff --git a/migrations/versions/5c63a89ee7b7_.py b/migrations/versions/5c63a89ee7b7_.py new file mode 100644 index 00000000..e16278aa --- /dev/null +++ b/migrations/versions/5c63a89ee7b7_.py @@ -0,0 +1,43 @@ +"""empty message + +Revision ID: 5c63a89ee7b7 +Revises: 9afbd55082a0 +Create Date: 2021-09-29 10:24:20.413807 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '5c63a89ee7b7' +down_revision = '9afbd55082a0' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_foreign_key(None, 'user', 'ldap_model', ['uid'], ['uid']) + op.drop_column('user', 'affiliation') + op.drop_column('user', 'email_address') + op.drop_column('user', 'eppn') + op.drop_column('user', 'title') + op.drop_column('user', 'first_name') + op.drop_column('user', 'last_name') + op.drop_column('user', 'display_name') + op.add_column('workflow_spec_category', sa.Column('admin', sa.Boolean(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('workflow_spec_category', 'admin') + op.add_column('user', sa.Column('display_name', sa.VARCHAR(), autoincrement=False, nullable=True)) + op.add_column('user', sa.Column('last_name', sa.VARCHAR(), autoincrement=False, nullable=True)) + op.add_column('user', sa.Column('first_name', sa.VARCHAR(), autoincrement=False, nullable=True)) + op.add_column('user', sa.Column('title', sa.VARCHAR(), autoincrement=False, nullable=True)) + op.add_column('user', sa.Column('eppn', sa.VARCHAR(), autoincrement=False, nullable=True)) + op.add_column('user', sa.Column('email_address', sa.VARCHAR(), autoincrement=False, nullable=True)) + op.add_column('user', sa.Column('affiliation', sa.VARCHAR(), autoincrement=False, nullable=True)) + # ### end Alembic commands ### diff --git a/tests/study/test_study_api.py b/tests/study/test_study_api.py index fc560761..3ac19731 100644 --- a/tests/study/test_study_api.py +++ b/tests/study/test_study_api.py @@ -69,6 +69,7 @@ class TestStudyApi(BaseTest): category = study.categories[0] self.assertEqual("test_category", category['name']) self.assertEqual("Test Category", category['display_name']) + self.assertEqual(False, category['admin']) self.assertEqual(1, len(category["workflows"])) workflow = category["workflows"][0] self.assertEqual("random_fact", workflow["name"])