Skip to content

Commit 8beaba2

Browse files
committed
nit(rbac): rename GroupAssignment to GroupRoleAssignment
1 parent 4bbdaf1 commit 8beaba2

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

alembic/versions/55c5d2499eee_add_rbac_tables.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def upgrade() -> None:
158158
)
159159
op.create_index(op.f("ix_scope_source"), "scope", ["source"], unique=False)
160160
op.create_table(
161-
"group_assignment",
161+
"group_role_assignment",
162162
sa.Column("id", sa.UUID(), nullable=False),
163163
sa.Column("organization_id", sa.UUID(), nullable=False),
164164
sa.Column("group_id", sa.UUID(), nullable=False),
@@ -174,50 +174,50 @@ def upgrade() -> None:
174174
sa.ForeignKeyConstraint(
175175
["assigned_by"],
176176
["user.id"],
177-
name=op.f("fk_group_assignment_assigned_by_user"),
177+
name=op.f("fk_group_role_assignment_assigned_by_user"),
178178
ondelete="SET NULL",
179179
),
180180
sa.ForeignKeyConstraint(
181181
["group_id"],
182182
["group.id"],
183-
name=op.f("fk_group_assignment_group_id_group"),
183+
name=op.f("fk_group_role_assignment_group_id_group"),
184184
ondelete="CASCADE",
185185
),
186186
sa.ForeignKeyConstraint(
187187
["organization_id"],
188188
["organization.id"],
189-
name=op.f("fk_group_assignment_organization_id_organization"),
189+
name=op.f("fk_group_role_assignment_organization_id_organization"),
190190
ondelete="CASCADE",
191191
),
192192
sa.ForeignKeyConstraint(
193193
["role_id"],
194194
["role.id"],
195-
name=op.f("fk_group_assignment_role_id_role"),
195+
name=op.f("fk_group_role_assignment_role_id_role"),
196196
ondelete="RESTRICT",
197197
),
198198
sa.ForeignKeyConstraint(
199199
["workspace_id"],
200200
["workspace.id"],
201-
name=op.f("fk_group_assignment_workspace_id_workspace"),
201+
name=op.f("fk_group_role_assignment_workspace_id_workspace"),
202202
ondelete="CASCADE",
203203
),
204-
sa.PrimaryKeyConstraint("id", name=op.f("pk_group_assignment")),
204+
sa.PrimaryKeyConstraint("id", name=op.f("pk_group_role_assignment")),
205205
sa.UniqueConstraint(
206206
"group_id",
207207
"workspace_id",
208-
name=op.f("uq_group_assignment_group_id_workspace_id"),
208+
name=op.f("uq_group_role_assignment_group_id_workspace_id"),
209209
),
210210
)
211211
op.create_index(
212-
"ix_group_assignment_group_org_unique",
213-
"group_assignment",
212+
"ix_group_role_assignment_group_org_unique",
213+
"group_role_assignment",
214214
["group_id"],
215215
unique=True,
216216
postgresql_where=sa.text("workspace_id IS NULL"),
217217
)
218218
op.create_index(
219-
op.f("ix_group_assignment_role_id"),
220-
"group_assignment",
219+
op.f("ix_group_role_assignment_role_id"),
220+
"group_role_assignment",
221221
["role_id"],
222222
unique=False,
223223
)
@@ -377,13 +377,15 @@ def downgrade() -> None:
377377
op.drop_table("user_role_assignment")
378378
op.drop_table("role_scope")
379379
op.drop_table("group_member")
380-
op.drop_index(op.f("ix_group_assignment_role_id"), table_name="group_assignment")
381380
op.drop_index(
382-
"ix_group_assignment_group_org_unique",
383-
table_name="group_assignment",
381+
op.f("ix_group_role_assignment_role_id"), table_name="group_role_assignment"
382+
)
383+
op.drop_index(
384+
"ix_group_role_assignment_group_org_unique",
385+
table_name="group_role_assignment",
384386
postgresql_where=sa.text("workspace_id IS NULL"),
385387
)
386-
op.drop_table("group_assignment")
388+
op.drop_table("group_role_assignment")
387389
op.drop_index(op.f("ix_scope_source"), table_name="scope")
388390
op.drop_index(op.f("ix_scope_organization_id"), table_name="scope")
389391
op.drop_index(

tracecat/db/models.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3212,8 +3212,8 @@ class Role(Base, TimestampMixin):
32123212
back_populates="roles",
32133213
lazy="select",
32143214
)
3215-
group_assignments: Mapped[list[GroupAssignment]] = relationship(
3216-
"GroupAssignment",
3215+
group_role_assignments: Mapped[list[GroupRoleAssignment]] = relationship(
3216+
"GroupRoleAssignment",
32173217
back_populates="role",
32183218
lazy="select",
32193219
)
@@ -3241,7 +3241,7 @@ class Group(Base, TimestampMixin):
32413241
"""Groups for organizing users within an organization.
32423242
32433243
Groups are assigned roles at either:
3244-
- Organization level (workspace_id=NULL in GroupAssignment): Scopes apply org-wide
3244+
- Organization level (workspace_id=NULL in GroupRoleAssignment): Scopes apply org-wide
32453245
- Workspace level: Scopes apply only within that workspace
32463246
32473247
Users inherit all scopes from groups they belong to.
@@ -3266,8 +3266,8 @@ class Group(Base, TimestampMixin):
32663266
secondary="group_member",
32673267
lazy="select",
32683268
)
3269-
assignments: Mapped[list[GroupAssignment]] = relationship(
3270-
"GroupAssignment",
3269+
role_assignments: Mapped[list[GroupRoleAssignment]] = relationship(
3270+
"GroupRoleAssignment",
32713271
back_populates="group",
32723272
cascade="all, delete",
32733273
lazy="select",
@@ -3290,7 +3290,7 @@ class GroupMember(Base):
32903290
)
32913291

32923292

3293-
class GroupAssignment(Base):
3293+
class GroupRoleAssignment(Base):
32943294
"""Assigns a role to a group at either org or workspace level.
32953295
32963296
- workspace_id=NULL: Org-wide assignment - scopes apply to all workspaces
@@ -3299,12 +3299,12 @@ class GroupAssignment(Base):
32993299
Each group can have at most one assignment per workspace (or one org-wide assignment).
33003300
"""
33013301

3302-
__tablename__ = "group_assignment"
3302+
__tablename__ = "group_role_assignment"
33033303
__table_args__ = (
33043304
UniqueConstraint("group_id", "workspace_id"),
33053305
# Partial unique index for org-wide assignments (workspace_id IS NULL)
33063306
Index(
3307-
"ix_group_assignment_group_org_unique",
3307+
"ix_group_role_assignment_group_org_unique",
33083308
"group_id",
33093309
unique=True,
33103310
postgresql_where=text("workspace_id IS NULL"),
@@ -3333,9 +3333,9 @@ class GroupAssignment(Base):
33333333

33343334
# Relationships
33353335
organization: Mapped[Organization] = relationship("Organization")
3336-
group: Mapped[Group] = relationship("Group", back_populates="assignments")
3336+
group: Mapped[Group] = relationship("Group", back_populates="role_assignments")
33373337
workspace: Mapped[Workspace | None] = relationship("Workspace")
3338-
role: Mapped[Role] = relationship("Role", back_populates="group_assignments")
3338+
role: Mapped[Role] = relationship("Role", back_populates="group_role_assignments")
33393339

33403340

33413341
class UserRoleAssignment(Base):

0 commit comments

Comments
 (0)