mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 20:31:35 +00:00
Update user attribute handling (#593)
* Update user attribute handling User attribite type handling issues. Custom types have their case lowered. * Use custom keyword as part of type Old - address, im, phone: type a|b|c|(custom <String>) New - address, im, phone: type a|b|c|<String> Dropping custom keyword will break existing scripts * Use separate keyword for custom type Old - organization: (type a|b|c) | (customtype <String>) New - organization: (type a|b|c|<String>) Dropping customtype keyword will break existing scripts Unlike all other attributes, you do not set type: custom when customType is set * Use implied custom Old - location: type a|b|c|<String> New - location: type a|b|c|<String> No change * Use implied custom, no type keyword Old - externalid, otheremail, relation, website: a|b|c|<String> New - externalid, otheremail, relation, website: a|b|c|<String> No change This update normalizes the type handling. Case of custom types is preserved. In update, for all fields, you can do: a|b|c|<String> a|b|c|custom <String> customtype <String> is still allowed for organization for backward compatability. * Just in case user does type work and then customtype xxx * Update documentation
This commit is contained in:
92
src/gam.py
92
src/gam.py
@@ -6434,6 +6434,33 @@ def doGetUserSchema():
|
|||||||
_showSchema(schema)
|
_showSchema(schema)
|
||||||
|
|
||||||
def getUserAttributes(i, cd, updateCmd=False):
|
def getUserAttributes(i, cd, updateCmd=False):
|
||||||
|
def getEntryType(i, entry, entryTypes, setTypeCustom=True):
|
||||||
|
""" Get attribute entry type
|
||||||
|
entryTypes is list of pre-defined types, a|b|c
|
||||||
|
Allow a|b|c|<String>, a|b|c|custom <String>
|
||||||
|
setTypeCustom=True, For all fields except organizations, when setting a custom type you do:
|
||||||
|
entry[u'type'] = u'custom'
|
||||||
|
entry[u'customType'] = <String>
|
||||||
|
setTypeCustom=False, For organizations, you don't set entry[u'type'] = u'custom'
|
||||||
|
Preserve case of custom types
|
||||||
|
"""
|
||||||
|
utype = sys.argv[i]
|
||||||
|
ltype = utype.lower()
|
||||||
|
if ltype == u'custom':
|
||||||
|
i += 1
|
||||||
|
utype = sys.argv[i]
|
||||||
|
ltype = utype.lower()
|
||||||
|
if ltype in entryTypes:
|
||||||
|
entry[u'type'] = ltype
|
||||||
|
entry.pop(u'customType', None)
|
||||||
|
else:
|
||||||
|
entry[u'customType'] = utype
|
||||||
|
if setTypeCustom:
|
||||||
|
entry[u'type'] = u'custom'
|
||||||
|
else:
|
||||||
|
entry.pop(u'type', None)
|
||||||
|
return i+1
|
||||||
|
|
||||||
def checkClearBodyList(i, body, itemName):
|
def checkClearBodyList(i, body, itemName):
|
||||||
if sys.argv[i].lower() == u'clear':
|
if sys.argv[i].lower() == u'clear':
|
||||||
if itemName in body:
|
if itemName in body:
|
||||||
@@ -6442,7 +6469,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def appendItemToBodyList(body, itemName, itemValue):
|
def appendItemToBodyList(body, itemName, itemValue, checkSystemId=False):
|
||||||
if (itemName in body) and (body[itemName] is None):
|
if (itemName in body) and (body[itemName] is None):
|
||||||
del body[itemName]
|
del body[itemName]
|
||||||
body.setdefault(itemName, [])
|
body.setdefault(itemName, [])
|
||||||
@@ -6450,6 +6477,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
if itemValue.get(u'primary', False):
|
if itemValue.get(u'primary', False):
|
||||||
for citem in body[itemName]:
|
for citem in body[itemName]:
|
||||||
if citem.get(u'primary', False):
|
if citem.get(u'primary', False):
|
||||||
|
if not checkSystemId or itemValue.get(u'systemId') == citem.get(u'systemId'):
|
||||||
print u'ERROR: Multiple {0} are marked primary, only one can be primary'.format(itemName)
|
print u'ERROR: Multiple {0} are marked primary, only one can be primary'.format(itemName)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
body[itemName].append(itemValue)
|
body[itemName].append(itemValue)
|
||||||
@@ -6587,12 +6615,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
if sys.argv[i].lower() != u'type':
|
if sys.argv[i].lower() != u'type':
|
||||||
print u'ERROR: wrong format for account address details. Expected type got %s' % sys.argv[i]
|
print u'ERROR: wrong format for account address details. Expected type got %s' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
i += 1
|
i = getEntryType(i+1, address, USER_ADDRESS_TYPES)
|
||||||
address[u'type'] = sys.argv[i].lower()
|
|
||||||
if address[u'type'] not in USER_ADDRESS_TYPES:
|
|
||||||
address[u'customType'] = address[u'type']
|
|
||||||
address[u'type'] = u'custom'
|
|
||||||
i += 1
|
|
||||||
if sys.argv[i].lower() in [u'unstructured', u'formatted']:
|
if sys.argv[i].lower() in [u'unstructured', u'formatted']:
|
||||||
i += 1
|
i += 1
|
||||||
address[u'sourceIsStructured'] = False
|
address[u'sourceIsStructured'] = False
|
||||||
@@ -6638,11 +6661,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
an_email = {}
|
an_email = {}
|
||||||
an_email[u'type'] = sys.argv[i].lower()
|
i = getEntryType(i, an_email, USER_EMAIL_TYPES)
|
||||||
if an_email[u'type'] not in USER_EMAIL_TYPES:
|
|
||||||
an_email[u'customType'] = an_email[u'type']
|
|
||||||
an_email[u'type'] = u'custom'
|
|
||||||
i += 1
|
|
||||||
an_email[u'address'] = sys.argv[i]
|
an_email[u'address'] = sys.argv[i]
|
||||||
i += 1
|
i += 1
|
||||||
appendItemToBodyList(body, u'emails', an_email)
|
appendItemToBodyList(body, u'emails', an_email)
|
||||||
@@ -6655,12 +6674,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
if sys.argv[i].lower() != u'type':
|
if sys.argv[i].lower() != u'type':
|
||||||
print u'ERROR: wrong format for account im details. Expected type got %s' % sys.argv[i]
|
print u'ERROR: wrong format for account im details. Expected type got %s' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
i += 1
|
i = getEntryType(i+1, im, USER_IM_TYPES)
|
||||||
im[u'type'] = sys.argv[i].lower()
|
|
||||||
if im[u'type'] not in USER_IM_TYPES:
|
|
||||||
im[u'customType'] = im[u'type']
|
|
||||||
im[u'type'] = u'custom'
|
|
||||||
i += 1
|
|
||||||
if sys.argv[i].lower() != u'protocol':
|
if sys.argv[i].lower() != u'protocol':
|
||||||
print u'ERROR: wrong format for account details. Expected protocol got %s' % sys.argv[i]
|
print u'ERROR: wrong format for account details. Expected protocol got %s' % sys.argv[i]
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
@@ -6699,12 +6713,12 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
elif myopt == u'title':
|
elif myopt == u'title':
|
||||||
organization[u'title'] = sys.argv[i+1]
|
organization[u'title'] = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif myopt == u'type':
|
elif myopt == u'customtype':
|
||||||
organization[u'type'] = sys.argv[i+1].lower()
|
organization[u'customType'] = sys.argv[i+1]
|
||||||
if organization[u'type'] not in USER_ORGANIZATION_TYPES:
|
organization.pop(u'type', None)
|
||||||
organization[u'customType'] = organization[u'type']
|
|
||||||
organization[u'type'] = u'custom'
|
|
||||||
i += 2
|
i += 2
|
||||||
|
elif myopt == u'type':
|
||||||
|
i = getEntryType(i+1, organization, USER_ORGANIZATION_TYPES, setTypeCustom=False)
|
||||||
elif myopt == u'department':
|
elif myopt == u'department':
|
||||||
organization[u'department'] = sys.argv[i+1]
|
organization[u'department'] = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
@@ -6743,11 +6757,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
phone[u'value'] = sys.argv[i+1]
|
phone[u'value'] = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
elif myopt == u'type':
|
elif myopt == u'type':
|
||||||
phone[u'type'] = sys.argv[i+1].lower()
|
i = getEntryType(i+1, phone, USER_PHONE_TYPES)
|
||||||
if phone[u'type'] not in USER_PHONE_TYPES:
|
|
||||||
phone[u'customType'] = phone[u'type']
|
|
||||||
phone[u'type'] = u'custom'
|
|
||||||
i += 2
|
|
||||||
elif myopt in [u'notprimary', u'primary']:
|
elif myopt in [u'notprimary', u'primary']:
|
||||||
phone[u'primary'] = myopt == u'primary'
|
phone[u'primary'] = myopt == u'primary'
|
||||||
i += 1
|
i += 1
|
||||||
@@ -6762,11 +6772,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
relation = {}
|
relation = {}
|
||||||
relation[u'type'] = sys.argv[i].lower()
|
i = getEntryType(i, relation, USER_RELATION_TYPES)
|
||||||
if relation[u'type'] not in USER_RELATION_TYPES:
|
|
||||||
relation[u'customType'] = relation[u'type']
|
|
||||||
relation[u'type'] = u'custom'
|
|
||||||
i += 1
|
|
||||||
relation[u'value'] = sys.argv[i]
|
relation[u'value'] = sys.argv[i]
|
||||||
i += 1
|
i += 1
|
||||||
appendItemToBodyList(body, u'relations', relation)
|
appendItemToBodyList(body, u'relations', relation)
|
||||||
@@ -6776,11 +6782,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
externalid = {}
|
externalid = {}
|
||||||
externalid[u'type'] = sys.argv[i].lower()
|
i = getEntryType(i, externalid, USER_EXTERNALID_TYPES)
|
||||||
if externalid[u'type'] not in USER_EXTERNALID_TYPES:
|
|
||||||
externalid[u'customType'] = externalid[u'type']
|
|
||||||
externalid[u'type'] = u'custom'
|
|
||||||
i += 1
|
|
||||||
externalid[u'value'] = sys.argv[i]
|
externalid[u'value'] = sys.argv[i]
|
||||||
i += 1
|
i += 1
|
||||||
appendItemToBodyList(body, u'externalIds', externalid)
|
appendItemToBodyList(body, u'externalIds', externalid)
|
||||||
@@ -6790,11 +6792,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
website = {}
|
website = {}
|
||||||
website[u'type'] = sys.argv[i].lower()
|
i = getEntryType(i, website, USER_WEBSITE_TYPES)
|
||||||
if website[u'type'] not in USER_WEBSITE_TYPES:
|
|
||||||
website[u'customType'] = website[u'type']
|
|
||||||
website[u'type'] = u'custom'
|
|
||||||
i += 1
|
|
||||||
website[u'value'] = sys.argv[i]
|
website[u'value'] = sys.argv[i]
|
||||||
i += 1
|
i += 1
|
||||||
myopt = sys.argv[i].lower()
|
myopt = sys.argv[i].lower()
|
||||||
@@ -6828,11 +6826,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
while True:
|
while True:
|
||||||
myopt = sys.argv[i].lower()
|
myopt = sys.argv[i].lower()
|
||||||
if myopt == u'type':
|
if myopt == u'type':
|
||||||
location[u'type'] = sys.argv[i+1].lower()
|
i = getEntryType(i+1, location, USER_LOCATION_TYPES)
|
||||||
if location[u'type'] not in USER_LOCATION_TYPES:
|
|
||||||
location[u'customType'] = location[u'type']
|
|
||||||
location[u'type'] = u'custom'
|
|
||||||
i += 2
|
|
||||||
elif myopt == u'area':
|
elif myopt == u'area':
|
||||||
location[u'area'] = sys.argv[i+1]
|
location[u'area'] = sys.argv[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
@@ -6920,7 +6914,7 @@ def getUserAttributes(i, cd, updateCmd=False):
|
|||||||
else:
|
else:
|
||||||
print u'ERROR: %s is not a valid argument for user posix details. Make sure user posix details end with an endposix argument'
|
print u'ERROR: %s is not a valid argument for user posix details. Make sure user posix details end with an endposix argument'
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
appendItemToBodyList(body, u'posixAccounts', posix)
|
appendItemToBodyList(body, u'posixAccounts', posix, checkSystemId=True)
|
||||||
elif myarg == u'clearschema':
|
elif myarg == u'clearschema':
|
||||||
if not updateCmd:
|
if not updateCmd:
|
||||||
print u'ERROR: %s is not a valid create user argument.' % sys.argv[i]
|
print u'ERROR: %s is not a valid create user argument.' % sys.argv[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user