Skip to content

Commit

Permalink
Minor: Add ability to invite user in cloud & all projects (#744)
Browse files Browse the repository at this point in the history
* Minor: Add ability to invite user in cloud & all projects

* Improve performance & fixes

* Fix cloud invite when project invite already exists

* Fix more bugs in invitation process.

* Fix bug where last admin can leave if an admin invit exists.

* Remove useless sql query.
  • Loading branch information
Bimdata-io committed May 20, 2024
1 parent 157b488 commit 5f6f792
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ Class | Method | HTTP request | Description
*CollaborationApi* | [**get_visas**](docs/CollaborationApi.md#get_visas) | **GET** /cloud/{cloud_pk}/project/{project_pk}/document/{document_pk}/visa | List all visas of a document
*CollaborationApi* | [**import_from_project**](docs/CollaborationApi.md#import_from_project) | **POST** /cloud/{cloud_pk}/project/{id}/import_from | Import data from a project
*CollaborationApi* | [**import_manage_group**](docs/CollaborationApi.md#import_manage_group) | **POST** /cloud/{cloud_pk}/project/{project_pk}/group/import | Import a group from another project
*CollaborationApi* | [**invite_cloud_user**](docs/CollaborationApi.md#invite_cloud_user) | **POST** /cloud/{cloud_pk}/invitation | Invite a cloud administrator
*CollaborationApi* | [**invite_cloud_user**](docs/CollaborationApi.md#invite_cloud_user) | **POST** /cloud/{cloud_pk}/invitation | Invite a cloud member
*CollaborationApi* | [**invite_project_user**](docs/CollaborationApi.md#invite_project_user) | **POST** /cloud/{cloud_pk}/project/{project_pk}/invitation | Invite a project member
*CollaborationApi* | [**leave_project**](docs/CollaborationApi.md#leave_project) | **POST** /cloud/{cloud_pk}/project/{id}/leave | Leave the project
*CollaborationApi* | [**leave_version_document_history**](docs/CollaborationApi.md#leave_version_document_history) | **POST** /cloud/{cloud_pk}/project/{project_pk}/document/{document_pk}/history/{id}/leave | Leave the history version
Expand Down Expand Up @@ -758,7 +758,7 @@ Class | Method | HTTP request | Description

- **Type**: OAuth
- **Flow**: implicit
- **Authorization URL**: http://fakeurl.bimdata.io/realms/bimdata/protocol/openid-connect/auth
- **Authorization URL**: http://fakeurl.bimdata.example/realms/bimdata/protocol/openid-connect/auth
- **Scopes**: N/A


Expand Down
6 changes: 3 additions & 3 deletions bimdata_api_client/api/collaboration_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8741,7 +8741,7 @@ def create_document(
):
"""Create a document # noqa: E501

Create a document. If the document is one of {'OBJ', 'DWG', 'POINT_CLOUD', 'DXF', 'IFC', 'GLTF'}, a model will be created and attached to this document Required scopes: document:write # noqa: E501
Create a document. If the document is one of {'OBJ', 'POINT_CLOUD', 'DXF', 'DWG', 'GLTF', 'IFC'}, a model will be created and attached to this document Required scopes: document:write # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True

Expand Down Expand Up @@ -15038,9 +15038,9 @@ def invite_cloud_user(
cloud_invitation_request,
**kwargs
):
"""Invite a cloud administrator # noqa: E501
"""Invite a cloud member # noqa: E501

Invite cloud administrators only. To invite in a project, see inviteProjectUser. You can't invite a user already in the cloud. Create multiple invitations of the same email in the same cloud will generate multiple invitation emails but not multiple invitation object Required scopes: org:manage # noqa: E501
Invite a cloud member. To invite in a project, see inviteProjectUser. You can't invite a user already in the cloud. Create multiple invitations of the same email in the same cloud will generate multiple invitation emails but not multiple invitation object Required scopes: org:manage # noqa: E501
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True

Expand Down
21 changes: 17 additions & 4 deletions bimdata_api_client/model/cloud_invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ class CloudInvitation(ModelNormal):
'100': 100,
'50': 50,
},
('project_role',): {
'100': 100,
'50': 50,
'25': 25,
},
}

validations = {
Expand Down Expand Up @@ -96,6 +101,8 @@ def openapi_types():
'email': (str,), # noqa: E501
'redirect_uri': (str,), # noqa: E501
'role': (int,), # noqa: E501
'project_role': (int,), # noqa: E501
'in_all_projects': (bool,), # noqa: E501
}

@cached_property
Expand All @@ -108,25 +115,25 @@ def discriminator():
'email': 'email', # noqa: E501
'redirect_uri': 'redirect_uri', # noqa: E501
'role': 'role', # noqa: E501
'project_role': 'project_role', # noqa: E501
'in_all_projects': 'in_all_projects', # noqa: E501
}

read_only_vars = {
'id', # noqa: E501
'role', # noqa: E501
}

_composed_schemas = {}

@classmethod
@convert_js_args_to_python_args
def _from_openapi_data(cls, id, email, redirect_uri, role, *args, **kwargs): # noqa: E501
def _from_openapi_data(cls, id, email, redirect_uri, *args, **kwargs): # noqa: E501
"""CloudInvitation - a model defined in OpenAPI
Args:
id (int):
email (str): email of the user to invite
redirect_uri (str): User will be redirected to this uri when they accept the invitation
role (int): * `100` - admin * `50` - user
Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
Expand Down Expand Up @@ -159,6 +166,9 @@ def _from_openapi_data(cls, id, email, redirect_uri, role, *args, **kwargs): #
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
role (int): * `100` - admin * `50` - user. [optional] if omitted the server will use the default value of 100 # noqa: E501
project_role (int): * `100` - admin * `50` - user * `25` - guest. [optional] # noqa: E501
in_all_projects (bool): When inviting non-admin cloud user, specify if the user will be invited in all existing projects. project_role needs to be specified.. [optional] if omitted the server will use the default value of False # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down Expand Up @@ -189,7 +199,6 @@ def _from_openapi_data(cls, id, email, redirect_uri, role, *args, **kwargs): #
self.id = id
self.email = email
self.redirect_uri = redirect_uri
self.role = role
for var_name, var_value in kwargs.items():
if var_name not in self.attribute_map and \
self._configuration is not None and \
Expand All @@ -215,6 +224,7 @@ def __init__(self, email, redirect_uri, *args, **kwargs): # noqa: E501
email (str): email of the user to invite
redirect_uri (str): User will be redirected to this uri when they accept the invitation
Keyword Args:
_check_type (bool): if True, values for parameters in openapi_types
will be type checked and a TypeError will be
Expand Down Expand Up @@ -246,6 +256,9 @@ def __init__(self, email, redirect_uri, *args, **kwargs): # noqa: E501
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
role (int): * `100` - admin * `50` - user. [optional] if omitted the server will use the default value of 100 # noqa: E501
project_role (int): * `100` - admin * `50` - user * `25` - guest. [optional] # noqa: E501
in_all_projects (bool): When inviting non-admin cloud user, specify if the user will be invited in all existing projects. project_role needs to be specified.. [optional] if omitted the server will use the default value of False # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down
21 changes: 21 additions & 0 deletions bimdata_api_client/model/cloud_invitation_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ class CloudInvitationRequest(ModelNormal):
"""

allowed_values = {
('role',): {
'100': 100,
'50': 50,
},
('project_role',): {
'100': 100,
'50': 50,
'25': 25,
},
}

validations = {
Expand Down Expand Up @@ -92,6 +101,9 @@ def openapi_types():
return {
'email': (str,), # noqa: E501
'redirect_uri': (str,), # noqa: E501
'role': (int,), # noqa: E501
'project_role': (int,), # noqa: E501
'in_all_projects': (bool,), # noqa: E501
}

@cached_property
Expand All @@ -102,6 +114,9 @@ def discriminator():
attribute_map = {
'email': 'email', # noqa: E501
'redirect_uri': 'redirect_uri', # noqa: E501
'role': 'role', # noqa: E501
'project_role': 'project_role', # noqa: E501
'in_all_projects': 'in_all_projects', # noqa: E501
}

read_only_vars = {
Expand Down Expand Up @@ -149,6 +164,9 @@ def _from_openapi_data(cls, email, redirect_uri, *args, **kwargs): # noqa: E501
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
role (int): * `100` - admin * `50` - user. [optional] if omitted the server will use the default value of 100 # noqa: E501
project_role (int): * `100` - admin * `50` - user * `25` - guest. [optional] # noqa: E501
in_all_projects (bool): When inviting non-admin cloud user, specify if the user will be invited in all existing projects. project_role needs to be specified.. [optional] if omitted the server will use the default value of False # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down Expand Up @@ -236,6 +254,9 @@ def __init__(self, email, redirect_uri, *args, **kwargs): # noqa: E501
Animal class but this time we won't travel
through its discriminator because we passed in
_visited_composed_classes = (Animal,)
role (int): * `100` - admin * `50` - user. [optional] if omitted the server will use the default value of 100 # noqa: E501
project_role (int): * `100` - admin * `50` - user * `25` - guest. [optional] # noqa: E501
in_all_projects (bool): When inviting non-admin cloud user, specify if the user will be invited in all existing projects. project_role needs to be specified.. [optional] if omitted the server will use the default value of False # noqa: E501
"""

_check_type = kwargs.pop('_check_type', True)
Expand Down
4 changes: 3 additions & 1 deletion docs/CloudInvitation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Name | Type | Description | Notes
**id** | **int** | | [readonly]
**email** | **str** | email of the user to invite |
**redirect_uri** | **str** | User will be redirected to this uri when they accept the invitation |
**role** | **int** | * `100` - admin * `50` - user | [readonly]
**role** | **int** | * `100` - admin * `50` - user | [optional] if omitted the server will use the default value of 100
**project_role** | **int** | * `100` - admin * `50` - user * `25` - guest | [optional]
**in_all_projects** | **bool** | When inviting non-admin cloud user, specify if the user will be invited in all existing projects. project_role needs to be specified. | [optional] if omitted the server will use the default value of False
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
3 changes: 3 additions & 0 deletions docs/CloudInvitationRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**email** | **str** | email of the user to invite |
**redirect_uri** | **str** | User will be redirected to this uri when they accept the invitation |
**role** | **int** | * `100` - admin * `50` - user | [optional] if omitted the server will use the default value of 100
**project_role** | **int** | * `100` - admin * `50` - user * `25` - guest | [optional]
**in_all_projects** | **bool** | When inviting non-admin cloud user, specify if the user will be invited in all existing projects. project_role needs to be specified. | [optional] if omitted the server will use the default value of False
**any string name** | **bool, date, datetime, dict, float, int, list, str, none_type** | any string name can be used but the value must be the correct type | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
Expand Down
13 changes: 8 additions & 5 deletions docs/CollaborationApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Method | HTTP request | Description
[**get_visas**](CollaborationApi.md#get_visas) | **GET** /cloud/{cloud_pk}/project/{project_pk}/document/{document_pk}/visa | List all visas of a document
[**import_from_project**](CollaborationApi.md#import_from_project) | **POST** /cloud/{cloud_pk}/project/{id}/import_from | Import data from a project
[**import_manage_group**](CollaborationApi.md#import_manage_group) | **POST** /cloud/{cloud_pk}/project/{project_pk}/group/import | Import a group from another project
[**invite_cloud_user**](CollaborationApi.md#invite_cloud_user) | **POST** /cloud/{cloud_pk}/invitation | Invite a cloud administrator
[**invite_cloud_user**](CollaborationApi.md#invite_cloud_user) | **POST** /cloud/{cloud_pk}/invitation | Invite a cloud member
[**invite_project_user**](CollaborationApi.md#invite_project_user) | **POST** /cloud/{cloud_pk}/project/{project_pk}/invitation | Invite a project member
[**leave_project**](CollaborationApi.md#leave_project) | **POST** /cloud/{cloud_pk}/project/{id}/leave | Leave the project
[**leave_version_document_history**](CollaborationApi.md#leave_version_document_history) | **POST** /cloud/{cloud_pk}/project/{project_pk}/document/{document_pk}/history/{id}/leave | Leave the history version
Expand Down Expand Up @@ -1541,7 +1541,7 @@ Name | Type | Description | Notes
Create a document

Create a document. If the document is one of {'OBJ', 'DWG', 'POINT_CLOUD', 'DXF', 'IFC', 'GLTF'}, a model will be created and attached to this document Required scopes: document:write
Create a document. If the document is one of {'OBJ', 'POINT_CLOUD', 'DXF', 'DWG', 'GLTF', 'IFC'}, a model will be created and attached to this document Required scopes: document:write

### Example

Expand Down Expand Up @@ -9616,9 +9616,9 @@ Name | Type | Description | Notes
# **invite_cloud_user**
> CloudInvitation invite_cloud_user(cloud_pk, cloud_invitation_request)
Invite a cloud administrator
Invite a cloud member

Invite cloud administrators only. To invite in a project, see inviteProjectUser. You can't invite a user already in the cloud. Create multiple invitations of the same email in the same cloud will generate multiple invitation emails but not multiple invitation object Required scopes: org:manage
Invite a cloud member. To invite in a project, see inviteProjectUser. You can't invite a user already in the cloud. Create multiple invitations of the same email in the same cloud will generate multiple invitation emails but not multiple invitation object Required scopes: org:manage

### Example

Expand Down Expand Up @@ -9677,11 +9677,14 @@ with bimdata_api_client.ApiClient(configuration) as api_client:
cloud_invitation_request = CloudInvitationRequest(
email="email_example",
redirect_uri="redirect_uri_example",
role=100,
project_role=100,
in_all_projects=False,
) # CloudInvitationRequest |

# example passing only required values which don't have defaults set
try:
# Invite a cloud administrator
# Invite a cloud member
api_response = api_instance.invite_cloud_user(cloud_pk, cloud_invitation_request)
pprint(api_response)
except bimdata_api_client.ApiException as e:
Expand Down
2 changes: 1 addition & 1 deletion test/test_collaboration_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_import_manage_group(self):
def test_invite_cloud_user(self):
"""Test case for invite_cloud_user
Invite a cloud administrator # noqa: E501
Invite a cloud member # noqa: E501
"""
pass

Expand Down

0 comments on commit 5f6f792

Please sign in to comment.