SUSI.AI has an admin panel where users with roles operator or above get an overview of various stats and manage other users and skills. The admin panel allows the system admins to get a list of all users registered on susi and also provide an option to change their user roles as well. The admin tab provides us with the statistics of its users. In this post we will discuss how this is implemented on susi server.
SUSI.AI server has an API called getUsers.java which can be accessed at endpoint
This API has a total of 5 parameters out of which minimum two are needed to make a successful call to the API
- access_token (required)
- Atleast one from the following parameters
To fetch user statistics from the server we need to pass the access token and the boolean parameter getUserStats. The following call is requested from the server
When this call is made the API first verifies the user role of the user from the access token to check whether the role is operator or above. It the user fails this verification they recieve an Error : 401 stating that this user role is not sufficient. On the other hand if they are positively verified then they receive users stats in form of a json object.
working of getUsers.java
The data about user registered to susi with their roles is stored in the authorisation.json file on the server so the first step is to fetch data from authorization.json and translate it into an array of string with each value is the id of the user which is done by the following codeblock
Once we have the array of IDs of users we can get the total user count by the size of keysArray. To calculate users with different roles we need to iterate the array and find their respective roles and then keep a count for each role. To find user role for a particular id, we use the DAO.getAuthorization(identity) method. This method returns an object with the authorization data of the identity which is passed to the function. To get its corresponding user role we define a variable userRole of data type UserRole and its value is fetched from authorization.getUserRole(). For their activation status we need their credentials using
Then we use these credentials to access their authentication object which is stored in the authentication.json file on the server. This authentication object has a boolean type key named activated which stores the activation status of the user. This is used to count users based on activation status. This along with roles status is send as the response as shown above.
- Java servlets – https://en.wikipedia.org/wiki/Java_servlet
- APIs – https://en.wikipedia.org/wiki/Application_programming_interface
- Classes and objects – https://www.geeksforgeeks.org/classes-objects-java/
- getUsers – https://github.com/fossasia/susi_server/blob/6d6be528da7f3aa3859c99e272a64dd5a8e01400/src/ai/susi/server/api/aaa/GetUsers.java