diff --git a/modules/admin.py b/modules/admin.py index e8af714c4d59c5ac4ccd4228c93ed0a314f26305..3029ce4f935f547803410aea4ad5dfa4a0580b80 100644 --- a/modules/admin.py +++ b/modules/admin.py @@ -8,15 +8,17 @@ from modules.tools.roles import Roles admin_route = Blueprint('admin', __name__, template_folder="templates") -# add page for admins to watch +# add page for admins to watch, assume only one admin per page @admin_route.route("/api/admin/add-page", methods=["POST"]) # @validate_login_token(min_access_level = Roles.SUPERADMIN) def add_page(): data = request.get_json() - + page = db.VizData.objects.with_id(data.get("page_id")) + curr_admin = db.User.objects(page_list__in = [page.id]) + if len(curr_admin) > 0: + curr_admin.update(pull__page_list = page.id) admin = db.User.objects.with_id(data.get("admin_id")) - admin.page_list.append(data.get("page_id")) - print(admin.page_list) + admin.page_list.append(page.id) admin.save() return jsonify({ "status":200, diff --git a/modules/page.py b/modules/page.py index c9fcb419e7cb83fcffb15bb40bd2ba34ca80e951..2d05ad9e22611263e854a632365d7e01780bf862 100644 --- a/modules/page.py +++ b/modules/page.py @@ -30,7 +30,6 @@ def get_top_page(): admin = admins[0] del admin.password del admin.page_list - print(admin) resp["admin_subdata"].append(admin) else: resp["admin_subdata"].append(None) @@ -74,7 +73,6 @@ def get_page(): admin = admins[0] del admin.password del admin.page_list - print(admin) resp["admin_subdata"].append(admin) else: resp["admin_subdata"].append(None) @@ -100,7 +98,58 @@ def get_page(): "message": str(e) }) +@page_route.route("/api/page/get-grandchildren", methods=["POST"]) +def get_grandchild(): + data_id = request.get_json().get("page_id") + return_admin = request.get_json().get("return_admin") + try: + vdata = db.VizData.objects.with_id(data_id) + if vdata is not None: + children = [child for child in vdata.subdata] + subdata = [] + for child in children: + for gc in child.subdata: + gc.categories = child.name + subdata.append(gc) + + resp = { + "status":200, + "data":vdata, + "subdata":subdata + } + + if return_admin: + resp["admin_subdata"] = [] + for x in subdata: + admins = db.User.objects(page_list__in = [x.id]) + if len(admins) > 0: + admin = admins[0] + del admin.password + del admin.page_list + resp["admin_subdata"].append(admin) + else: + resp["admin_subdata"].append(None) + admins = db.User.objects(page_list__in = [vdata.id]) + if len(admins) > 0: + admin = admins[0] + del admin.password + del admin.page_list + resp["admin"] = admin + else: + resp["admin"] = None + + return jsonify(resp) + else: + return jsonify({ + "status":404, + "message":"page not found" + }) + except Exception as e: + return jsonify({ + "status": 500, + "message": str(e) + }) @page_route.route("/api/hidden/add-data", methods=["POST"]) def add_page():