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

fixed PB130 PB131 validtions #4793

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
from typing import Iterable, List, Union

from demisto_sdk.commands.content_graph.objects.playbook import Playbook
from demisto_sdk.commands.content_graph.objects.trigger import Trigger
from demisto_sdk.commands.validate.validators.base_validator import (
BaseValidator,
ValidationResult,
)

ContentTypes = Union[Playbook, Trigger]
ContentTypes = Union[Playbook]


class IsSilentPlaybookValidator(BaseValidator[ContentTypes]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,28 @@ def get_types_for_err_msg(c: ContentItem) -> tuple[ContentType, ContentType]:
content_object=content_item,
)
for content_item in content_items
if not is_valid_relationship(content_item)
if not self.is_valid_relationship(content_item)
]

def is_valid_relationship(self, content_item: ContentTypes) -> bool:
"""
Validates the relationship between a content item and its associated playbook/trigger.
"""
if not content_item.is_silent:
# If the content item is not marked as silent, it's automatically valid
return True

def is_valid_relationship(content_item: ContentTypes) -> bool:
"""
Validates the relationship between a content item and its associated playbook/trigger.
"""
if not content_item.is_silent:
# If the content item is not marked as silent, it's automatically valid
return True

if content_item.content_type == ContentType.PLAYBOOK:
return any(
trigger.data.get("playbook_id") == content_item.data.get("id")
and trigger.is_silent
for trigger in content_item.pack.content_items.trigger
)
if content_item.content_type == ContentType.PLAYBOOK:
return any(
trigger.data.get("playbook_id") == content_item.data.get("id")
for trigger in self.graph.search(content_type=ContentType.TRIGGER, is_silent=True)
)

if content_item.content_type == ContentType.TRIGGER:
return any(
playbook.data.get("id") == content_item.data.get("playbook_id")
and playbook.is_silent
for playbook in content_item.pack.content_items.playbook
)
if content_item.content_type == ContentType.TRIGGER:
return any(
playbook.data.get("id") == content_item.data.get("playbook_id")
for playbook in self.graph.search(content_type=ContentType.PLAYBOOK, is_silent=True)
)

# Default case if content type is not PLAYBOOK or TRIGGER
return True
# Default case if content type is not PLAYBOOK or TRIGGER
return True
Loading