mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
refactor: ruff autofixes
This commit is contained in:
455 files changed
+12322
-14762
No files matched your search
@@ -26,7 +26,6 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ACE(BaseTable):
|
||||
|
||||
__tablename__ = "acl"
|
||||
|
||||
ace_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -34,11 +33,11 @@ class ACE(BaseTable):
|
||||
path = Column(String)
|
||||
propagate = Column(Boolean, default=True)
|
||||
allowed = Column(Boolean, default=True)
|
||||
user_id = Column(GUID, ForeignKey('users.user_id', ondelete="CASCADE"))
|
||||
user_id = Column(GUID, ForeignKey("users.user_id", ondelete="CASCADE"))
|
||||
user = relationship("User", back_populates="acl_entries")
|
||||
group_id = Column(GUID, ForeignKey('user_groups.user_group_id', ondelete="CASCADE"))
|
||||
group_id = Column(GUID, ForeignKey("user_groups.user_group_id", ondelete="CASCADE"))
|
||||
group = relationship("UserGroup", back_populates="acl_entries")
|
||||
role_id = Column(GUID, ForeignKey('roles.role_id', ondelete="CASCADE"))
|
||||
role_id = Column(GUID, ForeignKey("roles.role_id", ondelete="CASCADE"))
|
||||
role = relationship("Role", back_populates="acl_entries")
|
||||
|
||||
__table_args__ = (
|
||||
|
||||
@@ -20,7 +20,6 @@ from .base import BaseTable, GUID
|
||||
|
||||
|
||||
class ApiKey(BaseTable):
|
||||
|
||||
__tablename__ = "api_keys"
|
||||
|
||||
api_key_id = Column(GUID, primary_key=True)
|
||||
|
||||
@@ -84,7 +84,7 @@ class ListType(TypeDecorator):
|
||||
impl = VARCHAR
|
||||
cache_ok = True
|
||||
|
||||
def __init__(self, separator=',', *args, **kwargs):
|
||||
def __init__(self, separator=",", *args, **kwargs):
|
||||
|
||||
self._separator = separator
|
||||
super().__init__(*args, **kwargs)
|
||||
@@ -92,8 +92,7 @@ class ListType(TypeDecorator):
|
||||
def process_bind_param(self, value, dialect):
|
||||
if value is not None:
|
||||
if any(self._separator in str(item) for item in value):
|
||||
raise ListException(f"List values cannot contain '{self._separator}'"
|
||||
f"Please use a different separator.")
|
||||
raise ListException(f"List values cannot contain '{self._separator}'Please use a different separator.")
|
||||
return self._separator.join(map(str, value))
|
||||
|
||||
def process_result_value(self, value, dialect):
|
||||
@@ -104,7 +103,6 @@ class ListType(TypeDecorator):
|
||||
|
||||
|
||||
class BaseTable(Base):
|
||||
|
||||
__abstract__ = True
|
||||
|
||||
created_at = Column(DateTime, server_default=func.current_timestamp())
|
||||
|
||||
@@ -21,7 +21,6 @@ from .base import BaseTable, GUID
|
||||
|
||||
|
||||
class Compute(BaseTable):
|
||||
|
||||
__tablename__ = "computes"
|
||||
|
||||
compute_id = Column(GUID, primary_key=True)
|
||||
|
||||
@@ -25,12 +25,11 @@ image_template_map = Table(
|
||||
"image_template_map",
|
||||
Base.metadata,
|
||||
Column("image_id", Integer, ForeignKey("images.image_id", ondelete="CASCADE")),
|
||||
Column("template_id", GUID, ForeignKey("templates.template_id", ondelete="CASCADE"))
|
||||
Column("template_id", GUID, ForeignKey("templates.template_id", ondelete="CASCADE")),
|
||||
)
|
||||
|
||||
|
||||
class Image(BaseTable):
|
||||
|
||||
__tablename__ = "images"
|
||||
|
||||
image_id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
|
||||
@@ -50,21 +50,28 @@ class LLMModelConfig(BaseTable):
|
||||
__table_args__ = (
|
||||
# Ensure a config belongs to either a user or a group, not both
|
||||
CheckConstraint(
|
||||
"(user_id IS NOT NULL AND group_id IS NULL) OR "
|
||||
"(user_id IS NULL AND group_id IS NOT NULL)",
|
||||
name="single_owner_check"
|
||||
"(user_id IS NOT NULL AND group_id IS NULL) OR (user_id IS NULL AND group_id IS NOT NULL)",
|
||||
name="single_owner_check",
|
||||
),
|
||||
# Validate model_type values
|
||||
CheckConstraint(
|
||||
"model_type IN ('text', 'vision', 'stt', 'tts', 'multimodal', 'embedding', 'reranking', 'other')",
|
||||
name="valid_model_type_check"
|
||||
name="valid_model_type_check",
|
||||
),
|
||||
# Each user can have at most one default config (partial unique index, PostgreSQL only)
|
||||
Index("unique_user_default", "user_id", unique=True,
|
||||
postgresql_where=text("is_default = TRUE AND user_id IS NOT NULL")),
|
||||
Index(
|
||||
"unique_user_default",
|
||||
"user_id",
|
||||
unique=True,
|
||||
postgresql_where=text("is_default = TRUE AND user_id IS NOT NULL"),
|
||||
),
|
||||
# Each group can have at most one default config (partial unique index, PostgreSQL only)
|
||||
Index("unique_group_default", "group_id", unique=True,
|
||||
postgresql_where=text("is_default = TRUE AND group_id IS NOT NULL")),
|
||||
Index(
|
||||
"unique_group_default",
|
||||
"group_id",
|
||||
unique=True,
|
||||
postgresql_where=text("is_default = TRUE AND group_id IS NOT NULL"),
|
||||
),
|
||||
# Indexes for efficient queries
|
||||
Index("idx_llm_model_configs_user_id", "user_id"),
|
||||
Index("idx_llm_model_configs_group_id", "group_id"),
|
||||
|
||||
@@ -29,12 +29,11 @@ resource_pool_map = Table(
|
||||
"resource_pool_map",
|
||||
Base.metadata,
|
||||
Column("resource_id", GUID, ForeignKey("resources.resource_id", ondelete="CASCADE")),
|
||||
Column("resource_pool_id", GUID, ForeignKey("resource_pools.resource_pool_id", ondelete="CASCADE"))
|
||||
Column("resource_pool_id", GUID, ForeignKey("resource_pools.resource_pool_id", ondelete="CASCADE")),
|
||||
)
|
||||
|
||||
|
||||
class Resource(BaseTable):
|
||||
|
||||
__tablename__ = "resources"
|
||||
|
||||
resource_id = Column(GUID, primary_key=True)
|
||||
@@ -44,7 +43,6 @@ class Resource(BaseTable):
|
||||
|
||||
|
||||
class ResourcePool(BaseTable):
|
||||
|
||||
__tablename__ = "resource_pools"
|
||||
|
||||
resource_pool_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
|
||||
@@ -29,12 +29,11 @@ privilege_role_map = Table(
|
||||
"privilege_role_map",
|
||||
Base.metadata,
|
||||
Column("privilege_id", GUID, ForeignKey("privileges.privilege_id", ondelete="CASCADE")),
|
||||
Column("role_id", GUID, ForeignKey("roles.role_id", ondelete="CASCADE"))
|
||||
Column("role_id", GUID, ForeignKey("roles.role_id", ondelete="CASCADE")),
|
||||
)
|
||||
|
||||
|
||||
class Privilege(BaseTable):
|
||||
|
||||
__tablename__ = "privileges"
|
||||
|
||||
privilege_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -43,210 +42,60 @@ class Privilege(BaseTable):
|
||||
roles = relationship("Role", secondary=privilege_role_map, back_populates="privileges")
|
||||
|
||||
|
||||
@event.listens_for(Privilege.__table__, 'after_create')
|
||||
@event.listens_for(Privilege.__table__, "after_create")
|
||||
def create_default_roles(target, connection, **kw):
|
||||
|
||||
default_privileges = [
|
||||
{
|
||||
"description": "Create or delete a user",
|
||||
"name": "User.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a user",
|
||||
"name": "User.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a user",
|
||||
"name": "User.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a group",
|
||||
"name": "Group.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a group",
|
||||
"name": "Group.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a group",
|
||||
"name": "Group.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a role",
|
||||
"name": "Role.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a role",
|
||||
"name": "Role.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a role",
|
||||
"name": "Role.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete an ACE",
|
||||
"name": "ACE.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an ACE",
|
||||
"name": "ACE.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update an ACE",
|
||||
"name": "ACE.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a resource pool",
|
||||
"name": "Pool.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a resource pool",
|
||||
"name": "Pool.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a resource pool",
|
||||
"name": "Pool.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a template",
|
||||
"name": "Template.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a template",
|
||||
"name": "Template.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a template",
|
||||
"name": "Template.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a project",
|
||||
"name": "Project.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a project",
|
||||
"name": "Project.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a project",
|
||||
"name": "Project.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete project snapshots",
|
||||
"name": "Snapshot.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "Restore a snapshot",
|
||||
"name": "Snapshot.Restore"
|
||||
},
|
||||
{
|
||||
"description": "View a snapshot",
|
||||
"name": "Snapshot.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a node",
|
||||
"name": "Node.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a node",
|
||||
"name": "Node.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a node",
|
||||
"name": "Node.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Console access to a node",
|
||||
"name": "Node.Console"
|
||||
},
|
||||
{
|
||||
"description": "Power management for a node",
|
||||
"name": "Node.PowerMgmt"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a link",
|
||||
"name": "Link.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a link",
|
||||
"name": "Link.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a link",
|
||||
"name": "Link.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Capture packets on a link",
|
||||
"name": "Link.Capture"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a drawing",
|
||||
"name": "Drawing.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a drawing",
|
||||
"name": "Drawing.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update a drawing",
|
||||
"name": "Drawing.Modify"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a symbol",
|
||||
"name": "Symbol.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View a symbol",
|
||||
"name": "Symbol.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete an image",
|
||||
"name": "Image.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an image",
|
||||
"name": "Image.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete a compute",
|
||||
"name": "Compute.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "Update a compute",
|
||||
"name": "Compute.Modify"
|
||||
},
|
||||
{
|
||||
"description": "View a compute",
|
||||
"name": "Compute.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Install an appliance",
|
||||
"name": "Appliance.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an appliance",
|
||||
"name": "Appliance.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Create or delete an LLM model configuration",
|
||||
"name": "LLMConfig.Allocate"
|
||||
},
|
||||
{
|
||||
"description": "View an LLM model configuration",
|
||||
"name": "LLMConfig.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update an LLM model configuration",
|
||||
"name": "LLMConfig.Modify"
|
||||
},
|
||||
{
|
||||
"description": "View server settings",
|
||||
"name": "Server.Audit"
|
||||
},
|
||||
{
|
||||
"description": "Update server settings",
|
||||
"name": "Server.Modify"
|
||||
}
|
||||
{"description": "Create or delete a user", "name": "User.Allocate"},
|
||||
{"description": "View a user", "name": "User.Audit"},
|
||||
{"description": "Update a user", "name": "User.Modify"},
|
||||
{"description": "Create or delete a group", "name": "Group.Allocate"},
|
||||
{"description": "View a group", "name": "Group.Audit"},
|
||||
{"description": "Update a group", "name": "Group.Modify"},
|
||||
{"description": "Create or delete a role", "name": "Role.Allocate"},
|
||||
{"description": "View a role", "name": "Role.Audit"},
|
||||
{"description": "Update a role", "name": "Role.Modify"},
|
||||
{"description": "Create or delete an ACE", "name": "ACE.Allocate"},
|
||||
{"description": "View an ACE", "name": "ACE.Audit"},
|
||||
{"description": "Update an ACE", "name": "ACE.Modify"},
|
||||
{"description": "Create or delete a resource pool", "name": "Pool.Allocate"},
|
||||
{"description": "View a resource pool", "name": "Pool.Audit"},
|
||||
{"description": "Update a resource pool", "name": "Pool.Modify"},
|
||||
{"description": "Create or delete a template", "name": "Template.Allocate"},
|
||||
{"description": "View a template", "name": "Template.Audit"},
|
||||
{"description": "Update a template", "name": "Template.Modify"},
|
||||
{"description": "Create or delete a project", "name": "Project.Allocate"},
|
||||
{"description": "View a project", "name": "Project.Audit"},
|
||||
{"description": "Update a project", "name": "Project.Modify"},
|
||||
{"description": "Create or delete project snapshots", "name": "Snapshot.Allocate"},
|
||||
{"description": "Restore a snapshot", "name": "Snapshot.Restore"},
|
||||
{"description": "View a snapshot", "name": "Snapshot.Audit"},
|
||||
{"description": "Create or delete a node", "name": "Node.Allocate"},
|
||||
{"description": "View a node", "name": "Node.Audit"},
|
||||
{"description": "Update a node", "name": "Node.Modify"},
|
||||
{"description": "Console access to a node", "name": "Node.Console"},
|
||||
{"description": "Power management for a node", "name": "Node.PowerMgmt"},
|
||||
{"description": "Create or delete a link", "name": "Link.Allocate"},
|
||||
{"description": "View a link", "name": "Link.Audit"},
|
||||
{"description": "Update a link", "name": "Link.Modify"},
|
||||
{"description": "Capture packets on a link", "name": "Link.Capture"},
|
||||
{"description": "Create or delete a drawing", "name": "Drawing.Allocate"},
|
||||
{"description": "View a drawing", "name": "Drawing.Audit"},
|
||||
{"description": "Update a drawing", "name": "Drawing.Modify"},
|
||||
{"description": "Create or delete a symbol", "name": "Symbol.Allocate"},
|
||||
{"description": "View a symbol", "name": "Symbol.Audit"},
|
||||
{"description": "Create or delete an image", "name": "Image.Allocate"},
|
||||
{"description": "View an image", "name": "Image.Audit"},
|
||||
{"description": "Create or delete a compute", "name": "Compute.Allocate"},
|
||||
{"description": "Update a compute", "name": "Compute.Modify"},
|
||||
{"description": "View a compute", "name": "Compute.Audit"},
|
||||
{"description": "Install an appliance", "name": "Appliance.Allocate"},
|
||||
{"description": "View an appliance", "name": "Appliance.Audit"},
|
||||
{"description": "Create or delete an LLM model configuration", "name": "LLMConfig.Allocate"},
|
||||
{"description": "View an LLM model configuration", "name": "LLMConfig.Audit"},
|
||||
{"description": "Update an LLM model configuration", "name": "LLMConfig.Modify"},
|
||||
{"description": "View server settings", "name": "Server.Audit"},
|
||||
{"description": "Update server settings", "name": "Server.Modify"},
|
||||
]
|
||||
|
||||
stmt = target.insert().values(default_privileges)
|
||||
@@ -258,6 +107,7 @@ def create_default_roles(target, connection, **kw):
|
||||
def add_privileges_to_role(target, connection, role, privileges):
|
||||
|
||||
from .roles import Role
|
||||
|
||||
roles_table = Role.__table__
|
||||
privileges_table = Privilege.__table__
|
||||
|
||||
@@ -272,10 +122,11 @@ def add_privileges_to_role(target, connection, role, privileges):
|
||||
connection.execute(stmt)
|
||||
|
||||
|
||||
@event.listens_for(privilege_role_map, 'after_create')
|
||||
@event.listens_for(privilege_role_map, "after_create")
|
||||
def add_privileges_to_default_roles(target, connection, **kw):
|
||||
|
||||
from .roles import Role
|
||||
|
||||
roles_table = Role.__table__
|
||||
stmt = roles_table.select().where(roles_table.c.name == "Administrator")
|
||||
result = connection.execute(stmt)
|
||||
@@ -317,7 +168,7 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"Appliance.Allocate",
|
||||
"Appliance.Audit",
|
||||
"LLMConfig.Audit",
|
||||
"LLMConfig.Modify"
|
||||
"LLMConfig.Modify",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "User", user_privileges)
|
||||
@@ -333,7 +184,7 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"Symbol.Audit",
|
||||
"Image.Audit",
|
||||
"Compute.Audit",
|
||||
"Appliance.Audit"
|
||||
"Appliance.Audit",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "Auditor", auditor_privileges)
|
||||
@@ -348,7 +199,7 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"Image.Allocate",
|
||||
"Image.Audit",
|
||||
"Appliance.Allocate",
|
||||
"Appliance.Audit"
|
||||
"Appliance.Audit",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "Template manager", template_manager_privileges)
|
||||
@@ -360,20 +211,13 @@ def add_privileges_to_default_roles(target, connection, **kw):
|
||||
"User.Modify",
|
||||
"Group.Allocate",
|
||||
"Group.Audit",
|
||||
"Group.Modify"
|
||||
"Group.Modify",
|
||||
)
|
||||
|
||||
add_privileges_to_role(target, connection, "User manager", user_manager_privileges)
|
||||
|
||||
# add required privileges to the "ACL manager" role
|
||||
acl_manager_privileges = (
|
||||
"Role.Allocate",
|
||||
"Role.Audit",
|
||||
"Role.Modify",
|
||||
"ACE.Allocate",
|
||||
"ACE.Audit",
|
||||
"ACE.Modify"
|
||||
)
|
||||
acl_manager_privileges = ("Role.Allocate", "Role.Audit", "Role.Modify", "ACE.Allocate", "ACE.Audit", "ACE.Modify")
|
||||
|
||||
add_privileges_to_role(target, connection, "ACL manager", acl_manager_privileges)
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Role(BaseTable):
|
||||
|
||||
__tablename__ = "roles"
|
||||
|
||||
role_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -38,7 +37,7 @@ class Role(BaseTable):
|
||||
acl_entries = relationship("ACE")
|
||||
|
||||
|
||||
@event.listens_for(Role.__table__, 'after_create')
|
||||
@event.listens_for(Role.__table__, "after_create")
|
||||
def create_default_roles(target, connection, **kw):
|
||||
|
||||
default_roles = [
|
||||
@@ -48,7 +47,7 @@ def create_default_roles(target, connection, **kw):
|
||||
{"name": "Template manager", "description": "Role to manage templates", "is_builtin": True},
|
||||
{"name": "User manager", "description": "Role to manage users and groups", "is_builtin": True},
|
||||
{"name": "ACL manager", "description": "Role to manage other roles and the ACL", "is_builtin": True},
|
||||
{"name": "No Access", "description": "Role with no privileges (used to forbid access)", "is_builtin": True}
|
||||
{"name": "No Access", "description": "Role with no privileges (used to forbid access)", "is_builtin": True},
|
||||
]
|
||||
|
||||
stmt = target.insert().values(default_roles)
|
||||
|
||||
@@ -24,7 +24,6 @@ from .images import image_template_map
|
||||
|
||||
|
||||
class Template(BaseTable):
|
||||
|
||||
__tablename__ = "templates"
|
||||
|
||||
template_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -49,7 +48,6 @@ class Template(BaseTable):
|
||||
|
||||
|
||||
class CloudTemplate(Template):
|
||||
|
||||
__tablename__ = "cloud_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -63,7 +61,6 @@ class CloudTemplate(Template):
|
||||
|
||||
|
||||
class DockerTemplate(Template):
|
||||
|
||||
__tablename__ = "docker_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -89,7 +86,6 @@ class DockerTemplate(Template):
|
||||
|
||||
|
||||
class DynamipsTemplate(Template):
|
||||
|
||||
__tablename__ = "dynamips_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -132,7 +128,6 @@ class DynamipsTemplate(Template):
|
||||
|
||||
|
||||
class EthernetHubTemplate(Template):
|
||||
|
||||
__tablename__ = "ethernet_hub_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -142,7 +137,6 @@ class EthernetHubTemplate(Template):
|
||||
|
||||
|
||||
class EthernetSwitchTemplate(Template):
|
||||
|
||||
__tablename__ = "ethernet_switch_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -153,7 +147,6 @@ class EthernetSwitchTemplate(Template):
|
||||
|
||||
|
||||
class IOUTemplate(Template):
|
||||
|
||||
__tablename__ = "iou_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -173,7 +166,6 @@ class IOUTemplate(Template):
|
||||
|
||||
|
||||
class QemuTemplate(Template):
|
||||
|
||||
__tablename__ = "qemu_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -220,7 +212,6 @@ class QemuTemplate(Template):
|
||||
|
||||
|
||||
class VirtualBoxTemplate(Template):
|
||||
|
||||
__tablename__ = "virtualbox_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -243,7 +234,6 @@ class VirtualBoxTemplate(Template):
|
||||
|
||||
|
||||
class VMwareTemplate(Template):
|
||||
|
||||
__tablename__ = "vmware_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
@@ -265,7 +255,6 @@ class VMwareTemplate(Template):
|
||||
|
||||
|
||||
class VPCSTemplate(Template):
|
||||
|
||||
__tablename__ = "vpcs_templates"
|
||||
|
||||
template_id = Column(GUID, ForeignKey("templates.template_id", ondelete="CASCADE"), primary_key=True)
|
||||
|
||||
@@ -31,12 +31,11 @@ user_group_map = Table(
|
||||
"user_group_map",
|
||||
Base.metadata,
|
||||
Column("user_id", GUID, ForeignKey("users.user_id", ondelete="CASCADE")),
|
||||
Column("user_group_id", GUID, ForeignKey("user_groups.user_group_id", ondelete="CASCADE"))
|
||||
Column("user_group_id", GUID, ForeignKey("user_groups.user_group_id", ondelete="CASCADE")),
|
||||
)
|
||||
|
||||
|
||||
class User(BaseTable):
|
||||
|
||||
__tablename__ = "users"
|
||||
|
||||
user_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -52,7 +51,7 @@ class User(BaseTable):
|
||||
acl_entries = relationship("ACE")
|
||||
|
||||
|
||||
@event.listens_for(User.__table__, 'after_create')
|
||||
@event.listens_for(User.__table__, "after_create")
|
||||
def create_default_super_admin(target, connection, **kw):
|
||||
|
||||
config = Config.instance().settings
|
||||
@@ -63,7 +62,7 @@ def create_default_super_admin(target, connection, **kw):
|
||||
username=default_admin_username,
|
||||
full_name="Super Administrator",
|
||||
hashed_password=hashed_password,
|
||||
is_superadmin=True
|
||||
is_superadmin=True,
|
||||
)
|
||||
connection.execute(stmt)
|
||||
connection.commit()
|
||||
@@ -71,7 +70,6 @@ def create_default_super_admin(target, connection, **kw):
|
||||
|
||||
|
||||
class UserGroup(BaseTable):
|
||||
|
||||
__tablename__ = "user_groups"
|
||||
|
||||
user_group_id = Column(GUID, primary_key=True, default=generate_uuid)
|
||||
@@ -81,13 +79,10 @@ class UserGroup(BaseTable):
|
||||
acl_entries = relationship("ACE")
|
||||
|
||||
|
||||
@event.listens_for(UserGroup.__table__, 'after_create')
|
||||
@event.listens_for(UserGroup.__table__, "after_create")
|
||||
def create_default_user_groups(target, connection, **kw):
|
||||
|
||||
default_groups = [
|
||||
{"name": "Administrators", "is_builtin": True},
|
||||
{"name": "Users", "is_builtin": True}
|
||||
]
|
||||
default_groups = [{"name": "Administrators", "is_builtin": True}, {"name": "Users", "is_builtin": True}]
|
||||
|
||||
stmt = target.insert().values(default_groups)
|
||||
connection.execute(stmt)
|
||||
|
||||
Reference in new issue
Block a user