add command adduser

This commit is contained in:
Cayo Puigdefabregas 2023-06-15 17:56:34 +02:00
parent fad008b25d
commit 5f1c7c8b4a
3 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,24 @@
import click
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.agent.models import Person
from ereuse_devicehub.resources.user.models import User
class AddUser:
def __init__(self, app) -> None:
super().__init__()
self.app = app
self.schema = app.config.get('DB_SCHEMA')
self.app.cli.command('adduser', short_help='add a user.')(self.run)
@click.argument('email')
@click.argument('password')
def run(self, email, password):
name = email.split('@')[0]
user = User(email=email, password=password)
user.individuals.add(Person(name=name))
db.session.add(user)
db.session.commit()

View file

@ -1,6 +1,5 @@
from uuid import uuid4
import click
from boltons.urlutils import URL
from ereuse_devicehub.db import db

View file

@ -12,6 +12,7 @@ from flask_sqlalchemy import SQLAlchemy
import ereuse_devicehub.ereuse_utils.cli
from ereuse_devicehub.auth import Auth
from ereuse_devicehub.client import Client, UserClient
from ereuse_devicehub.commands.adduser import AddUser
from ereuse_devicehub.commands.initdatas import InitDatas
# from ereuse_devicehub.commands.reports import Report
@ -75,6 +76,7 @@ class Devicehub(Teal):
# self.report = Report(self)
self.get_token = GetToken(self)
self.initdata = InitDatas(self)
self.adduser = AddUser(self)
@self.cli.group(
short_help='Inventory management.',