Example #1
0
 def account_setup(account_setup: Dict, user: Text):
     """ Creating a new account based on details provided by the user """
     account = None
     bot = None
     user_details = None
     try:
         account = AccountProcessor.add_account(account_setup.get("account"), user)
         bot = AccountProcessor.add_bot(
             account_setup.get("bot"), account["_id"], user
         )
         user_details = AccountProcessor.add_user(
             email=account_setup.get("email"),
             first_name=account_setup.get("first_name"),
             last_name=account_setup.get("last_name"),
             password=account_setup.get("password").get_secret_value(),
             account=account["_id"].__str__(),
             bot=bot["_id"].__str__(),
             user=user,
             role="admin",
         )
     except Exception as e:
         if account and "_id" in account:
             Account.objects().get(id=account["_id"]).delete()
         if bot and "_id" in bot:
             Bot.objects().get(id=bot["_id"]).delete()
         raise e
     return user_details
Example #2
0
 def add_bot(name: str, account: int, user: str):
     """ Adds a bot to the specified user account """
     assert not Utility.check_empty_string(name), "Bot Name cannot be empty or blank spaces"
     Utility.is_exist(
         Bot,
         exp_message="Bot already exists!",
         name__iexact=name, account=account, status=True
     )
     return Bot(name=name, account=account, user=user).save().to_mongo().to_dict()
Example #3
0
 def add_bot(name: str, account: int, user: str):
     Utility.is_exist(
         Bot,
         query={
             "name": name,
             "account": account
         },
         exp_message="Bot already exists!",
     )
     return Bot(name=name, account=account,
                user=user).save().to_mongo().to_dict()
Example #4
0
 def get_bot(id: str):
     """ Loads the bot based on user ID """
     try:
         return Bot.objects().get(id=id).to_mongo().to_dict()
     except:
         raise DoesNotExist("Bot does not exists!")
Example #5
0
 def get_bot(id: str):
     try:
         return Bot.objects().get(id=id).to_mongo().to_dict()
     except:
         raise DoesNotExist("Bot does not exists!")