Skip to content

Commit 1b0d99a

Browse files
turalfturalf
andauthored
Add Cloud environment for Teams user (#16359)
* Add cloud environment enum * Add cloud environemnt to CommunicationIdentifierModel * Rename CommunicationCloudEnvironment * Add cloud environemtn to serialize/deserialzie * Rearrange microsoft teams user class position * Rename the kwarg name * Add cloud env into tests * Fix typos in identifier kind enums * Add cloud to serialize/deserialize tests for teams user * remove unused import * Add identifier to the identifier to the microsoft teams user model * Add idenitifier to the phone number * Add ids to the tests * Make id mandatory for deserilize * Fix lint error * Add identifier to the doc string * Throw when identifier type is not supported * Fix typo in test name * Add test_serialize_foreign_throws * Add test for unknown kind * Fix docstring for serialize method * Fix the typo in anonymous * Fix phone number doc string * Sync model to admin and chat * Fix the docstring for CommunicationIdentifierModel * Remove dev-tools * add mgmt core to setup py for mgmt package * Update the core dependency in mgmt package. * Sync models to admin, sms, identity * Change the exception message * Add idnetifier check in the test * sync model to other packages * Remove unnecessary mgmt dependency * change identity to identifier in docstrings * change core forzen requirement for identity * Change docstring for sms * Override shared reqs for core * Fix forzen requirements for core and sms * change core dependency version in chat,sms,admin * Add mgmt core back to the dependency * Add a new line at the end of file Co-authored-by: turalf <[email protected]>
1 parent 89e7f4b commit 1b0d99a

File tree

15 files changed

+456
-86
lines changed

15 files changed

+456
-86
lines changed

sdk/communication/azure-communication-administration/azure/communication/administration/_shared/models.py

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Copyright (c) Microsoft Corporation.
33
# Licensed under the MIT License.
44
# ------------------------------------
5+
# pylint: skip-file
6+
7+
from enum import Enum, EnumMeta
8+
from six import with_metaclass
9+
10+
import msrest
511

612
class CommunicationUserIdentifier(object):
713
"""
@@ -17,13 +23,14 @@ def __init__(self, identifier):
1723
class PhoneNumberIdentifier(object):
1824
"""
1925
Represents a phone number.
20-
:ivar value: Value for a phone number.
21-
:vartype value: str
22-
:param value: Value to initialize PhoneNumberIdentifier.
23-
:type value: str
26+
:param phone_number: The phone number in E.164 format.
27+
:type phone_number: str
28+
:param identifier: The full id of the phone number.
29+
:type identifier: str
2430
"""
25-
def __init__(self, phone_number):
31+
def __init__(self, phone_number, identifier=None):
2632
self.phone_number = phone_number
33+
self.identifier = identifier
2734

2835
class UnknownIdentifier(object):
2936
"""
@@ -38,18 +45,102 @@ class UnknownIdentifier(object):
3845
def __init__(self, identifier):
3946
self.identifier = identifier
4047

48+
class CommunicationIdentifierModel(msrest.serialization.Model):
49+
"""Communication Identifier Model.
50+
51+
All required parameters must be populated in order to send to Azure.
52+
53+
:param kind: Required. Kind of Communication Identifier.
54+
:type kind: CommunicationIdentifierKind
55+
:param id: Full id of the identifier.
56+
:type id: str
57+
:param phone_number: phone number in case the identifier is a phone number.
58+
:type phone_number: str
59+
:param is_anonymous: True if the identifier is anonymous.
60+
:type is_anonymous: bool
61+
:param microsoft_teams_user_id: Microsoft Teams user id.
62+
:type microsoft_teams_user_id: str
63+
:param communication_cloud_environment: Cloud environment that the user belongs to.
64+
:type communication_cloud_environment: CommunicationCloudEnvironment
65+
"""
66+
67+
_validation = {
68+
'kind': {'required': True},
69+
}
70+
71+
_attribute_map = {
72+
'kind': {'key': 'kind', 'type': 'str'},
73+
'id': {'key': 'id', 'type': 'str'},
74+
'phone_number': {'key': 'phoneNumber', 'type': 'str'},
75+
'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'},
76+
'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'},
77+
'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'},
78+
}
79+
80+
def __init__(
81+
self,
82+
**kwargs
83+
):
84+
super(CommunicationIdentifierModel, self).__init__(**kwargs)
85+
self.kind = kwargs['kind']
86+
self.id = kwargs.get('id', None)
87+
self.phone_number = kwargs.get('phone_number', None)
88+
self.is_anonymous = kwargs.get('is_anonymous', None)
89+
self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None)
90+
self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None)
91+
92+
class _CaseInsensitiveEnumMeta(EnumMeta):
93+
def __getitem__(cls, name):
94+
return super().__getitem__(name.upper())
95+
96+
def __getattr__(cls, name):
97+
"""Return the enum member matching `name`
98+
We use __getattr__ instead of descriptors or inserting into the enum
99+
class' __dict__ in order to support `name` and `value` being both
100+
properties for enum members (which live in the class' __dict__) and
101+
enum members themselves.
102+
"""
103+
try:
104+
return cls._member_map_[name.upper()]
105+
except KeyError:
106+
raise AttributeError(name)
107+
108+
class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
109+
"""Communication Identifier Kind.
110+
"""
111+
Unknown = "UNKNOWN"
112+
CommunicationUser = "COMMUNICATIONUSER"
113+
PhoneNumber = "PHONENUMBER"
114+
CallingApplication = "CALLINGAPPLICATION"
115+
MicrosoftTeamsUser = "MICROSOFTTEAMSUSER"
116+
117+
class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
118+
"""
119+
The cloud enviornment that the identifier belongs to
120+
"""
121+
122+
Public = "PUBLIC"
123+
Dod = "DOD"
124+
Gcch = "GCCH"
125+
41126
class MicrosoftTeamsUserIdentifier(object):
42127
"""
43128
Represents an identifier for a Microsoft Teams user.
44-
:ivar user_id: the string identifier representing the identity
129+
:ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.
45130
:vartype user_id: str
46131
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
47132
:type user_id: str
133+
:ivar identifier: The full id of the Microsoft Teams User identifier.
134+
:vartype identifier: str
135+
:ivar cloud: Cloud environment that this identifier belongs to
136+
:vartype cloud: CommunicationCloudEnvironment
48137
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
49138
:vartype is_anonymous: bool
50139
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
51140
:type is_anonymous: bool
52141
"""
53-
def __init__(self, user_id, is_anonymous=False):
142+
def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False):
143+
self.identifier = identifier
54144
self.user_id = user_id
55145
self.is_anonymous = is_anonymous
146+
self.cloud = cloud

