Skip to content

Commit ee923a6

Browse files
committed
feat: add last login filtering support to Users API
1 parent b89115f commit ee923a6

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

lib/provisioning/account.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,24 @@ function user(user_id, options = {}, callback) {
122122
* @param [prefix] {string} - Returns users where the name or email address begins with the specified case-insensitive
123123
* string.
124124
* @param [sub_account_id[ {string} - Only returns users who have access to the specified account.
125+
* @param [last_login] {boolean} - Returns users based on their last login within a specified date range. true for users who logged in, false for users who haven't logged in, undefined for all users.
126+
* @param [from_date] {Date|string} - Last login start date.
127+
* @param [to_date] {Date|string} - Last login end date.
125128
* @param [options] {object} - See {@link https://cloudinary.com/documentation/cloudinary_sdks#configuration_parameters|Configuration parameters} in the SDK documentation.
126129
* @param [callback] {function}
127130
*/
128-
function users(pending, user_ids, prefix, sub_account_id, options = {}, callback) {
131+
function users(pending, user_ids, prefix, sub_account_id, last_login, from_date, to_date, options = {}, callback) {
129132
let uri = ['users'];
130133
let params = {
131134
ids: user_ids,
132135
pending,
133136
prefix,
134-
sub_account_id
137+
sub_account_id,
138+
last_login,
139+
from: from_date,
140+
to: to_date
135141
};
136-
return call_account_api('GET', uri, pickOnlyExistingValues(params, "ids", "pending", "prefix", "sub_account_id"), callback, options);
142+
return call_account_api('GET', uri, pickOnlyExistingValues(params, "ids", "pending", "prefix", "sub_account_id", "last_login", "from", "to"), callback, options);
137143
}
138144

139145
/**

test/integration/api/provisioning/account_spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,29 @@ runOnlyForInternalPRs('account API - Provisioning', function () {
199199
expect(result.users.length).to.eql(1);
200200
});
201201

202+
it("Gets users by last login", async () => {
203+
const today = new Date();
204+
const result1 = await cloudinary.provisioning.account.users(
205+
null,
206+
[USER_ID_1],
207+
null,
208+
null,
209+
true,
210+
today,
211+
today
212+
);
213+
expect(result1.users.length).to.eql(0);
214+
215+
const result2 = await cloudinary.provisioning.account.users(
216+
null,
217+
[USER_ID_1],
218+
null,
219+
null,
220+
false
221+
);
222+
expect(result2.users.length).to.eql(1);
223+
});
224+
202225
it('Should throw an error when attempting to get users by a nonexistent sub_account_id', async () => {
203226
const random_id = Math.floor(Math.random() * 100000);
204227
try {

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ declare module 'cloudinary' {
14951495

14961496
function user(userId: string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;
14971497

1498-
function users(pending: boolean, userIds?: string[], prefix?: string, subAccountId?: string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;
1498+
function users(pending: boolean, userIds?: string[], prefix?: string, subAccountId?: string, lastLogin?: boolean, fromDate?: Date | string, toDate?: Date | string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;
14991499

15001500
function create_user(name: string, email: string, role: string, subAccountIds?: string[], options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;
15011501

0 commit comments

Comments
 (0)