Skip to content

Commit

Permalink
Add support for last_login field in users Provisioning API
Browse files Browse the repository at this point in the history
  • Loading branch information
YomesInc authored Sep 25, 2023
1 parent 801b7e0 commit eca5db6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cloudinary/provisioning/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def update_sub_account(sub_account_id, name=None, cloud_name=None, custom_attrib
return _call_account_api("put", uri, params=params, **options)


def users(user_ids=None, sub_account_id=None, pending=None, prefix=None, **options):
def users(user_ids=None, sub_account_id=None, pending=None, prefix=None, last_login=None, from_date=None, to_date=None, **options):
"""
List all users
:param user_ids: The ids of the users to fetch
Expand All @@ -136,6 +136,13 @@ def users(user_ids=None, sub_account_id=None, pending=None, prefix=None, **optio
:type pending: bool, optional
:param prefix: User prefix
:type prefix: str, optional
:param last_login: Return only users that last logged in in the specified range of dates (true),
users that didn't last logged in in that range (false), or all users (None).
:type last_login: bool, optional
:param from_date: Last login start date.
:type from_date: datetime, optional
:param to_date: Last login end date.
:type to_date: datetime, optional
:param options: Generic advanced options dict, see online documentation.
:type options: dict, optional
:return: List of users associated with the account
Expand All @@ -146,7 +153,10 @@ def users(user_ids=None, sub_account_id=None, pending=None, prefix=None, **optio
params = {"ids": user_ids,
"sub_account_id": sub_account_id,
"pending": pending,
"prefix": prefix}
"prefix": prefix,
"last_login": last_login,
"from": from_date,
"to": to_date}
return _call_account_api("get", uri, params=params, **options)


Expand Down
11 changes: 11 additions & 0 deletions test/test_provisioning_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ def test_get_users_by_nonexistent_sub_account_id(self):
with six.assertRaisesRegex(self, NotFound, "Cannot find sub account with id {}".format(UNIQUE_SUB_ACCOUNT_ID)):
cloudinary.provisioning.users(pending=True, sub_account_id=UNIQUE_SUB_ACCOUNT_ID)

@unittest.skipUnless(cloudinary.provisioning.account_config().provisioning_api_secret,
"requires provisioning_api_key/provisioning_api_secret")
def test_get_users_by_login(self):
res = cloudinary.provisioning.users(user_ids=[self.user_id_1], pending=None,
last_login=True, from_date=datetime.today(), to_date=datetime.today())
self.assertEqual(len(res["users"]), 0)

res = cloudinary.provisioning.users(user_ids=[self.user_id_1], pending=None,
last_login=False, from_date=datetime.today(), to_date=datetime.today())
self.assertEqual(len(res["users"]), 1)

@unittest.skipUnless(cloudinary.provisioning.account_config().provisioning_api_secret,
"requires provisioning_api_key/provisioning_api_secret")
def test_update_user_group(self):
Expand Down

0 comments on commit eca5db6

Please sign in to comment.