Skip to content

Commit

Permalink
Merge f75fdbb into 0e5c51a
Browse files Browse the repository at this point in the history
  • Loading branch information
mayabrandi committed Sep 30, 2020
2 parents 0e5c51a + f75fdbb commit 9ae5d6f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion NIPTool/commands/load/base.py
Expand Up @@ -10,6 +10,7 @@

# commands
from NIPTool.commands.load.batch import batch as batch_command
from NIPTool.commands.load.user import user as load_user_cmd

# Get version and doc decorator
from NIPTool import __version__
Expand All @@ -23,4 +24,5 @@ def load():
pass


load.add_command(batch_command)
load.add_command(load_batch_cmd)
load.add_command(load_user_cmd)
23 changes: 23 additions & 0 deletions NIPTool/commands/load/user.py
@@ -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()
7 changes: 7 additions & 0 deletions NIPTool/load/user.py
@@ -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)

0 comments on commit 9ae5d6f

Please sign in to comment.