mirror of
https://github.com/GNS3/gns3-server
synced 2025-01-13 01:20:58 +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:
|
if not user_group:
|
||||||
raise ControllerNotFoundError(f"User group '{user_group_id}' not found")
|
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")
|
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)
|
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:
|
if not user_group:
|
||||||
raise ControllerNotFoundError(f"User group '{user_group_id}' not found")
|
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")
|
raise ControllerForbiddenError(f"Built-in user group '{user_group_id}' cannot be deleted")
|
||||||
|
|
||||||
success = await users_repo.delete_user_group(user_group_id)
|
success = await users_repo.delete_user_group(user_group_id)
|
||||||
|
@ -95,7 +95,7 @@ async def update_role(
|
|||||||
if not role:
|
if not role:
|
||||||
raise ControllerNotFoundError(f"Role '{role_id}' not found")
|
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")
|
raise ControllerForbiddenError(f"Built-in role '{role_id}' cannot be updated")
|
||||||
|
|
||||||
return await rbac_repo.update_role(role_id, role_update)
|
return await rbac_repo.update_role(role_id, role_update)
|
||||||
@ -114,7 +114,7 @@ async def delete_role(
|
|||||||
if not role:
|
if not role:
|
||||||
raise ControllerNotFoundError(f"Role '{role_id}' not found")
|
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")
|
raise ControllerForbiddenError(f"Built-in role '{role_id}' cannot be deleted")
|
||||||
|
|
||||||
success = await rbac_repo.delete_role(role_id)
|
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)
|
role_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||||
name = Column(String)
|
name = Column(String)
|
||||||
description = 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")
|
permissions = relationship("Permission", secondary=permission_role_link, back_populates="roles")
|
||||||
groups = relationship("UserGroup", secondary=role_group_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):
|
def create_default_roles(target, connection, **kw):
|
||||||
|
|
||||||
default_roles = [
|
default_roles = [
|
||||||
{"name": "Administrator", "description": "Administrator role", "builtin": True},
|
{"name": "Administrator", "description": "Administrator role", "is_builtin": True},
|
||||||
{"name": "User", "description": "User role", "builtin": True},
|
{"name": "User", "description": "User role", "is_builtin": True},
|
||||||
]
|
]
|
||||||
|
|
||||||
stmt = target.insert().values(default_roles)
|
stmt = target.insert().values(default_roles)
|
||||||
|
@ -75,7 +75,7 @@ class UserGroup(BaseTable):
|
|||||||
|
|
||||||
user_group_id = Column(GUID, primary_key=True, default=generate_uuid)
|
user_group_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||||
name = Column(String, unique=True, index=True)
|
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")
|
users = relationship("User", secondary=user_group_link, back_populates="groups")
|
||||||
roles = relationship("Role", secondary=role_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):
|
def create_default_user_groups(target, connection, **kw):
|
||||||
|
|
||||||
default_groups = [
|
default_groups = [
|
||||||
{"name": "Administrators", "builtin": True},
|
{"name": "Administrators", "is_builtin": True},
|
||||||
{"name": "Users", "builtin": True}
|
{"name": "Users", "is_builtin": True}
|
||||||
]
|
]
|
||||||
|
|
||||||
stmt = target.insert().values(default_groups)
|
stmt = target.insert().values(default_groups)
|
||||||
|
@ -114,7 +114,7 @@ class RoleUpdate(RoleBase):
|
|||||||
class Role(DateTimeModelMixin, RoleBase):
|
class Role(DateTimeModelMixin, RoleBase):
|
||||||
|
|
||||||
role_id: UUID
|
role_id: UUID
|
||||||
builtin: bool
|
is_builtin: bool
|
||||||
permissions: List[Permission]
|
permissions: List[Permission]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
@ -85,7 +85,7 @@ class UserGroupUpdate(UserGroupBase):
|
|||||||
class UserGroup(DateTimeModelMixin, UserGroupBase):
|
class UserGroup(DateTimeModelMixin, UserGroupBase):
|
||||||
|
|
||||||
user_group_id: UUID
|
user_group_id: UUID
|
||||||
builtin: bool
|
is_builtin: bool
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
|
@ -208,7 +208,7 @@ class TestGroupRolesRoutes:
|
|||||||
roles = await user_repo.get_user_group_roles(group_in_db.user_group_id)
|
roles = await user_repo.get_user_group_roles(group_in_db.user_group_id)
|
||||||
assert len(roles) == 2 # 1 default role + 1 custom role
|
assert len(roles) == 2 # 1 default role + 1 custom role
|
||||||
for role in roles:
|
for role in roles:
|
||||||
if not role.builtin:
|
if not role.is_builtin:
|
||||||
assert role.name == test_role.name
|
assert role.name == test_role.name
|
||||||
|
|
||||||
async def test_get_user_group_roles(
|
async def test_get_user_group_roles(
|
||||||
|
Loading…
Reference in New Issue
Block a user