def delete_integration(request, id=None): """Function to delete an integration.""" print("In delete_integration") #print(id) access_token_dict = UserIntegration.objects.get(id=id) access_token = access_token_dict.yellowant_integration_token user_integration_id = access_token_dict.yellowant_integration_id #print(user_integration_id) #"https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) yellowant_user = YellowAnt(access_token=access_token) yellowant_user.delete_user_integration(id=user_integration_id) UserIntegration.objects.get(yellowant_integration_token=access_token).delete() #print(response_json) return HttpResponse("successResponse", status=200)
def view_integration(request, id=None): """ Function to View an integration when it is clicked. """ print("In view_integration") #print(id) access_token_dict = UserIntegration.objects.get(id=id) access_token = access_token_dict.yellowant_integration_token user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) yellowant_user = YellowAnt(access_token=access_token) yellowant_user.delete_user_integration(id=user_integration_id) #print(response_json) return HttpResponse("successResponse", status=200)
def user_detail_update_delete_view(request, id=None): print("In user_detail_update_delete_view") """ delete_integration function deletes the particular integration """ print("In user_detail_update_delete_view") print(id) user_integration_id = id # # if request.method == "GET": # pass # return HttpResponse(json.dumps({"ok" : True,"is_valid" : False})) if request.method == "DELETE": print("Deleting integration") access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user if user_id == request.user.id: access_token = access_token_dict.yellowant_token print(access_token) user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) print(yellowant_user) yellowant_user.delete_user_integration(id=user_integration_id) response = YellowUserToken.objects.get( yellowant_token=access_token).delete() print(response) return HttpResponse("successResponse", status=200) else: return HttpResponse("Not Authenticated", status=403) elif request.method == "POST": print("In submitting data") data = json.loads(request.body.decode("utf-8")) print(data) user_integration = data['user_integration'] qut_object = QuickbookUserToken.objects.get( user_integration_id=user_integration) qut_object.login_update_flag = True qut_object.save() return HttpResponse(json.dumps({"ok": True, "is_valid": True}))
def delete_integration(request, integrationId=None): print("In delete_integration") print(integrationId) access_token_dict = YellowUserToken.objects.get(id=integrationId) user_id = access_token_dict.user if user_id == request.user.id: access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) yellowant_user = YellowAnt(access_token=access_token) yellowant_user.delete_user_integration(id=user_integration_id) response_json = YellowUserToken.objects.get( yellowant_token=access_token).delete() print(response_json) return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403)
def user_detail_update_delete_view(request, id=None): """ delete_integration function deletes the particular integration """ #print("In user_detail_update_delete_view") #print(id) user_integration_id = id if request.method == "GET": pass # return user data # smut = DropBoxUserToken.objects.get(user_integration=user_integration_id) # return HttpResponse(json.dumps({ # "is_valid": True # })) elif request.method == "DELETE": print("Deleting integration") access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user if user_id == request.user.id: access_token = access_token_dict.yellowant_token print(access_token) user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) yellowant_user = YellowAnt(access_token=access_token) print(yellowant_user) yellowant_user.delete_user_integration(id=user_integration_id) response = YellowUserToken.objects.get(yellowant_token=access_token).delete() print(response) return HttpResponse("successResponse", status=200) else: return HttpResponse("Not Authenticated", status=403) elif request.method == "PUT": pass
def user_detail_update_delete_view(request, id=None): """ This function handles the updating, deleting and viewing user details """ print("In user_detail_update_delete_view") print(id) user_integration_id = id # if request.method == "GET": # # return user data # print("in get") # pdut = ZohoInvoiceUserToken.objects.get(user_integration=user_integration_id) # return HttpResponse(json.dumps({ # "is_valid": pdut.apikey_login_update_flag # })) if request.method == "DELETE": # deletes the integration print("In delete_integration") # print(id)this is a test subject # print("user is ", request.user.id) access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user # print("id is ", user_id) if user_id == request.user.id: access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) yellowant_user.delete_user_integration(id=user_integration_id) response_json = YellowUserToken.objects.get( yellowant_token=access_token).delete() print(response_json) return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403)
def delete_integration(request, id=None): # Function for deleting an integration by taking the id as input. print(id) access_token_dict = UserIntegration.objects.get(id=id) user_id = access_token_dict.user if user_id == request.user.id: access_token = access_token_dict.yellowant_integration_token user_integration_id = access_token_dict.yellowant_integration_id url = "https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) yellowant_user = YellowAnt(access_token=access_token) profile = yellowant_user.delete_user_integration(id=user_integration_id) response_json = UserIntegration.objects.get(yellowant_integration_token=access_token).delete() return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403)
def delete_integration(request, integrationId=None): print("In delete_integration") print(integrationId) access_token_dict = YellowUserToken.objects.get(id=integrationId) access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_intergration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) profile = yellowant_user.delete_user_integration(id=user_integration_id) response_json = YellowUserToken.objects.get( yellowant_token=access_token).delete() print(response_json) return HttpResponse("successResponse", status=204)
def delete_integration(request, id=None): print("In delete_integration") print(id) print("user is ", request.user.id) access_token_dict = UserIntegration.objects.get(id=id) user_id = access_token_dict.user if user_id == request.user.id: access_token = access_token_dict.yellowant_integration_token user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) profile = yellowant_user.delete_user_integration( id=user_integration_id) response_json = UserIntegration.objects.get( yellowant_integration_token=access_token).delete() print(response_json) return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403)
def delete_integration(request, id=None): """ Function for deleting an integration by taking the id as input.""" # print(request.user.id) # access_token_dict = UserIntegration.objects.get(id=id) # access_token = access_token_dict.yellowant_integration_token # user_integration_id = access_token_dict.yellowant_integration_id # print(user_integration_id) # url = "https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) # yellowant_user = YellowAnt(access_token=access_token) # # # deletes all the data related to that integration # yellowant_user.delete_user_integration(id=user_integration_id) # response_json = UserIntegration.objects.get(yellowant_integration_token=access_token).delete() # return HttpResponse("successResponse", status=200) print("In delete_integration") print(id) print("user is ", request.user.id) access_token_dict = UserIntegration.objects.get(id=id) #print(access_token_dict.user_id) user_id = access_token_dict.user_id print(request.user.id) print(user_id) if user_id == request.user.id: print("asdfghjk") access_token = access_token_dict.yellowant_integration_token user_integration_id = access_token_dict.yellowant_integration_id # print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) profile = yellowant_user.delete_user_integration( id=user_integration_id) response_json = UserIntegration.objects.get( yellowant_integration_token=access_token).delete() # print(response_json) return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403)
def user_detail_update_delete_view(request, id=None): """ delete_integration function deletes the particular integration """ #print("In user_detail_update_delete_view") #print(id) user_integration_id = id if request.method == "GET": # return user data smut = StatuspageUserToken.objects.get( user_integration=user_integration_id) # ct = PageDetail.objects.count() # pages = [None]*ct # # if smut.apikey_login_update_flag == True: # # for page in range(0,ct): # pages[page] = "*************" # # return HttpResponse(json.dumps({ # "is_valid": smut.apikey_login_update_flag, # "pages": pages, # "api_key": "****************************************", # })) # # else: return HttpResponse( json.dumps({ "is_valid": smut.apikey_login_update_flag, "pages": [""], "api_key": "", "email": "" })) elif request.method == "DELETE": access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user #print(access_token) if user_id == request.user.id: access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_integration_id #print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) #print(yellowant_user) yellowant_user.delete_user_integration(id=user_integration_id) response = YellowUserToken.objects.get( yellowant_token=access_token).delete() #print(response) return HttpResponse("successResponse", status=200) else: return HttpResponse("Not Authenticated", status=403) elif request.method == "PUT": data = json.loads(request.body.decode("utf-8")) print(data) api_key = data['statuspage_api_key'] pages = data['pages'] user_integration = data['user_integration'] email = str(data['email']) print(email) headers = { "Authorization": "OAuth %s" % (api_key), "Content-Type": "application/json" } for page in pages: page_id = page url = "https://api.statuspage.io/v1/pages/" + page_id + ".json" response = requests.get(url, headers=headers) if response.status_code != 200: print("Invalid") return HttpResponse( json.dumps({ "ok": False, "is_valid": False })) else: print("Valid") sp_object = StatuspageUserToken.objects.get( user_integration_id=user_integration) print(sp_object.statuspage_access_token) sp_object.statuspage_access_token = api_key page_detail_object = PageDetail.objects.create( user_integration_id=user_integration, page_id=page_id) sp_object.apikey_login_update_flag = True sp_object.save() print(sp_object.statuspage_access_token) print(page_detail_object.page_id) ### Subscribing for webhooks webhook_id = sp_object.webhook_id print(webhook_id) endpoint = settings.BASE_URL + "/webhook/" + str( webhook_id) + "/" print(endpoint) for page in pages: page_id = page # Endpoint url = "https://api.statuspage.io/v1/pages/" + page_id + "/subscribers" + settings.END payload = { "subscriber": { "email": email, "endpoint": endpoint, } } response = requests.post(url, headers=headers, json=payload) print(response.json()) return HttpResponse(json.dumps({"ok": True, "is_valid": True}))
def user_detail_update_delete_view(request, id=None): """ delete_integration function deletes the particular integration """ #print("In user_detail_update_delete_view") user_integration_id = id if request.method == "GET": # return user data smut = MailGunUserToken.objects.get( user_integration=user_integration_id) return HttpResponse( json.dumps({ "is_valid": smut.apikey_login_update_flag, "pages": [""], "api_key": "", "email": "" })) elif request.method == "DELETE": access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user #print(access_token) if user_id == request.user.id: access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_integration_id #print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % ( user_integration_id) yellowant_user = YellowAnt(access_token=access_token) #print(yellowant_user) yellowant_user.delete_user_integration(id=user_integration_id) response = YellowUserToken.objects.get( yellowant_token=access_token).delete() #print(response) return HttpResponse("successResponse", status=200) else: return HttpResponse("Not Authenticated", status=403) elif request.method == "PUT": print("In put") data = json.loads(request.body.decode("utf-8")) print(data) api_key = data['api_key'] user_integration = data['user_integration'] domain_name = str(data['domain_name']) ## Making an API call just to check if the credentials entered is Valid or not auth = ("api", api_key) # Consuming the API r = requests.get("https://api.mailgun.net/v3/domains/" + str(domain_name), auth=auth) # Response check if r.status_code == 200: mg_object = MailGunUserToken.objects.get( user_integration_id=user_integration) mg_object.apikey_login_update_flag = True mg_object.accessToken = api_key mg_object.domain_name = domain_name mg_object.save() return HttpResponse("Submitted successfully !") else: print(r.status_code) return HttpResponse("Invalid credentials. Please try again !")
def user_detail_update_delete_view(request, id=None): """ This function handles the updating, deleting and viewing user details """ print("In user_detail_update_delete_view") print(id) user_integration_id = id if request.method == "GET": # return user data print("in get") pdut = PipedriveUserToken.objects.get(user_integration=user_integration_id) return HttpResponse(json.dumps({ "is_valid": pdut.apikey_login_update_flag })) elif request.method == "DELETE": # deletes the integration # print("In delete_integration") # print(id) # print("user is ", request.user.id) access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user # print("id is ", user_id) if user_id == request.user.id: access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_integration_id print(user_integration_id) url = "https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) yellowant_user = YellowAnt(access_token=access_token) yellowant_user.delete_user_integration(id=user_integration_id) response_json = YellowUserToken.objects.get(yellowant_token=access_token).delete() print(response_json) return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403) elif request.method == "PUT": # adds a new integration data = json.loads(request.body.decode("utf-8")) print(data) api_token = data['pipedrive_api_token'] user_integration = data['user_integration'] headers = { 'Content-Type': 'application/json', } url = 'https://api.pipedrive.com/v1/users?api_token=' + api_token response = requests.get(url, headers=headers) print(response.text) access_token_dict = YellowUserToken.objects.get(id=user_integration) print(access_token_dict) # access_token = access_token_dict.yellowant_token webhook_id = access_token_dict.webhook_id print(webhook_id) user_integration_id = access_token_dict.yellowant_integration_id hash_str = webhook_id print(hash_str) webhook_url = settings.BASE_URL + "/webhook/" + hash_str + "/" webhook_post_url = settings.PIPEDRIVE_WEBHOOK_URL + api_token print(webhook_url) headers = { 'Content-Type': 'application/json', } body = { "subscription_url": webhook_url, "event_action": "added", "event_object": "*" } if response.status_code == 200: print("Valid") api_new = PipedriveUserToken.objects.get(user_integration_id=user_integration) api_new.pipedrive_api_token = api_token api_new.apikey_login_update_flag = True api_new.save() # print(api_new.victorops_api_id) # print(api_new.victorops_api_key) web_response = requests.post(webhook_post_url, headers=headers, data=json.dumps(body)) print(web_response) print(web_response.text) return HttpResponse("Submitted", status=200) else: print("Invalid") return HttpResponse("Invalid Credentials", status=401)
def user_detail_update_delete_view(request, id=None): """ This function handles the updating, deleting and viewing user details """ # print("In user_detail_update_delete_view") # print(id) user_integration_id = id if request.method == "GET": # return user data vout = VictorOpsUserToken.objects.get(user_integration=user_integration_id) return HttpResponse(json.dumps({ "is_valid": vout.apikey_login_update_flag })) elif request.method == "DELETE": # deletes the integration access_token_dict = YellowUserToken.objects.get(id=id) user_id = access_token_dict.user if user_id == request.user.id: access_token = access_token_dict.yellowant_token user_integration_id = access_token_dict.yellowant_integration_id url = "https://api.yellowant.com/api/user/integration/%s" % (user_integration_id) yellowant_user = YellowAnt(access_token=access_token) yellowant_user.delete_user_integration(id=user_integration_id) response_json = YellowUserToken.objects.get(yellowant_token=access_token).delete() # print(response_json) return HttpResponse("successResponse", status=204) else: return HttpResponse("Not Authenticated", status=403) elif request.method == "PUT": # adds a new integration data = json.loads(request.body.decode("utf-8")) # print(data) user_id = data['user_id'] api_id = data['victorops_api_id'] api_key = data['victorops_api_key'] user_integration = data['user_integration'] headers = { 'Content-Type': 'application/json', 'X-VO-Api-Id': api_id, 'X-VO-Api-Key': api_key} url = 'https://api.victorops.com/api-public/v1/user' response = requests.get(url, headers=headers) response_json = response.json() data = response_json['users'][0] response.status_code = 401 for i in range(len(data)): if data[i]['username'] == user_id: response.status_code = 200 if response.status_code == 200: # print("Valid") api_new = VictorOpsUserToken.objects.get(user_integration_id=user_integration) api_new.victorops_user_id = user_id api_new.victorops_api_id = api_id api_new.victorops_api_key = api_key api_new.apikey_login_update_flag = True api_new.save() return HttpResponse("Submitted", status=200) else: # print("Invalid") return HttpResponse("Invalid Credentials", status=401)