1 var REST = library.REST.REST();
  2 
  3 /**
  4  * Gets the searches for the current user.
  5  */
  6 function getSavedSearches() {
  7   var aSearches = searchManager.getSavedSearchesForUser(context.getUser());
  8   for (var i in aSearches) {
  9     var aSearch = aSearches[i];
 10     var aSearchName = aSearch.name;
 11     if (isAdminSearch(aSearchName) && !isAdmin(context.getUser()))
 12     {
 13     	continue;
 14     }
 15     var aJSON = {
 16       id: aSearch.id,
 17       name: aSearchName,
 18       description: aSearch.description,
 19       type: aSearch.type,
 20       owner: aSearch.owner,
 21     };
 22     REST.push(null, aJSON, true);
 23   }
 24 }
 25 
 26 /**
 27  * Does the given user have the admin rights?
 28  */
 29 function isAdmin(theUser)
 30 {
 31 	var aType = theUser.getType();
 32 	return "Global Administrator" === aType || "Group Administrator" === aType;
 33 }
 34 
 35 /**
 36  * Is admin search?
 37  */
 38 function isAdminSearch(theSearchName)
 39 {
 40 	return theSearchName.indexOf("Admin - ") === 0;
 41 }
 42 
 43 /**
 44  * @name SavedSearches
 45  * @class Shows the saved searches available to the current user.
 46  * @description Displays the saved searches available to the current user.
 47  * Searches can be executed by running the Search endpoint with the saved searches id.
 48  * @param [FILTERS] Filtering can be applied to the "id", "name", "description", "type", "shared"
 49  * @returns [{SearchData}, ... ]
 50  * @example /wf/restapi/v2/savedSearches
 51  *
 52  * Parameters:
 53  *
 54  Response:
 55  [
 56 	 {
 57 	    "id": 1,
 58 	    "name": "Test Saved Search",
 59 	    "description": "Saved Search description",
 60 	    "type": "advancedSearch",
 61 	    "creator": "root",
 62 	    "shared": false
 63 	  },
 64 	 {
 65 	    "id": 5,
 66 	    "name": "Test Keywords search",
 67 	    "description": "",
 68 	    "type": "keywordSearch",
 69 	    "creator": "root",
 70 	    "shared": true
 71 	  }
 72  ]
 73  */
 74 function main() {
 75   REST.setCallback(getSavedSearches);
 76   return REST.execute();
 77 }
 78 
 79 main();
 80