Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/provisioning/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,24 @@ function user(user_id, options = {}, callback) {
* @param [prefix] {string} - Returns users where the name or email address begins with the specified case-insensitive
* string.
* @param [sub_account_id[ {string} - Only returns users who have access to the specified account.
* @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.
* @param [from_date] {Date|string} - Last login start date.
* @param [to_date] {Date|string} - Last login end date.
* @param [options] {object} - See {@link https://cloudinary.com/documentation/cloudinary_sdks#configuration_parameters|Configuration parameters} in the SDK documentation.
* @param [callback] {function}
*/
function users(pending, user_ids, prefix, sub_account_id, options = {}, callback) {
function users(pending, user_ids, prefix, sub_account_id, last_login, from_date, to_date, options = {}, callback) {
let uri = ['users'];
let params = {
ids: user_ids,
pending,
prefix,
sub_account_id
sub_account_id,
last_login,
from: from_date,
to: to_date
};
return call_account_api('GET', uri, pickOnlyExistingValues(params, "ids", "pending", "prefix", "sub_account_id"), callback, options);
return call_account_api('GET', uri, pickOnlyExistingValues(params, "ids", "pending", "prefix", "sub_account_id", "last_login", "from", "to"), callback, options);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions test/integration/api/provisioning/account_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,29 @@ runOnlyForInternalPRs('account API - Provisioning', function () {
expect(result.users.length).to.eql(1);
});

it("Gets users by last login", async () => {
const today = new Date();
const result1 = await cloudinary.provisioning.account.users(
null,
[USER_ID_1],
null,
null,
true,
today,
today
);
expect(result1.users.length).to.eql(0);

const result2 = await cloudinary.provisioning.account.users(
null,
[USER_ID_1],
null,
null,
false
);
expect(result2.users.length).to.eql(1);
});

it('Should throw an error when attempting to get users by a nonexistent sub_account_id', async () => {
const random_id = Math.floor(Math.random() * 100000);
try {
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ declare module 'cloudinary' {

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

function users(pending: boolean, userIds?: string[], prefix?: string, subAccountId?: string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;
function users(pending: boolean, userIds?: string[], prefix?: string, subAccountId?: string, lastLogin?: boolean, fromDate?: Date | string, toDate?: Date | string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move lastLogin, fromDate and toDate to options object.
Also, extend the typescript definition of the options object, so it includes those fields and its types.
Keep in mind that it should be backwards compatible, so we aim towards extending the contract rather then changing it. Options could look like this:

function users(..., options?: ProvisioningApiOptions | { lastLogin?: boolean; fromDate?: Date | string; toDate?: Date | string })

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as requested, to ensure backward compatibility. I moved the new parameters into the options object and updated the typescript definition to include those new fields in options.
All checks passed.


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

Expand Down
Loading