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