@@ -1583,37 +1583,40 @@ export class AdapterClass extends EventEmitter {
1583
1583
}
1584
1584
1585
1585
private async _checkPassword ( options : InternalCheckPasswordOptions ) : Promise < void > {
1586
- if ( options . user && ! options . user . startsWith ( 'system.user.' ) ) {
1586
+ let { user } = options ;
1587
+ const { callback, pw } = options ;
1588
+
1589
+ if ( user && ! user . startsWith ( 'system.user.' ) ) {
1587
1590
// it's not yet a `system.user.xy` id, thus we assume it's a username
1588
- if ( ! this . usernames [ options . user ] ) {
1591
+ if ( ! this . usernames [ user ] ) {
1589
1592
// we did not find the id of the username in our cache -> update cache
1590
1593
try {
1591
1594
await this . _updateUsernameCache ( ) ;
1592
1595
} catch ( e ) {
1593
1596
this . _logger . error ( `${ this . namespaceLog } ${ e . message } ` ) ;
1594
1597
}
1595
- if ( ! this . usernames [ options . user ] ) {
1598
+ if ( ! this . usernames [ user ] ) {
1596
1599
// user still not there, it's no valid user -> fallback to legacy check
1597
- options . user = `system.user.${ options . user
1600
+ user = `system.user.${ user
1598
1601
. toString ( )
1599
1602
. replace ( this . FORBIDDEN_CHARS , '_' )
1600
1603
. replace ( / \s / g, '_' )
1601
1604
. replace ( / \. / g, '_' )
1602
1605
. toLowerCase ( ) } `;
1603
1606
} else {
1604
- options . user = this . usernames [ options . user ] . id ;
1607
+ user = this . usernames [ user ] . id ;
1605
1608
}
1606
1609
} else {
1607
- options . user = this . usernames [ options . user ] . id ;
1610
+ user = this . usernames [ user ] . id ;
1608
1611
}
1609
1612
}
1610
1613
1611
- this . getForeignObject ( options . user , options , ( err , obj ) => {
1612
- if ( err || ! obj || ! obj . common || ( ! obj . common . enabled && options . user !== SYSTEM_ADMIN_USER ) ) {
1613
- return tools . maybeCallback ( options . callback , false , options . user ) ;
1614
+ this . getForeignObject ( user , options , ( err , obj ) => {
1615
+ if ( err || ! obj || ! obj . common || ( ! obj . common . enabled && user !== SYSTEM_ADMIN_USER ) ) {
1616
+ return tools . maybeCallback ( callback , false , user ) ;
1614
1617
} else {
1615
- password ( options . pw ) . check ( obj . common . password , ( err , res ) => {
1616
- return tools . maybeCallback ( options . callback , ! ! res , options . user ) ;
1618
+ password ( pw ) . check ( obj . common . password , ( err , res ) => {
1619
+ return tools . maybeCallback ( callback , ! ! res , user ) ;
1617
1620
} ) ;
1618
1621
}
1619
1622
} ) ;
@@ -1995,7 +1998,10 @@ export class AdapterClass extends EventEmitter {
1995
1998
private async _calculatePermissions (
1996
1999
options : InternalCalculatePermissionsOptions
1997
2000
) : Promise < void | ioBroker . PermissionSet > {
1998
- if ( options . user && ! options . user . startsWith ( 'system.user.' ) ) {
2001
+ const { user } = options ;
2002
+ let userId : ioBroker . ObjectIDs . User ;
2003
+
2004
+ if ( user && ! user . startsWith ( 'system.user.' ) ) {
1999
2005
// it's not yet a `system.user.xy` id, thus we assume it's a username
2000
2006
if ( ! this . usernames [ options . user ] ) {
2001
2007
// we did not find the id of the username in our cache -> update cache
@@ -2005,24 +2011,26 @@ export class AdapterClass extends EventEmitter {
2005
2011
this . _logger . error ( `${ this . namespaceLog } ${ e . message } ` ) ;
2006
2012
}
2007
2013
// user still not there, fallback
2008
- if ( ! this . usernames [ options . user ] ) {
2009
- options . user = `system.user.${ options . user
2014
+ if ( ! this . usernames [ user ] ) {
2015
+ userId = `system.user.${ user
2010
2016
. toString ( )
2011
2017
. replace ( this . FORBIDDEN_CHARS , '_' )
2012
2018
. replace ( / \s / g, '_' )
2013
2019
. replace ( / \. / g, '_' )
2014
2020
. toLowerCase ( ) } `;
2015
2021
} else {
2016
- options . user = this . usernames [ options . user ] . id ;
2022
+ userId = this . usernames [ user ] . id as ioBroker . ObjectIDs . User ;
2017
2023
}
2018
2024
} else {
2019
- options . user = this . usernames [ options . user ] . id ;
2025
+ userId = this . usernames [ user ] . id as ioBroker . ObjectIDs . User ;
2020
2026
}
2027
+ } else {
2028
+ userId = user as ioBroker . ObjectIDs . User ;
2021
2029
}
2022
2030
2023
2031
// read all groups
2024
- let acl : Partial < ioBroker . PermissionSet > = { user : options . user } ;
2025
- if ( options . user === SYSTEM_ADMIN_USER ) {
2032
+ let acl : Partial < ioBroker . PermissionSet > = { user : userId } ;
2033
+ if ( userId === SYSTEM_ADMIN_USER ) {
2026
2034
acl . groups = [ SYSTEM_ADMIN_GROUP ] ;
2027
2035
for ( const commandPermission of Object . values ( options . commandsPermissions ) ) {
2028
2036
if ( ! commandPermission . type ) {
@@ -2041,12 +2049,7 @@ export class AdapterClass extends EventEmitter {
2041
2049
// aggregate all groups permissions, where this user is
2042
2050
if ( groups ) {
2043
2051
for ( const g of Object . keys ( groups ) ) {
2044
- if (
2045
- groups [ g ] &&
2046
- groups [ g ] . common &&
2047
- groups [ g ] . common . members &&
2048
- groups [ g ] . common . members . includes ( options . user )
2049
- ) {
2052
+ if ( groups [ g ] ?. common ?. members && groups [ g ] . common . members . includes ( userId ) ) {
2050
2053
acl . groups . push ( groups [ g ] . _id ) ;
2051
2054
if ( groups [ g ] . _id === SYSTEM_ADMIN_GROUP ) {
2052
2055
acl = {
@@ -2071,7 +2074,7 @@ export class AdapterClass extends EventEmitter {
2071
2074
create : true ,
2072
2075
list : true
2073
2076
} ,
2074
- user : options . user ,
2077
+ user : userId ,
2075
2078
users : {
2076
2079
read : true ,
2077
2080
write : true ,
@@ -3768,11 +3771,14 @@ export class AdapterClass extends EventEmitter {
3768
3771
}
3769
3772
3770
3773
// external signatures
3771
- getObjectList ( params : ioBroker . GetObjectListParams | null , callback : ioBroker . GetObjectListCallback ) : void ;
3774
+ getObjectList (
3775
+ params : ioBroker . GetObjectListParams | null ,
3776
+ callback : ioBroker . GetObjectListCallback < ioBroker . Object >
3777
+ ) : void ;
3772
3778
getObjectList (
3773
3779
params : ioBroker . GetObjectListParams | null ,
3774
3780
options : { sorted ?: boolean } | Record < string , any > ,
3775
- callback : ioBroker . GetObjectListCallback
3781
+ callback : ioBroker . GetObjectListCallback < ioBroker . Object >
3776
3782
) : void ;
3777
3783
3778
3784
/**
@@ -3902,7 +3908,7 @@ export class AdapterClass extends EventEmitter {
3902
3908
if ( err ) {
3903
3909
return tools . maybeCallbackWithError ( callback , err ) ;
3904
3910
}
3905
- if ( res && res . rows ) {
3911
+ if ( res ? .rows ) {
3906
3912
for ( const row of res . rows ) {
3907
3913
result [ row . id ] = row . value ;
3908
3914
}
@@ -4040,7 +4046,7 @@ export class AdapterClass extends EventEmitter {
4040
4046
const result : {
4041
4047
[ groupName : string ] : Record < string , ioBroker . Enum > ;
4042
4048
} = { } ;
4043
- if ( res && res . rows ) {
4049
+ if ( res ? .rows ) {
4044
4050
for ( const row of res . rows ) {
4045
4051
const parts : string [ ] = row . id . split ( '.' , 3 ) ;
4046
4052
if ( ! parts [ 2 ] ) {
@@ -4553,9 +4559,8 @@ export class AdapterClass extends EventEmitter {
4553
4559
// read all underlying states
4554
4560
adapterObjects ! . getObjectList ( selector , options , ( err , res ) => {
4555
4561
res &&
4556
- res . rows &&
4557
4562
res . rows . forEach (
4558
- ( item : ioBroker . GetObjectListItem ) =>
4563
+ ( item : ioBroker . GetObjectListItem < ioBroker . Object > ) =>
4559
4564
! tasks . find ( task => task . id === item . id ) &&
4560
4565
( ! item . value || ! item . value . common || ! item . value . common . dontDelete ) && // exclude objects with dontDelete flag
4561
4566
tasks . push ( { id : item . id , state : item . value && item . value . type === 'state' } )
@@ -4569,7 +4574,7 @@ export class AdapterClass extends EventEmitter {
4569
4574
return tools . maybeCallbackWithError ( callback , err ) ;
4570
4575
} else if ( obj ) {
4571
4576
// do not allow deletion of objects with dontDelete flag
4572
- if ( obj . common && obj . common . dontDelete ) {
4577
+ if ( obj . common ? .dontDelete ) {
4573
4578
return tools . maybeCallbackWithError ( callback , new Error ( 'not deletable' ) ) ;
4574
4579
}
4575
4580
@@ -5687,7 +5692,7 @@ export class AdapterClass extends EventEmitter {
5687
5692
return tools . maybeCallbackWithError ( callback , err ) ;
5688
5693
}
5689
5694
5690
- if ( res && res . rows ) {
5695
+ if ( res ) {
5691
5696
for ( const row of res . rows ) {
5692
5697
try {
5693
5698
const obj = ( await adapterObjects ! . getObject ( row . id , options ) ) as
@@ -6419,7 +6424,7 @@ export class AdapterClass extends EventEmitter {
6419
6424
} ,
6420
6425
options ,
6421
6426
async ( err , res ) => {
6422
- if ( err || ! res || ! res . rows ) {
6427
+ if ( err || ! res ) {
6423
6428
return tools . maybeCallbackWithError ( callback , err ) ;
6424
6429
}
6425
6430
@@ -7176,7 +7181,7 @@ export class AdapterClass extends EventEmitter {
7176
7181
endkey : `${ instanceName } .\u9999`
7177
7182
} ) ;
7178
7183
7179
- if ( res ?. rows ) {
7184
+ if ( res ) {
7180
7185
for ( const row of res . rows ) {
7181
7186
try {
7182
7187
await adapterStates ! . pushMessage ( row . id , obj ) ;
@@ -7337,7 +7342,7 @@ export class AdapterClass extends EventEmitter {
7337
7342
// if states is no longer existing, we do not need to unsubscribe
7338
7343
return ;
7339
7344
}
7340
- if ( ! err && res ?. rows ? .length ) {
7345
+ if ( ! err && res ?. rows . length ) {
7341
7346
for ( const row of res . rows ) {
7342
7347
const parts : string [ ] = row . id . split ( '.' ) ;
7343
7348
// ignore system.host.name.alive and so on
@@ -8915,7 +8920,7 @@ export class AdapterClass extends EventEmitter {
8915
8920
8916
8921
if ( _obj ?. rows ) {
8917
8922
for ( const row of _obj . rows ) {
8918
- if ( row . value . common && row . value . common . type === 'storage' ) {
8923
+ if ( row . value ? .common && row . value . common . type === 'storage' ) {
8919
8924
this . defaultHistory = row . id . substring ( 'system.adapter.' . length ) ;
8920
8925
break ;
8921
8926
}
@@ -9406,7 +9411,7 @@ export class AdapterClass extends EventEmitter {
9406
9411
options . checked = undefined ;
9407
9412
}
9408
9413
9409
- if ( ! res || ! res . rows ) {
9414
+ if ( ! res ) {
9410
9415
return tools . maybeCallbackWithError ( callback , null , { } ) ;
9411
9416
}
9412
9417
const keys = [ ] ;
@@ -10415,14 +10420,12 @@ export class AdapterClass extends EventEmitter {
10415
10420
endkey : 'system.adapter.\u9999'
10416
10421
} ) ;
10417
10422
10418
- if ( res && res . rows ) {
10419
- this . autoSubscribe = [ ] ;
10420
- for ( const row of res . rows ) {
10421
- if ( row . value . common . subscribable ) {
10422
- const _id = row . id . substring ( 15 ) ; // cut system.adapter.
10423
- if ( ! this . autoSubscribe . includes ( _id ) ) {
10424
- this . autoSubscribe . push ( _id ) ;
10425
- }
10423
+ this . autoSubscribe = [ ] ;
10424
+ for ( const row of res . rows ) {
10425
+ if ( row . value ?. common . subscribable ) {
10426
+ const _id = row . id . substring ( 15 ) ; // cut system.adapter.
10427
+ if ( ! this . autoSubscribe . includes ( _id ) ) {
10428
+ this . autoSubscribe . push ( _id ) ;
10426
10429
}
10427
10430
}
10428
10431
}
0 commit comments