Add name and description

This commit is contained in:
Beto Dealmeida
2025-12-17 21:52:32 -05:00
parent b66729ad08
commit 3ad694e5a9
8 changed files with 173 additions and 61 deletions

View File

@@ -63,6 +63,8 @@ class DataAccessRulesRestApi(BaseSupersetModelRestApi):
list_columns = [
"id",
"name",
"description",
"role_id",
"role.id",
"role.name",
@@ -74,19 +76,26 @@ class DataAccessRulesRestApi(BaseSupersetModelRestApi):
]
order_columns = [
"id",
"name",
"role_id",
"changed_on_delta_humanized",
]
add_columns = [
"name",
"description",
"role_id",
"rule",
]
edit_columns = [
"name",
"description",
"role_id",
"rule",
]
show_columns = [
"id",
"name",
"description",
"role_id",
"role.name",
"role.id",

View File

@@ -68,7 +68,7 @@ from __future__ import annotations
from typing import Any
from flask_appbuilder import Model
from sqlalchemy import Column, ForeignKey, Integer, Text
from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship
from superset import security_manager
@@ -87,6 +87,8 @@ class DataAccessRule(Model, AuditMixinNullable):
__tablename__ = "data_access_rules"
id = Column(Integer, primary_key=True)
name = Column(String(250), nullable=True)
description = Column(Text, nullable=True)
role_id = Column(Integer, ForeignKey("ab_role.id"), nullable=False)
rule = Column(Text, nullable=False)
@@ -97,7 +99,7 @@ class DataAccessRule(Model, AuditMixinNullable):
)
def __repr__(self) -> str:
return f"<DataAccessRule(id={self.id}, role_id={self.role_id})>"
return f"<DataAccessRule(id={self.id}, name={self.name!r}, role_id={self.role_id})>"
@property
def rule_dict(self) -> dict[str, Any]:

View File

@@ -66,6 +66,8 @@ class DataAccessRuleListSchema(Schema):
"""Schema for listing data access rules."""
id = fields.Integer(metadata={"description": "Unique ID of the rule"})
name = fields.String(metadata={"description": "Name of the rule"})
description = fields.String(metadata={"description": "Description of the rule"})
role_id = fields.Integer(metadata={"description": "ID of the associated role"})
role = fields.Nested(RoleSchema)
rule = fields.String(metadata={"description": rule_description})
@@ -80,6 +82,8 @@ class DataAccessRuleShowSchema(Schema):
"""Schema for showing a single data access rule."""
id = fields.Integer(metadata={"description": "Unique ID of the rule"})
name = fields.String(metadata={"description": "Name of the rule"})
description = fields.String(metadata={"description": "Description of the rule"})
role_id = fields.Integer(metadata={"description": "ID of the associated role"})
role = fields.Nested(RoleSchema)
rule = fields.String(metadata={"description": rule_description})
@@ -92,6 +96,16 @@ class DataAccessRuleShowSchema(Schema):
class DataAccessRulePostSchema(Schema):
"""Schema for creating a data access rule."""
name = fields.String(
metadata={"description": "Name for this rule (optional)"},
required=False,
allow_none=True,
)
description = fields.String(
metadata={"description": "Description of the rule (optional)"},
required=False,
allow_none=True,
)
role_id = fields.Integer(
metadata={"description": "ID of the role this rule applies to"},
required=True,
@@ -159,6 +173,16 @@ class DataAccessRulePostSchema(Schema):
class DataAccessRulePutSchema(Schema):
"""Schema for updating a data access rule."""
name = fields.String(
metadata={"description": "Name for this rule (optional)"},
required=False,
allow_none=True,
)
description = fields.String(
metadata={"description": "Description of the rule (optional)"},
required=False,
allow_none=True,
)
role_id = fields.Integer(
metadata={"description": "ID of the role this rule applies to"},
required=False,