Skip to content

Commit

Permalink
feat(organiztion): adds command to remove user
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Aug 16, 2023
1 parent 4ae0974 commit 1da6003
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 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.invite_user import invite_user
from riocli.organization.list import list_organizations
from riocli.organization.remove_user import remove_user
from riocli.organization.select import select_organization
from riocli.organization.users import list_users

Expand All @@ -36,5 +37,6 @@ def organization() -> None:

organization.add_command(list_users)
organization.add_command(invite_user)
organization.add_command(remove_user)
organization.add_command(list_organizations)
organization.add_command(select_organization)
49 changes: 49 additions & 0 deletions riocli/organization/remove_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# 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 email_validator import EmailNotValidError, validate_email

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


@click.command(
'remove-user',
cls=HelpColorsCommand,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
@click.argument('user-email', type=str)
@click.pass_context
def remove_user(ctx: click.Context, user_email: str) -> None:
"""
Remove a user from the current organization
"""
ctx = get_root_context(ctx)

try:
validate_email(user_email)
except EmailNotValidError as e:
click.secho('{} {} is not a valid email address'.format(Symbols.ERROR, user_email), fg=Colors.RED)
raise SystemExit(1) from e

try:
remove_user_from_org(ctx.obj.data['organization_id'], user_email)
click.secho('{} User removed successfully.'.format(Symbols.SUCCESS), fg=Colors.GREEN)
except Exception as e:
click.secho('{} Failed to remove user: {}'.format(Symbols.ERROR, e), fg=Colors.RED)
raise SystemExit(1) from e
5 changes: 5 additions & 0 deletions riocli/organization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,8 @@ def get_organization_details(organization_guid: str) -> typing.Dict:
def invite_user_to_org(organization_guid: str, user_email: str) -> typing.Dict:
payload = {'userEmail': user_email}
return _api_call(HttpMethod.PUT, '{}/adduser'.format(organization_guid), payload=payload)


def remove_user_from_org(organization_guid: str, user_email: str) -> typing.Dict:
payload = {'userEmail': user_email}
return _api_call(HttpMethod.DELETE, '{}/removeuser'.format(organization_guid), payload=payload)

0 comments on commit 1da6003

Please sign in to comment.