Skip to content

Commit

Permalink
fix: remove model Ruleset and Rule (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei authored Nov 26, 2024
1 parent 13f647e commit 892af73
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 452 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.16 on 2024-11-22 21:18

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("core", "0052_remove_eventstream_url"),
]

operations = [
migrations.AlterUniqueTogether(
name="ruleset",
unique_together=None,
),
migrations.RemoveField(
model_name="ruleset",
name="rulebook",
),
migrations.DeleteModel(
name="Rule",
),
migrations.DeleteModel(
name="Ruleset",
),
]
11 changes: 1 addition & 10 deletions src/aap_eda/core/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@
from .organization import Organization
from .project import Project
from .queue import ActivationRequestQueue
from .rulebook import (
AuditAction,
AuditEvent,
AuditRule,
Rule,
Rulebook,
Ruleset,
)
from .rulebook import AuditAction, AuditEvent, AuditRule, Rulebook
from .rulebook_process import (
RulebookProcess,
RulebookProcessLog,
Expand All @@ -60,9 +53,7 @@
"JobInstance",
"Job",
"Project",
"Rule",
"Rulebook",
"Ruleset",
"User",
"AwxToken",
"Credential",
Expand Down
26 changes: 0 additions & 26 deletions src/aap_eda/core/models/rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

__all__ = (
"Rulebook",
"Ruleset",
"Rule",
"AuditRule",
)

Expand Down Expand Up @@ -62,30 +60,6 @@ def get_rulesets_data(self) -> list[dict]:
)


class Ruleset(models.Model):
class Meta:
db_table = "core_ruleset"
unique_together = ["rulebook_id", "name"]

name = models.TextField(null=False)
sources = models.JSONField(default=dict)
rulebook = models.ForeignKey(
"Rulebook", on_delete=models.CASCADE, null=True
)
created_at = models.DateTimeField(auto_now_add=True, null=False)
modified_at = models.DateTimeField(auto_now=True, null=False)


class Rule(models.Model):
class Meta:
db_table = "core_rule"
unique_together = ["ruleset", "name"]

ruleset = models.ForeignKey("Ruleset", on_delete=models.CASCADE, null=True)
name = models.TextField(null=False)
action = models.JSONField(default=dict, null=False)


class AuditRule(BaseOrgModel):
router_basename = "auditrule"

Expand Down
4 changes: 0 additions & 4 deletions src/aap_eda/services/project/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from aap_eda.core import models
from aap_eda.core.types import StrPath
from aap_eda.services.project.scm import ScmEmptyError, ScmRepository
from aap_eda.services.rulebook import insert_rulebook_related_data

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -180,7 +179,6 @@ def _import_rulebook(
rulesets=rulebook_info.raw_content,
organization=project.organization,
)
insert_rulebook_related_data(rulebook, rulebook_info.content)
return rulebook

def _sync_rulebook(
Expand All @@ -196,8 +194,6 @@ def _sync_rulebook(
return
rulebook.rulesets = rulebook_info.raw_content
rulebook.save()
rulebook.ruleset_set.clear()
insert_rulebook_related_data(rulebook, rulebook_info.content)
models.Activation.objects.filter(rulebook=rulebook).update(
rulebook_rulesets=rulebook.rulesets,
git_hash=git_hash,
Expand Down
68 changes: 0 additions & 68 deletions src/aap_eda/services/rulebook.py

This file was deleted.

4 changes: 0 additions & 4 deletions tests/integration/api/test_rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,6 @@ def test_delete_project_and_rulebooks(
default_project: models.Project,
default_activation: models.Activation,
default_rulebook: models.Rulebook,
ruleset_1: models.Ruleset,
default_rule: models.Rule,
admin_client: APIClient,
):
response = admin_client.delete(
Expand All @@ -531,5 +529,3 @@ def test_delete_project_and_rulebooks(
assert activation.rulebook is None
assert not models.Project.objects.filter(id=default_project.id).exists()
assert not models.Rulebook.objects.filter(id=default_rulebook.id).exists()
assert not models.Ruleset.objects.filter(id=ruleset_1.id).exists()
assert not models.Rule.objects.filter(id=default_rule.id).exists()
42 changes: 0 additions & 42 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,48 +387,6 @@ def source_list() -> List[dict]:
]


@pytest.fixture
def ruleset_1(
default_rulebook: models.Rulebook, source_list: List[dict]
) -> models.Ruleset:
return models.Ruleset.objects.create(
name="ruleset-1",
sources=source_list,
rulebook=default_rulebook,
)


@pytest.fixture
def ruleset_2(
default_rulebook: models.Rulebook, source_list: List[dict]
) -> models.Ruleset:
return models.Ruleset.objects.create(
name="ruleset-2",
sources=source_list,
rulebook=default_rulebook,
)


@pytest.fixture
def ruleset_3(
rulebook_with_job_template: models.Rulebook, source_list: List[dict]
) -> models.Ruleset:
return models.Ruleset.objects.create(
name="ruleset-3",
sources=source_list,
rulebook=rulebook_with_job_template,
)


@pytest.fixture
def default_rule(ruleset_1: models.Ruleset) -> models.Rule:
return models.Rule.objects.create(
name="say hello",
action={"run_playbook": {"name": "ansible.eda.hello"}},
ruleset=ruleset_1,
)


#################################################################
# Activations and Activation Instances
#################################################################
Expand Down
42 changes: 0 additions & 42 deletions tests/integration/services/data/project-01-import.json

This file was deleted.

42 changes: 0 additions & 42 deletions tests/integration/services/data/project-03-import.json

This file was deleted.

33 changes: 0 additions & 33 deletions tests/integration/services/data/project-05-import.json

This file was deleted.

Loading

0 comments on commit 892af73

Please sign in to comment.