1

API for User and all units associated to that user under user edit

(17/06/2021 10:28:27 отредактировано arsalanqayum332)

Тема: API for User and all units associated to that user under user edit

Hi,

I have to search a user and all units associated to that user.

I am working on a web app from I have to edit users, when editing a individual user, I need to get all units which are assigned to that user.

Perhaps, it is similar to searching "avl_unit" and it's all sub itmes such as "unit_sensors", explained here: https://sdk.wialon.com/wiki/en/sidebar/ … arch_items


Please take a look on the screenshot attached below. It shows a user edit in a modal, and under access tab, you can see colored units which are assigned to that user.

Want I want is to search all units which associates with a user. In the Wailon CMS dashboard, it works fine. But I could not find the API to search the same results.

I also could not find the API to search "Presets of access rights for units"

Can anyone here help me find these APIs? Or let me know what APIs I need to hit in order to get the same results? Thanks

I look forward to hearing from you.

2

API for User and all units associated to that user under user edit

Re: API for User and all units associated to that user under user edit

Hi Arsalan,

If I understand you correctly, you need to get all user which have access to some units.
In this case you can use request core/check_accessors - https://sdk.wialon.com/wiki/en/sidebar/ … _accessors
You will get the all users (user's id) which have access to unit(s , except user-creator of unit.

To get access right of current user - it's used the following request https://sdk.wialon.com/wiki/en/sidebar/ … ms_billing

Diana Cheley
Wialon Hosting Expert
Gurtam
3

API for User and all units associated to that user under user edit

(17/06/2021 10:28:48 отредактировано arsalanqayum332)

Re: API for User and all units associated to that user under user edit

Hi Diana,

Thank you for your reply.

However, I am still not able to find the API I am looking for. Let me briefly re define what I am looking for.

We are trying to figure out what API call will allow us to look up a user for example Arsalan Qayum, and see what units are assigned with what specific permissions to this specific user.

For example, how do we have our web app pull the following circled information for this specific user seen in the screenshot below.

I look forward to hearing from you.

  • API for User and all units associated to that user under user edit
4

API for User and all units associated to that user under user edit

Re: API for User and all units associated to that user under user edit

Hi Arsalan,

To get info about access to item class (as on screenshot) you can execute request user/get_items_access
For example with the following parameters we will get all items (resources, group, units) which user have access (direct access and exceeded access(fir example via group's access to units)

params":{"userId":19463338,"directAccess":0,"itemSuperclass":"","flags":3} 

You can also to specify "itemSuperclas",  for example "itemSuperclas":"avl_unit"  returns only units.

Diana Cheley
Wialon Hosting Expert
Gurtam
5

API for User and all units associated to that user under user edit

Re: API for User and all units associated to that user under user edit

Hi Diana

Thank you for the help. It worked.

I am able to achieve my descried result with following two APIs. core/search_items - avl_unit and user/get_items_access - avl_unit. Had to use two APIs and play around the response to achieve the functionality.

I am attaching the code snippet in case anyone else need the same.   

wialon.core.Remote.getInstance().remoteCall(                        
                'core/batch',
                {
                    "params":[
                        { 
                            "svc":"core/search_items",
                            "params":{
                                "spec":{
                                    "itemsType":"user",
                                    "propName":"sys_name",
                                    "propValueMask":"*",
                                    "sortType":"sys_name",
                                    "propType":"avl_unit"
                                },
                                "force":1,
                                "flags":1,
                                "from":0,
                                "to":0
                            } 
                        },                 
                        {                    
                            "svc":"core/search_items",
                            "params":{  
                                "spec":{   
                                    "itemsType":"avl_unit",
                                    "propName":"sys_name", 
                                    "propValueMask":"*",
                                    "sortType":"sys_name"
                                },
                                "force":1, 
                                "flags":1439,
                                "from":0,
                                "to":0
                            }
                        },
                        {
                            "svc":"user/get_items_access", 
                            "params":{
                               "userId": user_id,
                               "directAccess":0,
                               "itemSuperclass":"avl_unit",
                               "flags":0
                            }
                         },
                    ],
                    "flags":0
                },
    
                function(callback,response){ 
                    if(callback==0){ 
                        let unit_items = response[1].items; 
                        let user_unit = response[2];
                        var user_unit_data = [];
                        for (var i = 0; i < response[1].items.length; i++) {
                            for (let key in user_unit) {
                                if (response[1].items[i].id == key) {  
                                    user_unit_data.push(response[1].items[i]);
                                } 
                            } 
                        }
                        var html='';
                        for(var i=0;i<response[1]['items'].length;i++){
                              let obj=_.find(user_unit_data,{id:response[1]['items'][i].id});
                              if(obj){
                                html+="<option disabled  value="+response[1]['items'][i].id+">"+response[1]['items'][i].nm+"</option>";
                              }else{
                                html+="<option   value="+response[1]['items'][i].id+">"+response[1]['items'][i].nm+"</option>";
                              }
                        }
                        $("#assign_unit").html(html);
                        spinner.hide();
                    }else{
                        Swal.fire("Operation failed", '', 'error')
                        spinner.hide();
                    }
                }
            )