Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cloud environment for Teams user #16359

Merged
merged 41 commits into from
Jan 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2f6289a
Add cloud environment enum
Jan 26, 2021
9898c8f
Add cloud environemnt to CommunicationIdentifierModel
Jan 26, 2021
0b4df96
Rename CommunicationCloudEnvironment
Jan 26, 2021
77c3689
Add cloud environemtn to serialize/deserialzie
Jan 26, 2021
f360d21
Rearrange microsoft teams user class position
Jan 26, 2021
b987067
Rename the kwarg name
Jan 26, 2021
d059b55
Add cloud env into tests
Jan 26, 2021
ac44487
Fix typos in identifier kind enums
Jan 26, 2021
15b844d
Add cloud to serialize/deserialize tests for teams user
Jan 26, 2021
f4caf9c
remove unused import
Jan 26, 2021
d97e8f8
Add identifier to the identifier to the microsoft teams user model
Jan 27, 2021
09a47b8
Add idenitifier to the phone number
Jan 27, 2021
1bd495f
Add ids to the tests
Jan 27, 2021
c12bce4
Make id mandatory for deserilize
Jan 27, 2021
b1c9b34
Fix lint error
Jan 28, 2021
3309e69
Add identifier to the doc string
Jan 28, 2021
fa4ffaa
Throw when identifier type is not supported
Jan 28, 2021
2cd2e41
Fix typo in test name
Jan 28, 2021
e65ce70
Add test_serialize_foreign_throws
Jan 28, 2021
a6b0e10
Add test for unknown kind
Jan 28, 2021
5ee9907
Fix docstring for serialize method
Jan 28, 2021
3792c89
Fix the typo in anonymous
Jan 28, 2021
903f7eb
Fix phone number doc string
Jan 28, 2021
fb9003e
Sync model to admin and chat
Jan 29, 2021
cfb85a0
Fix the docstring for CommunicationIdentifierModel
Jan 29, 2021
8dabd70
Remove dev-tools
Jan 29, 2021
dd759ad
add mgmt core to setup py for mgmt package
Jan 29, 2021
61e3341
Update the core dependency in mgmt package.
Jan 29, 2021
92a6c14
Sync models to admin, sms, identity
Jan 29, 2021
6cb8d97
Change the exception message
Jan 29, 2021
d7ee2b4
Add idnetifier check in the test
Jan 29, 2021
0bd0a12
sync model to other packages
Jan 29, 2021
9c8cae6
Remove unnecessary mgmt dependency
Jan 29, 2021
3cd86b7
change identity to identifier in docstrings
Jan 29, 2021
c881ca4
change core forzen requirement for identity
Jan 29, 2021
088b41d
Change docstring for sms
Jan 29, 2021
c0bbf9c
Override shared reqs for core
Jan 29, 2021
624b3cc
Fix forzen requirements for core and sms
Jan 29, 2021
22b727e
change core dependency version in chat,sms,admin
Jan 29, 2021
6b6a902
Add mgmt core back to the dependency
Jan 29, 2021
d703523
Add a new line at the end of file
Jan 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------
# pylint: skip-file

from enum import Enum, EnumMeta
from six import with_metaclass

import msrest

class CommunicationUserIdentifier(object):
"""
Expand All @@ -17,13 +23,14 @@ def __init__(self, identifier):
class PhoneNumberIdentifier(object):
"""
Represents a phone number.
:ivar value: Value for a phone number.
:vartype value: str
:param value: Value to initialize PhoneNumberIdentifier.
:type value: str
:param phone_number: The phone number in E.164 format.
:type phone_number: str
:param identifier: The full id of the phone number.
:type identifier: str
"""
def __init__(self, phone_number):
def __init__(self, phone_number, identifier=None):
self.phone_number = phone_number
self.identifier = identifier

class UnknownIdentifier(object):
"""
Expand All @@ -38,18 +45,102 @@ class UnknownIdentifier(object):
def __init__(self, identifier):
self.identifier = identifier

