Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
35 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logging | ||
import click | ||
from NIPTool.load.user import load_user | ||
from flask.cli import with_appcontext, current_app | ||
from NIPTool.exeptions import NIPToolError | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
@click.command("user", short_help="load a user into db.") | ||
@click.option("-n", "--name", help="User name") | ||
@click.option("-r", "--role", help="User role") | ||
@click.option("-e", "--email", help="User email") | ||
@with_appcontext | ||
def user(name, role, email): | ||
"""Loading new user to db.""" | ||
|
||
try: | ||
load_user(current_app.adapter, email, name, role) | ||
except NIPToolError as e: | ||
LOG.error(e.message) | ||
raise click.Abort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
def load_user(adapter, email: str, name: str, role: str)-> None: | ||
"""Function to load a new user to the database.""" | ||
|
||
user = {'_id': email, 'email': email, 'name': name, 'role': role} | ||
adapter.add_or_update_document(user, adapter.user_collection) |