def request_status(): object = json.loads(str(request.data).replace("b", "", 1).replace("'", "")) print(object) if object["status"] == "approve": del object["status"] access_collection = mc.return_collection("users_access_data") parameter_to_find = {"file": object["file"], "owner": object["owner"]} find_result = mc.find_one(parameter_to_find, access_collection) del find_result["_id"] replacing_result = s3.create_replace_record(find_result, object) result = mc.replace(parameter_to_find, replacing_result, access_collection) print(result.modified_count) if result.modified_count == 1: collection = mc.return_collection("user_access_request") replace_result = s3.status_change(collection, object, "approved") if replace_result.modified_count == 1: return jsonify({"status": True}) else: return jsonify({"status": False}) else: collection = mc.return_collection("user_access_request") replace_result = s3.status_change(collection, object, "rejected") if replace_result.modified_count == 1: return jsonify({"status": True}) else: return jsonify({"status": False})
def validate_user(): username = request.args.get('username') session_id = request.args.get('sessionid') result = mc.find_one({"username": username, "authentication_server_sessionId": session_id}) if (result) != "": print("The User data exists .......") return jsonify({"status":True})
def find_one(): login_credentials = data_extraction(request.data) result = mc.find_one(login_credentials) if (result) != "": print("The User data is exists .......") return jsonify({"status":True}) else: print("The data doesn't exists.......") return jsonify({"status":False})
def sign_out(): username = request.args.get('username') result = mc.find_one({"username": username}) del result["_id"] del result["authentication_server_sessionId"] replace_result = mc.replace({"username": username}, result) if replace_result.modified_count == 1: print("The User has been logged out .......") return jsonify({"status": True}) else: print("The User has not been logged out.......") return jsonify({"status": False})
def branch_assignment(original_name, name): temp = {} temp["name"] = name temp["trueName"] = original_name temp["children"] = [] collection = mc.return_collection("users_access_data") parameter = {"file": temp["trueName"]} metadata = mc.find_one(parameter, collection) if (metadata): temp["owner"] = metadata["owner"] for user in metadata["accessing_users"]: if (user["name"] == username): if "read" in user: temp["read"] = user["read"] if "write" in user: temp["write"] = user["write"] if "delete" in user: temp["delete"] = user["delete"] return temp
def leaf_assignemnt(object): temp = object["objectName"].split("/") del temp[-1] root_folder_name = "/".join(temp) + "/" temp = {} temp["name"] = object["objectName"].replace(root_folder_name, "").strip() temp["trueName"] = object["objectName"] temp["value"] = round(object["size"] / 1024, 2) collection = mc.return_collection("users_access_data") parameter = {"file": object["objectName"]} metadata = mc.find_one(parameter, collection) if (metadata): temp["owner"] = metadata["owner"] for user in metadata["accessing_users"]: if (user["name"] == username): if "read" in user: temp["read"] = user["read"] if "write" in user: temp["write"] = user["write"] if "delete" in user: temp["delete"] = user["delete"] return temp
def delete_objects(): objects = json.loads(str(request.data).replace("b", "", 1).replace("'", "")) data = objects["Objects"] username = objects["owner"] del objects["owner"] folder_access = [] backups = [] for file in data: folder_access_temp = {} folder_access_temp["owner"] = username folder_access_temp["file"] = file["Key"] backup = mc.find_one(folder_access_temp, mc.return_collection("users_access_data")) del backup["_id"] backups.append(backup) folder_access.append(folder_access_temp) print("backup", backups) mc.delete_many(folder_access, mc.return_collection("users_access_data")) results = [] results.append(s3.delete_objects(objects)) print(results) def worker(): access_collection = mc.return_collection("users_access_data") access_collection.insert_many(backups) if (False in results): print("inside rollback") try: delete_roll_back_thread = threading.Thread(target=worker()) thread = threading.Thread(target=s3.roll_back, args=(objects["Objects"],)) thread.daemon = True delete_roll_back_thread.daemon = True delete_roll_back_thread.start() thread.start() except: print("Error: unable to Rollback") return jsonify({"status": False}) else: return jsonify({"status": True})
def status_change(collection, filter, status): if "status" in filter: del filter["status"] find_result = mc.find_one(filter, collection) find_result["status"] = status return mc.replace(filter, find_result, collection)