MCPcopy Index your code
hub / github.com/O365/python-o365 / get_users

Method get_users

O365/directory.py:231–291  ·  view source on GitHub ↗

Gets a list of users from the active directory When querying the Active Directory the Users endpoint will be used. Only a limited set of information will be available unless you have access to scope 'User.Read.All' which requires App Administration Consent.

(self, limit=100, *, query=None, order_by=None, batch=None)

Source from the content-addressed store, hash-verified

229 return 'Active Directory'
230
231 def get_users(self, limit=100, *, query=None, order_by=None, batch=None):
232 """ Gets a list of users from the active directory
233
234 When querying the Active Directory the Users endpoint will be used.
235 Only a limited set of information will be available unless you have
236 access to scope 'User.Read.All' which requires App Administration
237 Consent.
238
239 Also using endpoints has some limitations on the querying capabilities.
240
241 To use query an order_by check the OData specification here:
242 http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/
243 part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions
244 -complete.html
245
246 :param limit: max no. of contacts to get. Over 999 uses batch.
247 :type limit: int or None
248 :param query: applies a OData filter to the request
249 :type query: Query or str
250 :param order_by: orders the result set based on this condition
251 :type order_by: Query or str
252 :param int batch: batch size, retrieves items in
253 batches allowing to retrieve more items than the limit.
254 :return: list of users
255 :rtype: list[User] or Pagination
256 """
257
258 url = self.build_url('') # target the main_resource
259
260 if limit is None or limit > self.protocol.max_top_value:
261 batch = self.protocol.max_top_value
262
263 params = {'$top': batch if batch else limit}
264
265 if order_by:
266 params['$orderby'] = order_by
267
268 if query:
269 if isinstance(query, str):
270 params['$filter'] = query
271 else:
272 params.update(query.as_params())
273
274 response = self.con.get(url, params=params)
275 if not response:
276 return iter(())
277
278 data = response.json()
279
280 # Everything received from cloud must be passed as self._cloud_data_key
281 users = (self.user_constructor(parent=self, **{self._cloud_data_key: user})
282 for user in data.get('value', []))
283
284 next_link = data.get(NEXT_LINK_KEYWORD, None)
285
286 if batch and next_link:
287 return Pagination(parent=self, data=users,
288 constructor=self.user_constructor,

Callers

nothing calls this directly

Calls 6

PaginationClass · 0.85
build_urlMethod · 0.80
as_paramsMethod · 0.80
jsonMethod · 0.80
updateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected