Updated gam <UserTypeEntity> create|update chatspace to support the new permissions settings

This commit is contained in:
Ross Scroggs
2024-09-23 17:11:48 -07:00
parent a6016825ff
commit 8ecbe67054
13 changed files with 136 additions and 9794 deletions

View File

@@ -2048,6 +2048,7 @@ gam setup chat
lastactivetime|
membershipcount|
name|
permissionsettings|
singleuserbotdm|
spacedetails|
spacehistorystate|
@@ -6093,7 +6094,7 @@ gam <UserTypeEntity> print focustime|outofoffice|workinglocation
<String> must contain only lowercase letters, numbers, and hyphens up to 56 characters in length.
gam <UserTypeEntity> create chatspace
[type <ChatSpaceType>]
[type <ChatSpaceType>] [announcement|collaboration]
[restricted|(audience <String>)]
[externalusersrallowed <Boolean>]
[members <UserTypeEntity>]
@@ -6108,6 +6109,13 @@ gam <UserTypeEntity> update chatspace <ChatSpace>
[type space]
[description <String>] [guidelines|rules <String>]
[history <Boolean>])
[managemembersandgroups managers|members]
[modifyspacedetails managers|members]
[togglehistory managers|members]
[useatmentionall managers|members]
[manageapps managers|members]
[managewebhooks managers|members]
[replymessages managers|members]
[formatjson]
gam <UserTypeEntity> delete chatspace <ChatSpace>

View File

@@ -1,3 +1,10 @@
7.00.06
Updated `gam <UserTypeEntity> create|update chatspace` to support the new permissions settings
for Chat spaces that are in Developer Preview.
* See: https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces#Space.FIELDS.predefined_permission_settings
7.00.05
Fixed bug that caused an error when creating a calendar birthday event.

File diff suppressed because it is too large Load Diff

View File

