7
7
8
8
import * as os from 'os' ;
9
9
import { flags , FlagsConfig , SfdxCommand } from '@salesforce/command' ;
10
- import { Aliases , Connection , Messages , User , AuthInfo , Org , UserFields , SfdxError } from '@salesforce/core' ;
10
+ import { Aliases , Connection , Messages , Org , SfdxError , User } from '@salesforce/core' ;
11
+ import { QueryResult } from 'jsforce' ;
11
12
12
13
Messages . importMessagesDirectory ( __dirname ) ;
13
14
const messages = Messages . loadMessages ( '@salesforce/plugin-user' , 'permset.assign' ) ;
@@ -54,19 +55,21 @@ export class UserPermsetAssignCommand extends SfdxCommand {
54
55
} else {
55
56
this . usernames = [ this . org . getUsername ( ) ] ;
56
57
}
58
+ const connection : Connection = this . org . getConnection ( ) ;
59
+ const org = await Org . create ( { connection } ) ;
57
60
58
61
for ( const username of this . usernames ) {
59
62
// Convert any aliases to usernames
60
63
const aliasOrUsername = ( await Aliases . fetch ( username ) ) || username ;
61
- const connection : Connection = await Connection . create ( {
62
- authInfo : await AuthInfo . create ( { username } ) ,
63
- } ) ;
64
- const org = await Org . create ( { connection } ) ;
65
64
const user : User = await User . create ( { org } ) ;
66
- const fields : UserFields = await user . retrieve ( username ) ;
65
+ // get userId of whomever the permset will be assigned to via query to avoid AuthInfo if remote user
66
+ const queryResult : QueryResult < { Id : string } > = await connection . query (
67
+ `SELECT Id FROM User WHERE Username='${ username } '`
68
+ ) ;
69
+ const userId = queryResult . records [ 0 ] . Id ;
67
70
68
71
try {
69
- await user . assignPermissionSets ( fields . id , [ this . flags . permsetname ] ) ;
72
+ await user . assignPermissionSets ( userId , [ this . flags . permsetname ] ) ;
70
73
this . successes . push ( {
71
74
name : aliasOrUsername ,
72
75
value : this . flags . permsetname ,
@@ -84,12 +87,10 @@ export class UserPermsetAssignCommand extends SfdxCommand {
84
87
85
88
this . print ( ) ;
86
89
87
- const result : Result = {
90
+ return {
88
91
successes : this . successes ,
89
92
failures : this . failures ,
90
93
} ;
91
-
92
- return result ;
93
94
}
94
95
95
96
private print ( ) : void {
0 commit comments