Skip to content

Commit

Permalink
Added commands to display user's contact groups and other contacts us…
Browse files Browse the repository at this point in the history
…ing the People API.
  • Loading branch information
taers232c committed Apr 28, 2021
1 parent e126c3e commit b0d7e34
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 14 deletions.
40 changes: 34 additions & 6 deletions src/GamCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5339,6 +5339,12 @@ gam <UserTypeEntity> sync license <SKUID> [product|productid <ProductID>] [addon

# Users - People - Contacts and Profile

<OtherContactFieldName> ::=
emailaddresses|
phonenumbers|
names
<OtherContactFieldNameList> ::= "<OtherContactFieldName>(,<OtherContactFieldName>)*"

<PeopleFieldName> ::=
addresses|
ageranges|
Expand Down Expand Up @@ -5371,6 +5377,22 @@ gam <UserTypeEntity> sync license <SKUID> [product|productid <ProductID>] [addon
userdefined
<PeopleFieldNameList> ::= "<PeopleFieldName>(,<PeopleFieldName>)*"

gam <UserTypeEntity> show peopleprofiles
[allfields|(fields <PeopleFieldNameList>)]
[formatjson]
gam <UserTypeEntity> print peopleprofiles [todrive <ToDriveAttribute>*]
[allfields|(fields <PeopleFieldNameList>)]
[formatjson [quotechar <Character>]]

gam <UserTypeEntity> show othercontacts
[query <String>]
[allfields|(fields <OtherContactFieldNameList>)]
[formatjson]
gam <UserTypeEntity> print othercontacts [todrive <ToDriveAttribute>*]
[query <String>]
[allfields|(fields <OtherContactFieldNameList>)]
[formatjson [quotechar <Character>]]

gam <UserTypeEntity> show peoplecontacts
[query <String>]
[orderby firstname|lastname|(lastmodified asdending)|(lastnodified descending)
Expand All @@ -5382,12 +5404,18 @@ gam <UserTypeEntity> print peoplecontacts [todrive <ToDriveAttribute>*]
[allfields|(fields <PeopleFieldNameList>)]
[formatjson [quotechar <Character>]]

gam <UserTypeEntity> show peopleprofiles
[allfields|(fields <PeopleFieldNameList>)]
[formatjson]
gam <UserTypeEntity> print peopleprofiles [todrive <ToDriveAttribute>*]
[allfields|(fields <PeopleFieldNameList>)]
[formatjson [quotechar <Character>]]
<PeopleContactGroupFieldName> ::=
clientdata|
grouptype|
membercount|
metadata|
name
<PeopleContactGroupFieldNameList> ::= "<PeopleContactGroupFieldName>(,<PeopleContactGroupFieldName>)*"

gam <UserTypeEntity> print peoplecontactgroups [todrive <ToDriveAttribute>*]
[fields <PeoplaContactGroupFieldNameList>] [formatjson [quotechar <Character>]]
gam <UserTypeEntity> show peoplacontactgroups
[fields <PeoplaContactGroupFieldNameList>] [formatjson]

# Users - Photo

Expand Down
15 changes: 15 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
6.03.04

Added commands to display user's other contacts using the People API.
* https://github.com/taers232c/GAMADV-XTD3/wiki/Users-People

To use this feature you must add the `People API` to your project and authorize the appropriate scopes:
* `People API - Other Contacts - read only`: https://www.googleapis.com/auth/contacts.other.readonly
```
gam update project
gam user [email protected] check serviceaccount
```

Added commands to display user's contact groups using the People API.
* https://github.com/taers232c/GAMADV-XTD3/wiki/Users-People

6.03.03

Added commands to display user's contacts using the People API.
Expand Down
119 changes: 115 additions & 4 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__author__ = 'Ross Scroggs <[email protected]>'
__version__ = '6.03.03'
__version__ = '6.03.04'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

import base64
Expand Down Expand Up @@ -3898,7 +3898,7 @@ def getSvcAcctCredentials(scopesOrAPI, userEmail):
GM.Globals[GM.CURRENT_SVCACCT_API_SCOPES] = GM.Globals[GM.SVCACCT_SCOPES].get(scopesOrAPI, [])
if not GM.Globals[GM.CURRENT_SVCACCT_API_SCOPES]:
systemErrorExit(OAUTH2SERVICE_JSON_REQUIRED_RC, Msg.NO_SVCACCT_ACCESS_ALLOWED)
if scopesOrAPI in {API.PEOPLE, API.PEOPLE_DIRECTORY}:
if scopesOrAPI in {API.PEOPLE, API.PEOPLE_DIRECTORY, API.PEOPLE_OTHERCONTACTS}:
GM.Globals[GM.CURRENT_SVCACCT_API_SCOPES].append(API.USERINFO_PROFILE_SCOPE)
else:
GM.Globals[GM.CURRENT_SVCACCT_API] = ''
Expand Down Expand Up @@ -32904,7 +32904,7 @@ def printShowUserPeopleContacts(users):
user, people = buildGAPIServiceObject(API.PEOPLE, user, i, count)
if not people:
continue
printGettingAllEntityItemsForWhom(Ent.CONTACT, user, i, count, query=query)
printGettingAllEntityItemsForWhom(Ent.PEOPLE_CONTACT, user, i, count, query=query)
try:
if not query:
entityList = callGAPIpages(people.people().connections(), 'list', 'connections',
Expand All @@ -32919,10 +32919,115 @@ def printShowUserPeopleContacts(users):
entityList = results.get('results', [])
except (GAPI.serviceNotAvailable, GAPI.forbidden, GAPI.permissionDenied):
ClientAPIAccessDeniedExit()
_printPersonEntityList(Ent.CONTACT, entityList, entityType, user, i, count, csvPF, FJQC)
_printPersonEntityList(Ent.PEOPLE_CONTACT, entityList, entityType, user, i, count, csvPF, FJQC)
if csvPF:
csvPF.writeCSVfile('People Contacts')

PEOPLE_OTHER_CONTACTS_FIELDS_CHOICE_MAP = {
'emailaddresses': 'emailAddresses',
'names': 'names',
'phonenumbers': 'phoneNumbers',
}

# gam <UserTypeEntity> print othercontacts [todrive <ToDriveAttribute>*]
# [query <String>]
# [fields <OtherContactFieldNameList>] [formatjson [quotechar <Character>]]
# gam <UserTypeEntity> show othercontacts
# [query <String>]
# [fields <OtherContactFieldNameList>] [formatjson]
def printShowUserOtherContacts(users):
entityType = Ent.USER
entityTypeName = Ent.Singular(entityType)
csvPF = CSVPrintFile([entityTypeName, 'resourceName']) if Act.csvFormat() else None
FJQC = FormatJSONQuoteChar(csvPF)
fieldsList = []
query = None
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if csvPF and myarg == 'todrive':
csvPF.GetTodriveParameters()
elif myarg == 'allfields':
for field in PEOPLE_OTHER_CONTACTS_FIELDS_CHOICE_MAP:
addFieldToFieldsList(field, PEOPLE_OTHER_CONTACTS_FIELDS_CHOICE_MAP, fieldsList)
elif getFieldsList(myarg, PEOPLE_OTHER_CONTACTS_FIELDS_CHOICE_MAP, fieldsList):
pass
elif myarg == 'query':
query = getString(Cmd.OB_QUERY)
else:
FJQC.GetFormatJSONQuoteChar(myarg, True)
fields = ','.join(set(fieldsList)) if fieldsList else 'names,emailAddresses,phoneNumbers'
i, count, users = getEntityArgument(users)
for user in users:
i += 1
user, people = buildGAPIServiceObject(API.PEOPLE_OTHERCONTACTS, user, i, count)
if not people:
continue
printGettingAllEntityItemsForWhom(Ent.OTHER_CONTACT, user, i, count, query=query)
try:
if not query:
entityList = callGAPIpages(people.otherContacts(), 'list', 'otherContacts',
pageMessage=getPageMessage(),
throwReasons=GAPI.PEOPLE_ACCESS_THROW_REASONS,
readMask=fields, fields='nextPageToken,otherContacts')
else:
results = callGAPI(people.otherContacts(), 'search',
throwReasons=GAPI.PEOPLE_ACCESS_THROW_REASONS,
readMask=fields, query=query)
entityList = results.get('results', [])
except (GAPI.serviceNotAvailable, GAPI.forbidden, GAPI.permissionDenied):
ClientAPIAccessDeniedExit()
_printPersonEntityList(Ent.OTHER_CONTACT, entityList, entityType, user, i, count, csvPF, FJQC)
if csvPF:
csvPF.writeCSVfile('Other Contacts')

PEOPLE_CONTACTGROUPS_FIELDS_CHOICE_MAP = {
'clientdata': 'clientData',
'grouptype': 'groupType',
'membercount': 'memberCount',
'metadata': 'metadata',
'name': 'name',
}

# gam <UserTypeEntity> print peoplecontactgroups [todrive <ToDriveAttribute>*]
# [fields <PeoplaContactGroupFieldNameList>] [formatjson [quotechar <Character>]]
# gam <UserTypeEntity> show peoplacontactgroups
# [fields <PeoplaContactGroupFieldNameList>] [formatjson]
def printShowUserPeopleContactGroups(users):
entityType = Ent.USER
entityTypeName = Ent.Singular(entityType)
csvPF = CSVPrintFile([entityTypeName, 'resourceName']) if Act.csvFormat() else None
FJQC = FormatJSONQuoteChar(csvPF)
fieldsList = []
while Cmd.ArgumentsRemaining():
myarg = getArgument()
if csvPF and myarg == 'todrive':
csvPF.GetTodriveParameters()
elif myarg == 'allfields':
for field in PEOPLE_CONTACTGROUPS_FIELDS_CHOICE_MAP:
addFieldToFieldsList(field, PEOPLE_CONTACTGROUPS_FIELDS_CHOICE_MAP, fieldsList)
elif getFieldsList(myarg, PEOPLE_CONTACTGROUPS_FIELDS_CHOICE_MAP, fieldsList):
pass
else:
FJQC.GetFormatJSONQuoteChar(myarg, True)
fields = ','.join(set(fieldsList)) if fieldsList else None
i, count, users = getEntityArgument(users)
for user in users:
i += 1
user, people = buildGAPIServiceObject(API.PEOPLE, user, i, count)
if not people:
continue
printGettingAllEntityItemsForWhom(Ent.PEOPLE_CONTACTGROUP, user, i, count)
try:
entityList = callGAPIpages(people.contactGroups(), 'list', 'contactGroups',
pageMessage=getPageMessage(),
throwReasons=GAPI.PEOPLE_ACCESS_THROW_REASONS,
groupFields=fields, fields='nextPageToken,contactGroups')
except (GAPI.serviceNotAvailable, GAPI.forbidden, GAPI.permissionDenied):
ClientAPIAccessDeniedExit()
_printPersonEntityList(Ent.PEOPLE_CONTACTGROUP, entityList, entityType, user, i, count, csvPF, FJQC)
if csvPF:
csvPF.writeCSVfile('People Contact Groupss')

SITEVERIFICATION_METHOD_CHOICE_MAP = {
'cname': 'DNS_CNAME',
'dnscname': 'DNS_CNAME',
Expand Down Expand Up @@ -53644,8 +53749,10 @@ def processResourcesCommands():
Cmd.ARG_GUARDIAN: printShowGuardians,
Cmd.ARG_LABEL: printShowLabels,
Cmd.ARG_MESSAGE: printShowMessages,
Cmd.ARG_OTHERCONTACT: printShowUserOtherContacts,
Cmd.ARG_PEOPLE: printShowPeople,
Cmd.ARG_PEOPLECONTACT: printShowUserPeopleContacts,
Cmd.ARG_PEOPLECONTACTGROUP: printShowUserPeopleContactGroups,
Cmd.ARG_PEOPLEPROFILE: printShowPeopleProfile,
Cmd.ARG_SENDAS: printShowSendAs,
Cmd.ARG_SHEET: infoPrintShowSheets,
Expand Down Expand Up @@ -53703,8 +53810,10 @@ def processResourcesCommands():
Cmd.ARG_LABEL: printShowLabels,
Cmd.ARG_LANGUAGE: showLanguage,
Cmd.ARG_MESSAGE: printShowMessages,
Cmd.ARG_OTHERCONTACT: printShowUserOtherContacts,
Cmd.ARG_PEOPLE: printShowPeople,
Cmd.ARG_PEOPLECONTACT: printShowUserPeopleContacts,
Cmd.ARG_PEOPLECONTACTGROUP: printShowUserPeopleContactGroups,
Cmd.ARG_PEOPLEPROFILE: printShowPeopleProfile,
Cmd.ARG_POP: showPop,
Cmd.ARG_PROFILE: showProfile,
Expand Down Expand Up @@ -53877,7 +53986,9 @@ def processResourcesCommands():
Cmd.ARG_MEMBERS: Cmd.ARG_GROUPMEMBERS,
Cmd.ARG_MESSAGES: Cmd.ARG_MESSAGE,
Cmd.ARG_OAUTH: Cmd.ARG_TOKEN,
Cmd.ARG_OTHERCONTACTS: Cmd.ARG_OTHERCONTACT,
Cmd.ARG_PEOPLECONTACTS: Cmd.ARG_PEOPLECONTACT,
Cmd.ARG_PEOPLECONTACTGROUPS: Cmd.ARG_PEOPLECONTACTGROUP,
Cmd.ARG_PEOPLEPROFILES: Cmd.ARG_PEOPLEPROFILE,
Cmd.ARG_PERMISSIONS: Cmd.ARG_PERMISSION,
Cmd.ARG_POP3: Cmd.ARG_POP,
Expand Down
14 changes: 10 additions & 4 deletions src/gam/gamlib/glapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
OAUTH2 = 'oauth2'
PEOPLE = 'people'
PEOPLE_DIRECTORY = 'peopledirectory'
PEOPLE_OTHERCONTACTS = 'peopleothercontacts'
PRINTERS = 'printers'
PUBSUB = 'pubsub'
REPORTS = 'reports'
Expand Down Expand Up @@ -166,6 +167,7 @@
OAUTH2: {'name': 'OAuth2 API', 'version': 'v2', 'v2discovery': False},
PEOPLE: {'name': 'People API', 'version': 'v1', 'v2discovery': True},
PEOPLE_DIRECTORY: {'name': 'People Directory API', 'version': 'v1', 'v2discovery': True, 'mappedAPI': 'people'},
PEOPLE_OTHERCONTACTS: {'name': 'People API - Other Contacts', 'version': 'v1', 'v2discovery': True, 'mappedAPI': 'people'},
PRINTERS: {'name': 'Directory API Printers', 'version': 'directory_v1', 'v2discovery': False, 'mappedAPI': 'admin'},
PUBSUB: {'name': 'Pub / Sub API', 'version': 'v1', 'v2discovery': True},
REPORTS: {'name': 'Reports API', 'version': 'reports_v1', 'v2discovery': False, 'mappedAPI': 'admin'},
Expand Down Expand Up @@ -320,14 +322,14 @@
'api': LICENSING,
'subscopes': [],
'scope': 'https://www.googleapis.com/auth/apps.licensing'},
{'name': 'People API',
'api': PEOPLE,
'subscopes': READONLY,
'scope': 'https://www.googleapis.com/auth/contacts'},
{'name': 'People Directory API - read only',
'api': PEOPLE_DIRECTORY,
'subscopes': [],
'scope': 'https://www.googleapis.com/auth/directory.readonly'},
{'name': 'People API',
'api': PEOPLE,
'subscopes': READONLY,
'scope': 'https://www.googleapis.com/auth/contacts'},
{'name': 'Directory API - Printers',
'api': PRINTERS,
'subscopes': READONLY,
Expand Down Expand Up @@ -470,6 +472,10 @@
'api': PEOPLE,
'subscopes': READONLY,
'scope': 'https://www.googleapis.com/auth/contacts'},
{'name': 'People API - Other Contacts - read only',
'api': PEOPLE_OTHERCONTACTS,
'subscopes': [],
'scope': 'https://www.googleapis.com/auth/contacts.other.readonly'},
{'name': 'People Directory API - read only',
'api': PEOPLE_DIRECTORY,
'subscopes': [],
Expand Down
4 changes: 4 additions & 0 deletions src/gam/gamlib/glclargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ class GamCLArgs():
ARG_ORGS = 'orgs'
ARG_ORGTREE = 'orgtree'
ARG_ORPHANS = 'orphans'
ARG_OTHERCONTACT = 'othercontact'
ARG_OTHERCONTACTS = 'othercontacts'
ARG_OU = 'ou'
ARG_OUS = 'ous'
ARG_OUTREE = 'outree'
Expand All @@ -519,6 +521,8 @@ class GamCLArgs():
ARG_PEOPLE = 'people'
ARG_PEOPLECONTACT = 'peoplecontact'
ARG_PEOPLECONTACTS = 'peoplecontacts'
ARG_PEOPLECONTACTGROUP = 'peoplecontactgroup'
ARG_PEOPLECONTACTGROUPS = 'peoplecontactgroups'
ARG_PEOPLEPROFILE = 'peopleprofile'
ARG_PEOPLEPROFILES = 'peopleprofiles'
ARG_PERMISSION = 'permission'
Expand Down
6 changes: 6 additions & 0 deletions src/gam/gamlib/glentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,14 @@ class GamEntity():
OAUTH2_TXT_FILE = 'oaut'
OAUTH2SERVICE_JSON_FILE = 'oau2'
ORGANIZATIONAL_UNIT = 'org'
OTHER_CONTACT = 'otco'
OWNER = 'ownr'
OWNER_ID = 'owid'
PAGE_SIZE = 'page'
PARENT_ORGANIZATIONAL_UNIT = 'porg'
PARTICIPANT = 'part'
PEOPLE_CONTACT = 'peco'
PEOPLE_CONTACTGROUP = 'pecg'
PEOPLE_PHOTO = 'peph'
PEOPLE_PROFILE = 'pepr'
PERMISSION = 'perm'
Expand Down Expand Up @@ -444,11 +447,14 @@ class GamEntity():
OAUTH2_TXT_FILE: ['Client OAuth2 File', 'Client OAuth2 File'],
OAUTH2SERVICE_JSON_FILE: ['Service Account OAuth2 File', 'Service Account OAuth2 File'],
ORGANIZATIONAL_UNIT: ['Organizational Units', 'Organizational Unit'],
OTHER_CONTACT: ['Other Contacts', 'Other Contact'],
OWNER: ['Owners', 'Owner'],
OWNER_ID: ['Owner IDs', 'Owner ID'],
PAGE_SIZE: ['Page Size', 'Page Size'],
PARENT_ORGANIZATIONAL_UNIT: ['Parent Organizational Units', 'Parent Organizational Unit'],
PARTICIPANT: ['Participants', 'Participant'],
PEOPLE_CONTACT: ['People Contacts', 'Person Contact'],
PEOPLE_CONTACTGROUP: ['People Contact Groups', 'People Contact Group'],
PEOPLE_PHOTO: ['People Photos', 'Person Photo'],
PEOPLE_PROFILE: ['People Profiles', 'People Profile'],
PERMISSION: ['Permissions', 'Permission'],
Expand Down

0 comments on commit b0d7e34

Please sign in to comment.