mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 01:41:36 +00:00
workingLocation cleanup (not public)
This commit is contained in:
@@ -4498,7 +4498,7 @@ def refreshCredentialsWithReauth(credentials):
|
||||
gcloud_path_result = subprocess.run(['gcloud',
|
||||
'info',
|
||||
'--format=value(config.paths.global_config_dir)'],
|
||||
capture_output=True, ckeck=False)
|
||||
capture_output=True, check=False)
|
||||
except KeyboardInterrupt as e:
|
||||
# avoids loss of terminal echo on *nix
|
||||
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')
|
||||
if not credentials._rapt_token:
|
||||
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):
|
||||
"""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}),
|
||||
'updated': ('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 = {
|
||||
@@ -34815,9 +34816,12 @@ def _getCalendarListEventsProperty(myarg, attributes, kwargs):
|
||||
kwargs[attrName] = getChoice(attribute['choices'], mapChoice=True)
|
||||
elif attrType == GC.TYPE_DATETIME:
|
||||
kwargs[attrName] = getTimeOrDeltaFromNow()
|
||||
else: # GC.TYPE_INTEGER
|
||||
elif attrType == GC.TYPE_INTEGER:
|
||||
minVal, maxVal = attribute[GC.VAR_LIMITS]
|
||||
kwargs[attrName] = getInteger(minVal=minVal, maxVal=maxVal)
|
||||
else: # elif attrType == GC.TYPE_CHOICE_LIST:
|
||||
if attrName == 'eventTypes':
|
||||
kwargs[attrName] = _getEventTypes()
|
||||
return True
|
||||
|
||||
def _getCalendarListEventsDisplayProperty(myarg, calendarEventEntity):
|
||||
@@ -34915,6 +34919,41 @@ EVENT_JSONATTENDEES_SUBFIELD_CLEAR_FIELDS = {
|
||||
'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 clearJSONfields(body, clearFields):
|
||||
for field in clearFields:
|
||||
@@ -35062,6 +35101,8 @@ def _getCalendarEventAttribute(myarg, body, parameters, function):
|
||||
body['extendedProperties'].setdefault('shared', {})
|
||||
key = getString(Cmd.OB_PROPERTY_KEY)
|
||||
body['extendedProperties']['shared'][key] = getString(Cmd.OB_PROPERTY_VALUE, minLen=0)
|
||||
elif myarg == 'workinglocation':
|
||||
getWorkingLocationProperties(body)
|
||||
elif function == 'update' and myarg == 'clearprivateproperty':
|
||||
body.setdefault('extendedProperties', {})
|
||||
body['extendedProperties'].setdefault('private', {})
|
||||
@@ -35337,12 +35378,12 @@ def _createCalendarEvents(user, origCal, function, calIds, count, body, paramete
|
||||
if function == 'insert':
|
||||
event = callGAPI(cal.events(), 'insert',
|
||||
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)
|
||||
else:
|
||||
event = callGAPI(cal.events(), 'import_',
|
||||
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],
|
||||
calendarId=calId, conferenceDataVersion=1, supportsAttachments=True, body=body, fields=fields)
|
||||
if parameters['csvPF'] is None:
|
||||
@@ -35352,7 +35393,7 @@ def _createCalendarEvents(user, origCal, function, calIds, count, body, paramete
|
||||
_getEventDaysOfWeek(event)
|
||||
_printCalendarEvent(user, calId, event, parameters['csvPF'], parameters['FJQC'])
|
||||
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)
|
||||
except GAPI.duplicate as e:
|
||||
entityActionFailedWarning([Ent.CALENDAR, calId, Ent.EVENT, event['id']], str(e), i, count)
|
||||
@@ -35717,6 +35758,85 @@ def doCalendarsEmptyTrash(calIds):
|
||||
Act.Set(Act.PURGE)
|
||||
_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 = {
|
||||
'anyonecanaddself': 'anyoneCanAddSelf',
|
||||
'attachments': 'attachments',
|
||||
@@ -35848,6 +35968,22 @@ def _addEventEntitySelectFields(calendarEventEntity, fieldsList):
|
||||
if calendarEventEntity['maxinstances'] != -1:
|
||||
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):
|
||||
FJQC = FormatJSONQuoteChar()
|
||||
fieldsList = []
|
||||
@@ -35960,85 +36096,6 @@ def _getEventDaysOfWeek(event):
|
||||
except (iso8601.ParseError, OverflowError):
|
||||
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>*
|
||||
# [fields <EventFieldNameList>] [showdayofweek]
|
||||
# [countsonly] [formatjson [quotechar <Character>]] [todrive <ToDriveAttribute>*]
|
||||
@@ -47674,27 +47731,33 @@ def printShowCalendarEvents(users):
|
||||
csvPF.writeCSVfile('Calendar Events')
|
||||
|
||||
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':
|
||||
lastDate = getYYYYMMDD(minLen=1, returnDateTime=True)
|
||||
lastDate = getYYYYMMDD(minLen=1, returnDateTime=True).replace(tzinfo=GC.Values[GC.TIMEZONE])
|
||||
deltaDay = datetime.timedelta(days=1)
|
||||
deltaWeek = datetime.timedelta(weeks=1)
|
||||
if dateType == 'date':
|
||||
dateList.append({'first': firstDate, 'last': firstDate+deltaDay,
|
||||
'udelta': deltaDay, 'pdelta': deltaDay})
|
||||
'ulast': firstDate, 'udelta': deltaDay})
|
||||
elif dateType == 'range':
|
||||
dateList.append({'first': firstDate, 'last': lastDate+deltaDay,
|
||||
'udelta': deltaDay, 'pdelta': datetime.timedelta(days=(lastDate-firstDate).days+1)})
|
||||
'ulast': lastDate, 'udelta': deltaDay})
|
||||
elif dateType == 'daily':
|
||||
argRepeat = getInteger(minVal=1, maxVal=366)
|
||||
dateList.append({'first': firstDate, 'last': firstDate+datetime.timedelta(days=argRepeat),
|
||||
'udelta': deltaDay, 'pdelta': deltaDay})
|
||||
'ulast': firstDate+datetime.timedelta(days=argRepeat), 'udelta': deltaDay})
|
||||
else: #weekly
|
||||
argRepeat = getInteger(minVal=1, maxVal=52)
|
||||
dateList.append({'first': firstDate, 'last': firstDate+datetime.timedelta(weeks=argRepeat),
|
||||
'udelta': deltaWeek, 'pdelta': deltaWeek})
|
||||
dateList.append({'first': firstDate, 'last': firstDate+deltaDay, 'pdelta': deltaWeek, 'repeats': argRepeat,
|
||||
'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_TIME_CHOICES = {'timerange'}
|
||||
WORKING_LOCATION_CHOICE_MAP = {
|
||||
'custom': 'customLocation',
|
||||
'home': 'homeOffice',
|
||||
@@ -47709,7 +47772,7 @@ def _showCalendarWorkingLocation(primaryEmail, calId, eventEntityType, event, k,
|
||||
printEntity([eventEntityType, event['id']], k, kcount)
|
||||
skipObjects = {'id'}
|
||||
Ind.Increment()
|
||||
showJSON(None, event, skipObjects)
|
||||
showJSON(None, event, skipObjects, EVENT_TIME_OBJECTS)
|
||||
Ind.Decrement()
|
||||
|
||||
# gam <UserTypeEntity> update workinglocation
|
||||
@@ -47720,76 +47783,91 @@ def _showCalendarWorkingLocation(primaryEmail, calId, eventEntityType, event, k,
|
||||
# ((date yyyy-mm-dd)|
|
||||
# (range yyyy-mm-dd yyyy-mm-dd)|
|
||||
# (daily yyyy-mm-dd N)|
|
||||
# (weekly yyyy-mm-dd N))+
|
||||
# (weekly yyyy-mm-dd N)|
|
||||
# (timerange <Time> <Time>))+
|
||||
def updateWorkingLocation(users):
|
||||
body = {'start': {'date': None}, 'end': {'date': None}, 'eventType': 'workingLocation', 'visibility': 'public', 'transparency': 'transparent',
|
||||
'workingLocationProperties': {'type': None}}
|
||||
body = {'start': {'date': None}, 'end': {'date': None}}
|
||||
calId = 'primary'
|
||||
dateList = []
|
||||
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
|
||||
timeList = []
|
||||
location = getWorkingLocationProperties(body)
|
||||
while Cmd.ArgumentsRemaining():
|
||||
myarg = getArgument()
|
||||
if myarg in WORKING_LOCATION_DATE_CHOICES:
|
||||
getWorkingLocationDate(myarg, dateList)
|
||||
elif myarg in WORKING_LOCATION_TIME_CHOICES:
|
||||
getWorkingLocationTimeRange(timeList)
|
||||
elif myarg == 'json':
|
||||
body.update(getJSON([]))
|
||||
else:
|
||||
unknownArgumentExit()
|
||||
if not dateList:
|
||||
missingChoiceExit(WORKING_LOCATION_DATE_CHOICES)
|
||||
kvlist = [Ent.USER, '', Ent.DATE, '', Ent.LOCATION, f"{body['workingLocationProperties'].get(location, {}).get('label', location)}"]
|
||||
if not dateList and not timeList:
|
||||
missingChoiceExit(WORKING_LOCATION_DATE_CHOICES|WORKING_LOCATION_TIME_CHOICES)
|
||||
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)
|
||||
for user in users:
|
||||
i += 1
|
||||
user, cal = buildGAPIServiceObject(API.CALENDAR, user, i, count)
|
||||
if not cal:
|
||||
continue
|
||||
kvlist[1] = user
|
||||
datekvList[1] = user
|
||||
jcount = len(dateList)
|
||||
j = 0
|
||||
for wlDate in dateList:
|
||||
j += 1
|
||||
first = wlDate['first']
|
||||
last = wlDate['last']
|
||||
kvlist[3] = first.strftime(YYYYMMDD_FORMAT)
|
||||
while first <= last:
|
||||
last = wlDate['ulast']
|
||||
while first < last:
|
||||
datekvList[3] = first.strftime(YYYYMMDD_FORMAT)
|
||||
body['start']['date'] = first.strftime(YYYYMMDD_FORMAT)
|
||||
body['end']['date'] = (first+datetime.timedelta(days=1)).strftime(YYYYMMDD_FORMAT)
|
||||
try:
|
||||
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)
|
||||
entityActionPerformed(datekvList, j, jcount)
|
||||
first += wlDate['udelta']
|
||||
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(datekvList, str(e), j, jcount)
|
||||
break
|
||||
except (GAPI.serviceNotAvailable, GAPI.authError):
|
||||
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
|
||||
break
|
||||
entityActionPerformed(kvlist, j, jcount)
|
||||
first += wlDate['udelta']
|
||||
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):
|
||||
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
|
||||
break
|
||||
|
||||
# gam <UserTypeEntity> show workinglocation
|
||||
# ((date yyyy-mm-dd)|
|
||||
@@ -47806,11 +47884,10 @@ def updateWorkingLocation(users):
|
||||
# [showdayofweek]
|
||||
# [formatjson [quotechar <Character>]] [todrive <ToDriveAttribute>*]
|
||||
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)
|
||||
kwargs = {'eventTypes': ['workingLocation'], 'showDeleted': False, 'singleEvents': True,
|
||||
# kwargs = {'showDeleted': False, 'singleEvents': True,
|
||||
'timeMax': None, 'timeMin': None}
|
||||
'timeMax': None, 'timeMin': None, 'orderBy': 'startTime'}
|
||||
calId = 'primary'
|
||||
showDayOfWeek = False
|
||||
dateList = []
|
||||
@@ -47840,14 +47917,14 @@ def printShowWorkingLocation(users):
|
||||
j += 1
|
||||
first = wlDate['first']
|
||||
last = wlDate['last']
|
||||
while first <= last:
|
||||
kwargs['timeMin'] = first.strftime(YYYYMMDDTHHMMSSZ_FORMAT)
|
||||
kwargs['timeMax'] = last.strftime(YYYYMMDDTHHMMSSZ_FORMAT)
|
||||
for _ in range(1, wlDate.get('repeats', 1)+1):
|
||||
kwargs['timeMin'] = ISOformatTimeStamp(first)
|
||||
kwargs['timeMax'] = ISOformatTimeStamp(last)
|
||||
try:
|
||||
events = callGAPIpages(cal.events(), 'list', 'items',
|
||||
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID],
|
||||
calendarId=calId, fields='nextPageToken,items(id,start,workingLocationProperties)', **kwargs)
|
||||
except (GAPI.notACalendarUser, GAPI.notFound, GAPI.forbidden, GAPI.invalid) as e:
|
||||
throwReasons=GAPI.CALENDAR_THROW_REASONS+[GAPI.NOT_FOUND, GAPI.FORBIDDEN, GAPI.INVALID, GAPI.BAD_REQUEST],
|
||||
calendarId=calId, fields='nextPageToken,items(id,start,end,workingLocationProperties)', **kwargs)
|
||||
except (GAPI.notACalendarUser, GAPI.notFound, GAPI.forbidden, GAPI.invalid, GAPI.badRequest) as e:
|
||||
entityActionFailedWarning([Ent.USER, user], str(e), i, count)
|
||||
break
|
||||
except (GAPI.serviceNotAvailable, GAPI.authError):
|
||||
@@ -47868,7 +47945,9 @@ def printShowWorkingLocation(users):
|
||||
if showDayOfWeek:
|
||||
_getEventDaysOfWeek(event)
|
||||
_printCalendarEvent(user, calId, event, csvPF, FJQC)
|
||||
first += wlDate['pdelta']
|
||||
if 'pdelta' in wlDate:
|
||||
first += wlDate['pdelta']
|
||||
last += wlDate['pdelta']
|
||||
if csvPF:
|
||||
csvPF.writeCSVfile('Calendar Working Locations')
|
||||
|
||||
|
||||
@@ -400,6 +400,7 @@ Values = {DEBUG_LEVEL: 0}
|
||||
TYPE_BOOLEAN = 'bool'
|
||||
TYPE_CHARACTER = 'char'
|
||||
TYPE_CHOICE = 'choi'
|
||||
TYPE_CHOICE_LIST = 'chol'
|
||||
TYPE_DATETIME = 'datm'
|
||||
TYPE_DIRECTORY = 'dire'
|
||||
TYPE_EMAIL = 'emai'
|
||||
|
||||
Reference in New Issue
Block a user