From 149f7875904031174d034270f0fb95fe18136e31 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Thu, 15 Apr 2021 16:29:45 +0200 Subject: [PATCH] Now user_add accepts role as arg --- app/commands/commands.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/app/commands/commands.py b/app/commands/commands.py index 4282b43..f2672b8 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -12,7 +12,7 @@ from sqlalchemy.orm import Session from sqlalchemy import create_engine from app.models import db, Agent, Service, Project, Capacity, Period, Charge -from app.auth.models import User +from app.auth.models import User, _nameToRole from . import bp @@ -220,18 +220,25 @@ def create_db(): @click.argument('name') @click.argument('login') @click.argument('password') -def user_add(email, name, login, password): +@click.argument('role') +def user_add(email, name, login, password, role): """ Add a new user in db.""" - user = User.query.filter(User.name==name).one_or_none() - if( user ): + user = User.query.filter(User.name == name).one_or_none() + if (user): current_app.logger.error(f"user already exists {name}") return - user = User(email=email, name=name, login=login, password=password) + user = User(email=email, name=name, login=login, password=password, role=role) db.session.add(user) db.session.commit() current_app.logger.info(f"added {name}") +@bp.cli.command('show_roles') +def show_roles(): + """ List all available roles for a user""" + print("\n".join(list(_nameToRole))) + + @bp.cli.command('user_show_all') def user_show_all(): """ Show all users in db.""" -- libgit2 0.21.2