Compare commits

...

3 Commits

Author SHA1 Message Date
Dr. Kiji
24f24f5f8f backup plane 2024-11-21 19:29:36 +09:00
Dr. Kiji
bb100c3d0b fix: prevent non-admin users from modifying app settings 2024-11-21 19:28:59 +09:00
Dr. Kiji
9a5852d6ec feat: add is_admin property to Account model and is_admin_role method to TenantAccountRole 2024-11-21 19:28:44 +09:00
3 changed files with 23 additions and 0 deletions

View File

@@ -107,6 +107,10 @@ class Account(UserMixin, db.Model):
@property
def is_admin_or_owner(self):
return TenantAccountRole.is_privileged_role(self._current_tenant.current_role)
@property
def is_admin(self):
return TenantAccountRole.is_admin_role(self._current_tenant.current_role)
@property
def is_editor(self):
@@ -147,6 +151,10 @@ class TenantAccountRole(str, enum.Enum):
def is_privileged_role(role: str) -> bool:
return role and role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN}
@staticmethod
def is_admin_role(role: str) -> bool:
return role and role in {TenantAccountRole.ADMIN}
@staticmethod
def is_non_owner_role(role: str) -> bool:
return role and role in {

View File

@@ -75,6 +75,17 @@ class App(db.Model):
workflow_id = db.Column(StringUUID, nullable=True)
status = db.Column(db.String(255), nullable=False, server_default=db.text("'normal'::character varying"))
enable_site = db.Column(db.Boolean, nullable=False)
# to enable/disable public site URL
# _enable_site = db.Column("enable_site", db.Boolean, nullable=False, server_default=db.text("false"))
# @property
# def enable_site(self) -> Literal[False]:
# return False
# @enable_site.setter
# def enable_site(self, value: bool) -> None:
# self._enable_site = value
enable_api = db.Column(db.Boolean, nullable=False)
api_rpm = db.Column(db.Integer, nullable=False, server_default=db.text("0"))
api_rph = db.Column(db.Integer, nullable=False, server_default=db.text("0"))

View File

@@ -268,6 +268,10 @@ class AppService:
:param enable_site: enable site status
:return: App instance
"""
if not current_user.is_admin:
return app
if enable_site == app.enable_site:
return app