graphdb-workbench
Version:
The web application for GraphDB APIs
2 lines • 15.1 kB
JavaScript
export const __webpack_esm_id__=94229;export const __webpack_esm_ids__=[33760,48477,94229];export const __webpack_esm_modules__={33760(e,t,r){r.d(t,{B1:()=>u,DX:()=>i,_5:()=>c,aj:()=>o,n5:()=>s,w0:()=>a,xF:()=>n});const s="SYSTEM",o="READ_REPO",n="READ_REPO_",i="WRITE_REPO",a="GRAPHQL",c="WRITE_REPO_",u="GRAPHQL_"},48477(){angular.module("graphdb.framework.security.directives",[]).directive("customPrefixTagsInput",function(){return{restrict:"A",link:function(e,t,r){const s=[];function o(e){return e.startsWith("CUSTOM_")||e.startsWith("!CUSTOM_")}const n="tags-input"===t[0].nodeName.toLowerCase();if(n&&r.ngModel){const i=t.controller("ngModel");n&&(i.$parsers.push(function(e){return Array.isArray(e)&&(i.$warning=e.some(e=>o(e))),e}),s.push(e.$watch(r.ngModel,function(e){Array.isArray(e)&&(i.$warning=e.some(e=>o(e)))},!0)))}s.push(e.$on("$destroy",()=>{s.forEach(e=>e())}))}}})},94229(e,t,r){r(82493),r(98599),r(2243);var s=r(92900),o=(r(48477),r(33760)),n=r(57154);const i=angular.module("graphdb.framework.security.controllers",["ngCookies","ui.bootstrap","graphdb.framework.core.services.jwtauth","graphdb.framework.core.services.security-service","toastr","ngTagsInput"]);i.controller("UsersCtrl",["$scope","$uibModal","toastr","$window","$jwtAuth","$timeout","ModalService","SecurityService","$translate",function(e,t,r,s,i,a,c,u,d){const p=(0,n.service)(n.AuthorizationService),l=(0,n.service)(n.AuthenticationService),h=(0,n.service)(n.SecurityService),E=(0,n.service)(n.OntoToastrService),A=(0,n.service)(n.UsersService),g=(0,n.service)(n.RepositoryService);e.usersData=[],e.loader=!0,e.securityEnabled=function(){return l.isSecurityEnabled()},e.hasExternalAuth=function(){return i.hasExternalAuth()},e.getAuthImplementation=function(){return i.getAuthImplementation()},e.freeAccessEnabled=function(){return p.hasFreeAccess()},e.getUsers=()=>A.getUsers().then(function(t){e.usersData=t.map(e=>({username:e.username,dateCreated:e.dateCreated,userType:e.getUserType(),userTypeDescription:e.getUserTypeDescription(),repositories:e.authorities.getRepositoriesPermissions(),customRoles:e.authorities.getCustomRoles()})),e.loader=!1}).catch(function(t){const s=getError(t);r.error(s,d.instant("common.error")),e.loader=!1}),e.getUsers(),e.$on("repositoryIsSet",function(){e.getUsers()}),e.toggleSecurity=function(){const e=l.isSecurityEnabled();i.toggleSecurity(!e).then(()=>{s.location.reload()})};const f=function(e,t){return h.setFreeAccess(e,t)};e.toggleFreeAccess=function(e){!p.hasFreeAccess()||p.hasFreeAccess()&&e?h.getFreeAccess().then(t=>{const r=(0,n.mapGrantedAuthoritiesResponseToModel)(t.authorities).getItems(),s=t.appSettings??{DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0};return m(s,r,e)}).then(t=>f(e||!i.isFreeAccessEnabled(),t)).then(()=>{const t=e?"jwt.auth.free.access.updated.msg":"jwt.auth.free.access.status";E.success(d.instant(t,{status:d.instant("enabled.status")}))}).catch(e=>{"cancel"!==e&&E.error(e.data??e,d.instant("common.error"))}):f(!p.hasFreeAccess()).then(()=>{E.success(d.instant("jwt.auth.free.access.status",{status:d.instant("disabled.status")}))}).catch(e=>{E.error(e.data,d.instant("common.error"))})};const m=(r,s,i)=>t.open({templateUrl:"js/angular/security/templates/modal/default-authorities.html",controller:"DefaultAuthoritiesCtrl",resolve:{data:function(){return{defaultAuthorities:function(){const t={[o.aj]:{},[o.DX]:{},[o.w0]:{}},r=_.mapKeys(e.getRepositories(),function(e){return g.getLocationSpecificId(e)});return _.each(s,function(e){0===e.indexOf(o._5)?r.hasOwnProperty(e.substr(11))&&(t[o.DX][e.substr(11)]=!0):0===e.indexOf(o.xF)?r.hasOwnProperty(e.substr(10))&&(t[o.aj][e.substr(10)]=!0):0===e.indexOf(o.B1)&&r.hasOwnProperty(e.substr(8))&&(t[o.w0][e.substr(8)]=!0)}),t},appSettings:r}}}}).result.then(function(e){return s=e.authorities,r=e.appSettings,(0,n.mapAuthSettingsResponseToModel)({enabled:i||!p.hasFreeAccess(),appSettings:r,authorities:s})});e.editFreeAccess=function(){e.toggleFreeAccess(!0)},e.removeUser=function(t){c.openSimpleModal({title:d.instant("common.confirm.delete"),message:d.instant("security.confirm.delete.user",{name:t}),warning:!0}).result.then(function(){e.loader=!0,A.deleteUser(t).then(()=>e.getUsers()).catch(t=>{const s=getError(t);r.error(s,d.instant("common.error")),e.loader=!1})})},e.encodeURIComponent=function(e){return encodeURIComponent(e)}}]),i.controller("DefaultAuthoritiesCtrl",["$scope","$http","$uibModalInstance","data","$rootScope",function(e,t,r,s,i){const a=(0,n.service)(n.RepositoryService);e.grantedAuthorities=s.defaultAuthorities(),e.appSettings=s.appSettings,e.hasActiveLocation=function(){return!_.isEmpty(i.globalLocation)},e.getRepositories=function(){return i.globalRepositories},e.ok=function(){const t=[];e.repositoryCheckError=!0;for(const r in e.grantedAuthorities.WRITE_REPO)e.grantedAuthorities.WRITE_REPO[r]&&(t.push(o._5+r),t.push(o.xF+r),e.repositoryCheckError=!1);for(const r in e.grantedAuthorities.READ_REPO)e.grantedAuthorities.READ_REPO[r]&&-1===t.indexOf(o.xF+r)&&(t.push(o.xF+r),e.repositoryCheckError=!1);for(const r in e.grantedAuthorities.GRAPHQL)e.grantedAuthorities.GRAPHQL[r]&&-1===t.indexOf(o.B1+r)&&t.push(o.B1+r);e.repositoryCheckError||r.close({authorities:t,appSettings:e.appSettings})},e.cancel=function(){r.dismiss("cancel")},e.createUniqueKey=function(e){return a.getLocationSpecificId(e)}}]),i.controller("CommonUserCtrl",["$rootScope","$scope","$http","toastr","$window","$timeout","$location","$jwtAuth","$translate","passwordPlaceholder",function(e,t,r,i,a,c,u,d,p,l){const h=(0,n.service)(n.AuthorizationService),E=(0,n.service)(n.RepositoryService);e.$on("$translateChangeSuccess",function(){t.passwordPlaceholder=p.instant(l)}),t.isAdmin=function(){return h.hasRole(s.gG.ROLE_ADMIN)},t.hasExternalAuth=function(){return d.hasExternalAuth()},t.hasEditRestrictions=function(){return t.user&&t.user.username===s.ut.ADMIN},t.isOverrideAuth=function(){return d.isDefaultAuthEnabled()},t.setGrantedAuthorities=function(){function e(...e){for(let r=0;r<e.length;r++){const s=e[r];_.indexOf(t.user.grantedAuthorities,s)<0&&t.user.grantedAuthorities.push(s)}}if(t.user.grantedAuthorities=[],t.repositoryCheckError=!0,t.userType===s.ut.ADMIN)t.repositoryCheckError=!1,e(s.gG.ROLE_ADMIN);else if(t.userType===s.ut.REPO_MANAGER)t.repositoryCheckError=!1,e(s.gG.ROLE_REPO_MANAGER);else{e(s.gG.ROLE_USER);for(const r in t.grantedAuthorities.WRITE_REPO)t.grantedAuthorities.WRITE_REPO[r]&&(t.repositoryCheckError=!1,e(o._5+r,o.xF+r));for(const r in t.grantedAuthorities.READ_REPO)t.grantedAuthorities.READ_REPO[r]&&(t.repositoryCheckError=!1,e(o.xF+r));for(const r in t.grantedAuthorities.GRAPHQL)t.grantedAuthorities.GRAPHQL[r]&&e(o.B1+r)}t.customRoles&&t.customRoles.forEach(t=>e("CUSTOM_"+t))},t.$watch("userType",function(){t.isUser()||(t.customRoles="")}),t.isUser=function(){return t.userType===s.ut.USER},t.hasReadPermission=function(e){const r=E.getLocationSpecificId(e);return t.userType===s.ut.ADMIN||t.userType===s.ut.REPO_MANAGER||e.id!==o.n5&&(t.grantedAuthorities.READ_REPO["*"]||t.grantedAuthorities.WRITE_REPO["*"])||t.grantedAuthorities.READ_REPO[r]||t.grantedAuthorities.WRITE_REPO[r]},t.hasWritePermission=function(e){const r=E.getLocationSpecificId(e);return t.userType===s.ut.ADMIN||t.userType===s.ut.REPO_MANAGER||e.id!==o.n5&&t.grantedAuthorities.WRITE_REPO["*"]||t.grantedAuthorities.WRITE_REPO[r]},t.hasGraphqlPermission=function(e){const r=E.getLocationSpecificId(e);return e.id!==o.n5&&t.grantedAuthorities.GRAPHQL["*"]||t.grantedAuthorities.GRAPHQL[r]},t.readCheckDisabled=function(e){return t.hasWritePermission(e)||e.id!==o.n5&&"*"!==e&&t.grantedAuthorities.READ_REPO["*"]||t.hasEditRestrictions()},t.writeCheckDisabled=function(e){return t.userType===s.ut.ADMIN||t.userType===s.ut.REPO_MANAGER||e.id!==o.n5&&"*"!==e&&t.grantedAuthorities.WRITE_REPO["*"]||t.hasEditRestrictions()},t.graphqlCheckDisabled=function(e){if(t.userType===s.ut.ADMIN||t.userType===s.ut.REPO_MANAGER)return!0;if(t.hasEditRestrictions())return!0;if("*"!==e&&t.grantedAuthorities.GRAPHQL["*"])return!0;if("*"===e&&t.grantedAuthorities.GRAPHQL["*"])return!1;let r;r=null!==e&&"object"==typeof e?E.getLocationSpecificId(e):e;const o=t.grantedAuthorities.READ_REPO["*"],n=t.grantedAuthorities.WRITE_REPO["*"],i=t.grantedAuthorities.READ_REPO[r],a=t.grantedAuthorities.WRITE_REPO[r];return!(o||n||i||a)},t.createUniqueKey=function(e){return E.getLocationSpecificId(e)},t.userType=s.ut.USER,t.grantedAuthorities={[o.aj]:{},[o.DX]:{},[o.w0]:{}},t.validatePassword=function(){return t.noPassword?(t.passwordError="",t.confirmPasswordError="",!0):t.user.password!==t.user.confirmpassword?(t.user.password?(t.passwordError="",t.confirmPasswordError=p.instant("security.confirm.password")):(t.passwordError=p.instant("security.enter.password"),t.confirmPasswordError=""),!1):(t.passwordError="",t.confirmPasswordError="",!0)},t.isLocalAuthentication=function(){return"Local"===d.getAuthImplementation()},t.updateUser=function(){if(!t.validateForm())return!1;t.isLocalAuthentication()&&t.setGrantedAuthorities(),t.repositoryCheckError||t.updateUserHttp()},t.setNoPassword=function(){t.noPassword&&(t.user.password="",t.user.confirmpassword="",t.passwordError="",t.confirmPasswordError="")},t.shouldDisableSameAs=function(){const e=$("#sameAsCheck");return t.user&&!t.user.appSettings.DEFAULT_INFERENCE&&e.prop("checked")&&(e.prop("checked",!1),t.user.appSettings.DEFAULT_SAMEAS=!1),t.user&&!t.user.appSettings.DEFAULT_INFERENCE},t.isRoleValid=!0,t.addCustomRole=function(e){return t.isRoleValid=!0,e.text=e.text.toUpperCase(),e},t.isCustomRoleValid=function(e){return t.isRoleValid=e.text.length>=2,t.isRoleValid},t.checkUserInput=function(e){8!==e.keyCode&&46!==e.keyCode||(t.isRoleValid=!0)},t.removeErrorOnCut=function(){t.isRoleValid=!0}}]),i.controller("AddUserCtrl",["$scope","$http","toastr","$window","$timeout","$location","$jwtAuth","$controller","SecurityService","ModalService","$translate",function(e,t,r,o,i,a,c,u,d,p,l){angular.extend(this,u("CommonUserCtrl",{$scope:e,passwordPlaceholder:"security.password.placeholder"}));const h=(0,n.service)(n.UsersService);e.mode="add",e.saveButtonText=l.instant("common.create.btn"),e.goBack=function(){const t=i(function(){o.history.back()},100);e.$on("$destroy",function(){i.cancel(t)})},e.pageTitle=l.instant("view.create.user.title"),e.passwordPlaceholder=l.instant("security.password.placeholder"),e.user={username:"",password:"",confirmpassword:"",grantedAuthorities:[],appSettings:{DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0}},e.submit=function(){e.noPassword&&e.userType===s.ut.ADMIN?p.openSimpleModal({title:l.instant("security.create.admin"),message:l.instant("security.admin.login.warning"),warning:!0}).result.then(function(){e.createUser()}):e.createUser()},e.createUserHttp=function(){e.loader=!0;const t=new n.User({username:e.user.username,password:e.user.password,appSettings:new n.AppSettings(e.user.appSettings),authorities:new n.AuthorityList(e.user.grantedAuthorities)});h.createUser(t).then(()=>{r.success(l.instant("security.user.created",{name:e.user.username}));const t=i(function(){e.loader=!1,a.path("/users")},2e3);e.$on("$destroy",function(){i.cancel(t)})}).catch(async t=>{e.loader=!1,r.error(getError(t),l.instant("common.error"))})},e.createUser=function(){e.validateForm()&&(e.setGrantedAuthorities(),e.repositoryCheckError||e.createUserHttp())},e.validateForm=function(){let t=!0;return e.user.username?e.usernameError="":(e.usernameError=l.instant("security.enter.username"),t=!1),e.noPassword?(e.passwordError="",e.confirmPasswordError=""):(e.user.password?e.passwordError="":(e.passwordError=l.instant("security.enter.password"),t=!1),e.user.confirmpassword&&e.user.password===e.user.confirmpassword?e.confirmPasswordError="":(e.confirmPasswordError=l.instant("security.confirm.password"),t=!1)),t}}]),i.controller("EditUserCtrl",["$scope","$http","toastr","$window","$routeParams","$timeout","$location","$jwtAuth","$controller","SecurityService","ModalService","$translate",function(e,t,r,o,i,a,c,u,d,p,l,h){angular.extend(this,d("CommonUserCtrl",{$scope:e,passwordPlaceholder:"security.new.password"}));const E=(0,n.service)(n.UsersService),A=(0,n.service)(n.AuthorizationService),g=(0,n.service)(n.SecurityContextService);e.mode="edit",e.saveButtonText=h.instant("common.save.btn"),e.goBack=function(){const t=a(function(){o.history.back()},100);e.$on("$destroy",function(){a.cancel(t)})},e.params=i,e.pageTitle=h.instant("view.edit.user.title",{userId:e.params.userId}),e.passwordPlaceholder=h.instant("security.new.password"),e.userType=s.ut.USER;const f={DEFAULT_SAMEAS:!0,DEFAULT_INFERENCE:!0,EXECUTE_COUNT:!0,IGNORE_SHARED_QUERIES:!1,DEFAULT_VIS_GRAPH_SCHEMA:!0};A.hasRole(s.gG.ROLE_ADMIN)||c.url("settings"),e.getUserData=function(){E.getUser(e.params.userId).then(function(t){e.user={username:t.username},e.user.password="",e.user.confirmpassword="",e.user.external=t.external,e.user.appSettings=t.appSettings||f,e.userType=t.getUserType(),e.grantedAuthorities=t.authorities.toUIModel(),e.customRoles=t.authorities.getCustomRoles()}).catch(function(e){const t=getError(e);r.error(t,h.instant("common.error"))})},e.getUserData(),e.submit=function(){e.noPassword&&e.userType===s.ut.ADMIN?l.openSimpleModal({title:h.instant("security.save.admin.settings"),message:h.instant("security.admin.pass.unset"),warning:!0}).result.then(function(){e.updateUser()}):e.updateUser()},e.updateUserHttp=function(){e.loader=!0;const t=new n.User({username:e.user.username,password:e.noPassword?"":e.user.password||void 0,appSettings:new n.AppSettings(e.user.appSettings),authorities:new n.AuthorityList(e.user.grantedAuthorities)});E.updateUser(t).then(()=>{r.success(h.instant("security.user.updated",{name:e.user.username}));const t=a(function(){e.loader=!1,o.history.back()},2e3);e.$on("$destroy",function(){a.cancel(t)});const s=g.getAuthenticatedUser();e.user.username===s.username&&s.setAppSettings(new n.AppSettings(e.user.appSettings))}).catch(t=>{const s=getError(t);e.loader=!1,r.error(s,h.instant("common.error"))})},e.validateForm=function(){return e.validatePassword()}}]),i.controller("RolesMappingController",["$scope","toastr","SecurityService","$translate",function(e,t,r,s){e.debugMapping=function(e,t){const s=t.split(":");r.getRolesMapping({role:e,method:s[1],mapping:s[0]})},e.$on("repositoryIsSet",function(){r.getRoles().success(function(t){e.roleMappings=t,e.roles=_.keys(e.roleMappings),e.mappings=_.keys(e.roleMappings[e.roles[0]]);const r=_.map(e.roles,function(t){return[t,_.filter(e.roleMappings[t]).length]});e.roles=_.reverse(_.map(_.orderBy(r,function(e){return e[1]}),function(e){return e[0]}))}).error(function(r){const o=getError(r);e.loader=!1,t.error(o,s.instant("common.error"))})})}]),i.controller("DeleteUserCtrl",["$scope","$uibModalInstance","username",function(e,t,r){e.username=r,e.ok=function(){t.close()},e.cancel=function(){t.dismiss("cancel")}}])}};
//# sourceMappingURL=94229.47dbdba202106c61dff1.bundle.js.map