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

Fixes #14829 Simple condition (without and/or) does not work in event rule #14870

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

Julio-Oliveira-Encora
Copy link
Contributor

Fixes: #14829

This change allows the addition of simple conditions in the Event Rule. Currently, it only allows to add conditions with logical operators.

netbox/extras/conditions.py Outdated Show resolved Hide resolved
netbox/extras/conditions.py Show resolved Hide resolved
netbox/extras/conditions.py Outdated Show resolved Hide resolved
netbox/extras/tests/test_event_rules.py Outdated Show resolved Hide resolved
Copy link
Contributor

This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is taken.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label May 15, 2024
@jeremystretch jeremystretch removed the pending closure Requires immediate attention to avoid being closed for inactivity label May 20, 2024
@jeremystretch
Copy link
Member

@Julio-Oliveira-Encora would you mind tackling the merge conflicts here? It should just be changes from enabling translation of the error messages.

@Julio-Oliveira-Encora
Copy link
Contributor Author

@Julio-Oliveira-Encora would you mind tackling the merge conflicts here? It should just be changes from enabling translation of the error messages.

Done!

@jeremystretch jeremystretch removed their request for review May 29, 2024 14:29
@jeremystretch
Copy link
Member

@arthanson you're free to review this & merge as you see fit.

netbox/extras/conditions.py Outdated Show resolved Hide resolved
netbox/extras/conditions.py Outdated Show resolved Hide resolved
netbox/extras/tests/test_event_rules.py Outdated Show resolved Hide resolved
ConditionSet(rule) if is_ruleset(rule) else Condition(**rule)
for rule in ruleset[self.logic]
]
if len(ruleset) == 1:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct order below - it seems like they are reversed, the and-or processing is being done if the len(ruleset) == 1 which seems like it should be in the else clause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the correct order because of the ruleset below, for example, has length = 1 and this case is deal inside the if. All other conditions must be deal in the else. Does it make sense?

{
    "or": [
        {
            "and": [
                {
                    "attr": "status.value",
                    "value": "active"
                },
                {
                    "attr": "primary_ip4",
                    "negate": true,
                    "value": null
                }
            ]
        },
        {
            "attr": "tags.slug",
            "op": "contains",
            "value": "exempt"
        }
    ]
}

self.logic = (list(ruleset.keys())[0]).lower()
if self.logic not in (AND, OR):
raise ValueError(_(
f"Invalid logic type: {self.logic} (must be 'AND' or 'OR'). Please check documentation."))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the f-string here, f strings can't be internationalized

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simple condition (without and/or) does not work in event rule
4 participants