mirror of
https://github.com/GAM-team/GAM.git
synced 2025-05-29 12:27:21 +00:00
Schema updates no longer deletes fields. Fixes #229.
This commit is contained in:
parent
e1e49f8edf
commit
f66aa71ec1
35
src/gam.py
35
src/gam.py
@ -6346,11 +6346,23 @@ def doDelSchema():
|
||||
|
||||
def doCreateOrUpdateUserSchema(function):
|
||||
cd = buildGAPIObject(u'directory')
|
||||
schemaName = sys.argv[3]
|
||||
body = {u'schemaName': schemaName, u'fields': []}
|
||||
schemaKey = sys.argv[3]
|
||||
if function == u'update':
|
||||
try:
|
||||
body = callGAPI(cd.schemas(), u'get', throw_reasons=[u'notFound'], customerId=GC_Values[GC_CUSTOMER_ID], schemaKey=schemaKey)
|
||||
except googleapiclient.errors.HttpError:
|
||||
print u'ERROR: Schema %s does not exist.' % schemaKey
|
||||
sys.exit(3)
|
||||
else: # function == insert
|
||||
body = {u'schemaName': schemaKey, u'fields': []}
|
||||
i = 4
|
||||
while i < len(sys.argv):
|
||||
if sys.argv[i] in [u'field']:
|
||||
if function != u'insert': # clear field if it exists on update
|
||||
for n, field in enumerate(body[u'fields']):
|
||||
if field[u'fieldName'].lower() == sys.argv[i+1].lower():
|
||||
del(body[u'fields'][n])
|
||||
break
|
||||
a_field = {u'fieldName': sys.argv[i+1]}
|
||||
i += 2
|
||||
while True:
|
||||
@ -6379,14 +6391,27 @@ def doCreateOrUpdateUserSchema(function):
|
||||
else:
|
||||
print u'ERROR: %s is not a valid argument for "gam create schema"' % sys.argv[i]
|
||||
sys.exit(2)
|
||||
elif sys.argv[i] in [u'deletefield']:
|
||||
field_found = False
|
||||
for n, field in enumerate(body[u'fields']):
|
||||
if field[u'fieldName'].lower() == sys.argv[i+1].lower():
|
||||
del(body[u'fields'][n])
|
||||
field_found = True
|
||||
break
|
||||
else:
|
||||
print "%s != %s" % (field[u'fieldName'].lower(), sys.argv[i+1].lower())
|
||||
if not field_found:
|
||||
print u'ERROR: field %s not found in schema %s' % (sys.argv[i+1], schemaKey)
|
||||
sys.exit(3)
|
||||
i += 2
|
||||
else:
|
||||
print u'ERROR: %s is not a valid argument for "gam create schema"' % sys.argv[i]
|
||||
sys.exit(2)
|
||||
if function == u'insert':
|
||||
result = callGAPI(cd.schemas(), function, customerId=GC_Values[GC_CUSTOMER_ID], body=body)
|
||||
result = callGAPI(cd.schemas(), u'insert', customerId=GC_Values[GC_CUSTOMER_ID], body=body)
|
||||
print u'Created user schema %s' % result[u'schemaName']
|
||||
else:
|
||||
result = callGAPI(cd.schemas(), function, customerId=GC_Values[GC_CUSTOMER_ID], body=body, schemaKey=schemaName)
|
||||
else: # function == update
|
||||
result = callGAPI(cd.schemas(), u'update', customerId=GC_Values[GC_CUSTOMER_ID], body=body, schemaKey=schemaKey)
|
||||
print u'Updated user schema %s' % result[u'schemaName']
|
||||
|
||||
def _showSchema(schema):
|
||||
|
Loading…
x
Reference in New Issue
Block a user