Adding GetReportedSkill API on SUSI.AI Server

The GetReportedSkill API was implemented for Admins to view the reported feedback given by users, admin can then monitor skills, which are working fine and in which users are having problems. This can help in deleting buggy/erroneous skills directly from the reported skills tab in the admin panel.

The endpoint is of GET type, and accept 2 parameters: 

  • access_token(compulsory): It is the access token of the logged-in user. It is of a string data type.
  • search: It is a string param that helps us to fetch a list of feedback related to the search term

The minimal role is set to OPERATOR as Admin section access is required for reported skill list.

API Development

Here is a sample response from api:

{
  “session”: {“identity”: {
    “type”: “host”,
    “name”: “0:0:0:0:0:0:0:1_d9aaded8”,
    “anonymous”: true
  }},
  “accepted”: true,
  “list”: [
    {
      “feedback”: “test”,
      “skill_name”: “GSOC”,
      “email”: “shubhamsuperpro@gmail.com”,
      “timestamp”: “2019-06-15 03:25:29.425”
    },
    {
      “feedback”: “test101”,
      “skill_name”: “GSOC”,
      “email”: “shubham@gmail.com”,
      “timestamp”: “2019-06-15 12:18:33.641”
    }
  ],
  “message”: “Success: Fetched all Reported Skills”
}

The reported skills are stored in DAO under reportedSkills, for fetching the list we need to traverse it’s JSONObject.

JsonTray reportedSkills = DAO.reportedSkills;
JSONObject reportedSkillsListObj = reportedSkills.toJSON();

api/cms/GetReportSkillService.java

Code

For creating a list we need to access each property of JSONObject of reportedSkill, in the following order:

Model → Group → Language → Skill Name → Reported feedback list

for (String key:JSONObject.getNames(reportedSkillsListObj)) {
  modelName = reportedSkillsListObj.getJSONObject(key);
      if (reportedSkillsListObj.has(key)) {
        for (String group_name : JSONObject.getNames(modelName)) {
          groupName = modelName.getJSONObject(group_name);
          if (modelName.has(group_name)) {
            for (String language_name : JSONObject.getNames(groupName)) {
              languageName = groupName.getJSONObject(language_name);
              if (groupName.has(language_name)) {

api/cms/GetReportSkillService.java

If search parameter is passed, check if skillName matches with search parameter, if both strings are equal, create a new reportedObject and append it to reportList, which is a list of reported skills

if (call.get("search", null) != null) {
  String skill_name = call.get("search", null);
    if (languageName.has(skill_name)) {
      skillName = languageName.getJSONObject(skill_name);
      reports = skillName.getJSONArray("reports");
      for (int i = 0; i < reports.length(); i++) {
        JSONObject reportObject = new JSONObject();
        reportObject = reports.getJSONObject(i);
        reportObject.put("skill_name", skill_name);
        reportList.add(reportObject);

api/cms/GetReportSkillService.java

If search parameter is not passed, traversed all reported skills and append it to array(reportList).

getNames returns an array of keys as string stored in JSONObject, we traverse the array and put all the reported skill name, feedback, email and timestamp in reportObject and add it to reportList

} else {
   for (String skill_name : JSONObject.getNames(languageName)) {
      skillName = languageName.getJSONObject(skill_name);
      if (languageName.has(skill_name)) {
        reports = skillName.getJSONArray("reports");
           for (int i = 0; i < reports.length(); i++) {
             JSONObject reportObject = new JSONObject();
   reportObject = reports.getJSONObject(i);
   reportObject.put("skill_name", skill_name);    reportList.add(reportObject);
                 }
            }
       }
  }

api/cms/GetReportSkillService.java

Once we have the list of reported skills reportList return the service response

try {
   result.put("list", reportList);
   result.put("accepted", true);
   result.put("message", "Success: Fetched all Reported  Skills");
   return new ServiceResponse(result);
  } catch (Exception e) {
       throw new APIException(500, "Failed to fetch the requested list!");}

api/cms/GetReportSkillService.java

To conclude, the Admin’s now can take decisions based on reports submitted by the user to delete a skill or ignore the feedback.

Link to PR: https://github.com/fossasia/susi_server/pull/1274

Resources

Tags

SUSI.AI, FOSSASIA, GSoC`19, API Development, SUSI Server, SUSI Skills

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.