MR comments

- NO_ACCESS_ROLE_ID constant moved to models.py
- added docstring for batch create request body
This commit is contained in:
Davor 2022-07-21 14:14:22 +02:00
parent d140a1a6cb
commit 66b44ae1a0
3 changed files with 7 additions and 7 deletions

View file

@ -3,6 +3,8 @@ from database import db
class Role(db.Model): class Role(db.Model):
NO_ACCESS_ROLE_ID = 3
id = db.Column(Integer, primary_key=True) id = db.Column(Integer, primary_key=True)
name = db.Column(String(length=64)) name = db.Column(String(length=64))

View file

@ -1,6 +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 areas.roles import Role, RoleService
from helpers import KratosApi from helpers import KratosApi
from flask import current_app from flask import current_app
@ -9,8 +9,6 @@ from helpers.error_handler import KratosError
class UserService: class UserService:
no_access_role_id = 3
@staticmethod @staticmethod
def get_users(): def get_users():
res = KratosApi.get("/admin/identities").json() res = KratosApi.get("/admin/identities").json()
@ -39,7 +37,7 @@ class UserService:
app = App.query.filter_by(slug=ar["name"]).first() app = App.query.filter_by(slug=ar["name"]).first()
app_role = AppRole( app_role = AppRole(
user_id=res["id"], user_id=res["id"],
role_id=ar["role_id"] if "role_id" in ar else UserService.no_access_role_id, role_id=ar["role_id"] if "role_id" in ar else Role.NO_ACCESS_ROLE_ID,
app_id=app.id, app_id=app.id,
) )
@ -50,7 +48,7 @@ class UserService:
for app in all_apps: for app in all_apps:
app_role = AppRole( app_role = AppRole(
user_id=res["id"], user_id=res["id"],
role_id=UserService.no_access_role_id, role_id=Role.NO_ACCESS_ROLE_ID,
app_id=app.id, app_id=app.id,
) )
@ -100,8 +98,7 @@ class UserService:
@staticmethod @staticmethod
def post_multiple_users(data): def post_multiple_users(data):
# check if data is array # check if data is array
# for every item in array call Kratos - check if there can be batch create on Kratos # for every item in array call Kratos
# - if yes, what happens with the batch if there is at least one existing email
created_users = [] created_users = []
existing_users = [] existing_users = []
creation_failed_users = [] creation_failed_users = []

View file

@ -70,6 +70,7 @@ def delete_user(id):
@expects_json(schema_multiple) @expects_json(schema_multiple)
@admin_required() @admin_required()
def post_multiple_users(): def post_multiple_users():
"""Expects an array of user JSON schema in request body."""
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)