@@ -164,8 +164,9 @@ export class MenuCtrl {
164164 this . path = this . $location . path ( ) ;
165165 }
166166 hasrole ( role : string ) {
167- if ( this . WebSocketClientService . user === null || this . WebSocketClientService . user === undefined ) return false ;
168- const hits = this . WebSocketClientService . user . roles . filter ( member => member . name == role ) ;
167+ if ( WebSocketClient . instance === null || WebSocketClient . instance === undefined ) return false ;
168+ if ( WebSocketClient . instance . user === null || WebSocketClient . instance . user === undefined ) return false ;
169+ const hits = WebSocketClient . instance . user . roles . filter ( member => member . name == role ) ;
169170 return ( hits . length == 1 )
170171 }
171172 hascordova ( ) {
@@ -189,9 +190,9 @@ export class MenuCtrl {
189190 async EditCustomer ( customer ) {
190191 try {
191192 if ( customer == null ) return ;
192- this . WebSocketClientService . user . selectedcustomerid = customer . _id ;
193+ WebSocketClient . instance . user . selectedcustomerid = customer . _id ;
193194 this . WebSocketClientService . customer = customer as any ;
194- await NoderedUtil . SelectCustomer ( this . WebSocketClientService . user . selectedcustomerid , null , 2 ) ;
195+ await NoderedUtil . SelectCustomer ( WebSocketClient . instance . user . selectedcustomerid , null , 2 ) ;
195196 this . $location . path ( "/Customer/" + customer . _id ) ;
196197 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
197198 } catch ( error ) {
@@ -207,16 +208,16 @@ export class MenuCtrl {
207208 try {
208209 this . customer = customer ;
209210 if ( customer != null ) {
210- this . WebSocketClientService . user . selectedcustomerid = customer . _id ;
211- await NoderedUtil . SelectCustomer ( this . WebSocketClientService . user . selectedcustomerid , null , 2 ) ;
211+ WebSocketClient . instance . user . selectedcustomerid = customer . _id ;
212+ await NoderedUtil . SelectCustomer ( WebSocketClient . instance . user . selectedcustomerid , null , 2 ) ;
212213 this . WebSocketClientService . customer = customer as any ;
213214 if ( this . PathIs ( "/Customer" ) ) {
214215 this . $location . path ( "/Customer/" + customer . _id ) ;
215216 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
216217 }
217218 } else {
218- this . WebSocketClientService . user . selectedcustomerid = null ;
219- await NoderedUtil . SelectCustomer ( this . WebSocketClientService . user . selectedcustomerid , null , 2 ) ;
219+ WebSocketClient . instance . user . selectedcustomerid = null ;
220+ await NoderedUtil . SelectCustomer ( WebSocketClient . instance . user . selectedcustomerid , null , 2 ) ;
220221 this . WebSocketClientService . customer = null ;
221222 }
222223 // this.$rootScope.$broadcast("menurefresh");
@@ -1877,10 +1878,10 @@ export class MainCtrl extends entitiesCtrl<Base> {
18771878 // this.basequery = { state: { $ne: "completed" }, $and: [{ form: { $exists: true } }, { form: { "$ne": "none" } }] };
18781879 // this.basequery = { state: { $ne: "completed" }, form: { $exists: true } };
18791880 this . preloadData = ( ) => {
1880- const user = this . WebSocketClientService . user ;
1881+ const user = WebSocketClient . instance . user ;
18811882 const ors : any [ ] = [ ] ;
18821883 ors . push ( { targetid : user . _id } ) ;
1883- this . WebSocketClientService . user . roles . forEach ( role => {
1884+ WebSocketClient . instance . user . roles . forEach ( role => {
18841885 ors . push ( { targetid : role . _id } ) ;
18851886 } ) ;
18861887 this . basequery = { } ;
@@ -2436,13 +2437,18 @@ export class UserCtrl extends entityCtrl<TokenUser> {
24362437 }
24372438 async processdata ( ) {
24382439 if ( this . model != null && ( this . model . _id != null && this . model . _id != "" ) ) {
2439- this . memberof = await NoderedUtil . Query ( "users" ,
2440- {
2441- $and : [
2442- { _type : "role" } ,
2443- { members : { $elemMatch : { _id : this . model . _id } } }
2444- ]
2445- } , null , { _type : - 1 , name : 1 } , 5 , 0 , null , null , null , 2 ) ;
2440+ if ( this . model . _id == WebSocketClient . instance . user . _id ) {
2441+ console . log ( WebSocketClient . instance . user )
2442+ this . memberof = WebSocketClient . instance . user . roles as any ;
2443+ } else {
2444+ this . memberof = await NoderedUtil . Query ( "users" ,
2445+ {
2446+ $and : [
2447+ { _type : "role" } ,
2448+ { members : { $elemMatch : { _id : this . model . _id } } }
2449+ ]
2450+ } , null , { _type : - 1 , name : 1 } , 50 , 0 , null , null , null , 2 ) ;
2451+ }
24462452 } else {
24472453 this . memberof = [ ] ;
24482454 }
@@ -2499,12 +2505,12 @@ export class UserCtrl extends entityCtrl<TokenUser> {
24992505 for ( let i = 0 ; i < this . removedmembers . length ; i ++ ) {
25002506 const roles = await NoderedUtil . Query ( "users" , { _type : "role" , _id : this . removedmembers [ i ] . _id } , null , { _type : - 1 , name : 1 } , 5 , 0 , null , null , null , 2 ) ;
25012507 if ( roles . length > 0 ) {
2502- const memberof = this . removedmembers [ i ] ;
2503- if ( this . memberof == null || this . memberof == undefined ) this . memberof = [ ] ;
2504- const exists = this . memberof . filter ( x => x . _id == this . model . _id ) ;
2508+ const memberof = roles [ i ] ;
2509+ const exists = memberof . members . filter ( x => x . _id == this . model . _id ) ;
25052510 if ( exists . length > 0 ) {
25062511 memberof . members = memberof . members . filter ( x => x . _id != this . model . _id ) ;
25072512 try {
2513+ console . log ( "Updating " + memberof . name , memberof ) ;
25082514 await NoderedUtil . UpdateOne ( "users" , null , memberof , 1 , false , null , 2 ) ;
25092515 } catch ( error ) {
25102516 console . error ( "Error updating " + memberof . name , error ) ;
@@ -2518,6 +2524,7 @@ export class UserCtrl extends entityCtrl<TokenUser> {
25182524 }
25192525 this . $location . path ( "/Users" ) ;
25202526 } catch ( error ) {
2527+ debugger ;
25212528 this . errormessage = error . message ? error . message : error ;
25222529 }
25232530 if ( ! this . $scope . $$phase ) { this . $scope . $apply ( ) ; }
@@ -3060,7 +3067,7 @@ export class EditFormCtrl extends entityCtrl<Form> {
30603067 // http://www.alpacajs.org/demos/form-builder/form-builder.html
30613068 // https://github.com/kevinchappell/formBuilder - https://formbuilder.online/ - https://kevinchappell.github.io/formBuilder/
30623069 const roles : any = { } ;
3063- this . WebSocketClientService . user . roles . forEach ( role => {
3070+ WebSocketClient . instance . user . roles . forEach ( role => {
30643071 roles [ role . _id ] = role . name ;
30653072 } ) ;
30663073
@@ -3557,7 +3564,7 @@ export class FormCtrl extends entityCtrl<WorkflowInstance> {
35573564 if ( this . form . fbeditor === true ) {
35583565 console . debug ( "renderform" ) ;
35593566 const roles : any = { } ;
3560- this . WebSocketClientService . user . roles . forEach ( role => {
3567+ WebSocketClient . instance . user . roles . forEach ( role => {
35613568 roles [ role . _id ] = role . name ;
35623569 } ) ;
35633570 if ( typeof this . form . formData === 'string' || this . form . formData instanceof String ) {
@@ -3796,7 +3803,7 @@ export class EntityCtrl extends entityCtrl<Base> {
37963803 for ( let i : number = this . keys . length - 1 ; i >= 0 ; i -- ) {
37973804 if ( this . keys [ i ] . startsWith ( '_' ) ) this . keys . splice ( i , 1 ) ;
37983805 }
3799- this . searchSelectedItem = WebSocketClientService . user ;
3806+ this . searchSelectedItem = WebSocketClient . instance . user ;
38003807 this . adduser ( ) ;
38013808 this . processdata ( ) ;
38023809 //if (!this.$scope.$$phase) { this.$scope.$apply(); }
@@ -4279,8 +4286,8 @@ export class NoderedCtrl {
42794286 this . loading = true ;
42804287 this . userid = $routeParams . id ;
42814288 if ( this . userid == null || this . userid == undefined || this . userid == "" ) {
4282- this . name = WebSocketClientService . user . username ;
4283- this . userid = WebSocketClientService . user . _id ;
4289+ this . name = WebSocketClient . instance . user . username ;
4290+ this . userid = WebSocketClient . instance . user . _id ;
42844291 const users : NoderedUser [ ] = await NoderedUtil . Query ( "users" , { _id : this . userid } , null , null , 1 , 0 , null , null , null , 2 ) ;
42854292 if ( users . length == 0 ) {
42864293 this . instancestatus = "Unknown id! " + this . userid ;
@@ -5053,7 +5060,7 @@ export class CredentialCtrl extends entityCtrl<Base> {
50535060 this . model = new Base ( ) ;
50545061 this . model . _type = "credential" ;
50555062 this . model . _encrypt = [ "password" ] ;
5056- this . searchSelectedItem = WebSocketClientService . user ;
5063+ this . searchSelectedItem = WebSocketClient . instance . user ;
50575064 this . adduser ( ) ;
50585065 }
50595066 } ) ;
@@ -5098,7 +5105,7 @@ export class CredentialCtrl extends entityCtrl<Base> {
50985105 ace . _id = this . searchSelectedItem . _id ;
50995106 ace . name = this . searchSelectedItem . name ;
51005107 // ace.rights = "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8=";
5101- if ( this . WebSocketClientService . user . _id != ace . _id ) {
5108+ if ( WebSocketClient . instance . user . _id != ace . _id ) {
51025109 ace . rights = this . unsetBit ( ace . rights , 1 ) ;
51035110 ace . rights = this . setBit ( ace . rights , 2 ) ;
51045111 ace . rights = this . unsetBit ( ace . rights , 3 ) ;
@@ -5827,7 +5834,7 @@ export class CustomerCtrl extends entityCtrl<Customer> {
58275834 if ( NoderedUtil . IsNullUndefinded ( this . model ) ) {
58285835 this . model = { } as any ;
58295836
5830- if ( this . model . name == null || this . model . name == "" ) this . model . name = WebSocketClientService . user . name ;
5837+ if ( this . model . name == null || this . model . name == "" ) this . model . name = WebSocketClient . instance . user . name ;
58315838 this . model . _type = "customer" ;
58325839 var results = await NoderedUtil . Query ( this . collection , { "_type" : "billing" , "userid" : user . _id } , null , null , 1 , 0 , null , null , null , 2 ) ;
58335840
@@ -5838,15 +5845,15 @@ export class CustomerCtrl extends entityCtrl<Customer> {
58385845 this . model . vatnumber = results [ 0 ] . vatnumber ;
58395846 this . model . vattype = results [ 0 ] . vattype ;
58405847 } else {
5841- var results = await NoderedUtil . Query ( this . collection , { "_type" : "user" , "_id" : WebSocketClientService . user . _id } , null , null , 1 , 0 , null , null , null , 2 ) ;
5848+ var results = await NoderedUtil . Query ( this . collection , { "_type" : "user" , "_id" : WebSocketClient . instance . user . _id } , null , null , 1 , 0 , null , null , null , 2 ) ;
58425849 if ( results . length > 0 && ! NoderedUtil . IsNullEmpty ( ( results [ 0 ] as any ) . company ) ) {
58435850 this . model . name = ( results [ 0 ] as any ) . company ;
58445851 }
58455852 }
5846- this . model . email = ( WebSocketClientService . user as any ) . username ;
5847- if ( ( WebSocketClientService . user as any ) . email ) this . model . email = ( WebSocketClientService . user as any ) . email ;
5853+ this . model . email = ( WebSocketClient . instance . user as any ) . username ;
5854+ if ( ( WebSocketClient . instance . user as any ) . email ) this . model . email = ( WebSocketClient . instance . user as any ) . email ;
58485855 if ( this . model . email && this . model . email . indexOf ( "@" ) == - 1 ) {
5849- this . model . email = ( WebSocketClientService . user as any ) . username + "@domain.com" ;
5856+ this . model . email = ( WebSocketClient . instance . user as any ) . username + "@domain.com" ;
58505857 }
58515858 console . debug ( "Create new customer" ) ;
58525859 }
@@ -5896,8 +5903,8 @@ export class CustomerCtrl extends entityCtrl<Customer> {
58965903 this . errormessage = "" ;
58975904 // this.stripe_customer = await NoderedUtil.EnsureStripeCustomer(this.model, this.userid, null, 2);
58985905 if ( this . model != null ) {
5899- if ( this . WebSocketClientService . user . selectedcustomerid != this . model . _id ) {
5900- this . WebSocketClientService . user . selectedcustomerid = this . model . _id ;
5906+ if ( WebSocketClient . instance . user . selectedcustomerid != this . model . _id ) {
5907+ WebSocketClient . instance . user . selectedcustomerid = this . model . _id ;
59015908 this . $rootScope . $broadcast ( "menurefresh" ) ;
59025909 }
59035910 }
@@ -6332,7 +6339,7 @@ export class EntityRestrictionCtrl extends entityCtrl<Base> {
63326339 ace . _id = this . searchSelectedItem . _id ;
63336340 ace . name = this . searchSelectedItem . name ;
63346341 // ace.rights = "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8=";
6335- if ( this . WebSocketClientService . user . _id != ace . _id ) {
6342+ if ( WebSocketClient . instance . user . _id != ace . _id ) {
63366343 ace . rights = this . setBit ( ace . rights , 1 ) ;
63376344 ace . rights = this . unsetBit ( ace . rights , 2 ) ;
63386345 ace . rights = this . unsetBit ( ace . rights , 3 ) ;
0 commit comments