Fix setrole cli function
This commit is contained in:
parent
3c8c900d2c
commit
0ef90ecc1e
1 changed files with 5 additions and 1 deletions
|
@ -11,10 +11,12 @@ import ory_kratos_client
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
from flask.cli import AppGroup
|
from flask.cli import AppGroup
|
||||||
from ory_kratos_client.api import v0alpha2_api as kratos_api
|
from ory_kratos_client.api import v0alpha2_api as kratos_api
|
||||||
|
from sqlalchemy import func
|
||||||
|
|
||||||
from config import *
|
from config import *
|
||||||
from helpers import KratosUser
|
from helpers import KratosUser
|
||||||
from cliapp import cli
|
from cliapp import cli
|
||||||
|
from areas.roles import Role
|
||||||
from areas.apps import AppRole, App
|
from areas.apps import AppRole, App
|
||||||
from database import db
|
from database import db
|
||||||
|
|
||||||
|
@ -136,10 +138,12 @@ def setrole(email, app_slug, role):
|
||||||
if role_obj:
|
if role_obj:
|
||||||
db.session.delete(role_obj)
|
db.session.delete(role_obj)
|
||||||
|
|
||||||
|
role = Role.query.filter(func.lower(Role.name) == func.lower(role)).first()
|
||||||
|
|
||||||
obj = AppRole()
|
obj = AppRole()
|
||||||
obj.user_id = user.uuid
|
obj.user_id = user.uuid
|
||||||
obj.app_id = app_obj.id
|
obj.app_id = app_obj.id
|
||||||
obj.role = role
|
obj.role_id = role.id if role else None
|
||||||
|
|
||||||
db.session.add(obj)
|
db.session.add(obj)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Loading…
Reference in a new issue