Skip to content

Commit

Permalink
- Auditlog delete case (#1398)
Browse files Browse the repository at this point in the history
* - Auditlog delete case

* - Auditlog delete case

* - test cases fix for auditlog

---------

Co-authored-by: hghuge <[email protected]>
  • Loading branch information
hiteshghuge and hghuge authored Sep 17, 2024
1 parent 272fc4e commit 1b7abb2
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 149 deletions.
6 changes: 3 additions & 3 deletions kairon/api/app/routers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def delete_bot(
"""
Deletes bot.
"""
AccountProcessor.delete_bot(bot)
AccountProcessor.delete_bot(bot, current_user.get_user())
return {'message': 'Bot removed'}


Expand Down Expand Up @@ -209,7 +209,7 @@ async def delete_account(current_user: User = Depends(Authentication.get_current
"""
Deletes user account.
"""
AccountProcessor.delete_account(current_user.account)
AccountProcessor.delete_account(current_user.account, current_user.get_user())
return {"message": "Account deleted"}


Expand Down Expand Up @@ -238,5 +238,5 @@ async def delete_organization(org_id: str, current_user: User = Depends(Authenti
"""
Delete organization.
"""
OrgProcessor.delete_org(current_user.account, org_id)
OrgProcessor.delete_org(current_user.account, org_id, user=current_user.get_user())
return Response(message="Organization deleted")
2 changes: 1 addition & 1 deletion kairon/api/app/routers/bot/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ async def update_live_agent(
async def disable_live_agent(
current_user: User = Security(Authentication.get_current_user_and_bot, scopes=DESIGNER_ACCESS)
):
mongo_processor.disable_live_agent(current_user.get_bot())
mongo_processor.disable_live_agent(current_user.get_bot(), current_user.get_user())
return Response(message="Live Agent Action disabled!")


Expand Down
2 changes: 1 addition & 1 deletion kairon/api/app/routers/bot/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ async def delete_live_agent_config(
"""
Deletes the live agent config.
"""
LiveAgentsProcessor.delete_config(current_user.get_bot())
LiveAgentsProcessor.delete_config(current_user.get_bot(), user=current_user.get_user())
return Response(message='Live agent system deleted')
14 changes: 7 additions & 7 deletions kairon/api/app/routers/bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ async def remove_response(
Deletes existing utterance example.
"""
mongo_processor.delete_response(
response_id, current_user.get_bot()
response_id, current_user.get_bot(), user=current_user.get_user()
)
return {
"message": "Response removed!",
Expand All @@ -344,7 +344,7 @@ async def remove_responses(
Deletes existing utterance completely along with its examples.
"""
mongo_processor.delete_utterance(
utterance, current_user.get_bot()
utterance, current_user.get_bot(), user=current_user.get_user()
)
return {
"message": "Utterance removed!",
Expand Down Expand Up @@ -1130,7 +1130,7 @@ async def delete_synonym_value(
Deletes existing synonym with value.
"""
mongo_processor.delete_synonym(
id=id, bot=current_user.get_bot()
id=id, bot=current_user.get_bot(), user=current_user.get_user()
)
return {
"message": "Synonym removed!"
Expand All @@ -1147,7 +1147,7 @@ async def delete_synonym_value(
Deletes existing synonym value.
"""
mongo_processor.delete_synonym_value(
synonym_name=name, value_id=id, bot=current_user.get_bot()
synonym_name=name, value_id=id, bot=current_user.get_bot(), user=current_user.get_user()
)
return {
"message": "Synonym value removed!"
Expand Down Expand Up @@ -1388,7 +1388,7 @@ async def delete_lookup_value(
Deletes existing lookup value.
"""
mongo_processor.delete_lookup_value(
id, name, current_user.get_bot()
id, name, current_user.get_bot(), user=current_user.get_user()
)
return {
"message": "Lookup value removed!"
Expand All @@ -1404,7 +1404,7 @@ async def delete_lookup(
Deletes existing lookup.
"""
mongo_processor.delete_lookup(
id, current_user.get_bot()
id, current_user.get_bot(), user=current_user.get_user()
)
return {
"message": "Lookup removed!"
Expand Down Expand Up @@ -1453,7 +1453,7 @@ async def delete_slot_mapping(mapping_id: str = Path(description="Slot Mapping i
"""
Deletes a slot mapping.
"""
mongo_processor.delete_single_slot_mapping(mapping_id)
mongo_processor.delete_single_slot_mapping(mapping_id, user=current_user.get_user())
return Response(message='Slot mapping deleted')


Expand Down
2 changes: 1 addition & 1 deletion kairon/api/app/routers/bot/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def delete_channel_config(
"""
Deletes the channel config.
"""
ChatDataProcessor.delete_channel_config(current_user.get_bot(), id=channel_id)
ChatDataProcessor.delete_channel_config(current_user.get_bot(), user=current_user.get_user(), id=channel_id)
return Response(message='Channel deleted')


Expand Down
2 changes: 1 addition & 1 deletion kairon/api/app/routers/bot/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async def delete_custom_widget(
"""
Delete a particular custom widget.
"""
CustomWidgetsProcessor.delete_config(widget_id, current_user.get_bot())
CustomWidgetsProcessor.delete_config(widget_id, current_user.get_bot(), user=current_user.get_user())
return Response(message='Widget config removed!')


Expand Down
4 changes: 2 additions & 2 deletions kairon/api/app/routers/bot/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async def delete_cognition_schema(
"""
Deletes cognition content of the bot
"""
cognition_processor.delete_cognition_schema(schema_id, current_user.get_bot())
cognition_processor.delete_cognition_schema(schema_id, current_user.get_bot(), user=current_user.get_user())
return {
"message": "Schema deleted!"
}
Expand Down Expand Up @@ -147,7 +147,7 @@ async def delete_cognition_data(
"""
Deletes cognition content of the bot
"""
cognition_processor.delete_cognition_data(row_id, current_user.get_bot())
cognition_processor.delete_cognition_data(row_id, current_user.get_bot(), user=current_user.get_user())
return {
"message": "Record deleted!"
}
Expand Down
2 changes: 1 addition & 1 deletion kairon/api/app/routers/bot/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ async def delete_key_value(
"""
Deletes key value.
"""
mongo_processor.delete_secret(key, current_user.get_bot())
mongo_processor.delete_secret(key, current_user.get_bot(), user=current_user.get_user())
return Response(data=None, message="Secret deleted!")
2 changes: 1 addition & 1 deletion kairon/api/app/routers/idp.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ async def delete_idp_config(current_user: User = Depends(Authentication.get_curr
"""
Disable the idp config
"""
IDPProcessor.delete_idp(realm_name)
IDPProcessor.delete_idp(realm_name, user=current_user.get_user())
return Response(message="IDP config deleted")

5 changes: 3 additions & 2 deletions kairon/idp/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,12 @@ def get_supported_provider_list():
return KEYCLOAK_SUPPORTED_PROVIDER

@staticmethod
def delete_idp(realm_name):
def delete_idp(realm_name, user: str = None):
try:
helper = IDPFactory.get_supported_idp(Utility.environment["idp"]["type"])
helper.delete_realm(realm_name)
idp_config_data = IdpConfig.objects(realm_name=realm_name, status=True).get()
idp_config_data.delete()
Utility.delete_documents(idp_config_data, user)

except DoesNotExist:
raise AppException("IDP config not found")
8 changes: 5 additions & 3 deletions kairon/shared/account/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def update_bot(name: Text, bot: Text):
raise AppException("Bot not found")

@staticmethod
def delete_bot(bot: Text):
def delete_bot(bot: Text, user: Text = None):
from kairon.shared.data.data_objects import (
Intents,
Responses,
Expand Down Expand Up @@ -296,6 +296,7 @@ def delete_bot(bot: Text):
ValidationLogs,
],
bot,
user=user
)
AccountProcessor.remove_bot_access(bot)
except DoesNotExist:
Expand Down Expand Up @@ -1182,7 +1183,7 @@ def get_ui_config(user: str):
return config

@staticmethod
def delete_account(account_id: int):
def delete_account(account_id: int, email: str = None):
"""
Delete User Account
Expand All @@ -1192,14 +1193,15 @@ def delete_account(account_id: int):
"""
try:
account_obj = Account.objects(id=account_id, status=True).get()

except DoesNotExist:
raise AppException("Account does not exist!")

# List all bots for the account
account_bots = list(AccountProcessor.list_bots(account_id))
# Delete all account_owned bots
for bot in account_bots:
AccountProcessor.delete_bot(bot["_id"])
AccountProcessor.delete_bot(bot["_id"], email)
UserActivityLogger.add_log(

a_type=UserActivityType.delete_bot.value,
Expand Down
8 changes: 4 additions & 4 deletions kairon/shared/cognition/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def save_cognition_schema(self, schema: Dict, user: Text, bot: Text):
metadata_id = metadata_obj.save().to_mongo().to_dict()["_id"].__str__()
return metadata_id

def delete_cognition_schema(self, schema_id: str, bot: Text):
def delete_cognition_schema(self, schema_id: str, bot: Text, user: str = None):
try:
metadata = CognitionSchema.objects(bot=bot, id=schema_id).get()
CognitionDataProcessor.validate_collection_name(bot, metadata['collection_name'])
Expand All @@ -91,7 +91,7 @@ def delete_cognition_schema(self, schema_id: str, bot: Text):
if cognition_data:
for data in cognition_data:
data.delete()
metadata.delete()
Utility.delete_documents(metadata, user)
except DoesNotExist:
raise AppException("Schema does not exists!")

Expand Down Expand Up @@ -300,10 +300,10 @@ def update_cognition_data(self, row_id: str, payload: Dict, user: Text, bot: Tex
except DoesNotExist:
raise AppException("Payload with given id not found!")

def delete_cognition_data(self, row_id: str, bot: Text):
def delete_cognition_data(self, row_id: str, bot: Text, user: str = None):
try:
payload = CognitionData.objects(bot=bot, id=row_id).get()
payload.delete()
Utility.delete_documents(payload, user)
except DoesNotExist:
raise AppException("Payload does not exists!")

Expand Down
4 changes: 2 additions & 2 deletions kairon/shared/custom_widgets/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def list_widgets(bot: Text):
return [w_id.__str__() for w_id in CustomWidgets.objects(bot=bot).values_list('id')]

@staticmethod
def delete_config(widget_id: Text, bot: Text):
def delete_config(widget_id: Text, bot: Text, user: str = None):
try:
widget = CustomWidgets.objects(id=widget_id, bot=bot).get()
widget.delete()
Utility.delete_documents(widget, user)
except DoesNotExist as e:
logger.exception(e)
raise AppException("Widget does not exists!")
Expand Down
Loading

0 comments on commit 1b7abb2

Please sign in to comment.