Fixed issue when not returning anything in GetItems() and updated GetUsers to use GetItems
All checks were successful
Build python package / Build (push) Successful in 35s
All checks were successful
Build python package / Build (push) Successful in 35s
This commit is contained in:
37
GLPIAPI.py
37
GLPIAPI.py
@@ -142,8 +142,10 @@ class GLPIAPI:
|
|||||||
else:
|
else:
|
||||||
itemID = list(search["data"].keys())
|
itemID = list(search["data"].keys())
|
||||||
return itemID, search["data"], search["totalcount"]
|
return itemID, search["data"], search["totalcount"]
|
||||||
|
else:
|
||||||
|
return None, None, 0
|
||||||
|
|
||||||
return None, search.status, 0
|
return None, search.status_code, 0
|
||||||
|
|
||||||
def GetUsers(self, username=None, email=None):
|
def GetUsers(self, username=None, email=None):
|
||||||
'''
|
'''
|
||||||
@@ -154,35 +156,16 @@ class GLPIAPI:
|
|||||||
|
|
||||||
Returns a tuple with user id, user data and user count
|
Returns a tuple with user id, user data and user count
|
||||||
'''
|
'''
|
||||||
searchAll = False
|
fieldName = None
|
||||||
|
fieldValue = None
|
||||||
if(username != None):
|
if(username != None):
|
||||||
search_parameter = f'is_deleted=0&criteria[0][field]=1&withindexes=true&criteria[0][searchtype]=contains&criteria[0][value]=^{username}$'
|
fieldName = 'login'
|
||||||
|
fieldValue = username
|
||||||
elif(email != None):
|
elif(email != None):
|
||||||
search_parameter = f'is_deleted=0&criteria[0][field]=5&withindexes=true&criteria[0][searchtype]=contains&criteria[0][value]=^{email}$'
|
fieldName = 'Emails'
|
||||||
else:
|
fieldValue = email
|
||||||
searchAll = True
|
|
||||||
|
|
||||||
if(searchAll):
|
|
||||||
searchUri = f"{self.Server}/apirest.php/search/User/?range=0-9999999&is_deleted=0"
|
|
||||||
else:
|
|
||||||
searchUri = f"{self.Server}/apirest.php/search/User?{search_parameter}"
|
|
||||||
search = requests.get(searchUri, headers=self.Headers)
|
|
||||||
if(search.status_code == 200):
|
|
||||||
search = search.json()
|
|
||||||
if(search["totalcount"] == 1):
|
|
||||||
userID = list(search["data"].keys())[0]
|
|
||||||
data = search["data"][userID]
|
|
||||||
|
|
||||||
return userID, data, search["totalcount"]
|
|
||||||
elif(search["totalcount"] > 1):
|
|
||||||
if(searchAll):
|
|
||||||
# requires id to be in the display preferences of the api user
|
|
||||||
userID = [i["2"] for i in search["data"]]
|
|
||||||
else:
|
|
||||||
userID = list(search["data"].keys())
|
|
||||||
return userID, search["data"], search["totalcount"]
|
|
||||||
|
|
||||||
return None, None, 0
|
return self.GetItems("User", fieldName, fieldValue)
|
||||||
|
|
||||||
def GetSearchOptions(self, itemType, fieldName=None):
|
def GetSearchOptions(self, itemType, fieldName=None):
|
||||||
queryUri = f"{self.Server}/apirest.php/listSearchOptions/{itemType}"
|
queryUri = f"{self.Server}/apirest.php/listSearchOptions/{itemType}"
|
||||||
|
|||||||
Reference in New Issue
Block a user