class CommunicationIdentifierModel(msrest.serialization.Model):
"""Communication Identifier Model.

All required parameters must be populated in order to send to Azure.

:param kind: Required. Kind of Communication Identifier.
:type kind: CommunicationIdentifierKind
:param id: Full id of the identifier.
:type id: str
:param phone_number: phone number in case the identifier is a phone number.
:type phone_number: str
:param is_anonymous: True if the identifier is anonymous.
:type is_anonymous: bool
:param microsoft_teams_user_id: Microsoft Teams user id.
:type microsoft_teams_user_id: str
:param communication_cloud_environment: Cloud environment that the user belongs to.
:type communication_cloud_environment: CommunicationCloudEnvironment
"""

_validation = {
'kind': {'required': True},
}

_attribute_map = {
'kind': {'key': 'kind', 'type': 'str'},
'id': {'key': 'id', 'type': 'str'},
'phone_number': {'key': 'phoneNumber', 'type': 'str'},
'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'},
'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'},
'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'},
}

def __init__(
self,
**kwargs
):
super(CommunicationIdentifierModel, self).__init__(**kwargs)
self.kind = kwargs['kind']
self.id = kwargs.get('id', None)
self.phone_number = kwargs.get('phone_number', None)
self.is_anonymous = kwargs.get('is_anonymous', None)
self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None)
self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None)

class _CaseInsensitiveEnumMeta(EnumMeta):
def __getitem__(cls, name):
return super().__getitem__(name.upper())

def __getattr__(cls, name):
"""Return the enum member matching `name`
We use __getattr__ instead of descriptors or inserting into the enum
class' __dict__ in order to support `name` and `value` being both
properties for enum members (which live in the class' __dict__) and
enum members themselves.
"""
try:
return cls._member_map_[name.upper()]
except KeyError:
raise AttributeError(name)

class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
"""Communication Identifier Kind.
"""
Unknown = "UNKNOWN"
CommunicationUser = "COMMUNICATIONUSER"
PhoneNumber = "PHONENUMBER"
CallingApplication = "CALLINGAPPLICATION"
MicrosoftTeamsUser = "MICROSOFTTEAMSUSER"

class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
"""
The cloud enviornment that the identifier belongs to
"""

Public = "PUBLIC"
Dod = "DOD"
Gcch = "GCCH"

