Added command to upload changes to Google Docs.

This commit is contained in:
Ross Scroggs
2024-02-29 22:08:17 -08:00
parent a328ac8ea9
commit 63b1ca7e30
5 changed files with 116 additions and 44 deletions

View File

@@ -58328,6 +58328,55 @@ def getGoogleDocument(users):
break
Ind.Decrement()
# gam <UserTypeEntity> update docuument <DriveFileEntity>
# ((json [charset <Charset>] <SpreadsheetJSONUpdateRequest>) |
# (json file <FileName> [charset <Charset>]))
# [formatjson]
def updateGoogleDocument(users):
fileIdEntity = getDriveFileEntity()
body = {}
FJQC = FormatJSONQuoteChar()
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if myarg == 'json':
body = getJSON([])
else:
FJQC.GetFormatJSON(myarg)
i, count, users = getEntityArgument(users)
for user in users:
i += 1
user, drive, jcount = _validateUserGetFileIDs(user, i, count, fileIdEntity, entityType=Ent.DOCUMENT if not FJQC.formatJSON else None)
if jcount == 0:
continue
_, docs = buildGAPIServiceObject(API.DOCS, user, i, count)
if not docs:
continue
Ind.Increment()
j = 0
for documentId in fileIdEntity['list']:
j += 1
try:
result = callGAPI(docs.documents(), 'batchUpdate',
throwReasons=GAPI.DOCS_ACCESS_THROW_REASONS,
documentId=documentId, body=body)
if FJQC.formatJSON:
printLine('{'+f'"User": "{user}", "documentId": "{documentId}", "JSON": {json.dumps(result, ensure_ascii=False, sort_keys=False)}'+'}')
continue
entityActionPerformed([Ent.USER, user, Ent.DOCUMENT, documentId], j, jcount)
Ind.Increment()
for field in ['replies', 'writeControl']:
if field in result:
showJSON(field, result[field])
Ind.Decrement()
except (GAPI.fileNotFound, GAPI.forbidden, GAPI.permissionDenied,
GAPI.internalError, GAPI.insufficientFilePermissions, GAPI.badRequest,
GAPI.invalid, GAPI.invalidArgument, GAPI.failedPrecondition) as e:
entityActionFailedWarning([Ent.USER, user, Ent.DOCUMENT, documentId], str(e), j, jcount)
except (GAPI.serviceNotAvailable, GAPI.authError, GAPI.domainPolicy) as e:
userSvcNotApplicableOrDriveDisabled(user, str(e), i, count)
break
Ind.Decrement()
# gam <UserTypeEntity> collect orphans
# [(targetuserfoldername <DriveFolderName>)(targetuserfolderid <DriveFolderID>)]
# [useshortcuts [<Boolean>]]
@@ -73646,6 +73695,7 @@ USER_COMMANDS_WITH_OBJECTS = {
Cmd.ARG_CSEIDENTITY: createUpdateCSEIdentity,
Cmd.ARG_LOOKERSTUDIOPERMISSION: processLookerStudioPermissions,
Cmd.ARG_DELEGATE: updateDelegates,
Cmd.ARG_DOCUMENT: updateGoogleDocument,
Cmd.ARG_DRIVEFILE: updateDriveFile,
Cmd.ARG_DRIVEFILEACL: updateDriveFileACLs,
Cmd.ARG_EVENT: updateCalendarEvents,

View File

@@ -249,6 +249,8 @@ DRIVE3_MODIFY_LABEL_THROW_REASONS = DRIVE_USER_THROW_REASONS+[FILE_NOT_FOUND, NO
UNKNOWN_ERROR, INVALID_INPUT, BAD_REQUEST,
LABEL_MULTIPLE_VALUES_FOR_SINGULAR_FIELD, LABEL_MUTATION_FORBIDDEN,
LABEL_MUTATION_ILLEGAL_SELECTION, LABEL_MUTATION_UNKNOWN_FIELD]
DOCS_ACCESS_THROW_REASONS = DRIVE_USER_THROW_REASONS+[NOT_FOUND, PERMISSION_DENIED, FORBIDDEN, INTERNAL_ERROR, INSUFFICIENT_FILE_PERMISSIONS,
BAD_REQUEST, INVALID, INVALID_ARGUMENT, FAILED_PRECONDITION]
GMAIL_THROW_REASONS = [SERVICE_NOT_AVAILABLE, BAD_REQUEST]
GMAIL_LIST_THROW_REASONS = [FAILED_PRECONDITION, PERMISSION_DENIED, INVALID, INVALID_ARGUMENT]
GMAIL_SMIME_THROW_REASONS = [SERVICE_NOT_AVAILABLE, BAD_REQUEST, INVALID_ARGUMENT, FORBIDDEN, NOT_FOUND, PERMISSION_DENIED]

View File

@@ -62,12 +62,12 @@ _SKUS = {
'product': '101031', 'aliases': ['gwepstaff', 'workspaceeducationplusstaff'], 'displayName': 'Google Workspace for Education Plus (Staff)'},
'1010310010': {
'product': '101031', 'aliases': ['gwepstudent', 'workspaceeducationplusstudent'], 'displayName': 'Google Workspace for Education Plus (Extra Student)'},
'1010330002': {
'product': '101033', 'aliases': ['gvpremier', 'voicepremier', 'googlevoicepremier'], 'displayName': 'Google Voice Premier'},
'1010330003': {
'product': '101033', 'aliases': ['gvstarter', 'voicestarter', 'googlevoicestarter'], 'displayName': 'Google Voice Starter'},
'1010330004': {
'product': '101033', 'aliases': ['gvstandard', 'voicestandard', 'googlevoicestandard'], 'displayName': 'Google Voice Standard'},
'1010330002': {
'product': '101033', 'aliases': ['gvpremier', 'voicepremier', 'googlevoicepremier'], 'displayName': 'Google Voice Premier'},
'1010350001': {
'product': '101035', 'aliases': ['cloudsearch'], 'displayName': 'Cloud Search'},
'1010360001': {