Skip to content

Commit

Permalink
catch JSON decode error if no LDAP users exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Wahl committed Feb 23, 2021
1 parent 74c4170 commit b201188
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions seafadm
Original file line number Diff line number Diff line change
Expand Up @@ -575,20 +575,27 @@ def get_users():
users = dict()
# returned lsit of users comes in different dictionaries in JSON
for user_db in USER_API_KEYS:
result = json.loads(get_ajax(f'/api/v2.1/admin/{user_db}?per_page={PER_PAGE}'))
if result.get(USER_API_KEYS[user_db]):
for item in result[USER_API_KEYS[user_db]]:
# LDAP users do not have name property - just use mail address instead
user = User(name=item.get('name', item['email']),
id=item['email'],
mail=item['email'],
creation=item['create_time'],
used_space=int(item['quota_usage']/1000000),
quota=int(item['quota_total']/1000000)
)
users[user.id] = user
url = f'/api/v2.1/admin/{user_db}?per_page={PER_PAGE}'
ajax = get_ajax(url)
try:
result = json.loads(get_ajax(f'/api/v2.1/admin/{user_db}?per_page={PER_PAGE}'))
if result.get(USER_API_KEYS[user_db]):
for item in result[USER_API_KEYS[user_db]]:
# LDAP users do not have name property - just use mail address instead
user = User(name=item.get('name', item['email']),
id=item['email'],
mail=item['email'],
creation=item['create_time'],
used_space=int(item['quota_usage']/1000000),
quota=int(item['quota_total']/1000000)
)
users[user.id] = user
except json.JSONDecodeError:
# no valid JSON given, for example if there are no LDAP users
pass
return users


def get_libaries():
"""
retrieve information about all libraries
Expand Down

0 comments on commit b201188

Please sign in to comment.