sdk/communication/azure-communication-administration/dev_requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
-e ../../../tools/azure-sdk-tools
2-
-e ../../../tools/azure-devtools
32
-e ../../identity/azure-identity
43
../../core/azure-core
54
../azure-communication-nspkg

sdk/communication/azure-communication-administration/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
]),
6565
install_requires=[
6666
"msrest>=0.6.0",
67-
"azure-core<2.0.0,>=1.6.0",
67+
"azure-core<2.0.0,>=1.9.0",
6868
],
6969
extras_require={
7070
":python_version<'3.0'": ['azure-communication-nspkg'],

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/communication_identifier_serializer.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class CommunicationUserIdentifierSerializer(object):
1919
def serialize(cls, communicationIdentifier):
2020
""" Serialize the Communication identifier into CommunicationIdentifierModel
2121
22-
:param identifier: Communication service identifier
23-
:type identifier: Union[CommunicationUserIdentifier, CommunicationPhoneNumberIdentifier]
22+
:param identifier: Identifier object
23+
:type identifier: Union[CommunicationUserIdentifier,
24+
PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier, UnknownIdentifier]
2425
:return: CommunicationIdentifierModel
2526
:rtype: ~azure.communication.chat.CommunicationIdentifierModel
27+
:raises Union[TypeError, ValueError]
2628
"""
2729
if isinstance(communicationIdentifier, CommunicationUserIdentifier):
2830
return CommunicationIdentifierModel(
@@ -32,18 +34,24 @@ def serialize(cls, communicationIdentifier):
3234
if isinstance(communicationIdentifier, PhoneNumberIdentifier):
3335
return CommunicationIdentifierModel(
3436
kind=CommunicationIdentifierKind.PhoneNumber,
35-
id=communicationIdentifier.phone_number
37+
id=communicationIdentifier.identifier,
38+
phone_number=communicationIdentifier.phone_number
3639
)
3740
if isinstance(communicationIdentifier, MicrosoftTeamsUserIdentifier):
3841
return CommunicationIdentifierModel(
3942
kind=CommunicationIdentifierKind.MicrosoftTeamsUser,
40-
id=communicationIdentifier.user_id
43+
id=communicationIdentifier.identifier,
44+
microsoft_teams_user_id=communicationIdentifier.user_id,
45+
communication_cloud_environment=communicationIdentifier.cloud
4146
)
4247

43-
return CommunicationIdentifierModel(
44-
kind=CommunicationIdentifierKind.Unknown,
45-
id=communicationIdentifier.identifier
46-
)
48+
if isinstance(communicationIdentifier, UnknownIdentifier):
49+
return CommunicationIdentifierModel(
50+
kind=CommunicationIdentifierKind.Unknown,
51+
id=communicationIdentifier.identifier
52+
)
53+
54+
raise TypeError("Unsupported identifier type " + communicationIdentifier.__class__.__name__)
4755

4856
@classmethod
4957
def deserialize(cls, identifierModel):
@@ -58,26 +66,27 @@ def deserialize(cls, identifierModel):
5866
"""
5967

6068
identifier, kind = identifierModel.id, identifierModel.kind
69+
if not identifier:
70+
raise ValueError("Identifier must have a valid id")
6171

6272
if kind == CommunicationIdentifierKind.CommunicationUser:
63-
if not identifier:
64-
raise ValueError("CommunictionUser must have a valid id")
6573
return CommunicationUserIdentifier(id)
6674
if kind == CommunicationIdentifierKind.PhoneNumber:
6775
if not identifierModel.phone_number:
6876
raise ValueError("PhoneNumberIdentifier must have a valid attribute - phone_number")
69-
return PhoneNumberIdentifier(identifierModel.phone_number)
77+
return PhoneNumberIdentifier(identifierModel.phone_number, identifier=identifier)
7078
if kind == CommunicationIdentifierKind.MicrosoftTeamsUser:
7179
if identifierModel.is_anonymous not in [True, False]:
7280
raise ValueError("MicrosoftTeamsUser must have a valid attribute - is_anonymous")
7381
if not identifierModel.microsoft_teams_user_id:
7482
raise ValueError("MicrosoftTeamsUser must have a valid attribute - microsoft_teams_user_id")
83+
if not identifierModel.communication_cloud_environment:
84+
raise ValueError("MicrosoftTeamsUser must have a valid attribute - communication_cloud_environment")
7585
return MicrosoftTeamsUserIdentifier(
7686
identifierModel.microsoft_teams_user_id,
77-
is_anonymous=identifierModel.is_anonymous
87+
identifier=identifier,
88+
is_anonymous=identifierModel.is_anonymous,
89+
cloud=identifierModel.communication_cloud_environment
7890
)
7991

80-
if not identifier:
81-
raise ValueError("UnknownIdentifier must have a valid id")
82-
8392
return UnknownIdentifier(identifier)

sdk/communication/azure-communication-chat/azure/communication/chat/_shared/models.py

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ def __init__(self, identifier):
2323
class PhoneNumberIdentifier(object):
2424
"""
2525
Represents a phone number.
26-
:ivar value: Value for a phone number.
27-
:vartype value: str
28-
:param value: Value to initialize PhoneNumberIdentifier.
29-
:type value: str
26+
:param phone_number: The phone number in E.164 format.
27+
:type phone_number: str
28+
:param identifier: The full id of the phone number.
29+
:type identifier: str
3030
"""
31-
def __init__(self, phone_number):
31+
def __init__(self, phone_number, identifier=None):
3232
self.phone_number = phone_number
33+
self.identifier = identifier
3334

3435
class UnknownIdentifier(object):
3536
"""
@@ -44,37 +45,23 @@ class UnknownIdentifier(object):
4445
def __init__(self, identifier):
4546
self.identifier = identifier
4647

47-
class MicrosoftTeamsUserIdentifier(object):
48-
"""
49-
Represents an identifier for a Microsoft Teams user.
50-
:ivar user_id: the string identifier representing the identity
51-
:vartype user_id: str
52-
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
53-
:type user_id: str
54-
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
55-
:vartype is_anonymous: bool
56-
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
57-
:type is_anonymous: bool
58-
"""
59-
def __init__(self, user_id, is_anonymous=False):
60-
self.user_id = user_id
61-
self.is_anonymous = is_anonymous
62-
6348
class CommunicationIdentifierModel(msrest.serialization.Model):
6449
"""Communication Identifier Model.
6550
6651
All required parameters must be populated in order to send to Azure.
6752
6853
:param kind: Required. Kind of Communication Identifier.
6954
:type kind: CommunicationIdentifierKind
70-
:param id: identifies the Communication Identitity.
55+
:param id: Full id of the identifier.
7156
:type id: str
72-
:param phone_number: phone number in case the identity is phone number.
57+
:param phone_number: phone number in case the identifier is a phone number.
7358
:type phone_number: str
74-
:param is_anonymous: is the Microsoft Teams user is anaynimous.
59+
:param is_anonymous: True if the identifier is anonymous.
7560
:type is_anonymous: bool
7661
:param microsoft_teams_user_id: Microsoft Teams user id.
7762
:type microsoft_teams_user_id: str
63+
:param communication_cloud_environment: Cloud environment that the user belongs to.
64+
:type communication_cloud_environment: CommunicationCloudEnvironment
7865
"""
7966

8067
_validation = {
@@ -87,6 +74,7 @@ class CommunicationIdentifierModel(msrest.serialization.Model):
8774
'phone_number': {'key': 'phoneNumber', 'type': 'str'},
8875
'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'},
8976
'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'},
77+
'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'},
9078
}
9179

