mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Change RBAC field names from builtin to is_builtin
This commit is contained in:
parent
4dd3bc6a98
commit
4e33d29af8
@ -99,7 +99,7 @@ async def update_user_group(
|
||||
if not user_group:
|
||||
raise ControllerNotFoundError(f"User group '{user_group_id}' not found")
|
||||
|
||||
if user_group.builtin:
|
||||
if user_group.is_builtin:
|
||||
raise ControllerForbiddenError(f"Built-in user group '{user_group_id}' cannot be updated")
|
||||
|
||||
return await users_repo.update_user_group(user_group_id, user_group_update)
|
||||
@ -121,7 +121,7 @@ async def delete_user_group(
|
||||
if not user_group:
|
||||
raise ControllerNotFoundError(f"User group '{user_group_id}' not found")
|
||||
|
||||
if user_group.builtin:
|
||||
if user_group.is_builtin:
|
||||
raise ControllerForbiddenError(f"Built-in user group '{user_group_id}' cannot be deleted")
|
||||
|
||||
success = await users_repo.delete_user_group(user_group_id)
|
||||
|
@ -95,7 +95,7 @@ async def update_role(
|
||||
if not role:
|
||||
raise ControllerNotFoundError(f"Role '{role_id}' not found")
|
||||
|
||||
if role.builtin:
|
||||
if role.is_builtin:
|
||||
raise ControllerForbiddenError(f"Built-in role '{role_id}' cannot be updated")
|
||||
|
||||
return await rbac_repo.update_role(role_id, role_update)
|
||||
@ -114,7 +114,7 @@ async def delete_role(
|
||||
if not role:
|
||||
raise ControllerNotFoundError(f"Role '{role_id}' not found")
|
||||
|
||||
if role.builtin:
|
||||
if role.is_builtin:
|
||||
raise ControllerForbiddenError(f"Built-in role '{role_id}' cannot be deleted")
|
||||
|
||||
success = await rbac_repo.delete_role(role_id)
|
||||
|
@ -40,7 +40,7 @@ class Role(BaseTable):
|
||||
role_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
name = Column(String)
|
||||
description = Column(String)
|
||||
builtin = Column(Boolean, default=False)
|
||||
is_builtin = Column(Boolean, default=False)
|
||||
permissions = relationship("Permission", secondary=permission_role_link, back_populates="roles")
|
||||
groups = relationship("UserGroup", secondary=role_group_link, back_populates="roles")
|
||||
|
||||
@ -49,8 +49,8 @@ class Role(BaseTable):
|
||||
def create_default_roles(target, connection, **kw):
|
||||
|
||||
default_roles = [
|
||||
{"name": "Administrator", "description": "Administrator role", "builtin": True},
|
||||
{"name": "User", "description": "User role", "builtin": True},
|
||||
{"name": "Administrator", "description": "Administrator role", "is_builtin": True},
|
||||
{"name": "User", "description": "User role", "is_builtin": True},
|
||||
]
|
||||
|
||||
stmt = target.insert().values(default_roles)
|
||||
|
@ -75,7 +75,7 @@ class UserGroup(BaseTable):
|
||||
|
||||
user_group_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
name = Column(String, unique=True, index=True)
|
||||
builtin = Column(Boolean, default=False)
|
||||
is_builtin = Column(Boolean, default=False)
|
||||
users = relationship("User", secondary=user_group_link, back_populates="groups")
|
||||
roles = relationship("Role", secondary=role_group_link, back_populates="groups")
|
||||
|
||||
@ -84,8 +84,8 @@ class UserGroup(BaseTable):
|
||||
def create_default_user_groups(target, connection, **kw):
|
||||
|
||||
default_groups = [
|
||||
{"name": "Administrators", "builtin": True},
|
||||
{"name": "Users", "builtin": True}
|
||||
{"name": "Administrators", "is_builtin": True},
|
||||
{"name": "Users", "is_builtin": True}
|
||||
]
|
||||
|
||||
stmt = target.insert().values(default_groups)
|
||||
|
@ -114,7 +114,7 @@ class RoleUpdate(RoleBase):
|
||||
class Role(DateTimeModelMixin, RoleBase):
|
||||
|
||||
role_id: UUID
|
||||
builtin: bool
|
||||
is_builtin: bool
|
||||
permissions: List[Permission]
|
||||
|
||||
class Config:
|
||||
|
@ -85,7 +85,7 @@ class UserGroupUpdate(UserGroupBase):
|
||||
class UserGroup(DateTimeModelMixin, UserGroupBase):
|
||||
|
||||
user_group_id: UUID
|
||||
builtin: bool
|
||||
is_builtin: bool
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
@ -208,7 +208,7 @@ class TestGroupRolesRoutes:
|
||||
roles = await user_repo.get_user_group_roles(group_in_db.user_group_id)
|
||||
assert len(roles) == 2 # 1 default role + 1 custom role
|
||||
for role in roles:
|
||||
if not role.builtin:
|
||||
if not role.is_builtin:
|
||||
assert role.name == test_role.name
|
||||
|
||||
async def test_get_user_group_roles(
|
||||
|
Loading…
Reference in New Issue
Block a user