import json from flask import Blueprint, request, jsonify, g from blueprints.admin.utils import role_required from utils import setting_loader, logger from utils.misc import error # prefix: /admin/setting bl_admin_setting = Blueprint("admin_setting", __name__) # get settings @bl_admin_setting.route("/", methods=["GET"]) @role_required(["setting.edit"]) def setting_get(): return jsonify(setting_loader.loadset()), 200 # edit settings @bl_admin_setting.route("/", methods=["POST"]) @role_required(["setting.edit"]) def setting_edit(): opuser = g.opuser.user req = request.json d = None for r in req: d = setting_loader.writeset(r, req.get(r)) if d == 0: return error("Failed"), 401 logger.logger("setting.modify", "User:%s modified settings: %s"%(opuser, json.dumps(request.json))) return jsonify(d), 200