mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 12:21:35 +00:00
workingLocation cleanup (not public)
This commit is contained in:
@@ -4498,7 +4498,7 @@ def refreshCredentialsWithReauth(credentials):
|
|||||||
gcloud_path_result = subprocess.run(['gcloud',
|
gcloud_path_result = subprocess.run(['gcloud',
|
||||||
'info',
|
'info',
|
||||||
'--format=value(config.paths.global_config_dir)'],
|
'--format=value(config.paths.global_config_dir)'],
|
||||||
capture_output=True, ckeck=False)
|
capture_output=True, check=False)
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
# avoids loss of terminal echo on *nix
|
# avoids loss of terminal echo on *nix
|
||||||
if 'termios' in sys.modules:
|
if 'termios' in sys.modules:
|
||||||
@@ -4516,7 +4516,7 @@ def refreshCredentialsWithReauth(credentials):
|
|||||||
f'Failed to run gcloud as {admin_email}. Please make sure it\'s setup')
|
f'Failed to run gcloud as {admin_email}. Please make sure it\'s setup')
|
||||||
if not credentials._rapt_token:
|
if not credentials._rapt_token:
|
||||||
systemErrorExit(SYSTEM_ERROR_RC,
|
systemErrorExit(SYSTEM_ERROR_RC,
|
||||||
f'Failed to retrieve reauth token from gcloud. You may need to wait until gcloud is also prompted for reauth.')
|
'Failed to retrieve reauth token from gcloud. You may need to wait until gcloud is also prompted for reauth.')
|
||||||
|
|
||||||
def getClientCredentials(forceRefresh=False, forceWrite=False, filename=None, api=None, noDASA=False, refreshOnly=False, noScopes=False):
|
def getClientCredentials(forceRefresh=False, forceWrite=False, filename=None, api=None, noDASA=False, refreshOnly=False, noScopes=False):
|
||||||
"""Gets OAuth2 credentials which are guaranteed to be fresh and valid.
|
"""Gets OAuth2 credentials which are guaranteed to be fresh and valid.
|
||||||
@@ -34781,6 +34781,7 @@ LIST_EVENTS_SELECT_PROPERTIES = {
|
|||||||
'timemin': ('timeMin', {GC.VAR_TYPE: GC.TYPE_DATETIME}),
|
'timemin': ('timeMin', {GC.VAR_TYPE: GC.TYPE_DATETIME}),
|
||||||
'updated': ('updatedMin', {GC.VAR_TYPE: GC.TYPE_DATETIME}),
|
'updated': ('updatedMin', {GC.VAR_TYPE: GC.TYPE_DATETIME}),
|
||||||
'updatedmin': ('updatedMin', {GC.VAR_TYPE: GC.TYPE_DATETIME}),
|
'updatedmin': ('updatedMin', {GC.VAR_TYPE: GC.TYPE_DATETIME}),
|
||||||
|
'eventtypes': ('eventTypes', {GC.VAR_TYPE: GC.TYPE_CHOICE_LIST}),
|
||||||
}
|
}
|
||||||
|
|
||||||
LIST_EVENTS_MATCH_FIELDS = {
|
LIST_EVENTS_MATCH_FIELDS = {
|
||||||
@@ -34815,9 +34816,12 @@ def _getCalendarListEventsProperty(myarg, attributes, kwargs):
|
|||||||
kwargs[attrName] = getChoice(attribute['choices'], mapChoice=True)
|
kwargs[attrName] = getChoice(attribute['choices'], mapChoice=True)
|
||||||
elif attrType == GC.TYPE_DATETIME:
|
elif attrType == GC.TYPE_DATETIME:
|
||||||
kwargs[attrName] = getTimeOrDeltaFromNow()
|
kwargs[attrName] = getTimeOrDeltaFromNow()
|
||||||
else: # GC.TYPE_INTEGER
|
elif attrType == GC.TYPE_INTEGER:
|
||||||
minVal, maxVal = attribute[GC.VAR_LIMITS]
|
minVal, maxVal = attribute[GC.VAR_LIMITS]
|
||||||
kwargs[attrName] = getInteger(minVal=minVal, maxVal=maxVal)
|
kwargs[attrName] = getInteger(minVal=minVal, maxVal=maxVal)
|
||||||
|
else: # elif attrType == GC.TYPE_CHOICE_LIST:
|
||||||
|
if attrName == 'eventTypes':
|
||||||
|
kwargs[attrName] = _getEventTypes()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _getCalendarListEventsDisplayProperty(myarg, calendarEventEntity):
|
def _getCalendarListEventsDisplayProperty(myarg, calendarEventEntity):
|
||||||
@@ -34915,6 +34919,41 @@ EVENT_JSONATTENDEES_SUBFIELD_CLEAR_FIELDS = {
|
|||||||
'attendees': ['id', 'organizer', 'self'],
|
'attendees': ['id', 'organizer', 'self'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WORKING_LOCATION_CHOICE_MAP = {
|
||||||
|
'custom': 'customLocation',
|
||||||
|
'home': 'homeOffice',
|
||||||
|
'office': 'officeLocation',
|
||||||
|
}
|
||||||
|
|
||||||
|
def getWorkingLocationProperties(body):
|
||||||
|
body.update({'eventType': 'workingLocation', 'workingLocationProperties': {},
|
||||||
|
'visibility': 'public', 'transparency':'transparent'})
|
||||||
|
location = getChoice(WORKING_LOCATION_CHOICE_MAP, mapChoice=True)
|
||||||
|
body['workingLocationProperties']['type'] = location
|
||||||
|
if location == 'homeOffice':
|
||||||
|
pass
|
||||||
|
elif location == 'customLocation':
|
||||||
|
body['workingLocationProperties'][location] = {'label': getString(Cmd.OB_STRING)}
|
||||||
|
else: #officeLocation
|
||||||
|
body['workingLocationProperties'][location] = {'label': getString(Cmd.OB_STRING)}
|
||||||
|
entry = body['workingLocationProperties'][location]
|
||||||
|
while Cmd.ArgumentsRemaining():
|
||||||
|
argument = getArgument()
|
||||||
|
if argument in {'building', 'buildingid'}:
|
||||||
|
entry['buildingId'] = _getBuildingByNameOrId(None)
|
||||||
|
elif argument in {'floor', 'floorname'}:
|
||||||
|
entry['floorId'] = getString(Cmd.OB_STRING, minLen=0)
|
||||||
|
elif argument in {'section', 'floorsection'}:
|
||||||
|
entry['floorSectionId'] = getString(Cmd.OB_STRING, minLen=0)
|
||||||
|
elif argument in {'desk', 'deskcode'}:
|
||||||
|
entry['deskId'] = getString(Cmd.OB_STRING, minLen=0)
|
||||||
|
elif argument == 'endlocation':
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
Cmd.Backup()
|
||||||
|
break
|
||||||
|
return location
|
||||||
|
|
||||||
def _getCalendarEventAttribute(myarg, body, parameters, function):
|
def _getCalendarEventAttribute(myarg, body, parameters, function):
|
||||||
def clearJSONfields(body, clearFields):
|
def clearJSONfields(body, clearFields):
|
||||||
for field in clearFields:
|
for field in clearFields:
|
||||||
@@ -35062,6 +35101,8 @@ def _getCalendarEventAttribute(myarg, body, parameters, function):
|
|||||||
body['extendedProperties'].setdefault('shared', {})
|
body['extendedProperties'].setdefault('shared', {})
|
||||||
key = getString(Cmd.OB_PROPERTY_KEY)
|
key = getString(Cmd.OB_PROPERTY_KEY)
|
||||||
body['extendedProperties']['shared'][key] = getString(Cmd.OB_PROPERTY_VALUE, minLen=0)
|
body['extendedProperties']['shared'][key] = getString(Cmd.OB_PROPERTY_VALUE, minLen=0)
|
||||||
|
elif myarg == 'workinglocation':
|
||||||
|
getWorkingLocationProperties(body)
|
||||||
elif function == 'update' and myarg == 'clearprivateproperty':
|
elif function == 'update' and myarg == 'clearprivateproperty':
|
||||||
body.setdefault('extendedProperties', {})
|
body.setdefault('extendedProperties', {})
|
||||||
body['extendedProperties'].setdefault('private', {})
|
body['extendedProperties'].setdefault('private', {})
|
||||||
@@ -35337,12 +35378,12 @@ def _createCalendarEvents(user, origCal, function, calIds, count, body, paramete
|
|||||||
if function == 'insert':
|
if function == 'insert':
|
||||||
event = callGAPI(cal.events(), 'insert',
|
event = callGAPI(cal.events(), 'insert',
|
||||||
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.INVALID, GAPI.REQUIRED, GAPI.TIME_RANGE_EMPTY, GAPI.EVENT_DURATION_EXCEEDS_LIMIT,
|
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.INVALID, GAPI.REQUIRED, GAPI.TIME_RANGE_EMPTY, GAPI.EVENT_DURATION_EXCEEDS_LIMIT,
|
||||||
GAPI.REQUIRED_ACCESS_LEVEL, GAPI.DUPLICATE, GAPI.FORBIDDEN],
|
GAPI.REQUIRED_ACCESS_LEVEL, GAPI.DUPLICATE, GAPI.FORBIDDEN, GAPI.MALFORMED_WORKING_LOCATION_EVENT],
|
||||||
calendarId=calId, conferenceDataVersion=1, sendUpdates=parameters['sendUpdates'], supportsAttachments=True, body=body, fields=fields)
|
calendarId=calId, conferenceDataVersion=1, sendUpdates=parameters['sendUpdates'], supportsAttachments=True, body=body, fields=fields)
|
||||||
else:
|
else:
|
||||||
event = callGAPI(cal.events(), 'import_',
|
event = callGAPI(cal.events(), 'import_',
|
||||||
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.INVALID, GAPI.REQUIRED, GAPI.TIME_RANGE_EMPTY, GAPI.EVENT_DURATION_EXCEEDS_LIMIT,
|
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.INVALID, GAPI.REQUIRED, GAPI.TIME_RANGE_EMPTY, GAPI.EVENT_DURATION_EXCEEDS_LIMIT,
|
||||||
GAPI.REQUIRED_ACCESS_LEVEL, GAPI.DUPLICATE, GAPI.FORBIDDEN,
|
GAPI.REQUIRED_ACCESS_LEVEL, GAPI.DUPLICATE, GAPI.FORBIDDEN, GAPI.MALFORMED_WORKING_LOCATION_EVENT,
|
||||||
GAPI.PARTICIPANT_IS_NEITHER_ORGANIZER_NOR_ATTENDEE],
|
GAPI.PARTICIPANT_IS_NEITHER_ORGANIZER_NOR_ATTENDEE],
|
||||||
calendarId=calId, conferenceDataVersion=1, supportsAttachments=True, body=body, fields=fields)
|
calendarId=calId, conferenceDataVersion=1, supportsAttachments=True, body=body, fields=fields)
|
||||||
if parameters['csvPF'] is None:
|
if parameters['csvPF'] is None:
|
||||||
@@ -35352,7 +35393,7 @@ def _createCalendarEvents(user, origCal, function, calIds, count, body, paramete
|
|||||||
_getEventDaysOfWeek(event)
|
_getEventDaysOfWeek(event)
|
||||||
_printCalendarEvent(user, calId, event, parameters['csvPF'], parameters['FJQC'])
|
_printCalendarEvent(user, calId, event, parameters['csvPF'], parameters['FJQC'])
|
||||||
except (GAPI.invalid, GAPI.required, GAPI.timeRangeEmpty, GAPI.eventDurationExceedsLimit,
|
except (GAPI.invalid, GAPI.required, GAPI.timeRangeEmpty, GAPI.eventDurationExceedsLimit,
|
||||||
GAPI.requiredAccessLevel, GAPI.participantIsNeitherOrganizerNorAttendee) as e:
|
GAPI.requiredAccessLevel, GAPI.participantIsNeitherOrganizerNorAttendee, GAPI.malformedWorkingLocationEvent) as e:
|
||||||
entityActionFailedWarning([Ent.CALENDAR, calId, Ent.EVENT, event['id']], str(e), i, count)
|
entityActionFailedWarning([Ent.CALENDAR, calId, Ent.EVENT, event['id']], str(e), i, count)
|
||||||
except GAPI.duplicate as e:
|
except GAPI.duplicate as e:
|
||||||
entityActionFailedWarning([Ent.CALENDAR, calId, Ent.EVENT, event['id']], str(e), i, count)
|
entityActionFailedWarning([Ent.CALENDAR, calId, Ent.EVENT, event['id']], str(e), i, count)
|
||||||
@@ -35717,6 +35758,85 @@ def doCalendarsEmptyTrash(calIds):
|
|||||||
Act.Set(Act.PURGE)
|
Act.Set(Act.PURGE)
|
||||||
_emptyCalendarTrash(None, None, calIds, len(calIds))
|
_emptyCalendarTrash(None, None, calIds, len(calIds))
|
||||||
|
|
||||||
|
EVENT_SHOW_ORDER = ['id', 'summary', 'status', 'description', 'location',
|
||||||
|
'start', 'end', 'endTimeUnspecified',
|
||||||
|
'creator', 'organizer', 'created', 'updated', 'iCalUID']
|
||||||
|
EVENT_PRINT_ORDER = ['id', 'summary', 'status', 'description', 'location',
|
||||||
|
'created', 'updated', 'iCalUID']
|
||||||
|
|
||||||
|
EVENT_TIME_OBJECTS = {'created', 'updated', 'dateTime'}
|
||||||
|
|
||||||
|
def _showCalendarEvent(primaryEmail, calId, eventEntityType, event, k, kcount, FJQC):
|
||||||
|
if FJQC.formatJSON:
|
||||||
|
if primaryEmail:
|
||||||
|
printLine(json.dumps(cleanJSON({'primaryEmail': primaryEmail, 'calendarId': calId, 'event': event},
|
||||||
|
timeObjects=EVENT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
|
||||||
|
else:
|
||||||
|
printLine(json.dumps(cleanJSON({'calendarId': calId, 'event': event},
|
||||||
|
timeObjects=EVENT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
|
||||||
|
return
|
||||||
|
printEntity([eventEntityType, event['id']], k, kcount)
|
||||||
|
skipObjects = {'id'}
|
||||||
|
Ind.Increment()
|
||||||
|
for field in EVENT_SHOW_ORDER:
|
||||||
|
if field in event:
|
||||||
|
showJSON(field, event[field], skipObjects, EVENT_TIME_OBJECTS)
|
||||||
|
skipObjects.add(field)
|
||||||
|
showJSON(None, event, skipObjects)
|
||||||
|
Ind.Decrement()
|
||||||
|
|
||||||
|
def _printCalendarEvent(user, calId, event, csvPF, FJQC):
|
||||||
|
row = {'calendarId': calId, 'id': event['id']}
|
||||||
|
if user:
|
||||||
|
row['primaryEmail'] = user
|
||||||
|
flattenJSON(event, flattened=row, timeObjects=EVENT_TIME_OBJECTS)
|
||||||
|
if not FJQC.formatJSON:
|
||||||
|
csvPF.WriteRowTitles(row)
|
||||||
|
elif csvPF.CheckRowTitles(row):
|
||||||
|
row = {'calendarId': calId, 'id': event['id'],
|
||||||
|
'JSON': json.dumps(cleanJSON(event, timeObjects=EVENT_TIME_OBJECTS),
|
||||||
|
ensure_ascii=False, sort_keys=False)}
|
||||||
|
if user:
|
||||||
|
row['primaryEmail'] = user
|
||||||
|
csvPF.WriteRowNoFilter(row)
|
||||||
|
|
||||||
|
def _printShowCalendarEvents(origUser, user, origCal, calIds, count, calendarEventEntity,
|
||||||
|
csvPF, FJQC, fieldsList):
|
||||||
|
i = 0
|
||||||
|
for calId in calIds:
|
||||||
|
i += 1
|
||||||
|
if csvPF:
|
||||||
|
printGettingEntityItemForWhom(Ent.EVENT, calId, i, count)
|
||||||
|
calId, _, events, jcount = _validateCalendarGetEvents(origUser, user, origCal, calId, i, count, calendarEventEntity,
|
||||||
|
fieldsList, not csvPF and not FJQC.formatJSON and not calendarEventEntity['countsOnly'])
|
||||||
|
if not csvPF:
|
||||||
|
if not calendarEventEntity['countsOnly']:
|
||||||
|
Ind.Increment()
|
||||||
|
j = 0
|
||||||
|
for event in events:
|
||||||
|
j += 1
|
||||||
|
if calendarEventEntity['showDayOfWeek']:
|
||||||
|
_getEventDaysOfWeek(event)
|
||||||
|
_showCalendarEvent(user, calId, Ent.EVENT, event, j, jcount, FJQC)
|
||||||
|
Ind.Decrement()
|
||||||
|
else:
|
||||||
|
printKeyValueList([Ent.Singular(Ent.CALENDAR), calId, Ent.Choose(Ent.EVENT, jcount), jcount])
|
||||||
|
else:
|
||||||
|
if not calendarEventEntity['countsOnly']:
|
||||||
|
if events:
|
||||||
|
for event in events:
|
||||||
|
if calendarEventEntity['showDayOfWeek']:
|
||||||
|
_getEventDaysOfWeek(event)
|
||||||
|
_printCalendarEvent(user, calId, event, csvPF, FJQC)
|
||||||
|
elif GC.Values[GC.CSV_OUTPUT_USERS_AUDIT] and user:
|
||||||
|
csvPF.WriteRowNoFilter({'calendarId': calId, 'primaryEmail': user, 'id': ''})
|
||||||
|
else:
|
||||||
|
row = {'calendarId': calId}
|
||||||
|
if user:
|
||||||
|
row['primaryEmail'] = user
|
||||||
|
row['events'] = jcount
|
||||||
|
csvPF.WriteRow(row)
|
||||||
|
|
||||||
EVENT_FIELDS_CHOICE_MAP = {
|
EVENT_FIELDS_CHOICE_MAP = {
|
||||||
'anyonecanaddself': 'anyoneCanAddSelf',
|
'anyonecanaddself': 'anyoneCanAddSelf',
|
||||||
'attachments': 'attachments',
|
'attachments': 'attachments',
|
||||||
@@ -35848,6 +35968,22 @@ def _addEventEntitySelectFields(calendarEventEntity, fieldsList):
|
|||||||
if calendarEventEntity['maxinstances'] != -1:
|
if calendarEventEntity['maxinstances'] != -1:
|
||||||
fieldsList.append('recurrence')
|
fieldsList.append('recurrence')
|
||||||
|
|
||||||
|
EVENT_TYPES_CHOICE_MAP = {
|
||||||
|
'default': 'default',
|
||||||
|
'focustime': 'focusTime',
|
||||||
|
'outofoffice': 'outOfOffice',
|
||||||
|
'workinglocation': 'workingLocation',
|
||||||
|
}
|
||||||
|
|
||||||
|
def _getEventTypes():
|
||||||
|
typesList = []
|
||||||
|
for field in _getFieldsList():
|
||||||
|
if field in EVENT_TYPES_CHOICE_MAP:
|
||||||
|
addFieldToFieldsList(field, EVENT_TYPES_CHOICE_MAP, typesList)
|
||||||
|
else:
|
||||||
|
invalidChoiceExit(field, EVENT_TYPES_CHOICE_MAP, True)
|
||||||
|
return ','.join(typesList)
|
||||||
|
|
||||||
def _getCalendarInfoEventOptions(calendarEventEntity):
|
def _getCalendarInfoEventOptions(calendarEventEntity):
|
||||||
FJQC = FormatJSONQuoteChar()
|
FJQC = FormatJSONQuoteChar()
|
||||||
fieldsList = []
|
fieldsList = []
|
||||||
@@ -35960,85 +36096,6 @@ def _getEventDaysOfWeek(event):
|
|||||||
except (iso8601.ParseError, OverflowError):
|
except (iso8601.ParseError, OverflowError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
EVENT_SHOW_ORDER = ['id', 'summary', 'status', 'description', 'location',
|
|
||||||
'start', 'end', 'endTimeUnspecified',
|
|
||||||
'creator', 'organizer', 'created', 'updated', 'iCalUID']
|
|
||||||
EVENT_PRINT_ORDER = ['id', 'summary', 'status', 'description', 'location',
|
|
||||||
'created', 'updated', 'iCalUID']
|
|
||||||
|
|
||||||
EVENT_TIME_OBJECTS = {'created', 'updated', 'dateTime'}
|
|
||||||
|
|
||||||
def _showCalendarEvent(primaryEmail, calId, eventEntityType, event, k, kcount, FJQC):
|
|
||||||
if FJQC.formatJSON:
|
|
||||||
if primaryEmail:
|
|
||||||
printLine(json.dumps(cleanJSON({'primaryEmail': primaryEmail, 'calendarId': calId, 'event': event},
|
|
||||||
timeObjects=EVENT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
|
|
||||||
else:
|
|
||||||
printLine(json.dumps(cleanJSON({'calendarId': calId, 'event': event},
|
|
||||||
timeObjects=EVENT_TIME_OBJECTS), ensure_ascii=False, sort_keys=True))
|
|
||||||
return
|
|
||||||
printEntity([eventEntityType, event['id']], k, kcount)
|
|
||||||
skipObjects = {'id'}
|
|
||||||
Ind.Increment()
|
|
||||||
for field in EVENT_SHOW_ORDER:
|
|
||||||
if field in event:
|
|
||||||
showJSON(field, event[field], skipObjects, EVENT_TIME_OBJECTS)
|
|
||||||
skipObjects.add(field)
|
|
||||||
showJSON(None, event, skipObjects)
|
|
||||||
Ind.Decrement()
|
|
||||||
|
|
||||||
def _printCalendarEvent(user, calId, event, csvPF, FJQC):
|
|
||||||
row = {'calendarId': calId, 'id': event['id']}
|
|
||||||
if user:
|
|
||||||
row['primaryEmail'] = user
|
|
||||||
flattenJSON(event, flattened=row, timeObjects=EVENT_TIME_OBJECTS)
|
|
||||||
if not FJQC.formatJSON:
|
|
||||||
csvPF.WriteRowTitles(row)
|
|
||||||
elif csvPF.CheckRowTitles(row):
|
|
||||||
row = {'calendarId': calId, 'id': event['id'],
|
|
||||||
'JSON': json.dumps(cleanJSON(event, timeObjects=EVENT_TIME_OBJECTS),
|
|
||||||
ensure_ascii=False, sort_keys=False)}
|
|
||||||
if user:
|
|
||||||
row['primaryEmail'] = user
|
|
||||||
csvPF.WriteRowNoFilter(row)
|
|
||||||
|
|
||||||
def _printShowCalendarEvents(origUser, user, origCal, calIds, count, calendarEventEntity,
|
|
||||||
csvPF, FJQC, fieldsList):
|
|
||||||
i = 0
|
|
||||||
for calId in calIds:
|
|
||||||
i += 1
|
|
||||||
if csvPF:
|
|
||||||
printGettingEntityItemForWhom(Ent.EVENT, calId, i, count)
|
|
||||||
calId, _, events, jcount = _validateCalendarGetEvents(origUser, user, origCal, calId, i, count, calendarEventEntity,
|
|
||||||
fieldsList, not csvPF and not FJQC.formatJSON and not calendarEventEntity['countsOnly'])
|
|
||||||
if not csvPF:
|
|
||||||
if not calendarEventEntity['countsOnly']:
|
|
||||||
Ind.Increment()
|
|
||||||
j = 0
|
|
||||||
for event in events:
|
|
||||||
j += 1
|
|
||||||
if calendarEventEntity['showDayOfWeek']:
|
|
||||||
_getEventDaysOfWeek(event)
|
|
||||||
_showCalendarEvent(user, calId, Ent.EVENT, event, j, jcount, FJQC)
|
|
||||||
Ind.Decrement()
|
|
||||||
else:
|
|
||||||
printKeyValueList([Ent.Singular(Ent.CALENDAR), calId, Ent.Choose(Ent.EVENT, jcount), jcount])
|
|
||||||
else:
|
|
||||||
if not calendarEventEntity['countsOnly']:
|
|
||||||
if events:
|
|
||||||
for event in events:
|
|
||||||
if calendarEventEntity['showDayOfWeek']:
|
|
||||||
_getEventDaysOfWeek(event)
|
|
||||||
_printCalendarEvent(user, calId, event, csvPF, FJQC)
|
|
||||||
elif GC.Values[GC.CSV_OUTPUT_USERS_AUDIT] and user:
|
|
||||||
csvPF.WriteRowNoFilter({'calendarId': calId, 'primaryEmail': user, 'id': ''})
|
|
||||||
else:
|
|
||||||
row = {'calendarId': calId}
|
|
||||||
if user:
|
|
||||||
row['primaryEmail'] = user
|
|
||||||
row['events'] = jcount
|
|
||||||
csvPF.WriteRow(row)
|
|
||||||
|
|
||||||
# gam calendars <CalendarEntity> print events <EventEntity> <EventDisplayProperties>*
|
# gam calendars <CalendarEntity> print events <EventEntity> <EventDisplayProperties>*
|
||||||
# [fields <EventFieldNameList>] [showdayofweek]
|
# [fields <EventFieldNameList>] [showdayofweek]
|
||||||
# [countsonly] [formatjson [quotechar <Character>]] [todrive <ToDriveAttribute>*]
|
# [countsonly] [formatjson [quotechar <Character>]] [todrive <ToDriveAttribute>*]
|
||||||
@@ -47674,27 +47731,33 @@ def printShowCalendarEvents(users):
|
|||||||
csvPF.writeCSVfile('Calendar Events')
|
csvPF.writeCSVfile('Calendar Events')
|
||||||
|
|
||||||
def getWorkingLocationDate(dateType, dateList):
|
def getWorkingLocationDate(dateType, dateList):
|
||||||
firstDate = getYYYYMMDD(minLen=1, returnDateTime=True)
|
firstDate = getYYYYMMDD(minLen=1, returnDateTime=True).replace(tzinfo=GC.Values[GC.TIMEZONE])
|
||||||
if dateType == 'range':
|
if dateType == 'range':
|
||||||
lastDate = getYYYYMMDD(minLen=1, returnDateTime=True)
|
lastDate = getYYYYMMDD(minLen=1, returnDateTime=True).replace(tzinfo=GC.Values[GC.TIMEZONE])
|
||||||
deltaDay = datetime.timedelta(days=1)
|
deltaDay = datetime.timedelta(days=1)
|
||||||
deltaWeek = datetime.timedelta(weeks=1)
|
deltaWeek = datetime.timedelta(weeks=1)
|
||||||
if dateType == 'date':
|
if dateType == 'date':
|
||||||
dateList.append({'first': firstDate, 'last': firstDate+deltaDay,
|
dateList.append({'first': firstDate, 'last': firstDate+deltaDay,
|
||||||
'udelta': deltaDay, 'pdelta': deltaDay})
|
'ulast': firstDate, 'udelta': deltaDay})
|
||||||
elif dateType == 'range':
|
elif dateType == 'range':
|
||||||
dateList.append({'first': firstDate, 'last': lastDate+deltaDay,
|
dateList.append({'first': firstDate, 'last': lastDate+deltaDay,
|
||||||
'udelta': deltaDay, 'pdelta': datetime.timedelta(days=(lastDate-firstDate).days+1)})
|
'ulast': lastDate, 'udelta': deltaDay})
|
||||||
elif dateType == 'daily':
|
elif dateType == 'daily':
|
||||||
argRepeat = getInteger(minVal=1, maxVal=366)
|
argRepeat = getInteger(minVal=1, maxVal=366)
|
||||||
dateList.append({'first': firstDate, 'last': firstDate+datetime.timedelta(days=argRepeat),
|
dateList.append({'first': firstDate, 'last': firstDate+datetime.timedelta(days=argRepeat),
|
||||||
'udelta': deltaDay, 'pdelta': deltaDay})
|
'ulast': firstDate+datetime.timedelta(days=argRepeat), 'udelta': deltaDay})
|
||||||
else: #weekly
|
else: #weekly
|
||||||
argRepeat = getInteger(minVal=1, maxVal=52)
|
argRepeat = getInteger(minVal=1, maxVal=52)
|
||||||
dateList.append({'first': firstDate, 'last': firstDate+datetime.timedelta(weeks=argRepeat),
|
dateList.append({'first': firstDate, 'last': firstDate+deltaDay, 'pdelta': deltaWeek, 'repeats': argRepeat,
|
||||||
'udelta': deltaWeek, 'pdelta': deltaWeek})
|
'ulast': firstDate+datetime.timedelta(weeks=argRepeat), 'udelta': deltaWeek})
|
||||||
|
|
||||||
|
def getWorkingLocationTimeRange(timeList):
|
||||||
|
startTime = getEventTime()
|
||||||
|
endTime = getEventTime()
|
||||||
|
timeList.append({'start': startTime, 'end': endTime})
|
||||||
|
|
||||||
WORKING_LOCATION_DATE_CHOICES = {'date', 'range', 'daily', 'weekly'}
|
WORKING_LOCATION_DATE_CHOICES = {'date', 'range', 'daily', 'weekly'}
|
||||||
|
WORKING_LOCATION_TIME_CHOICES = {'timerange'}
|
||||||
WORKING_LOCATION_CHOICE_MAP = {
|
WORKING_LOCATION_CHOICE_MAP = {
|
||||||
'custom': 'customLocation',
|
'custom': 'customLocation',
|
||||||
'home': 'homeOffice',
|
'home': 'homeOffice',
|
||||||
@@ -47709,7 +47772,7 @@ def _showCalendarWorkingLocation(primaryEmail, calId, eventEntityType, event, k,
|
|||||||
printEntity([eventEntityType, event['id']], k, kcount)
|
printEntity([eventEntityType, event['id']], k, kcount)
|
||||||
skipObjects = {'id'}
|
skipObjects = {'id'}
|
||||||
Ind.Increment()
|
Ind.Increment()
|
||||||
showJSON(None, event, skipObjects)
|
showJSON(None, event, skipObjects, EVENT_TIME_OBJECTS)
|
||||||
Ind.Decrement()
|
Ind.Decrement()
|
||||||
|
|
||||||
# gam <UserTypeEntity> update workinglocation
|
# gam <UserTypeEntity> update workinglocation
|
||||||
@@ -47720,76 +47783,91 @@ def _showCalendarWorkingLocation(primaryEmail, calId, eventEntityType, event, k,
|
|||||||
# ((date yyyy-mm-dd)|
|
# ((date yyyy-mm-dd)|
|
||||||
# (range yyyy-mm-dd yyyy-mm-dd)|
|
# (range yyyy-mm-dd yyyy-mm-dd)|
|
||||||
# (daily yyyy-mm-dd N)|
|
# (daily yyyy-mm-dd N)|
|
||||||
# (weekly yyyy-mm-dd N))+
|
# (weekly yyyy-mm-dd N)|
|
||||||
|
# (timerange <Time> <Time>))+
|
||||||
def updateWorkingLocation(users):
|
def updateWorkingLocation(users):
|
||||||
body = {'start': {'date': None}, 'end': {'date': None}, 'eventType': 'workingLocation', 'visibility': 'public', 'transparency': 'transparent',
|
body = {'start': {'date': None}, 'end': {'date': None}}
|
||||||
'workingLocationProperties': {'type': None}}
|
|
||||||
calId = 'primary'
|
calId = 'primary'
|
||||||
dateList = []
|
dateList = []
|
||||||
location = getChoice(WORKING_LOCATION_CHOICE_MAP, mapChoice=True)
|
timeList = []
|
||||||
body['workingLocationProperties']['type'] = location
|
location = getWorkingLocationProperties(body)
|
||||||
if location == 'homeOffice':
|
|
||||||
pass
|
|
||||||
elif location == 'customLocation':
|
|
||||||
body['workingLocationProperties'][location] = {'label': getString(Cmd.OB_STRING)}
|
|
||||||
else: #officeLocation
|
|
||||||
body['workingLocationProperties'][location] = {'label': getString(Cmd.OB_STRING)}
|
|
||||||
entry = body['workingLocationProperties'][location]
|
|
||||||
while Cmd.ArgumentsRemaining():
|
|
||||||
argument = getArgument()
|
|
||||||
if argument in {'building', 'buildingid'}:
|
|
||||||
entry['buildingId'] = _getBuildingByNameOrId(None)
|
|
||||||
elif argument in {'floor', 'floorname'}:
|
|
||||||
entry['floorId'] = getString(Cmd.OB_STRING, minLen=0)
|
|
||||||
elif argument in {'section', 'floorsection'}:
|
|
||||||
entry['floorSectionId'] = getString(Cmd.OB_STRING, minLen=0)
|
|
||||||
elif argument in {'desk', 'deskcode'}:
|
|
||||||
entry['deskId'] = getString(Cmd.OB_STRING, minLen=0)
|
|
||||||
elif argument == 'endlocation':
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
Cmd.Backup()
|
|
||||||
break
|
|
||||||
while Cmd.ArgumentsRemaining():
|
while Cmd.ArgumentsRemaining():
|
||||||
myarg = getArgument()
|
myarg = getArgument()
|
||||||
if myarg in WORKING_LOCATION_DATE_CHOICES:
|
if myarg in WORKING_LOCATION_DATE_CHOICES:
|
||||||
getWorkingLocationDate(myarg, dateList)
|
getWorkingLocationDate(myarg, dateList)
|
||||||
|
elif myarg in WORKING_LOCATION_TIME_CHOICES:
|
||||||
|
getWorkingLocationTimeRange(timeList)
|
||||||
elif myarg == 'json':
|
elif myarg == 'json':
|
||||||
body.update(getJSON([]))
|
body.update(getJSON([]))
|
||||||
else:
|
else:
|
||||||
unknownArgumentExit()
|
unknownArgumentExit()
|
||||||
if not dateList:
|
if not dateList and not timeList:
|
||||||
missingChoiceExit(WORKING_LOCATION_DATE_CHOICES)
|
missingChoiceExit(WORKING_LOCATION_DATE_CHOICES|WORKING_LOCATION_TIME_CHOICES)
|
||||||
kvlist = [Ent.USER, '', Ent.DATE, '', Ent.LOCATION, f"{body['workingLocationProperties'].get(location, {}).get('label', location)}"]
|
datekvList = [Ent.USER, '', Ent.DATE, '', Ent.LOCATION, f"{body['workingLocationProperties'].get(location, {}).get('label', location)}"]
|
||||||
|
timekvList = [Ent.USER, '', Ent.START_TIME, '', Ent.END_TIME, '', Ent.LOCATION, f"{body['workingLocationProperties'].get(location, {}).get('label', location)}"]
|
||||||
i, count, users = getEntityArgument(users)
|
i, count, users = getEntityArgument(users)
|
||||||
for user in users:
|
for user in users:
|
||||||
i += 1
|
i += 1
|
||||||
user, cal = buildGAPIServiceObject(API.CALENDAR, user, i, count)
|
user, cal = buildGAPIServiceObject(API.CALENDAR, user, i, count)
|
||||||
if not cal:
|
if not cal:
|
||||||
continue
|
continue
|
||||||
kvlist[1] = user
|
datekvList[1] = user
|
||||||
jcount = len(dateList)
|
jcount = len(dateList)
|
||||||
j = 0
|
j = 0
|
||||||
for wlDate in dateList:
|
for wlDate in dateList:
|
||||||
j += 1
|
j += 1
|
||||||
first = wlDate['first']
|
first = wlDate['first']
|
||||||
last = wlDate['last']
|
last = wlDate['ulast']
|
||||||
kvlist[3] = first.strftime(YYYYMMDD_FORMAT)
|
while first < last:
|
||||||
while first <= last:
|
datekvList[3] = first.strftime(YYYYMMDD_FORMAT)
|
||||||
body['start']['date'] = first.strftime(YYYYMMDD_FORMAT)
|
body['start']['date'] = first.strftime(YYYYMMDD_FORMAT)
|
||||||
body['end']['date'] = (first+datetime.timedelta(days=1)).strftime(YYYYMMDD_FORMAT)
|
body['end']['date'] = (first+datetime.timedelta(days=1)).strftime(YYYYMMDD_FORMAT)
|
||||||
try:
|
try:
|
||||||
callGAPI(cal.events(), 'insert',
|
callGAPI(cal.events(), 'insert',
|
||||||
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID],
|
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID, GAPI.BAD_REQUEST,
|
||||||
|
GAPI.TIME_RANGE_EMPTY, GAPI.MALFORMED_WORKING_LOCATION_EVENT],
|
||||||
calendarId=calId, body=body)
|
calendarId=calId, body=body)
|
||||||
|
entityActionPerformed(datekvList, j, jcount)
|
||||||
|
first += wlDate['udelta']
|
||||||
except (GAPI.notACalendarUser, GAPI.forbidden, GAPI.invalid) as e:
|
except (GAPI.notACalendarUser, GAPI.forbidden, GAPI.invalid) as e:
|
||||||
entityActionFailedWarning([Ent.USER, user], str(e), i, count)
|
entityActionFailedWarning([Ent.USER, user], str(e), i, count)
|
||||||
break
|
break
|
||||||
|
except (GAPI.badRequest, GAPI.timeRangeEmpty, GAPI.malformedWorkingLocationEvent) as e:
|
||||||
|
entityActionFailedWarning(datekvList, str(e), j, jcount)
|
||||||
|
break
|
||||||
|
except (GAPI.serviceNotAvailable, GAPI.authError):
|
||||||
|
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
|
||||||
|
break
|
||||||
|
timekvList[1] = user
|
||||||
|
jcount = len(timeList)
|
||||||
|
j = 0
|
||||||
|
for wlTime in timeList:
|
||||||
|
j += 1
|
||||||
|
startTime = wlTime['start']
|
||||||
|
if 'dateTime' in startTime:
|
||||||
|
timekvList[3] = formatLocalTime(startTime['dateTime'])
|
||||||
|
else:
|
||||||
|
timekvList[3] = startTime['date'].strftime(YYYYMMDD_FORMAT)
|
||||||
|
endTime = wlTime['end']
|
||||||
|
if 'dateTime' in endTime:
|
||||||
|
timekvList[5] = formatLocalTime(endTime['dateTime'])
|
||||||
|
else:
|
||||||
|
timekvList[5] = endTime['date'].strftime(YYYYMMDD_FORMAT)
|
||||||
|
body.update(wlTime)
|
||||||
|
try:
|
||||||
|
callGAPI(cal.events(), 'insert',
|
||||||
|
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID, GAPI.BAD_REQUEST,
|
||||||
|
GAPI.TIME_RANGE_EMPTY, GAPI.MALFORMED_WORKING_LOCATION_EVENT],
|
||||||
|
calendarId=calId, body=body)
|
||||||
|
entityActionPerformed(timekvList, j, jcount)
|
||||||
|
except (GAPI.notACalendarUser, GAPI.forbidden, GAPI.invalid) as e:
|
||||||
|
entityActionFailedWarning([Ent.USER, user], str(e), i, count)
|
||||||
|
break
|
||||||
|
except (GAPI.badRequest, GAPI.timeRangeEmpty, GAPI.malformedWorkingLocationEvent) as e:
|
||||||
|
entityActionFailedWarning(timekvList, str(e), j, jcount)
|
||||||
except (GAPI.serviceNotAvailable, GAPI.authError):
|
except (GAPI.serviceNotAvailable, GAPI.authError):
|
||||||
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
|
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
|
||||||
break
|
break
|
||||||
entityActionPerformed(kvlist, j, jcount)
|
|
||||||
first += wlDate['udelta']
|
|
||||||
|
|
||||||
# gam <UserTypeEntity> show workinglocation
|
# gam <UserTypeEntity> show workinglocation
|
||||||
# ((date yyyy-mm-dd)|
|
# ((date yyyy-mm-dd)|
|
||||||
@@ -47806,11 +47884,10 @@ def updateWorkingLocation(users):
|
|||||||
# [showdayofweek]
|
# [showdayofweek]
|
||||||
# [formatjson [quotechar <Character>]] [todrive <ToDriveAttribute>*]
|
# [formatjson [quotechar <Character>]] [todrive <ToDriveAttribute>*]
|
||||||
def printShowWorkingLocation(users):
|
def printShowWorkingLocation(users):
|
||||||
csvPF = CSVPrintFile(['User', 'type'], 'sortall') if Act.csvFormat() else None
|
csvPF = CSVPrintFile(['primaryEmail', 'calendarId', 'id'], 'sortall') if Act.csvFormat() else None
|
||||||
FJQC = FormatJSONQuoteChar(csvPF)
|
FJQC = FormatJSONQuoteChar(csvPF)
|
||||||
kwargs = {'eventTypes': ['workingLocation'], 'showDeleted': False, 'singleEvents': True,
|
kwargs = {'eventTypes': ['workingLocation'], 'showDeleted': False, 'singleEvents': True,
|
||||||
# kwargs = {'showDeleted': False, 'singleEvents': True,
|
'timeMax': None, 'timeMin': None, 'orderBy': 'startTime'}
|
||||||
'timeMax': None, 'timeMin': None}
|
|
||||||
calId = 'primary'
|
calId = 'primary'
|
||||||
showDayOfWeek = False
|
showDayOfWeek = False
|
||||||
dateList = []
|
dateList = []
|
||||||
@@ -47840,14 +47917,14 @@ def printShowWorkingLocation(users):
|
|||||||
j += 1
|
j += 1
|
||||||
first = wlDate['first']
|
first = wlDate['first']
|
||||||
last = wlDate['last']
|
last = wlDate['last']
|
||||||
while first <= last:
|
for _ in range(1, wlDate.get('repeats', 1)+1):
|
||||||
kwargs['timeMin'] = first.strftime(YYYYMMDDTHHMMSSZ_FORMAT)
|
kwargs['timeMin'] = ISOformatTimeStamp(first)
|
||||||
kwargs['timeMax'] = last.strftime(YYYYMMDDTHHMMSSZ_FORMAT)
|
kwargs['timeMax'] = ISOformatTimeStamp(last)
|
||||||
try:
|
try:
|
||||||
events = callGAPIpages(cal.events(), 'list', 'items',
|
events = callGAPIpages(cal.events(), 'list', 'items',
|
||||||
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID],
|
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID, GAPI.BAD_REQUEST],
|
||||||
calendarId=calId, fields='nextPageToken,items(id,start,workingLocationProperties)', **kwargs)
|
calendarId=calId, fields='nextPageToken,items(id,start,end,workingLocationProperties)', **kwargs)
|
||||||
except (GAPI.notACalendarUser, GAPI.notFound, GAPI.forbidden, GAPI.invalid) as e:
|
except (GAPI.notACalendarUser, GAPI.notFound, GAPI.forbidden, GAPI.invalid, GAPI.badRequest) as e:
|
||||||
entityActionFailedWarning([Ent.USER, user], str(e), i, count)
|
entityActionFailedWarning([Ent.USER, user], str(e), i, count)
|
||||||
break
|
break
|
||||||
except (GAPI.serviceNotAvailable, GAPI.authError):
|
except (GAPI.serviceNotAvailable, GAPI.authError):
|
||||||
@@ -47868,7 +47945,9 @@ def printShowWorkingLocation(users):
|
|||||||
if showDayOfWeek:
|
if showDayOfWeek:
|
||||||
_getEventDaysOfWeek(event)
|
_getEventDaysOfWeek(event)
|
||||||
_printCalendarEvent(user, calId, event, csvPF, FJQC)
|
_printCalendarEvent(user, calId, event, csvPF, FJQC)
|
||||||
|
if 'pdelta' in wlDate:
|
||||||
first += wlDate['pdelta']
|
first += wlDate['pdelta']
|
||||||
|
last += wlDate['pdelta']
|
||||||
if csvPF:
|
if csvPF:
|
||||||
csvPF.writeCSVfile('Calendar Working Locations')
|
csvPF.writeCSVfile('Calendar Working Locations')
|
||||||
|
|
||||||
|
|||||||
@@ -400,6 +400,7 @@ Values = {DEBUG_LEVEL: 0}
|
|||||||
TYPE_BOOLEAN = 'bool'
|
TYPE_BOOLEAN = 'bool'
|
||||||
TYPE_CHARACTER = 'char'
|
TYPE_CHARACTER = 'char'
|
||||||
TYPE_CHOICE = 'choi'
|
TYPE_CHOICE = 'choi'
|
||||||
|
TYPE_CHOICE_LIST = 'chol'
|
||||||
TYPE_DATETIME = 'datm'
|
TYPE_DATETIME = 'datm'
|
||||||
TYPE_DIRECTORY = 'dire'
|
TYPE_DIRECTORY = 'dire'
|
||||||
TYPE_EMAIL = 'emai'
|
TYPE_EMAIL = 'emai'
|
||||||
|
|||||||
Reference in New Issue
Block a user