class MicrosoftTeamsUserIdentifier(object):
"""
Represents an identifier for a Microsoft Teams user.
:ivar user_id: the string identifier representing the identity
: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.
:vartype user_id: str
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
:type user_id: str
:ivar identifier: The full id of the Microsoft Teams User identifier.
:vartype identifier: str
:ivar cloud: Cloud environment that this identifier belongs to
:vartype cloud: CommunicationCloudEnvironment
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
:vartype is_anonymous: bool
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
:type is_anonymous: bool
"""
def __init__(self, user_id, is_anonymous=False):
def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False):
self.identifier = identifier
self.user_id = user_id
self.is_anonymous = is_anonymous
self.cloud = cloud
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-e ../../../tools/azure-sdk-tools
-e ../../../tools/azure-devtools
-e ../../identity/azure-identity
../../core/azure-core
../azure-communication-nspkg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
]),
install_requires=[
"msrest>=0.6.0",
"azure-core<2.0.0,>=1.6.0",
"azure-core<2.0.0,>=1.9.0",
],
extras_require={
":python_version<'3.0'": ['azure-communication-nspkg'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ class CommunicationUserIdentifierSerializer(object):
def serialize(cls, communicationIdentifier):
""" Serialize the Communication identifier into CommunicationIdentifierModel

:param identifier: Communication service identifier
:type identifier: Union[CommunicationUserIdentifier, CommunicationPhoneNumberIdentifier]
:param identifier: Identifier object
:type identifier: Union[CommunicationUserIdentifier,
PhoneNumberIdentifier, MicrosoftTeamsUserIdentifier, UnknownIdentifier]
:return: CommunicationIdentifierModel
:rtype: ~azure.communication.chat.CommunicationIdentifierModel
:raises Union[TypeError, ValueError]
"""
if isinstance(communicationIdentifier, CommunicationUserIdentifier):
return CommunicationIdentifierModel(
Expand All @@ -32,18 +34,24 @@ def serialize(cls, communicationIdentifier):
if isinstance(communicationIdentifier, PhoneNumberIdentifier):
turalf marked this conversation as resolved.
Show resolved Hide resolved
return CommunicationIdentifierModel(
kind=CommunicationIdentifierKind.PhoneNumber,
id=communicationIdentifier.phone_number
id=communicationIdentifier.identifier,
phone_number=communicationIdentifier.phone_number
)
if isinstance(communicationIdentifier, MicrosoftTeamsUserIdentifier):
return CommunicationIdentifierModel(
kind=CommunicationIdentifierKind.MicrosoftTeamsUser,
id=communicationIdentifier.user_id
id=communicationIdentifier.identifier,
microsoft_teams_user_id=communicationIdentifier.user_id,
communication_cloud_environment=communicationIdentifier.cloud
)

return CommunicationIdentifierModel(
kind=CommunicationIdentifierKind.Unknown,
id=communicationIdentifier.identifier
)
if isinstance(communicationIdentifier, UnknownIdentifier):
return CommunicationIdentifierModel(
kind=CommunicationIdentifierKind.Unknown,
id=communicationIdentifier.identifier
)

raise TypeError("Unsupported identifier type " + communicationIdentifier.__class__.__name__)

@classmethod
def deserialize(cls, identifierModel):
Expand All @@ -58,26 +66,27 @@ def deserialize(cls, identifierModel):
"""

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

if kind == CommunicationIdentifierKind.CommunicationUser:
if not identifier:
raise ValueError("CommunictionUser must have a valid id")
return CommunicationUserIdentifier(id)
if kind == CommunicationIdentifierKind.PhoneNumber:
if not identifierModel.phone_number:
raise ValueError("PhoneNumberIdentifier must have a valid attribute - phone_number")
return PhoneNumberIdentifier(identifierModel.phone_number)
return PhoneNumberIdentifier(identifierModel.phone_number, identifier=identifier)
if kind == CommunicationIdentifierKind.MicrosoftTeamsUser:
if identifierModel.is_anonymous not in [True, False]:
raise ValueError("MicrosoftTeamsUser must have a valid attribute - is_anonymous")
if not identifierModel.microsoft_teams_user_id:
raise ValueError("MicrosoftTeamsUser must have a valid attribute - microsoft_teams_user_id")
if not identifierModel.communication_cloud_environment:
raise ValueError("MicrosoftTeamsUser must have a valid attribute - communication_cloud_environment")
return MicrosoftTeamsUserIdentifier(
identifierModel.microsoft_teams_user_id,
is_anonymous=identifierModel.is_anonymous
identifier=identifier,
is_anonymous=identifierModel.is_anonymous,
cloud=identifierModel.communication_cloud_environment
)

if not identifier:
raise ValueError("UnknownIdentifier must have a valid id")

return UnknownIdentifier(identifier)
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ def __init__(self, identifier):
class PhoneNumberIdentifier(object):
"""
Represents a phone number.
:ivar value: Value for a phone number.
:vartype value: str
:param value: Value to initialize PhoneNumberIdentifier.
:type value: str
:param phone_number: The phone number in E.164 format.
:type phone_number: str
:param identifier: The full id of the phone number.
:type identifier: str
"""
def __init__(self, phone_number):
def __init__(self, phone_number, identifier=None):
turalf marked this conversation as resolved.
Show resolved Hide resolved
self.phone_number = phone_number
self.identifier = identifier

class UnknownIdentifier(object):
"""
Expand All @@ -44,37 +45,23 @@ class UnknownIdentifier(object):
def __init__(self, identifier):
self.identifier = identifier

class MicrosoftTeamsUserIdentifier(object):
"""
Represents an identifier for a Microsoft Teams user.
:ivar user_id: the string identifier representing the identity
:vartype user_id: str
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
:type user_id: str
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
:vartype is_anonymous: bool
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
:type is_anonymous: bool
"""
def __init__(self, user_id, is_anonymous=False):
self.user_id = user_id
self.is_anonymous = is_anonymous

class CommunicationIdentifierModel(msrest.serialization.Model):
"""Communication Identifier Model.

All required parameters must be populated in order to send to Azure.

:param kind: Required. Kind of Communication Identifier.
:type kind: CommunicationIdentifierKind
:param id: identifies the Communication Identitity.
:param id: Full id of the identifier.
:type id: str
:param phone_number: phone number in case the identity is phone number.
:param phone_number: phone number in case the identifier is a phone number.
:type phone_number: str
:param is_anonymous: is the Microsoft Teams user is anaynimous.
:param is_anonymous: True if the identifier is anonymous.
:type is_anonymous: bool
turalf marked this conversation as resolved.
Show resolved Hide resolved
:param microsoft_teams_user_id: Microsoft Teams user id.
:type microsoft_teams_user_id: str
:param communication_cloud_environment: Cloud environment that the user belongs to.
:type communication_cloud_environment: CommunicationCloudEnvironment
"""

_validation = {
Expand All @@ -87,6 +74,7 @@ class CommunicationIdentifierModel(msrest.serialization.Model):
'phone_number': {'key': 'phoneNumber', 'type': 'str'},
'is_anonymous': {'key': 'isAnonymous', 'type': 'bool'},
'microsoft_teams_user_id': {'key': 'microsoftTeamsUserId', 'type': 'str'},
'communication_cloud_environment': {'key': 'communicationCloudEnvironment', 'type': 'str'},
}

def __init__(
Expand All @@ -99,7 +87,7 @@ def __init__(
self.phone_number = kwargs.get('phone_number', None)
self.is_anonymous = kwargs.get('is_anonymous', None)
self.microsoft_teams_user_id = kwargs.get('microsoft_teams_user_id', None)

self.communication_cloud_environment = kwargs.get('communication_cloud_environment', None)

class _CaseInsensitiveEnumMeta(EnumMeta):
def __getitem__(cls, name):
Expand All @@ -121,7 +109,38 @@ class CommunicationIdentifierKind(with_metaclass(_CaseInsensitiveEnumMeta, str,
"""Communication Identifier Kind.
"""
Unknown = "UNKNOWN"
CommunicationUser = "COMMUNICATIONuSER"
PhoneNumber = "PHONEnUMBER"
CommunicationUser = "COMMUNICATIONUSER"
PhoneNumber = "PHONENUMBER"
CallingApplication = "CALLINGAPPLICATION"
MicrosoftTeamsUser = "MICROSOFTTEAMSuSER"
MicrosoftTeamsUser = "MICROSOFTTEAMSUSER"

class CommunicationCloudEnvironment(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)):
"""
The cloud enviornment that the identifier belongs to
"""

Public = "PUBLIC"
Dod = "DOD"
Gcch = "GCCH"

class MicrosoftTeamsUserIdentifier(object):
"""
Represents an identifier for a Microsoft Teams user.
: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.
:vartype user_id: str
:param user_id: Value to initialize MicrosoftTeamsUserIdentifier.
:type user_id: str
:ivar identifier: The full id of the Microsoft Teams User identifier.
:vartype identifier: str
:ivar cloud: Cloud environment that this identifier belongs to
:vartype cloud: CommunicationCloudEnvironment
:ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link
:vartype is_anonymous: bool
:param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier.
:type is_anonymous: bool
"""
def __init__(self, user_id, identifier=None, cloud=CommunicationCloudEnvironment.Public, is_anonymous=False):
turalf marked this conversation as resolved.
Show resolved Hide resolved
self.identifier = identifier
self.user_id = user_id
self.is_anonymous = is_anonymous
self.cloud = cloud
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
-e ../../../tools/azure-devtools
-e ../../../tools/azure-sdk-tools
../azure-communication-nspkg
-e ../azure-communication-identity
Expand Down
2 changes: 1 addition & 1 deletion sdk/communication/azure-communication-chat/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
'azure.communication'
]),
install_requires=[
'azure-core<2.0.0,>=1.6.0',
'azure-core<2.0.0,>=1.9.0',
'msrest>=0.6.0',
'six>=1.6'
],
Expand Down
Loading