Commit 149f7875904031174d034270f0fb95fe18136e31
1 parent
82642adb
Exists in
master
and in
4 other branches
Now user_add accepts role as arg
From a fix by Olivier Thauvin <olivier.thauvin@latmos.ipsl.fr>
Showing
1 changed file
with
12 additions
and
5 deletions
Show diff stats
app/commands/commands.py
... | ... | @@ -12,7 +12,7 @@ from sqlalchemy.orm import Session |
12 | 12 | from sqlalchemy import create_engine |
13 | 13 | |
14 | 14 | from app.models import db, Agent, Service, Project, Capacity, Period, Charge |
15 | -from app.auth.models import User | |
15 | +from app.auth.models import User, _nameToRole | |
16 | 16 | |
17 | 17 | from . import bp |
18 | 18 | |
... | ... | @@ -220,18 +220,25 @@ def create_db(): |
220 | 220 | @click.argument('name') |
221 | 221 | @click.argument('login') |
222 | 222 | @click.argument('password') |
223 | -def user_add(email, name, login, password): | |
223 | +@click.argument('role') | |
224 | +def user_add(email, name, login, password, role): | |
224 | 225 | """ Add a new user in db.""" |
225 | - user = User.query.filter(User.name==name).one_or_none() | |
226 | - if( user ): | |
226 | + user = User.query.filter(User.name == name).one_or_none() | |
227 | + if (user): | |
227 | 228 | current_app.logger.error(f"user already exists {name}") |
228 | 229 | return |
229 | - user = User(email=email, name=name, login=login, password=password) | |
230 | + user = User(email=email, name=name, login=login, password=password, role=role) | |
230 | 231 | db.session.add(user) |
231 | 232 | db.session.commit() |
232 | 233 | current_app.logger.info(f"added {name}") |
233 | 234 | |
234 | 235 | |
236 | +@bp.cli.command('show_roles') | |
237 | +def show_roles(): | |
238 | + """ List all available roles for a user""" | |
239 | + print("\n".join(list(_nameToRole))) | |
240 | + | |
241 | + | |
235 | 242 | @bp.cli.command('user_show_all') |
236 | 243 | def user_show_all(): |
237 | 244 | """ Show all users in db.""" | ... | ... |