UNPKG

harperdb

Version:

HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.

1 lines 6.09 kB
"use strict";(self.webpackChunkharperdb_studio=self.webpackChunkharperdb_studio||[]).push([[154],{2729:(e,s,r)=>{r.r(s),r.d(s,{default:()=>$});var a=r(9950),t=r(625),l=r(4084),n=r(8156),o=r(7176),c=r(6114),u=r(3452),i=r(5488),d=r(6713),m=r(7348),h=r(9435),x=r(127);const p=async e=>{let{auth:s,url:r,username:a,password:t,role:l}=e;return(0,x.A)({operation:{operation:"alter_user",role:l,username:a,password:t,active:!0},auth:s,url:r})};var A=r(5269),j=r(3150),g=r(3628),w=r(8222),b=r(4414);const y=function(){const{username:e}=(0,t.g)(),[s,r]=(0,a.useState)({}),[l,n]=(0,a.useState)({}),x=(0,m.MW)(),y=(0,d.O$)(A.A,(e=>e.auth)),f=(0,d.O$)(A.A,(e=>e.url));return(0,b.jsx)(h.tH,{onError:(e,s)=>(0,g.A)({error:{message:e.message,componentStack:s}}),FallbackComponent:j.A,children:(0,b.jsxs)(o.A,{children:[(0,b.jsxs)(c.A,{xs:"4",className:"py-1",children:["Change user password",(0,b.jsx)("br",{}),(0,b.jsx)("span",{className:"text-small",children:"Modify user's access credentials"})]}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(i.A,{id:"password",type:"text",className:"text-center",name:"password",placeholder:"enter new password",value:l.password||"",onChange:e=>n({...l,password:e.target.value})})}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(u.A,{block:!0,color:"success",onClick:async()=>{const{password:s}=l;if(s){r({submitted:!0});const a=await p({auth:y,url:f,username:e,password:s});n({}),-1!==a.message.indexOf("updated")?(x.success("password updated"),(0,w.A)({auth:y,url:f}),r({})):(x.error(a.message),r({}))}else r({error:"password is required"})},disabled:s.submitted||!l.password,children:"Update Password"})})]})})};var f=r(6359),v=r(9163),C=r.n(v);const k=function(){const{username:e}=(0,t.g)(),[s,r]=(0,a.useState)({}),[l,n]=(0,a.useState)({}),i=(0,m.MW)(),x=(0,d.O$)(A.A,(e=>e.auth)),y=(0,d.O$)(A.A,(e=>e.url)),v=(0,d.O$)(A.A,(e=>{var s;return parseFloat(null===(s=e.registration)||void 0===s?void 0:s.version)<3})),k=(0,d.O$)(A.A,(e=>e.roles.map((e=>({label:e.role,value:v?e.id:e.role}))))),N=(0,d.O$)(A.A,(s=>s.users&&s.users.find((s=>s.username===e))));return C()((()=>{var e;return n({...l,newRole:null===N||void 0===N||null===(e=N.role)||void 0===e?void 0:e.id})}),[]),(0,b.jsx)(h.tH,{onError:(e,s)=>(0,g.A)({error:{message:e.message,componentStack:s}}),FallbackComponent:j.A,children:(0,b.jsxs)(o.A,{children:[(0,b.jsxs)(c.A,{xs:"4",className:"py-1",children:["Change user role",(0,b.jsx)("br",{}),(0,b.jsx)("span",{className:"text-small",children:"Change what this user can do"})]}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(f.Ay,{className:"react-select-container",classNamePrefix:"react-select",onChange:e=>{let{value:s}=e;return n({...l,newRole:s})},options:k.filter((e=>e.value!==N.role.id)),value:k.find((e=>e.value===l.newRole)),isSearchable:!1,isClearable:!1,isLoading:!k,placeholder:"select a role",styles:{placeholder:e=>({...e,textAlign:"center",width:"100%",color:"#BCBCBC"})}})}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(u.A,{id:"updateRole",block:!0,color:"success",onClick:async()=>{const{newRole:s}=l;if(s)if(N.role.id===s)r({error:"user already has this role"});else{r({submitted:!0});const a=await p({auth:x,url:y,username:e,role:s});-1!==a.message.indexOf("updated")?(i.success("user role updated"),(0,w.A)({auth:x,url:y}),r({})):(i.error(a.message),r({}))}else r({error:"role is required"})},disabled:l.newRole===N.role.id||"submitted"===s,children:"Update Role"})})]})})};var N=r(2034);const O=function(){const{username:e}=(0,t.g)(),{pathname:s}=(0,t.zy)(),r=(0,t.Zp)(),[l,n]=(0,a.useState)({}),[x,p]=(0,a.useState)({}),y=(0,m.MW)(),f=(0,d.O$)(A.A,(e=>e.auth)),v=(0,d.O$)(A.A,(e=>e.url));return(0,b.jsx)(h.tH,{onError:(e,s)=>(0,g.A)({error:{message:e.message,componentStack:s}}),FallbackComponent:j.A,children:(0,b.jsxs)(o.A,{children:[(0,b.jsxs)(c.A,{xs:"4",className:"py-1",children:["Delete User",(0,b.jsx)("br",{}),(0,b.jsx)("span",{className:"text-small",children:"user will be removed from this instance"})]}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(i.A,{id:"delete_username",onChange:e=>n({delete_username:e.target.value}),type:"text",className:"text-center",title:"confirm username to delete",placeholder:`Enter "${e}" here to enable deletion.`,value:l.delete_username||""})}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(u.A,{id:"deleteUser",block:!0,color:"success",onClick:async()=>{if(l.delete_username!==e)y.error("Please type the username to delete this user");else{p({submitted:!0});const a=await(0,N.A)({auth:f,username:e,url:v});-1!==a.message.indexOf("successfully")?(y.success(a.message),(0,w.A)({auth:f,url:v}),p({}),setTimeout((()=>r(s.replace(`/users/${e}`,"/users"))),0)):(y.error(a.message),p({}))}},disabled:e!==l.delete_username||x.submitted,children:x.submitted?(0,b.jsx)("i",{className:"fa fa-spinner fa-spin text-white"}):(0,b.jsx)("span",{children:"Delete User"})})})]})})};const $=function(){const{username:e}=(0,t.g)(),{pathname:s}=(0,t.zy)(),r=(0,t.Zp)();return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"floating-card-header",children:["existing users > edit > ",(0,b.jsx)("b",{children:e})]}),(0,b.jsx)(l.A,{className:"my-3",children:(0,b.jsxs)(n.A,{children:[(0,b.jsx)(y,{}),(0,b.jsx)("hr",{className:"my-3"}),(0,b.jsx)(k,{}),(0,b.jsx)("hr",{className:"my-3"}),(0,b.jsx)(O,{}),(0,b.jsx)("hr",{className:"my-3"}),(0,b.jsxs)(o.A,{children:[(0,b.jsx)(c.A,{xs:"8",className:"py-1"}),(0,b.jsx)(c.A,{xs:"4",children:(0,b.jsx)(u.A,{id:"returnToUserList",block:!0,color:"grey",onClick:()=>r(s.replace(`/${e}`,"")),children:"Return to User List"})})]})]})})]})}},2034:(e,s,r)=>{r.d(s,{A:()=>t});var a=r(127);const t=async e=>{let{auth:s,username:r,url:t}=e;return(0,a.A)({operation:{operation:"drop_user",username:r},auth:s,url:t})}},8222:(e,s,r)=>{r.d(s,{A:()=>l});var a=r(127),t=r(5269);const l=async e=>{let{auth:s,url:r,signal:l}=e;const n=await(0,a.A)({operation:{operation:"list_users"},auth:s,url:r,signal:l}),o=Array.isArray(n)?[...n].map((e=>({username:e.username,role:e.role.role}))).sort(((e,s)=>e.username.toLowerCase()>s.username.toLowerCase()?1:-1)):[];return t.A.update((e=>{e.users=o})),o}}}]);