Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter get-users API by last login #546

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 11 additions & 5 deletions lib-es5/provisioning/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,27 @@ function user(user_id) {
* @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} - 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 (null).
* @param [from] {string} - Last login start date.
* @param [to] {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) {
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var callback = arguments[5];
function users(pending, user_ids, prefix, sub_account_id, last_login, from, to) {
var options = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : {};
var callback = arguments[8];

var uri = ['users'];
var params = {
ids: user_ids,
pending,
prefix,
sub_account_id
sub_account_id,
last_login,
from,
to
};
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
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} - 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 (null).
* @param [from] {string} - Last login start date.
* @param [to] {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, to, options = {}, callback) {
let uri = ['users'];
let params = {
ids: user_ids,
pending,
prefix,
sub_account_id
sub_account_id,
last_login,
from,
to
};
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
12 changes: 12 additions & 0 deletions test/integration/api/provisioning/account_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const cloudinary = require("../../../../cloudinary");
const TIMEOUT = require('../../../testUtils/testConstants').TIMEOUT;
const helper = require("../../../spechelper");
let runOnlyForInternalPRs = process.env.TRAVIS_SECURE_ENV_VARS ? describe : describe.skip;


Expand Down Expand Up @@ -199,6 +200,17 @@ runOnlyForInternalPRs('account API - Provisioning', function () {
expect(result.users.length).to.eql(1);
});

it('Gets users by last_login', async () => {
const from = helper.toISO8601DateOnly(new Date());
const to = helper.toISO8601DateOnly(new Date());

let result = await cloudinary.provisioning.account.users(true, null, USER_NAME_2, CLOUD_ID, true, from, to);
expect(result.users.length).to.eql(0);

result = await cloudinary.provisioning.account.users(true, null, USER_NAME_2, CLOUD_ID, false, from, to);
expect(result.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
3 changes: 3 additions & 0 deletions types/cloudinary_ts_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ cloudinary.v2.provisioning.account.users(
['str'],
'str',
'str',
true,
'str',
'str',
{},
(res) => {

Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,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, last_login?: boolean, from?: string, to?: string, options?: ProvisioningApiOptions, callback?: ResponseCallback): Promise<any>;

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

Expand Down