@@ -25630,13 +25630,18 @@ CHAT_SPACE_TYPE_MAP = {
'directmessage': 'DIRECT_MESSAGE',
}
CHAT_SPACE_PREDEFINED_PERMS_MAP = {
'announcement': 'ANNOUNCEMENT_SPACE',
'collaboration': 'COLLABORATION_SPACE',
}
CHAT_SPACE_MIN_MAX_MEMBERS = {
'SPACE': {'min': 0, 'max': 20},
'GROUP_CHAT': {'min': 2, 'max': 20},
'DIRECT_MESSAGE': {'min': 1, 'max': 1},
}
# gam <UserTypeEntity> create chatspace
# [type <ChatSpaceType>]
# [type <ChatSpaceType>] [announcement|collaboration]
# [restricted|(audience <String>)]
# [externalusersallowed <Boolean>]
# [members <UserTypeEntity>]
@@ -25647,9 +25652,7 @@ CHAT_SPACE_MIN_MAX_MEMBERS = {
# [formatjson|returnidonly]
def createChatSpace(users):
FJQC = FormatJSONQuoteChar()
body = {'space': {'spaceType': CHAT_SPACE_TYPE_MAP['space'], 'displayName': ''},
'requestId': str(uuid.uuid4()),
'memberships': []}
body = {'space': {'spaceType': CHAT_SPACE_TYPE_MAP['space'], 'displayName': ''}, 'requestId': str(uuid.uuid4())}
members = []
tbody = {}
returnIdOnly = False
@@ -25658,6 +25661,8 @@ def createChatSpace(users):
myarg = getArgument()
if getChatSpaceParameters(myarg, body['space'], CHAT_SPACE_TYPE_MAP, updateMask):
pass
elif myarg in CHAT_SPACE_PREDEFINED_PERMS_MAP:
body['space']['predefinedPermissionSettings'] = CHAT_SPACE_PREDEFINED_PERMS_MAP[myarg]
elif myarg == 'externalusersallowed':
body['space']['externalUserAllowed'] = getBoolean()
elif myarg == 'members':
@@ -25678,17 +25683,21 @@ def createChatSpace(users):
CHAT_SPACE_MIN_MAX_MEMBERS[spaceType]['min'],
CHAT_SPACE_MIN_MAX_MEMBERS[spaceType]['max']))
mtype = CHAT_MEMBER_TYPE_MAP['human']
for member in members:
name = normalizeEmailAddressOrUID(member)
body['memberships'].append({'member': {'name': f'users/{name}', 'type': mtype}})
if members:
body['memberships'] = []
for member in members:
name = normalizeEmailAddressOrUID(member)
body['memberships'].append({'member': {'name': f'users/{name}', 'type': mtype}})
if spaceType == 'SPACE':
if not body['space']['displayName']:
missingArgumentExit('displayname')
elif spaceType == 'GROUP_CHAT':
body['space'].pop('displayName', None)
body['space'].pop('predefinedPermissionSettings', None)
else: # DIRECT_MESSAGE
body['space'].pop('displayName', None)
body['space'].pop('spaceDetails', None)
body['space'].pop('predefinedPermissionSettings', None)
body['space']['singleUserBotDm'] = False
if tbody:
trimChatMessageIfRequired(tbody)
@@ -25737,12 +25746,34 @@ CHAT_UPDATE_SPACE_TYPE_MAP = {
'space': 'SPACE',
}
CHAT_SPACE_ROLE_PERMISSIONS_MAP = {
'managers': 'managersAllowed',
'members': 'membersAllowed',
}
CHAT_UPDATE_SPACE_PERMISSIONS_MAP = {
'managemembersandgroups': 'manageMembersAndGroups',
'modifyspacedetails': 'modifySpaceDetails',
'togglehistory': 'toggleHistory',
'useatmentionall': 'useAtMentionAll',
'manageapps': 'manageApps',
'managewebhooks': 'manageWebhooks',
'replymessages': 'replyMessages',
}
# gam <UserTypeEntity> update chatspace <ChatSpace>
# [restricted|(audience <String>)]|
# ([displayname <String>]
# [type space]
# [description <String>] [guidelines|rules <String>]
# [history <Boolean>])
# managemembersandgroups managers|members
# modifyspacedetails managers|members
# togglehistory managers|members
# useatmentionall managers|members
# manageapps managers|members
# managewebhooks managers|members
# replymessages managers|members
# [formatjson]
def updateChatSpace(users):
FJQC = FormatJSONQuoteChar()
@@ -25756,6 +25787,14 @@ def updateChatSpace(users):
name = getSpaceName(myarg)
elif getChatSpaceParameters(myarg, body, CHAT_UPDATE_SPACE_TYPE_MAP, updateMask):
pass
elif myarg in CHAT_UPDATE_SPACE_PERMISSIONS_MAP:
body.setdefault('permissionSettings', {})
permissionSetting = CHAT_UPDATE_SPACE_PERMISSIONS_MAP[myarg]
role = getChoice(CHAT_SPACE_ROLE_PERMISSIONS_MAP, mapChoice=True)
body['permissionSettings'][permissionSetting] = {'managersAllowed': True}
if role == 'membersAllowed':
body['permissionSettings'][permissionSetting].update({'membersAllowed': True})
updateMask.add(f'permissionSettings.{permissionSetting}')
else:
FJQC.GetFormatJSON(myarg)
if not name:
@@ -25823,6 +25862,7 @@ CHAT_SPACES_FIELDS_CHOICE_MAP = {
"lastactivetime": "lastActiveTime",
"membershipcount": "membershipCount",
"name": "name",
"permissionsettings": "permissionSettings",
"singleuserbotdm": "singleUserBotDm",
"spacedetails": "spaceDetails",
"spacehistorystate": "spaceHistoryState",

File diff suppressed because it is too large Load Diff

View File

@@ -206,15 +206,15 @@ _INFO = {
ANALYTICS_ADMIN: {'name': 'Analytics Admin API', 'version': 'v1beta', 'v2discovery': True},
CALENDAR: {'name': 'Calendar API', 'version': 'v3', 'v2discovery': True, 'mappedAPI': 'calendar-json'},
CBCM: {'name': 'Chrome Browser Cloud Management API', 'version': 'v1.1beta1', 'v2discovery': True, 'localjson': True},
CHAT: {'name': 'Chat API', 'version': 'v1', 'v2discovery': True, 'localjson': True},
CHAT_EVENTS: {'name': 'Chat API - Events', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_MEMBERSHIPS: {'name': 'Chat API - Memberships', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_MEMBERSHIPS_ADMIN: {'name': 'Chat API - Memberships Admin', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_MESSAGES: {'name': 'Chat API - Messages', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_SPACES: {'name': 'Chat API - Spaces', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_SPACES_ADMIN: {'name': 'Chat API - Spaces Admin', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_SPACES_DELETE: {'name': 'Chat API - Spaces Delete', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT_SPACES_DELETE_ADMIN: {'name': 'Chat API - Spaces Delete Admin', 'version': 'v1', 'v2discovery': True, 'localjson': True, 'mappedAPI': CHAT},
CHAT: {'name': 'Chat API', 'version': 'v1', 'v2discovery': True},
CHAT_EVENTS: {'name': 'Chat API - Events', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_MEMBERSHIPS: {'name': 'Chat API - Memberships', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_MEMBERSHIPS_ADMIN: {'name': 'Chat API - Memberships Admin', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_MESSAGES: {'name': 'Chat API - Messages', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_SPACES: {'name': 'Chat API - Spaces', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_SPACES_ADMIN: {'name': 'Chat API - Spaces Admin', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_SPACES_DELETE: {'name': 'Chat API - Spaces Delete', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CHAT_SPACES_DELETE_ADMIN: {'name': 'Chat API - Spaces Delete Admin', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHAT},
CLASSROOM: {'name': 'Classroom API', 'version': 'v1', 'v2discovery': True},
CHROMEMANAGEMENT: {'name': 'Chrome Management API', 'version': 'v1', 'v2discovery': True},
CHROMEMANAGEMENT_APPDETAILS: {'name': 'Chrome Management API - AppDetails', 'version': 'v1', 'v2discovery': True, 'mappedAPI': CHROMEMANAGEMENT},

View File

@@ -1170,9 +1170,11 @@ def createMethod(methodName, methodDesc, rootDesc, schema):
elif "response" not in methodDesc:
model = RawModel()
api_version = methodDesc.get("apiVersion", None)
headers = {}
headers, params, query, body = model.request(
headers, actual_path_params, actual_query_params, body_value
headers, actual_path_params, actual_query_params, body_value, api_version
)
expanded_url = uritemplate.expand(pathUrl, params)

View File

@@ -27,10 +27,18 @@ import json
import logging
import platform
import urllib
import warnings
from googleapiclient import version as googleapiclient_version
from googleapiclient.errors import HttpError
try:
from google.api_core.version_header import API_VERSION_METADATA_KEY
HAS_API_VERSION = True
except ImportError:
HAS_API_VERSION = False
_LIBRARY_VERSION = googleapiclient_version.__version__
_PY_VERSION = platform.python_version()
@@ -121,7 +129,7 @@ class BaseModel(Model):
LOGGER.info("query: %s", query)
LOGGER.info("--request-end--")
def request(self, headers, path_params, query_params, body_value):
def request(self, headers, path_params, query_params, body_value, api_version=None):
"""Updates outgoing requests with a serialized body.
Args:
@@ -129,7 +137,10 @@ class BaseModel(Model):
path_params: dict, parameters that appear in the request path
query_params: dict, parameters that appear in the query
body_value: object, the request body as a Python object, which must be
serializable by json.
serializable by json.
api_version: str, The precise API version represented by this request,
which will result in an API Version header being sent along with the
HTTP request.
Returns:
A tuple of (headers, path_params, query, body)
@@ -155,6 +166,15 @@ class BaseModel(Model):
_PY_VERSION,
)
if api_version and HAS_API_VERSION:
headers[API_VERSION_METADATA_KEY] = api_version
elif api_version:
warnings.warn(
"The `api_version` argument is ignored as a newer version of "
"`google-api-core` is required to use this feature."
"Please upgrade `google-api-core` to 2.19.0 or newer."
)
if body_value is not None:
headers["content-type"] = self.content_type
body_value = self.serialize(body_value)

View File

@@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
__version__ = "2.124.0"
__version__ = "2.146.0"