Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop old resource permissions #73

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Resource permissions simplification

Revision ID: 646fcad41144
Revises: 6bc0ee79a3ce
Create Date: 2024-01-25 06:23:58.687448

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '646fcad41144'
down_revision = '6bc0ee79a3ce'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
sa.Enum('admin', 'create', 'read', 'update', 'delete', name='resource_permissions_enum').create(op.get_bind())
op.add_column('resource_holder_permissions', sa.Column('permission', sa.Enum('admin', 'create', 'read', 'update', 'delete', name='resource_permissions_enum'), nullable=True))
op.drop_constraint('uq_resource_holder_permissions_user_id', 'resource_holder_permissions', type_='unique')

# Fulfill column
op.execute("UPDATE resource_holder_permissions SET permission = resource_permissions.permission::resource_permissions_enum FROM resource_permissions WHERE resource_permissions.id = resource_holder_permissions.permission_id")

op.create_index('uq_resource_holder_permissions_group_id_resource_id_permission', 'resource_holder_permissions', ['group_id', 'resource_id', 'permission'], unique=True, postgresql_where=sa.text('group_id IS NOT NULL'))
op.create_index('uq_resource_holder_permissions_user_id_resource_id_permission', 'resource_holder_permissions', ['user_id', 'resource_id', 'permission'], unique=True, postgresql_where=sa.text('user_id IS NOT NULL'))

op.alter_column("resource_holder_permissions", "permission", nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
return
op.drop_index('uq_resource_holder_permissions_user_id_resource_id_permission', table_name='resource_holder_permissions', postgresql_where=sa.text('user_id IS NOT NULL'))
op.drop_index('uq_resource_holder_permissions_group_id_resource_id_permission', table_name='resource_holder_permissions', postgresql_where=sa.text('group_id IS NOT NULL'))
op.create_unique_constraint('uq_resource_holder_permissions_user_id', 'resource_holder_permissions', ['user_id', 'group_id', 'resource_id', 'permission_id'])
op.drop_column('resource_holder_permissions', 'permission')
# ### end Alembic commands ###
3 changes: 3 additions & 0 deletions brood/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ async def set_user_in_group_handler(
user_type: models.Role = Form(...),
username: Optional[str] = Form(None),
email: Optional[str] = Form(None),
application_id: Optional[uuid.UUID] = Form(None),
db_session=Depends(yield_db_session_from_env),
) -> data.GroupUserResponse:
"""
Expand All @@ -1027,6 +1028,7 @@ async def set_user_in_group_handler(
- **group_id** (uuid): Group ID
- **user_type** (string): Required user permission in group
- **username** (string): User name
- **application_id** (string): Application ID
- **email** (string): User email
"""
is_token_restricted, current_user = user_authorization
Expand Down Expand Up @@ -1055,6 +1057,7 @@ async def set_user_in_group_handler(
user_type=user_type.value,
username=username,
email=email,
application_id=application_id,
)
except actions.LackOfUserSpace:
raise HTTPException(
Expand Down
Loading
Loading