(()=>{function e(){return{restrict:"EA",scope:{acl:"="},templateUrl:":::PLUGIN_PATH:::/aclEditor/aclEditor.html",controller:n}}function n(i,e,t,l,n){var r,c;function o(){i.newPermission=i.newPermission||{},i.newPermission.deviceSearch=null,i.newPermission.device=null,i.newPermission.scopeType=null,i.newPermission.type=null,i.newPermission.permissionType=null}function s(e){return e&&null!==e&&""!==e}o(),l.current().then(function(e){var n=l.hasRole(e,"ROLE_USER_MANAGEMENT_READ"),e=l.hasRole(e,"ROLE_USER_MANAGEMENT_ADMIN");r=n||e,i.allowView=r,c=e,i.allowEdit=c}),i.isValidPermission=function(e){return s(e.device)&&s(e.device.id)&&null!==e.scopeType&&s(e.type)&&null!==e.permissionType},i.add=function(e){var n=e.device.id,e=[e.scopeType.value,e.type,e.permissionType.value].join(":");i.acl[n]||(i.acl[n]=[]),_.includes(i.acl[n],e)||i.acl[n].push(e),o()},i.remove=function(e,n){i.acl[e]=i.acl[e].filter(function(e){return e!==n}),0===i.acl[e].length&&delete i.acl[e]},i.allowView=r,i.allowEdit=c,i.getDevices=function(e){var n={pageSize:20};return e&&(n.text=e),t.list(n).then(function(e){return _.uniqBy(e,"id")})},i.setDevice=function(e){i.newPermission.device=e},i.translatePermissionString=function(e){return e=e.split(":"),[n.getString(e[0]),e[1],n.getString(e[2])].join(":")}}n.$inject=["$scope","$q","c8yInventory","c8yUser","gettextCatalog"],angular.module("c8y.users").directive("c8yAclEditor",e).directive("aclEditor",e)})();