merge with master
This commit is contained in:
commit
310b7ed8ff
4 changed files with 42 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
from database import db
|
from database import db
|
||||||
from areas.apps import App, AppRole, AppsService
|
from areas.apps import App, AppRole, AppsService
|
||||||
|
from areas.roles.role_service import RoleService
|
||||||
from helpers import KratosApi
|
from helpers import KratosApi
|
||||||
|
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
|
@ -57,14 +58,16 @@ class UserService:
|
||||||
return UserService.get_user(res["id"])
|
return UserService.get_user(res["id"])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def put_user(id, data):
|
def put_user(id, user_editing_id, data):
|
||||||
kratos_data = {
|
kratos_data = {
|
||||||
"schema_id": "default",
|
"schema_id": "default",
|
||||||
"traits": {"email": data["email"], "name": data["name"]},
|
"traits": {"email": data["email"], "name": data["name"]},
|
||||||
}
|
}
|
||||||
KratosApi.put("/admin/identities/{}".format(id), kratos_data)
|
KratosApi.put("/admin/identities/{}".format(id), kratos_data)
|
||||||
|
|
||||||
if data["app_roles"]:
|
is_admin = RoleService.is_user_admin(user_editing_id)
|
||||||
|
|
||||||
|
if is_admin and data["app_roles"]:
|
||||||
app_roles = data["app_roles"]
|
app_roles = data["app_roles"]
|
||||||
for ar in app_roles:
|
for ar in app_roles:
|
||||||
app = App.query.filter_by(slug=ar["name"]).first()
|
app = App.query.filter_by(slug=ar["name"]).first()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from flask import jsonify, request
|
from flask import jsonify, request
|
||||||
from flask_jwt_extended import jwt_required
|
from flask_jwt_extended import get_jwt, jwt_required
|
||||||
from flask_cors import cross_origin
|
from flask_cors import cross_origin
|
||||||
from flask_expects_json import expects_json
|
from flask_expects_json import expects_json
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ def get_users():
|
||||||
@api_v1.route("/users/<string:id>", methods=["GET"])
|
@api_v1.route("/users/<string:id>", methods=["GET"])
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
|
@admin_required()
|
||||||
def get_user(id):
|
def get_user(id):
|
||||||
res = UserService.get_user(id)
|
res = UserService.get_user(id)
|
||||||
return jsonify(res)
|
return jsonify(res)
|
||||||
|
@ -43,9 +44,11 @@ def post_user():
|
||||||
@jwt_required()
|
@jwt_required()
|
||||||
@cross_origin()
|
@cross_origin()
|
||||||
@expects_json(schema)
|
@expects_json(schema)
|
||||||
|
@admin_required()
|
||||||
def put_user(id):
|
def put_user(id):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
res = UserService.put_user(id, data)
|
user_id = __get_user_id_from_jwt()
|
||||||
|
res = UserService.put_user(id, user_id, data)
|
||||||
return jsonify(res)
|
return jsonify(res)
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,3 +73,28 @@ def post_multiple_users():
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
res = UserService.post_multiple_users(data)
|
res = UserService.post_multiple_users(data)
|
||||||
return jsonify(res)
|
return jsonify(res)
|
||||||
|
|
||||||
|
|
||||||
|
@api_v1.route("/me", methods=["GET"])
|
||||||
|
@jwt_required()
|
||||||
|
@cross_origin()
|
||||||
|
def get_personal_info():
|
||||||
|
user_id = __get_user_id_from_jwt()
|
||||||
|
res = UserService.get_user(user_id)
|
||||||
|
return jsonify(res)
|
||||||
|
|
||||||
|
|
||||||
|
@api_v1.route("/me", methods=["PUT"])
|
||||||
|
@jwt_required()
|
||||||
|
@cross_origin()
|
||||||
|
@expects_json(schema)
|
||||||
|
def update_personal_info():
|
||||||
|
data = request.get_json()
|
||||||
|
user_id = __get_user_id_from_jwt()
|
||||||
|
res = UserService.put_user(user_id, user_id, data)
|
||||||
|
return jsonify(res)
|
||||||
|
|
||||||
|
|
||||||
|
def __get_user_id_from_jwt():
|
||||||
|
claims = get_jwt()
|
||||||
|
return claims["user_id"]
|
||||||
|
|
|
@ -40,7 +40,7 @@ services:
|
||||||
- kube_port_mysql
|
- kube_port_mysql
|
||||||
entrypoint: ["bash", "-c", "flask run --host $$(hostname -i)"]
|
entrypoint: ["bash", "-c", "flask run --host $$(hostname -i)"]
|
||||||
kube_port_kratos_admin:
|
kube_port_kratos_admin:
|
||||||
image: bitnami/kubectl:1.24.2
|
image: bitnami/kubectl:1.24.3
|
||||||
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
||||||
expose:
|
expose:
|
||||||
- 8000
|
- 8000
|
||||||
|
@ -48,7 +48,7 @@ services:
|
||||||
- "$KUBECONFIG:/.kube/config"
|
- "$KUBECONFIG:/.kube/config"
|
||||||
entrypoint: ["bash", "-c", "kubectl -n stackspin port-forward --address $$(hostname -i) service/kratos-admin 8000:80"]
|
entrypoint: ["bash", "-c", "kubectl -n stackspin port-forward --address $$(hostname -i) service/kratos-admin 8000:80"]
|
||||||
kube_port_hydra_admin:
|
kube_port_hydra_admin:
|
||||||
image: bitnami/kubectl:1.24.2
|
image: bitnami/kubectl:1.24.3
|
||||||
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
||||||
expose:
|
expose:
|
||||||
- 4445
|
- 4445
|
||||||
|
@ -56,7 +56,7 @@ services:
|
||||||
- "$KUBECONFIG:/.kube/config"
|
- "$KUBECONFIG:/.kube/config"
|
||||||
entrypoint: ["bash", "-c", "kubectl -n stackspin port-forward --address $$(hostname -i) service/hydra-admin 4445:4445"]
|
entrypoint: ["bash", "-c", "kubectl -n stackspin port-forward --address $$(hostname -i) service/hydra-admin 4445:4445"]
|
||||||
kube_port_kratos_public:
|
kube_port_kratos_public:
|
||||||
image: bitnami/kubectl:1.24.2
|
image: bitnami/kubectl:1.24.3
|
||||||
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
|
@ -66,7 +66,7 @@ services:
|
||||||
- "$KUBECONFIG:/.kube/config"
|
- "$KUBECONFIG:/.kube/config"
|
||||||
entrypoint: ["bash", "-c", "kubectl -n stackspin port-forward --address $$(hostname -i) service/kratos-public 8080:80"]
|
entrypoint: ["bash", "-c", "kubectl -n stackspin port-forward --address $$(hostname -i) service/kratos-public 8080:80"]
|
||||||
kube_port_mysql:
|
kube_port_mysql:
|
||||||
image: bitnami/kubectl:1.24.2
|
image: bitnami/kubectl:1.24.3
|
||||||
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
user: "${KUBECTL_UID}:${KUBECTL_GID}"
|
||||||
expose:
|
expose:
|
||||||
- 3306
|
- 3306
|
||||||
|
|
|
@ -2,10 +2,10 @@ from functools import wraps
|
||||||
|
|
||||||
from areas.roles.role_service import RoleService
|
from areas.roles.role_service import RoleService
|
||||||
|
|
||||||
from flask_jwt_extended import verify_jwt_in_request
|
from flask_jwt_extended import get_jwt, verify_jwt_in_request
|
||||||
from flask_jwt_extended import get_jwt
|
|
||||||
from helpers import Unauthorized
|
from helpers import Unauthorized
|
||||||
|
|
||||||
|
|
||||||
def admin_required():
|
def admin_required():
|
||||||
def wrapper(fn):
|
def wrapper(fn):
|
||||||
@wraps(fn)
|
@wraps(fn)
|
||||||
|
|
Loading…
Reference in a new issue