Skip to content

Commit

Permalink
feat(organization): adds command to list users
Browse files Browse the repository at this point in the history
Usage: python -m riocli organization users [OPTIONS]

  Lists all users in the organization.

Options:
  --help  Show this message and exit.
  • Loading branch information
pallabpain committed Jul 18, 2023
1 parent bbb5102 commit 992afca
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions riocli/organization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from riocli.constants import Colors
from riocli.organization.list import list_organizations
from riocli.organization.select import select_organization
from riocli.organization.users import list_users


@click.group(
Expand All @@ -32,5 +33,6 @@ def organization() -> None:
pass


organization.add_command(list_users)
organization.add_command(list_organizations)
organization.add_command(select_organization)
47 changes: 47 additions & 0 deletions riocli/organization/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2023 Rapyuta Robotics
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import click
from click_help_colors import HelpColorsCommand

from riocli.constants import Colors, Symbols
from riocli.organization.utils import get_organization_details
from riocli.utils import tabulate_data
from riocli.utils.context import get_root_context


@click.command(
'users',
cls=HelpColorsCommand,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
@click.pass_context
def list_users(ctx: click.Context) -> None:
"""
Lists all users in the organization.
"""
ctx = get_root_context(ctx)

try:
organization = get_organization_details(ctx.obj.data['organization_id'])
except Exception as e:
click.secho('{} Failed to get organization details'.format(Symbols.ERROR), fg=Colors.RED)
raise SystemExit(1) from e

users = organization.get('users')

data = [[u['guid'], '{} {}'.format(u['firstName'], u['lastName']), u['emailID'], u['state']] for u in users]

tabulate_data(data, headers=['GUID', 'Name', 'EmailID', 'Status'])
6 changes: 3 additions & 3 deletions riocli/organization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _api_call(
path: typing.Union[str, None] = None,
payload: typing.Union[typing.Dict, None] = None,
load_response: bool = True,
) -> typing.Any:
) -> typing.Dict:
config = Configuration()
coreapi_host = config.data.get(
'core_api_host',
Expand All @@ -51,5 +51,5 @@ def _api_call(
return data


def get_organization_details(organization_guid):
return _api_call(HttpMethod.GET, '{}/get'.format(organization_guid))
def get_organization_details(organization_guid: str) -> typing.Dict:
return _api_call(HttpMethod.GET, '{}/get'.format(organization_guid))

0 comments on commit 992afca

Please sign in to comment.