Skip to content

Commit

Permalink
Merge be410b1 into 0e5c51a
Browse files Browse the repository at this point in the history
  • Loading branch information
mayabrandi committed Sep 30, 2020
2 parents 0e5c51a + be410b1 commit 7b482a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
16 changes: 5 additions & 11 deletions NIPTool/commands/load/base.py
@@ -1,19 +1,12 @@
#!/usr/bin/env python
import logging

import click

from mongo_adapter import get_client
from NIPTool.adapter import NiptAdapter

LOG = logging.getLogger(__name__)

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

# Get version and doc decorator
# Get version
from NIPTool import __version__
from NIPTool.tools.cli_utils import add_doc as doc


@click.group()
Expand All @@ -23,4 +16,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 7b482a9

Please sign in to comment.