From 66b44ae1a02ad3533ef27f4760e2da4ebbf81bb8 Mon Sep 17 00:00:00 2001 From: Davor Date: Thu, 21 Jul 2022 14:14:22 +0200 Subject: [PATCH] MR comments - NO_ACCESS_ROLE_ID constant moved to models.py - added docstring for batch create request body --- areas/roles/models.py | 2 ++ areas/users/user_service.py | 11 ++++------- areas/users/users.py | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/areas/roles/models.py b/areas/roles/models.py index 8f7c53a..d822901 100644 --- a/areas/roles/models.py +++ b/areas/roles/models.py @@ -3,6 +3,8 @@ from database import db class Role(db.Model): + NO_ACCESS_ROLE_ID = 3 + id = db.Column(Integer, primary_key=True) name = db.Column(String(length=64)) diff --git a/areas/users/user_service.py b/areas/users/user_service.py index 2ad5a73..772af99 100644 --- a/areas/users/user_service.py +++ b/areas/users/user_service.py @@ -1,6 +1,6 @@ from database import db 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 flask import current_app @@ -9,8 +9,6 @@ from helpers.error_handler import KratosError class UserService: - no_access_role_id = 3 - @staticmethod def get_users(): res = KratosApi.get("/admin/identities").json() @@ -39,7 +37,7 @@ class UserService: app = App.query.filter_by(slug=ar["name"]).first() app_role = AppRole( 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, ) @@ -50,7 +48,7 @@ class UserService: for app in all_apps: app_role = AppRole( user_id=res["id"], - role_id=UserService.no_access_role_id, + role_id=Role.NO_ACCESS_ROLE_ID, app_id=app.id, ) @@ -100,8 +98,7 @@ class UserService: @staticmethod def post_multiple_users(data): # check if data is array - # for every item in array call Kratos - check if there can be batch create on Kratos - # - if yes, what happens with the batch if there is at least one existing email + # for every item in array call Kratos created_users = [] existing_users = [] creation_failed_users = [] diff --git a/areas/users/users.py b/areas/users/users.py index 1ef36cd..08f22c6 100644 --- a/areas/users/users.py +++ b/areas/users/users.py @@ -70,6 +70,7 @@ def delete_user(id): @expects_json(schema_multiple) @admin_required() def post_multiple_users(): + """Expects an array of user JSON schema in request body.""" data = request.get_json() res = UserService.post_multiple_users(data) return jsonify(res)