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

Bot Tags #1147

Open
wants to merge 2 commits 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
13 changes: 12 additions & 1 deletion kairon/shared/account/data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from kairon.shared.constants import UserActivityType
from kairon.shared.data.audit.data_objects import Auditlog
from kairon.shared.data.signals import push_notification, auditlogger
from kairon.shared.data.constant import ACCESS_ROLES, ACTIVITY_STATUS
from kairon.shared.data.constant import ACCESS_ROLES, ACTIVITY_STATUS, TagType
from kairon.shared.utils import Utility


Expand Down Expand Up @@ -68,12 +68,23 @@ class BotMetaData(EmbeddedDocument):
from_template = DynamicField(default=None)


class Tagging(EmbeddedDocument):
tag = StringField()
type = StringField(choices=[TagType.ADMIN.value, TagType.USER.value], default=None)
Comment on lines +71 to +73
Copy link

Choose a reason for hiding this comment

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

The Tagging embedded document class is well-defined with a tag field as a StringField and a type field that uses the TagType enum for its choices. This design ensures that the tag type is restricted to the predefined ADMIN and USER values, enhancing data integrity. However, consider setting a required=True constraint on the tag field to ensure that every tag has a name.

- tag = StringField()
+ tag = StringField(required=True)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
class Tagging(EmbeddedDocument):
tag = StringField()
type = StringField(choices=[TagType.ADMIN.value, TagType.USER.value], default=None)
class Tagging(EmbeddedDocument):
tag = StringField(required=True)
type = StringField(choices=[TagType.ADMIN.value, TagType.USER.value], default=None)



@auditlogger.log
class Tags(Auditlog):
tags = EmbeddedDocumentField(Tagging, default=None)
Comment on lines +77 to +78
Copy link

Choose a reason for hiding this comment

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

The modification of the Tags class to include a list of Tagging embedded documents is a significant change. However, there seems to be a misunderstanding in the implementation. The tags field is defined as an EmbeddedDocumentField instead of a ListField of EmbeddedDocumentField. This needs to be corrected to accurately represent a list of tags.

- tags = EmbeddedDocumentField(Tagging, default=None)
+ tags = ListField(EmbeddedDocumentField(Tagging))

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
class Tags(Auditlog):
tags = EmbeddedDocumentField(Tagging, default=None)
class Tags(Auditlog):
tags = ListField(EmbeddedDocumentField(Tagging))



@auditlogger.log
@push_notification.apply
class Bot(Auditlog):
name = StringField(required=True)
account = LongField(required=True)
user = StringField(required=True)
tags = ListField(EmbeddedDocumentField(Tagging, default=None))
metadata = EmbeddedDocumentField(BotMetaData, default=BotMetaData())
timestamp = DateTimeField(default=datetime.utcnow)
status = BooleanField(default=True)
Expand Down
5 changes: 5 additions & 0 deletions kairon/shared/data/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ class FeatureMappings(str, Enum):
CREATE_USER = "create_user"


class TagType(str, Enum):
ADMIN = "admin"
USER = "user"


ORG_SETTINGS_MESSAGES = {
"create_user": "User creation is blocked by your OrgAdmin from SSO",
"only_sso_login": "Login with your org SSO url, Login with username/password not allowed"
Expand Down
1 change: 1 addition & 0 deletions tests/integration_test/chat_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,6 +1633,7 @@ def _mock_validate_hub_signature(*args, **kwargs):
def test_whatsapp_valid_attachment_message_request():
def _mock_validate_hub_signature(*args, **kwargs):
return True
responses.reset()
responses.add(
"POST", "https://graph.facebook.com/v13.0/12345678/messages", json={}
)
Expand Down
Loading