diff --git a/apps/volunteer/admin/volunteer.py b/apps/volunteer/admin/volunteer.py index 398a0eba7..ec2b18201 100644 --- a/apps/volunteer/admin/volunteer.py +++ b/apps/volunteer/admin/volunteer.py @@ -39,6 +39,7 @@ class VolunteerUserModelView(VolunteerModelView): "volunteer_phone", "interested_roles", "trained_roles", + "admined_roles", "over_18", "allow_comms_during_event", "banned", diff --git a/migrations/versions/1267f408bc10_volunter_role_admin_versions.py b/migrations/versions/1267f408bc10_volunter_role_admin_versions.py new file mode 100644 index 000000000..ce8087bb5 --- /dev/null +++ b/migrations/versions/1267f408bc10_volunter_role_admin_versions.py @@ -0,0 +1,36 @@ +"""empty message + +Revision ID: 1267f408bc10 +Revises: b9db98f438aa +Create Date: 2024-05-15 21:17:04.246271 + +""" + +# revision identifiers, used by Alembic. +revision = '1267f408bc10' +down_revision = 'b9db98f438aa' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('volunteer_role_admin_version', + sa.Column('user_id', sa.Integer(), autoincrement=False, nullable=False), + sa.Column('role_id', sa.Integer(), autoincrement=False, nullable=False), + sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False), + sa.Column('operation_type', sa.SmallInteger(), nullable=False), + sa.PrimaryKeyConstraint('user_id', 'role_id', 'transaction_id', name=op.f('pk_volunteer_role_admin_version')) + ) + op.create_index(op.f('ix_volunteer_role_admin_version_operation_type'), 'volunteer_role_admin_version', ['operation_type'], unique=False) + op.create_index(op.f('ix_volunteer_role_admin_version_transaction_id'), 'volunteer_role_admin_version', ['transaction_id'], unique=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_volunteer_role_admin_version_transaction_id'), table_name='volunteer_role_admin_version') + op.drop_index(op.f('ix_volunteer_role_admin_version_operation_type'), table_name='volunteer_role_admin_version') + op.drop_table('volunteer_role_admin_version') + # ### end Alembic commands ### diff --git a/models/volunteer/role.py b/models/volunteer/role.py index c9b8c3372..2b902aaf0 100644 --- a/models/volunteer/role.py +++ b/models/volunteer/role.py @@ -61,6 +61,7 @@ class RolePermission(BaseModel): class RoleAdmin(BaseModel): __tablename__ = "volunteer_role_admin" + __versioned__: dict = {} user_id = db.Column( db.Integer, db.ForeignKey("user.id"), nullable=False, primary_key=True ) diff --git a/models/volunteer/volunteer.py b/models/volunteer/volunteer.py index 07d94fbd0..47666bee1 100644 --- a/models/volunteer/volunteer.py +++ b/models/volunteer/volunteer.py @@ -6,7 +6,7 @@ from .. import BaseModel from . import ShiftEntry - +from . import RoleAdmin # This effectively records the roles that a volunteer is interested in VolunteerRoleInterest = db.Table( @@ -25,7 +25,6 @@ db.Column("role_id", db.Integer, db.ForeignKey("volunteer_role.id"), primary_key=True), ) - class Volunteer(BaseModel, UserMixin): __table_name__ = "volunteer" __versioned__: dict = {} @@ -53,7 +52,15 @@ class Volunteer(BaseModel, UserMixin): secondary=VolunteerRoleTraining, lazy="dynamic", ) - + admined_roles = db.relationship( + "Role", + backref="role_admins", + secondary=RoleAdmin.__table__, + primaryjoin="RoleAdmin.user_id==Volunteer.user_id", + secondaryjoin="RoleAdmin.role_id==Role.id", + lazy="dynamic" + ) + def __repr__(self): return f""