Skip to content

Commit cea5a33

Browse files
committed
Added option includepermissionsforview published to print filelist/show fileinfo
1 parent 3a7f84e commit cea5a33

File tree

3 files changed

+76
-23
lines changed

3 files changed

+76
-23
lines changed

src/GamCommands.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6974,6 +6974,7 @@ gam <UserTypeEntity> info drivefile <DriveFileEntity>
69746974
[returnidonly]
69756975
[filepath|fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
69766976
[allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
6977+
[includepermissionsforview published]
69776978
(orderby <DriveFileOrderByFieldName> [ascending|descending])*
69786979
[showdrivename] [showshareddrivepermissions]
69796980
[(showlabels details|ids)|(includelabels <ClassificationLabelIDList>)]
@@ -7457,6 +7458,7 @@ gam <UserTypeEntity> show fileinfo <DriveFileEntity>
74577458
[returnidonly]
74587459
[filepath|fullpath] [folderpathonly [<Boolean>]] [pathdelimiter <Character>]
74597460
[allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
7461+
[includepermissionsforview published]
74607462
(orderby <DriveFileOrderByFieldName> [ascending|descending])*
74617463
[showdrivename] [showshareddrivepermissions]
74627464
[(showlabels details|ids)|(includelabels <ClassificationLabelIDList>)]
@@ -7570,6 +7572,7 @@ gam <UserTypeEntity> print filelist [todrive <ToDriveAttribute>*]
75707572
[sizefield quotabytesused|size] [minimumfilesize <Integer>] [maximumfilesize <Integer>]
75717573
[filenamematchpattern <REMatchPattern>]
75727574
<PermissionMatch>* [<PermissionMatchMode>] [<PermissionMatchAction>] [pmfilter] [oneitemperrow]
7575+
[includepermissionsforview published]
75737576
[excludetrashed]
75747577
[maxfiles <Integer>] [nodataheaders <String>]
75757578
[countsonly [summary none|only|plus] [summaryuser <String>]

src/GamUpdate.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
7.32.07
2+
3+
Added option `includepermissionsforview published` to `gam <UserTypeEntity> print filelist` and
4+
`gam <UserTypeEntity> show fileinfo`. From the Drive API documentation:
5+
```
6+
Specifies which additional view's permissions to include in the response. Only published is supported.
7+
```
8+
19
7.32.06
210

311
Added options to `gam <UserTypeEntity> copy drivefile ... copysubfiles` to limit copying
4-
of files whose `modifiedTime` meets specified requirements.
12+
to files whose `modifiedTime` meets specified requirements.
513
* `start|starttime <Date>|<Time>` - If specified, `modifiedTime` must be >= the value
614
* `end|endtime <Date>|<Time>` - If specified, `modifiedTime` must be <= the value
715
* `range <Date>|<Time> <Date>|<Time>` - first value <= `modifiedTime` <= second value

src/gam/__init__.py

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"""
2626

2727
__author__ = 'GAM Team <google-apps-manager@googlegroups.com>'
28-
__version__ = '7.32.06'
28+
__version__ = '7.32.07'
2929
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'
3030

3131
# pylint: disable=wrong-import-position
@@ -2308,10 +2308,10 @@ def getMatchSkipFields(fieldNames):
23082308

23092309
def checkMatchSkipFields(row, fieldnames, matchFields, skipFields):
23102310
for matchField, matchPattern in matchFields.items():
2311-
if (matchField not in row) or not matchPattern.search(row[matchField]):
2311+
if (matchField not in row) or not matchPattern.search(str(row[matchField])):
23122312
return False
23132313
for skipField, matchPattern in skipFields.items():
2314-
if (skipField in row) and matchPattern.search(row[skipField]):
2314+
if (skipField in row) and matchPattern.search(str(row[skipField])):
23152315
return False
23162316
if fieldnames and (GC.Values[GC.CSV_INPUT_ROW_FILTER] or GC.Values[GC.CSV_INPUT_ROW_DROP_FILTER]):
23172317
return RowFilterMatch(row, fieldnames,
@@ -57294,6 +57294,31 @@ def _mapDriveInfo(f_file, parentsSubFields, showParentsIdsAsList):
5729457294

5729557295
DRIVE_TIME_OBJECTS = {'createdTime', 'viewedByMeTime', 'modifiedByMeTime', 'modifiedTime', 'restrictionTime', 'sharedWithMeTime', 'trashedTime'}
5729657296

57297+
def _getIncludeLabels(includeLabels):
57298+
labelIds = getEntityList(Cmd.OB_CLASSIFICATION_LABEL_ID, shlexSplit=True)
57299+
for labelId in labelIds:
57300+
includeLabels.add(normalizeDriveLabelID(labelId))
57301+
57302+
def _finalizeIncludeLabels(includeLabels):
57303+
if includeLabels:
57304+
return ','.join(includeLabels)
57305+
return None
57306+
57307+
DRIVEFILE_PERMISSIONS_FOR_VIEW_CHOICES = ['published']
57308+
57309+
def _getIncludePermissionsForView(includePermissionsForView):
57310+
ipfwList = getEntityList(Cmd.OB_STRING_LIST)
57311+
for ipfw in ipfwList:
57312+
if ipfw in DRIVEFILE_PERMISSIONS_FOR_VIEW_CHOICES:
57313+
includePermissionsForView.add(ipfw)
57314+
else:
57315+
invalidChoiceExit(ipfw, DRIVEFILE_PERMISSIONS_FOR_VIEW_CHOICES, True)
57316+
57317+
def _finalizeIncludePermissionsForView(includePermissionsForView):
57318+
if includePermissionsForView:
57319+
return ','.join(includePermissionsForView)
57320+
return None
57321+
5729757322
def _getDriveFieldSubField(field, fieldsList, parentsSubFields):
5729857323
field, subField = field.split('.', 1)
5729957324
if field in DRIVE_SUBFIELDS_CHOICE_MAP:
@@ -57320,7 +57345,8 @@ def __init__(self):
5732057345
self.allFields = False
5732157346
self.OBY = OrderBy(DRIVEFILE_ORDERBY_CHOICE_MAP)
5732257347
self.fieldsList = []
57323-
self.includeLabels = []
57348+
self.includeLabels = set()
57349+
self.includePermissionsForView = set()
5732457350
self.parentsSubFields = {'id': False, 'isRoot': False, 'rootFolderId': None}
5732557351

5732657352
def SetAllParentsSubFields(self):
@@ -57354,9 +57380,9 @@ def ProcessArgument(self, myarg):
5735457380
else:
5735557381
_getDriveFieldSubField(field, self.fieldsList, self.parentsSubFields)
5735657382
elif myarg == 'includelabels':
57357-
labelIds = getEntityList(Cmd.OB_CLASSIFICATION_LABEL_ID, shlexSplit=True)
57358-
for labelId in labelIds:
57359-
self.includeLabels.append(normalizeDriveLabelID(labelId))
57383+
_getIncludeLabels(self.includeLabels)
57384+
elif myarg == 'includepermissionsforview':
57385+
_getIncludePermissionsForView(self.includePermissionsForView)
5736057386
elif myarg.find('.') != -1:
5736157387
_getDriveFieldSubField(myarg, self.fieldsList, self.parentsSubFields)
5736257388
elif myarg == 'orderby':
@@ -57416,6 +57442,7 @@ def _formatFileDriveLabels(showLabels, labels, result, printMode, delimiter):
5741657442
# (orderby <DriveFileOrderByFieldName> [ascending|descending])*
5741757443
# [showdrivename] [showshareddrivepermissions]
5741857444
# [(showlabels details|ids)|(includelabels <DriveLabelIDList>)]
57445+
# [includepermissionsforview published]
5741957446
# [showparentsidsaslist] [followshortcuts [<Boolean>]]
5742057447
# [stripcrsfromname] [formatjson]
5742157448
# gam <UserTypeEntity> show fileinfo <DriveFileEntity>
@@ -57425,6 +57452,7 @@ def _formatFileDriveLabels(showLabels, labels, result, printMode, delimiter):
5742557452
# (orderby <DriveFileOrderByFieldName> [ascending|descending])*
5742657453
# [showdrivename] [showshareddrivepermissions]
5742757454
# [(showlabels details|ids)|(includelabels <DriveLabelIDList>)]
57455+
# [includepermissionsforview published]
5742857456
# [showparentsidsaslist] [followshortcuts [<Boolean>]]
5742957457
# [stripcrsfromname] [formatjson]
5743057458
def showFileInfo(users):
@@ -57487,7 +57515,8 @@ def _setSelectionFields():
5748757515
DFF.SetAllParentsSubFields()
5748857516
skipObjects = skipObjects.union(DEFAULT_SKIP_OBJECTS)
5748957517
showNoParents = True
57490-
includeLabels = ','.join(DFF.includeLabels)
57518+
includeLabels = _finalizeIncludeLabels(DFF.includeLabels)
57519+
includePermissionsForView = _finalizeIncludePermissionsForView(DFF.includePermissionsForView)
5749157520
pathFields = FILEPATH_FIELDS
5749257521
i, count, users = getEntityArgument(users)
5749357522
for user in users:
@@ -57526,12 +57555,14 @@ def _setSelectionFields():
5752657555
try:
5752757556
result = callGAPI(drive.files(), 'get',
5752857557
throwReasons=GAPI.DRIVE_GET_THROW_REASONS+[GAPI.INVALID],
57529-
fileId=fileId, includeLabels=includeLabels, fields=fields, supportsAllDrives=True)
57558+
fileId=fileId, includeLabels=includeLabels, includePermissionsForView=includePermissionsForView,
57559+
fields=fields, supportsAllDrives=True)
5753057560
if followShortcuts and result['mimeType'] == MIMETYPE_GA_SHORTCUT:
5753157561
fileId = result['shortcutDetails']['targetId']
5753257562
result = callGAPI(drive.files(), 'get',
5753357563
throwReasons=GAPI.DRIVE_GET_THROW_REASONS+[GAPI.INVALID],
57534-
fileId=fileId, includeLabels=includeLabels, fields=fields, supportsAllDrives=True)
57564+
fileId=fileId, includeLabels=includeLabels, includePermissionsForView=includePermissionsForView,
57565+
fields=fields, supportsAllDrives=True)
5753557566
if stripCRsFromName:
5753657567
result['name'] = _stripControlCharsFromName(result['name'])
5753757568
driveId = result.get('driveId')
@@ -58859,6 +58890,7 @@ def _getGettingEntity(user, fileIdEntity):
5885958890
# [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
5886058891
# [showdrivename] [showshareddrivepermissions]
5886158892
# (showlabels details|ids)|(includelabels <DriveLabelIDList>)]
58893+
# [includepermissionsforview published]
5886258894
# [showparentsidsaslist] [showpermissionslast]
5886358895
# (orderby <DriveFileOrderByFieldName> [ascending|descending])* [delimiter <Character>]
5886458896
# [stripcrsfromname]
@@ -59039,7 +59071,8 @@ def _printChildDriveFolderContents(drive, fileEntry, user, i, count, depth):
5903959071
throwReasons=GAPI.DRIVE_USER_THROW_REASONS+[GAPI.INVALID_QUERY, GAPI.INVALID,
5904059072
GAPI.BAD_REQUEST],
5904159073
retryReasons=GAPI.SERVICE_NOT_AVAILABLE_RETRY_REASONS+[GAPI.UNKNOWN_ERROR],
59042-
q=q, orderBy=DFF.orderBy, includeLabels=includeLabels, fields=pagesFields,
59074+
q=q, orderBy=DFF.orderBy, includeLabels=includeLabels, includePermissionsForView=includePermissionsForView,
59075+
fields=pagesFields,
5904359076
pageSize=GC.Values[GC.DRIVE_MAX_RESULTS], includeItemsFromAllDrives=True, supportsAllDrives=True)
5904459077
for childEntryInfo in children:
5904559078
childFileId = childEntryInfo['id']
@@ -59056,8 +59089,12 @@ def _printChildDriveFolderContents(drive, fileEntry, user, i, count, depth):
5905659089
_printFileInfo(drive, user, childEntryInfo.copy(), stripCRsFromName)
5905759090
if childEntryInfo['mimeType'] == MIMETYPE_GA_FOLDER and (maxdepth == -1 or depth < maxdepth):
5905859091
_printChildDriveFolderContents(drive, childEntryInfo, user, i, count, depth+1)
59059-
except (GAPI.invalidQuery, GAPI.invalid, GAPI.badRequest):
59060-
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE, None], invalidQuery(selectSubQuery), i, count)
59092+
except (GAPI.invalidQuery, GAPI.invalid, GAPI.badRequest) as e:
59093+
errMsg = str(e)
59094+
if 'Invalid field selection' in errMsg or "Only a 'published' value is supported." in errMsg:
59095+
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE_OR_FOLDER, None], errMsg, i, count)
59096+
else:
59097+
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE, None], invalidQuery(selectSubQuery), i, count)
5906159098
except (GAPI.serviceNotAvailable, GAPI.authError, GAPI.domainPolicy) as e:
5906259099
userDriveServiceNotEnabledWarning(user, str(e), i, count)
5906359100

@@ -59279,7 +59316,8 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5927959316
if filepath and not countsOnly:
5928059317
csvPF.AddTitles('paths')
5928159318
csvPF.SetFixPaths(True)
59282-
includeLabels = ','.join(DFF.includeLabels)
59319+
includeLabels = _finalizeIncludeLabels(DFF.includeLabels)
59320+
includePermissionsForView = _finalizeIncludePermissionsForView(DFF.includePermissionsForView)
5928359321
csvPF.RemoveTitles(['capabilities'])
5928459322
if DLP.queryTimes and selectSubQuery:
5928559323
for queryTimeName, queryTimeValue in DLP.queryTimes.items():
@@ -59352,7 +59390,8 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5935259390
GAPI.BAD_REQUEST, GAPI.FILE_NOT_FOUND,
5935359391
GAPI.NOT_FOUND, GAPI.TEAMDRIVE_MEMBERSHIP_REQUIRED],
5935459392
retryReasons=GAPI.SERVICE_NOT_AVAILABLE_RETRY_REASONS+[GAPI.UNKNOWN_ERROR],
59355-
q=DLP.fileIdEntity['query'], orderBy=DFF.orderBy, includeLabels=includeLabels,
59393+
q=DLP.fileIdEntity['query'], orderBy=DFF.orderBy,
59394+
includeLabels=includeLabels, includePermissionsForView=includePermissionsForView,
5935659395
fields=pagesFields, pageSize=GC.Values[GC.DRIVE_MAX_RESULTS], **btkwargs)
5935759396
for files in feed:
5935859397
if showLabels is not None:
@@ -59383,7 +59422,7 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5938359422
DLP.GetLocationFileIdsFromTree(fileTree, fileIdEntity)
5938459423
except (GAPI.invalidQuery, GAPI.invalid, GAPI.badRequest) as e:
5938559424
errMsg = str(e)
59386-
if 'Invalid field selection' in errMsg:
59425+
if 'Invalid field selection' in errMsg or "Only a 'published' value is supported." in errMsg:
5938759426
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE_OR_FOLDER, None], errMsg, i, count)
5938859427
break
5938959428
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE_OR_FOLDER, None], invalidQuery(DLP.fileIdEntity['query']), i, count)
@@ -59415,8 +59454,9 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5941559454
else:
5941659455
try:
5941759456
fileEntryInfo = callGAPI(drive.files(), 'get',
59418-
throwReasons=GAPI.DRIVE_GET_THROW_REASONS,
59419-
fileId=fileId, includeLabels=includeLabels, fields=fields, supportsAllDrives=True)
59457+
throwReasons=GAPI.DRIVE_GET_THROW_REASONS+[GAPI.INVALID],
59458+
fileId=fileId, includeLabels=includeLabels, includePermissionsForView=includePermissionsForView,
59459+
fields=fields, supportsAllDrives=True)
5942059460
if stripCRsFromName:
5942159461
fileEntryInfo['name'] = _stripControlCharsFromName(fileEntryInfo['name'])
5942259462
if showLabels is not None:
@@ -59427,6 +59467,9 @@ def writeMimeTypeCountsRow(user, sourceId, sourceName, mimeTypeInfo):
5942759467
_formatFileDriveLabels(showLabels, labels, fileEntryInfo, True, delimiter)
5942859468
if filepath:
5942959469
fileTree[fileId] = {'info': fileEntryInfo}
59470+
except GAPI.invalid as e:
59471+
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE_OR_FOLDER, fileId], str(e), j, jcount)
59472+
continue
5943059473
except GAPI.fileNotFound:
5943159474
entityActionFailedWarning([Ent.USER, user, Ent.DRIVE_FILE_OR_FOLDER, fileId], Msg.NOT_FOUND, j, jcount)
5943259475
continue
@@ -67410,8 +67453,6 @@ def infoDriveFileACLs(users, useDomainAdminAccess=False):
6741067453
def doInfoDriveFileACLs():
6741167454
infoDriveFileACLs([_getAdminEmail()], True)
6741267455

67413-
DRIVEFILE_PERMISSIONS_FOR_VIEW_CHOICES = ['published']
67414-
6741567456
def getDriveFilePermissionsFields(myarg, fieldsList):
6741667457
if myarg in DRIVE_PERMISSIONS_SUBFIELDS_CHOICE_MAP:
6741767458
fieldsList.append(DRIVE_PERMISSIONS_SUBFIELDS_CHOICE_MAP[myarg])
@@ -67466,7 +67507,7 @@ def _printPermissionRow(baserow, permission):
6746667507
addTitle = None
6746767508
roles = set()
6746867509
oneItemPerRow = pmselect = showTitles = False
67469-
includePermissionsForView = None
67510+
includePermissionsForView = set()
6747067511
fieldsList = []
6747167512
OBY = OrderBy(DRIVEFILE_ORDERBY_CHOICE_MAP)
6747267513
PM = PermissionMatch()
@@ -67501,13 +67542,14 @@ def _printPermissionRow(baserow, permission):
6750167542
elif PM.ProcessArgument(myarg):
6750267543
pass
6750367544
elif myarg == 'includepermissionsforview':
67504-
includePermissionsForView = getChoice(DRIVEFILE_PERMISSIONS_FOR_VIEW_CHOICES)
67545+
_getIncludePermissionsForView(includePermissionsForView)
6750567546
else:
6750667547
FJQC.GetFormatJSONQuoteChar(myarg, True)
6750767548
_checkFileIdEntityDomainAccess(fileIdEntity, useDomainAdminAccess)
6750867549
if fieldsList:
6750967550
if roles:
6751067551
fieldsList.append('role')
67552+
includePermissionsForView = _finalizeIncludePermissionsForView(includePermissionsForView)
6751167553
fields = getItemFieldsFromFieldsList('permissions', fieldsList, True)
6751267554
printKeys, timeObjects = _getDriveFileACLPrintKeysTimeObjects()
6751367555
i, count, users = getEntityArgument(users)

0 commit comments

Comments
 (0)