Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add properties field in data source schema for model computed properties #2129

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions api/tacticalrmm/ee/reporting/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,36 @@
For details, see: https://license.tacticalrmm.com/ee
"""

import inspect


def get_property_fields(model_class):
"""
Get all @property fields of a Django model.
"""

model_name = model_class.__name__
# make sure model in is reporting models
if model_name not in [model for model, _ in REPORTING_MODELS]:
return []

# excluded properties
excluded = ["pk", "fields_that_trigger_task_update_on_agent"]

properties = [
name
for name, _ in inspect.getmembers(
model_class, lambda a: isinstance(a, property)
)
if name not in excluded
]
return properties


# (Model, app)
REPORTING_MODELS = (
("Agent", "agents"),
("Note", "agents"),
("AgentCustomField", "agents"),
("AgentHistory", "agents"),
("Alert", "alerts"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from django.conf import settings as djangosettings
from django.core.management.base import BaseCommand

from ...constants import REPORTING_MODELS
from ee.reporting.constants import (
REPORTING_MODELS,
get_property_fields,
)


if TYPE_CHECKING:
from django.db.models import Model
Expand Down Expand Up @@ -127,6 +131,14 @@ def generate_schema() -> None:
},
},
"order_by": {"type": "string", "enum": order_by},
"properties": {
"type": "array",
"items": {
"type": "string",
"minimum": 1,
"enum": get_property_fields(Model),
},
},
},
}
)
Expand Down
Loading
Loading