1 /** 2 * @name Groups 3 * @class Shows all of the current users groups/acls 4 * @description Displays the users Group/ACL info and flags which Group/ACL is currently active 5 * @param [showHidden=false] incude hidden groups in the response 6 * @returns 7 [ 8 { 9 name: string; 10 id: number; 11 description: string; 12 hidden: boolean; 13 active: boolean; 14 acls: [ 15 { 16 name: string; 17 id: string; 18 description: string; 19 rootPath: string; 20 active: boolean; 21 triggerworkflow: boolean; 22 } 23 ] 24 } 25 ] 26 * @example /wf/restapi/v2/groups 27 * 28 * Parameters: 29 * 30 Response: 31 [ 32 { 33 "name": "users", 34 "id": 6, 35 "description": "all of the system users", 36 "hidden": false, 37 "active": true, 38 "acls": [ 39 { 40 "name": "Index", 41 "id": "0_6_19C23781-5F8A-459F-A98F-7A83031775D0", 42 "description": "", 43 "rootPath": "", 44 "active": true, 45 "triggerworkflow": true 46 } 47 ] 48 }, 49 { 50 "name": "TwoAcls", 51 "id": 8, 52 "description": "This group has 2 acls", 53 "hidden": false, 54 "active": false, 55 "acls": [ 56 { 57 "name": "The first acl", 58 "id": "0_8_EDDAFC45-6C93-4AC1-B885-091BE211216E", 59 "description": "This is the first acl in the group", 60 "rootPath": "rootFolderPath/test/", 61 "active": false, 62 "triggerworkflow": true 63 }, 64 { 65 "name": "SecondAcl", 66 "id": "0_8_DF42509D-4D23-4206-98F2-19C08DC1C8DF", 67 "description": "this is the second acl", 68 "rootPath": "", 69 "active": false, 70 "triggerworkflow": true 71 } 72 ] 73 } 74 ] 75 */ 76 var REST = library.REST.REST(); 77 (function main() { 78 var aGroups = context.getUser().getGroups(); 79 var aShowHidden = !!context.getParameter("showHidden"); 80 var anOutput = []; 81 for (var i in aGroups) { 82 var aGroup = aGroups[i]; 83 if (aGroup.hidden && !aShowHidden) { 84 continue; 85 } 86 anOutput.push(jsGroup(aGroup)); 87 } 88 return REST.formatResponse(anOutput); 89 })(); 90 91 /** 92 * Builds a js group object 93 * @param theGroup 94 * @returns {{name: *, id: *, description: *, active: boolean, acls: Array}} 95 */ 96 function jsGroup(theGroup) { 97 var aCurrentGroup = context.getGroup(); 98 return { 99 name: theGroup.name, 100 id: theGroup.id, 101 description: theGroup.description, 102 hidden: theGroup.hidden, 103 active: aCurrentGroup.id === theGroup.id, 104 acls: jsAcls(theGroup), 105 }; 106 } 107 108 /** 109 * Builds a JS ACL object 110 * @param theGroup 111 * @returns {Array} 112 */ 113 function jsAcls(theGroup) { 114 var anAcls = []; 115 var anAclObjects = theGroup.getACLs(); 116 var aCurrentAcl = context.getACL(); 117 for (var i in anAclObjects) { 118 var anAcl = anAclObjects[i]; 119 anAcls[anAcls.length] = { 120 name: anAcl.name, 121 id: anAcl.id, 122 description: anAcl.description, 123 rootPath: anAcl.getRootPath(), 124 active: aCurrentAcl.id === anAcl.id, 125 hidden: anAcl.isMasked, 126 triggerworkflow: anAcl.getPermission("triggerWorkflow") === "yes", 127 revokedPermissions: !!anAcl.getRevokedPermissions().join(",") 128 ? anAcl.getRevokedPermissions().join(",").split(",") 129 : [], 130 }; 131 } 132 return anAcls; 133 } 134