9280
def __init__(
@@ -99,7 +87,7 @@ def __init__(
9987
self.phone_number = kwargs.get('phone_number', None)
10088
self.is_anonymous = kwargs.get('is_anonymous', None)
10189
self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None)
102-
90+
self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None)
10391

10492
class _CaseInsensitiveEnumMeta(EnumMeta):
10593
def __getitem__(cls, name):
@@ -121,7 +109,38 @@ class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str,
121109
"""Communication Identifier Kind.
122110
"""
123111
Unknown = "UNKNOWN"
124-
CommunicationUser = "COMMUNICATIONuSER"
125-
PhoneNumber = "PHONEnUMBER"
112+
CommunicationUser = "COMMUNICATIONUSER"
113+
PhoneNumber = "PHONENUMBER"
126114
CallingApplication = "CALLINGAPPLICATION"
127-
MicrosoftTeamsUser = "MICROSOFTTEAMSuSER"
115+
MicrosoftTeamsUser = "MICROSOFTTEAMSUSER"
116+
117+
class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
118+
"""
119+
The cloud enviornment that the identifier belongs to
120+
"""
121+
122+
Public = "PUBLIC"
123+
Dod = "DOD"
124+
Gcch = "GCCH"
125+
126+
class MicrosoftTeamsUserIdentifier(object):
127+
"""
128+
Represents an identifier for a Microsoft Teams user.
129+
:ivar user_id: The id of the Microsoft Teams user. If the user isn't anonymous, the id is the AAD object id of the user.
130+
:vartype user_id: str
131+
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
132+
:type user_id: str
133+
:ivar identifier: The full id of the Microsoft Teams User identifier.
134+
:vartype identifier: str
135+
:ivar cloud: Cloud environment that this identifier belongs to
136+
:vartype cloud: CommunicationCloudEnvironment
137+
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
138+
:vartype is_anonymous: bool
139+
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
140+
:type is_anonymous: bool
141+
"""
142+
def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False):
143+
self.identifier = identifier
144+
self.user_id = user_id
145+
self.is_anonymous = is_anonymous
146+
self.cloud = cloud

sdk/communication/azure-communication-chat/dev_requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-e ../../../tools/azure-devtools
21
-e ../../../tools/azure-sdk-tools
32
../azure-communication-nspkg
43
-e ../azure-communication-identity

sdk/communication/azure-communication-chat/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
'azure.communication'
6060
]),
6161
install_requires=[
62-
'azure-core<2.0.0,>=1.6.0',
62+
'azure-core<2.0.0,>=1.9.0',
6363
'msrest>=0.6.0',
6464
'six>=1.6'
6565
],

0 commit comments

Comments
 (0)