Skip to content
Snippets Groups Projects
Commit 8bfc56c8 authored by daphtya's avatar daphtya
Browse files

fixed admin/add-page

parent fb5dfc2f
1 merge request!5Develop
Pipeline #14496 failed with stage
...@@ -8,15 +8,17 @@ from modules.tools.roles import Roles ...@@ -8,15 +8,17 @@ from modules.tools.roles import Roles
admin_route = Blueprint('admin', __name__, template_folder="templates") 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"]) @admin_route.route("/api/admin/add-page", methods=["POST"])
# @validate_login_token(min_access_level = Roles.SUPERADMIN) # @validate_login_token(min_access_level = Roles.SUPERADMIN)
def add_page(): def add_page():
data = request.get_json() 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 = db.User.objects.with_id(data.get("admin_id"))
admin.page_list.append(data.get("page_id")) admin.page_list.append(page.id)
print(admin.page_list)
admin.save() admin.save()
return jsonify({ return jsonify({
"status":200, "status":200,
......
...@@ -30,7 +30,6 @@ def get_top_page(): ...@@ -30,7 +30,6 @@ def get_top_page():
admin = admins[0] admin = admins[0]
del admin.password del admin.password
del admin.page_list del admin.page_list
print(admin)
resp["admin_subdata"].append(admin) resp["admin_subdata"].append(admin)
else: else:
resp["admin_subdata"].append(None) resp["admin_subdata"].append(None)
...@@ -74,7 +73,6 @@ def get_page(): ...@@ -74,7 +73,6 @@ def get_page():
admin = admins[0] admin = admins[0]
del admin.password del admin.password
del admin.page_list del admin.page_list
print(admin)
resp["admin_subdata"].append(admin) resp["admin_subdata"].append(admin)
else: else:
resp["admin_subdata"].append(None) resp["admin_subdata"].append(None)
...@@ -100,7 +98,58 @@ def get_page(): ...@@ -100,7 +98,58 @@ def get_page():
"message": str(e) "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"]) @page_route.route("/api/hidden/add-data", methods=["POST"])
def add_page(): def add_page():
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment