Skip to content

Commit

Permalink
feat(organization): adds command to invite user
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Sep 27, 2023
1 parent baa823d commit b99fb5f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ yaspin = ">=2.3.0"
jsonschema = ">=4.0.0"
waiting = ">=1.4.1"
semver = ">=3.0.0"
email-validator = "==2.0.0.post2"

[requires]
python_version = "3"
18 changes: 17 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions riocli/organization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from riocli.constants import Colors
from riocli.organization.inspect import inspect_organization
from riocli.organization.invite_user import invite_user
from riocli.organization.list import list_organizations
from riocli.organization.select import select_organization
from riocli.organization.users import list_users
Expand All @@ -35,6 +36,7 @@ def organization() -> None:


organization.add_command(list_users)
organization.add_command(invite_user)
organization.add_command(list_organizations)
organization.add_command(select_organization)
organization.add_command(inspect_organization)
49 changes: 49 additions & 0 deletions riocli/organization/invite_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 invite_user_to_org
from riocli.utils.context import get_root_context


@click.command(
'invite-user',
cls=HelpColorsCommand,
help_headers_color=Colors.YELLOW,
help_options_color=Colors.GREEN,
)
@click.argument('user-email', type=str)
@click.pass_context
def invite_user(ctx: click.Context, user_email: str) -> None:
"""
Invite a new user to 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:
invite_user_to_org(ctx.obj.data['organization_id'], user_email)
click.secho('{} User invited successfully.'.format(Symbols.SUCCESS), fg=Colors.GREEN)
except Exception as e:
click.secho('{} Failed to invite 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 @@ -53,3 +53,8 @@ def _api_call(

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


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)
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import re

from setuptools import setup, find_packages
from setuptools import find_packages, setup

version = re.search(
'^__version__\s*=\s*"(.*)"', open("riocli/bootstrap.py").read(), re.M
Expand Down Expand Up @@ -59,6 +59,7 @@
"jsonschema==4.0.0",
"waiting>=1.4.1",
"semver>=3.0.0",
"email-validator==2.0.0.post2",
],
setup_requires=["flake8"],
)

0 comments on commit b99fb5f

Please sign in to comment.