Skip to content

Commit

Permalink
Merge pull request #336 from tobiaslohr/user-list-enhancements
Browse files Browse the repository at this point in the history
User list enhancements
  • Loading branch information
tobiaslohr authored Nov 17, 2022
2 parents cf99036 + 9b4979a commit 40b740c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
6 changes: 3 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ program
.description('List users eligible to manage')
.option('-c, --count <count>','Max count of list items (default is 25)')
.option('--start <start>','Zero-based index of first item to return (default is 0)')
.option('-o, --org <org>','Org to return users for (only works in combination with <role>)')
.option('-o, --org <org>','Org to return users for')
.option('-i, --instance <instance>','Instance to search users for. Can be an instance alias.')
.option('-l, --login <login>','Login of a user to get details for')
.option('-r, --role <role>','Limit users to a certain role')
Expand Down Expand Up @@ -1762,8 +1762,7 @@ program
console.log();
console.log(' Use --login to get details of a single user.');
console.log();
console.log(' If options --org and --role are used, you can filter users by organization and');
console.log(' role. --org only works in combination with --role. Only enabled users are returned.');
console.log(' Use options --org and --role, to filter users by organization, role or both.');
console.log();
console.log(' If option --instance is used, local users from this Commerce Cloud instance');
console.log(' are being returned. Use --query to narrow down the users.');
Expand All @@ -1787,6 +1786,7 @@ program
console.log(' $ sfcc-ci user:list --login my-login');
console.log(' $ sfcc-ci user:list --login my-login -j');
console.log(' $ sfcc-ci user:list --role account-admin');
console.log(' $ sfcc-ci user:list --org my-org');
console.log(' $ sfcc-ci user:list --org my-org --role bm-user');
console.log();
});
Expand Down
14 changes: 10 additions & 4 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ function getUsers(org, role, count, token, callback) {
if ( org && role ) {
// note, that this endpoint does not support paging, so size is ignored
endpoint = '/users/search/findByOrgAndRole?organization=' + org + '&role=' + role;
} else if ( org && !role ) {
// only org users
endpoint = '/users/search/findByOrg?organization=' + org;
} else if ( !org && role ) {
// note, that this endpoint does not support paging, so size is ignored
endpoint = '/users/search/findByRole?role=' + role;
Expand Down Expand Up @@ -1111,11 +1114,13 @@ module.exports.cli = {
}

// table fields
var data = [['mail','firstName','lastName','userState','passwordExpired','verifiers','linkedToSfIdentity']];
var data = [['mail','firstName','lastName','userState','passwordExpired','verifiers','linkedToSfIdentity',
'lastLoginDate']];
for (var i of list) {
var user = toExternalUser(i);
data.push([user.mail, user.firstName, user.lastName, user.userState,
(!!user.passwordExpirationTimestamp), ( user.verifiers.length > 0 ), user.linkedToSfIdentity]);
(!!user.passwordExpirationTimestamp), ( user.verifiers.length > 0 ), user.linkedToSfIdentity,
user.lastLoginDate]);
}

console.table(data);
Expand Down Expand Up @@ -1602,10 +1607,11 @@ module.exports.cli = {
}

// table fields
var data = [['login','email','first_name','last_name','disabled', 'external_id', 'roles']];
var data = [['login','email','first_name','last_name','disabled', 'external_id', 'roles',
'last_login_date']];
for (var i of list) {
data.push([i.login, i.email, i.first_name, i.last_name, i.disabled, i.external_id,
prettyPrintRoles(i.roles)]);
prettyPrintRoles(i.roles), i.last_login_date]);
}

console.table(data);
Expand Down
20 changes: 19 additions & 1 deletion test/unit/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ describe('Tests for lib/user.js', function() {
});

it('makes a get request ...', function() {
var user = proxyquire('../../lib/user', {
'request': requestStub,
'./auth': {
'getToken' : () => 'mytoken',
'getAMHost' : () => 'am.host'
},
'./log': {
'json' : jsonStub
}
});
user.cli.list(null, null, null, null, true, undefined);

const reqArgs = requestStub.getCall(0).args[0];
expect(reqArgs.uri).to.equal('https://am.host/dw/rest/v1/users?page=0&size=25');
expect(reqArgs.method).to.equal('GET');
});

it('searches by org', function() {
var user = proxyquire('../../lib/user', {
'request': requestStub,
'./auth': {
Expand All @@ -129,7 +147,7 @@ describe('Tests for lib/user.js', function() {
user.cli.list('myorg', null, null, null, true, undefined);

const reqArgs = requestStub.getCall(0).args[0];
expect(reqArgs.uri).to.equal('https://am.host/dw/rest/v1/users?page=0&size=25');
expect(reqArgs.uri).to.equal('https://am.host/dw/rest/v1/users/search/findByOrg?organization=myorg');
expect(reqArgs.method).to.equal('GET');
});

Expand Down

0 comments on commit 40b740c

Please sign in to comment.