def get_non_furnace(request): """ :param request: request django object :return: json response """ obj = None furnaces = None obj = query_params = None try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = lbt_non_furnace(furnaces) return obj.get_furnaces() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def update_price_input_data(request): """ :param request: request django object :return: json response """ obj = None obj = query_params = None try: if request.method == PUT_REQUEST: request_payload = json.loads(request.body.decode(UTF8_FORMAT)) jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = update_price(request_payload) return obj.update_price_input() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError as e: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_license_expiry_details(request): obj = None try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = Popup_Notification() return obj.license_expiry() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_algorithm_list(request, algorithm_name=None): """ This function will return the algorithm list and will return error if generated. :param request: request django object :param algorithm_name : this either can be none or else it will have the algorithm name :return: json response """ obj = None try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = AllAlgorithmList() if algorithm_name: return obj.get_algorithms_by_name_and_type(algorithm_name) else: return obj.get_algorithm_list() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_all_cases(request, console=None, equipment=None): """ This function will return all the cases :param console: Console name :param equipment: equipment name :param request: request django object :return: json response """ obj = None try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = GetCases(console, equipment) return obj.get_cases_values() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_lbt_external_targets(request): """ :param request: request django object :return: json response """ obj = None external = None try: if request.method == GET_REQUEST: loggedin_external_details = _TokenValidation.validate_token( request) r_name = loggedin_external_details['role'] names = ['superadmin', 'admin', 'operator'] if r_name in names: if loggedin_external_details: obj = lbt_external_targets(external) return obj.get_externl_targets() else: return JsonResponse({MESSAGE_KEY: "Bad request"}, status=HTTP_400_BAD_REQUEST) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def upload_algorithm_file(request, algorithm_name): """ This function will upload csv and xml files, file name and description and will return error if generated. :param request: request django object :param algorithm_name : this will have the algorithm name :return: json response """ obj = None try: if request.method == POST_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = UploadAlgorithmFile(request.FILES.getlist('files'), algorithm_name, request.POST.get('description'), request.POST.get('file_names')) return obj.upload_file() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def update_algorithm_params(request, algorithm_name): """ This function will update the algorithm with the passed json values. :param request: request django object :param algorithm_name : this either can be none or else it will have the algorithm name :return: json response """ obj = None try: if request.method == PUT_REQUEST: request_payload = json.loads(request.body.decode(UTF8_FORMAT)) jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = UpdateAlgorithmParams(request_payload, algorithm_name) return obj.update_algorithms() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_outage_graph(request, equipment_name=None, module_name=None): """ This function will return the graph data for the selected module :param module_name: module name :param equipment_name: equipment name :param request: request django object :return: json response """ query_params, obj = None, None try: query_params = request except: pass try: if request.method == GET_REQUEST: obj = OutageGraph(query_params, equipment_name, module_name) return obj.get_outage() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except Exception as e: excMsg = "get_outage_graph_data API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def authenticate_user(request): """ This function will validate the user and on successful response it will generate the JWT token :param request: request django object :return: json response """ obj = None try: if request.method == POST_REQUEST: request_payload = _RequestValidation().validate_request( request, [USEREMAIL_KEY, USERPASSWORD_KEY]) obj = UserAuthentication(request_payload) return obj.handle_login() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_gap_analysis_overview_details_data(request): """ :param request: request django object :return: json response """ obj = None obj = query_params = None try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) parameter = str(request.GET.get("basis")) if jwt_value: obj = gap_analysis_overview_details() return obj.get_overview_details_data(parameter) else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError as e: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def user_password_change(request): """ This function will reset the password for the existing user :param request: request django object :return: json object """ obj = None try: if request.method == PUT_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) if loggedin_user_details: request_payload = _RequestValidation().validate_request( request, [USERPASSWORD_KEY, USERFUTUREPASSWORD_KEY]) obj = UserPasswordChange(loggedin_user_details, request_payload) return obj.change_password_user() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_lbt_update_external_targets(request): """ This function will update the existing user :param request: request django object :return: jsonobject """ obj = query_params = None try: query_params = { EQUIPMENT: request.GET[EQUIPMENT], TAG_NAME_REQUEST: request.GET[TAG_NAME_REQUEST] } except: pass try: if request.method == PUT_REQUEST: loggedin_external_details = _TokenValidation.validate_token( request) r_name = loggedin_external_details['role'] names = ['superadmin', 'admin'] if r_name in names: if loggedin_external_details: request_payload = _RequestValidation().validate_request( request, [COMMENT_NAME]) obj = lbt_update_external_targets(query_params, request_payload) return obj.update_external_targets() else: return JsonResponse({MESSAGE_KEY: "Bad request"}, status=HTTP_400_BAD_REQUEST) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def update_user(request): """ This function will update the existing user :param request: request django object :return: jsonobject """ obj = None try: if request.method == PUT_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) r_name = loggedin_user_details['role'] names = ['Super Admin', 'Admin'] if r_name in names: if loggedin_user_details: request_payload = _RequestValidation().validate_request( request, [ USERID_KEY, NAME, LOGIN_ID, USEREMAIL_KEY, DESIGNATION, USER_TYPE, EAMIL_NOTIFICATION ]) obj = UpdateUser(loggedin_user_details, request_payload) return obj.update_user() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "update_users_data API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def get_revenue_graph(request, equipment_name=None, module_name=None): """ This function will return the revenue loss data for the overhead pdi module :param module_name: module name :param equipment_name: equipment name :param request: request django object :return: json response """ query_params, obj = None, None try: query_params = { TAG_NAME_REQUEST: request.GET[TAG_NAME_REQUEST], START_DATE_REQUEST: request.GET[START_DATE_REQUEST], END_DATE_REQUEST: request.GET[END_DATE_REQUEST] } except: pass try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) if loggedin_user_details: obj = RevenueGraph(query_params, equipment_name, module_name) return obj.get_values() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def create_user(request): """ This function will crete a new user :param request: request django object :return: json object """ obj = None try: if request.method == POST_REQUEST: jwt_value = _TokenValidation().validate_token(request) loggedin_user_details = _TokenValidation.validate_token(request) r_name = loggedin_user_details['role'] names = ['superadmin', 'admin'] if r_name in names: if loggedin_user_details: request_payload = _RequestValidation().validate_request( request, [ USERFIRSTNAME_KEY, USERMIDDLENAME_KEY, USERLASTNAME_KEY, USEREMAIL_KEY, USERPASSWORD_KEY, GENDER_KEY, AGE_KEY, PHONE_KEY, ADDRESS_KEY, STATUS_KEY, ROLE_ID ]) if jwt_value: obj = CreateUser(loggedin_user_details, request_payload) return obj.add_user() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) else: return JsonResponse({MESSAGE_KEY: "Bad request"}, status=HTTP_400_BAD_REQUEST) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_outage_multiline(request, equipment_name=None, module_name=None): """ This function will return the outage multiline graph data :param module_name: module name :param equipment_name: equipment name :param request: request django object :return: json response """ query_params, obj = None, None try: query_params = request except: pass try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) if loggedin_user_details: obj = OutageMultiLine(query_params, equipment_name, module_name) return obj.get_values() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "get_outage_multi_line_graph_data API : " + str( error_instance(e)) return excMsg finally: if obj: del obj
def download_algorithm_file(request, algorithm_name): """ This function will download csv, xml files and will return error if generated. :param request: request django object :param algorithm_name : this will have the algorithm name :return: json response """ query_params = obj = None try: query_params = {FILES_NAME_REQUEST: request.GET[FILES_NAME_REQUEST]} except: pass try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) permissions = loggedin_user_details['permissions']['Settings'] permission_name = 'Upload/Download Configuration Files' if permission_name in permissions: if loggedin_user_details: obj = DownloadAlgorithmFile(algorithm_name, query_params) return obj.download_file() else: return JsonResponse({MESSAGE_KEY: "Forbidden Error"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_algorithm_list(request, algorithm_name=None): """ This function will return the algorithm list and will return error if generated. :param request: request django object :param algorithm_name : this either can be none or else it will have the algorithm name :return: json response """ obj = None try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) r_name = loggedin_user_details['role'] names = ['Super Admin'] if r_name in names: if loggedin_user_details: obj = AllAlgorithmList() if algorithm_name: return obj.get_file_data_by_algorithm_name( algorithm_name) else: return obj.get_algorithms_details() else: return JsonResponse({MESSAGE_KEY: "Forbidden Error"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "get_access_list API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def get_namings_data(request): """ This function will return all the console name and equipment name :param request: request django object :return: json response """ obj = None try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) get_value = 0 if jwt_value['role'] in ['superadmin', 'admin', 'engineer']: get_value = 0 elif jwt_value['loggedin_useremail'] in ['*****@*****.**']: get_value = 1 elif jwt_value['loggedin_useremail'] in ['*****@*****.**']: get_value = 2 elif jwt_value['loggedin_useremail'] in ['*****@*****.**']: get_value = 3 elif jwt_value['loggedin_useremail'] in ['*****@*****.**']: get_value = 4 if jwt_value: obj = GetNamings(get_value) return obj.get_names_values() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def download_notifications_data(request): """ This function will download the notifications from the database :param request: request django object :return: json response """ query_params, obj = None, None try: query_params = request except: pass try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) if loggedin_user_details: obj = Notifications(loggedin_user_details, query_params) return obj.get_notifications(request) else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "get_notifications API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def get_hgi_graph(request, equipment_name=None, module_name=None): """ This function will return the graph data for the selected module :param module_name: module name :param equipment_name: equipment name :param request: request django object :return: json response """ query_params, obj = None, None try: query_params = request except: pass try: if request.method == GET_REQUEST: # # loggedin_user_details = _TokenValidation.validate_token(request) # if loggedin_user_details: obj = HgiGraph(query_params, equipment_name, module_name) return obj.get_hgi_graph() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) # except jwt.ExpiredSignatureError: # token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] # role = jwt.decode(token, verify=False) # ob = HashingSalting() # if role['role'] == 'Admin': # ob.decreasing_admin_login_count() # if role['role'] == 'Non Admin': # ob.decreasing_Non_Admin_login_count() # if role['role'] == 'Super Admin': # ob.decreasing_super_Admin_login_count() # return {MESSAGE_KEY: "Token Expired"} except Exception as e: return error_instance(e) finally: if obj: del obj
def update_access_configuration(request): """ This function will update the Access of users details with the passed json values. :param request: request django object :return: json response """ obj = None try: if request.method == PUT_REQUEST: request_payload = json.loads(request.body.decode(UTF8_FORMAT)) loggedin_user_details = _TokenValidation.validate_token(request) r_name = loggedin_user_details['role'] names = ['Super Admin'] if r_name in names: if loggedin_user_details: request_payload = _RequestValidation().validate_request( request, request_payload) obj = AccessUpdate(request_payload) return obj.update_access() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "Access_Update API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def get_user_data(request): """ This function will get the values for the equipment level as well as console level dynamic benchmarking :param request: request django object :param unit: unit name :param console: console name will be provided :param equipment: equipment name will be provided :return: json response """ obj = None try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) r_name = loggedin_user_details['role'] names = ['Super Admin'] if r_name in names: if loggedin_user_details: obj = user_get() return obj.get_user_values() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "get_all_users_data API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def update_algorithm_params(request): """ This function will update the algorithm with the passed json values. :param request: request django object :param algorithm_name : this either can be none or else it will have the algorithm name :return: json response """ obj = None try: if request.method == PUT_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) permissions = loggedin_user_details['permissions']['Settings'] permission_name = 'Module On/OFF' if permission_name in permissions: if loggedin_user_details: request_payload = json.loads( request.body.decode(UTF8_FORMAT)) obj = UpdateAlgorithmParams(request_payload) return obj.update_algorithms() else: return JsonResponse({MESSAGE_KEY: "Forbidden Error"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def delete_user(request, login_id=None): """ This function will delete the existing user :param login_id: it will give the log_in id of the deleting user :param request: request django object :param username : username that need to be deleted :return: json object """ obj = None try: if request.method == DELETE_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) r_name = loggedin_user_details['role'] names = ['Super Admin'] if r_name in names: if loggedin_user_details: obj = DeleteUser(loggedin_user_details, login_id) return obj.delete_user() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "delete_users_data API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def put_lbt_equipment_update(request): """ :param request: request django object :param equipment: equipment name will be provided :param feed_name: feed name will be provided :param is_active: is_active name will be provided :return: json response """ obj = query_params = None try: query_params = { EQUIPMENT: request.GET[EQUIPMENT], FEED_NAME: request.GET[FEED_NAME], IS_ACTIVE: request.GET[IS_ACTIVE] } except: pass try: if request.method == PUT_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = lbt_equipment_update(query_params, json.loads(request.body)) return obj.get_update_equip_query() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def get_furnaces_config(request): """ :param request: request django object :param IS_ACTIVE: IS_ACTIVE will be provided :param FEED_NAME: FEED_NAME name will be provided :return: json response """ obj = query_params = None try: query_params = { IS_ACTIVE: request.GET[IS_ACTIVE], FEED_NAME: request.GET[FEED_NAME] } except: pass try: if request.method == GET_REQUEST: jwt_value = _TokenValidation().validate_token(request) if jwt_value: obj = furnaces_config(query_params) return obj.get_furnaces() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj
def clear_notifications_data(request): """ This function will get the values for dynamic benchmarking :param request: request django object :return: json response """ obj = None try: if request.method == POST_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) if loggedin_user_details: request_payload = json.loads(request.body.decode(UTF8_FORMAT)) obj = ClearNotifications(loggedin_user_details, request_payload) return obj.clear_notifications() else: return JsonResponse({MESSAGE_KEY: "FORBIDDEN ERROR"}, status=HTTP_403_FORBIDDEN) log_debug(METHOD_NOT_ALLOWED) return json_MethodNotAllowed except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: excMsg = "clear_notifications API : " + str(error_instance(e)) return excMsg finally: if obj: del obj
def get_configscreen_data(request): print("hi") """ This function will get the values for the equipment level as well as console level dynamic benchmarking :param request: request django object :param unit: unit name :param console: console name will be provided :param equipment: equipment name will be provided :return: json response """ obj = None try: if request.method == GET_REQUEST: loggedin_user_details = _TokenValidation.validate_token(request) if loggedin_user_details: obj = ConfigScreen() return obj.get_values() log_debug(METHOD_NOT_ALLOWED) return JsonResponse({MESSAGE_KEY: METHOD_NOT_ALLOWED}, status=HTTP_405_METHOD_NOT_ALLOWED) except jwt.ExpiredSignatureError: token = request.META[HTTP_AUTHORIZATION_TOKEN].split(" ")[1] role = jwt.decode(token, verify=False) ob = HashingSalting() if role['role'] == 'Admin': ob.decreasing_admin_login_count() if role['role'] == 'Non Admin': ob.decreasing_Non_Admin_login_count() if role['role'] == 'Super Admin': ob.decreasing_super_Admin_login_count() return JsonResponse({MESSAGE_KEY: "Token Expired"}, status=HTTP_401_UNAUTHORIZED) except Exception as e: return error_instance(e) finally: if obj: del obj