"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2721],{52657:(e,s,a)=>{a.r(s),a.d(s,{default:()=>v});var t,r,i,n=a(36636),l=a(68404),o=a(18745),d=a(42147),c=a(90923),h=a(69783),u=a(33801),m=a(98163),g=a(8674),x=a(66728),j=a(58170),b=a(50641),p=a(45916);function v(e){let{match:s}=e;const a=(0,o.useSelector)((e=>e.navIndex)),v=(0,g.h)(a,"global-orgs"),f=parseInt(s.params.id,10),I=m.Vt.hasPermission(j.bW.OrgsWrite),N=m.Vt.hasPermission(j.bW.OrgUsersRead),[w,y]=(0,l.useState)([]),[R,C]=(0,d.Z)((()=>(async e=>await(0,c.getBackendSrv)().get("/api/orgs/"+e))(f)),[]),[,O]=(0,d.Z)((()=>(async e=>m.Vt.hasPermission(j.bW.OrgUsersRead)?await(0,c.getBackendSrv)().get(`/api/orgs/${e}/users`,(0,x.y)()):[])(f)),[]);(0,l.useEffect)((()=>{C(),O().then((e=>y(e)))}),[C,O]);return(0,p.jsx)(u.Z,{navModel:v,children:(0,p.jsx)(u.Z.Contents,{children:(0,p.jsxs)(p.Fragment,{children:[r||(r=(0,p.jsx)(h.Legend,{children:"Edit organization"})),R.value&&(0,p.jsx)(h.Form,{defaultValues:{orgName:R.value.name},onSubmit:async e=>await(async e=>await(0,c.getBackendSrv)().put("/api/orgs/"+f,Object.assign({},R.value,{name:e})))(e.orgName),children:e=>{let{register:s,errors:a}=e;return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(h.Field,{label:"Name",invalid:!!a.orgName,error:"Name is required",disabled:!I,children:(0,p.jsx)(h.Input,Object.assign({},s("orgName",{required:!0}),{id:"org-name-input"}))}),(0,p.jsx)(h.Button,{type:"submit",disabled:!I,children:"Update"})]})}}),(0,p.jsxs)("div",{className:n.css`
              margin-top: 20px;
            `,children:[i||(i=(0,p.jsx)(h.Legend,{children:"Organization users"})),!N&&(t||(t=(0,p.jsx)(h.Alert,{severity:"info",title:"Access denied",children:"You do not have permission to see users in this organization. To update this organization, contact your server administrator."}))),N&&!!w.length&&(0,p.jsx)(b.Z,{users:w,orgId:f,onRoleChange:(e,s)=>{(async(e,s)=>{await(0,c.getBackendSrv)().patch("/api/orgs/"+s+"/users/"+e.userId,e)})(Object.assign({},s,{role:e}),f),y(w.map((a=>s.userId===a.userId?Object.assign({},s,{role:e}):a))),O()},onRemoveUser:e=>{(async(e,s)=>{await(0,c.getBackendSrv)().delete("/api/orgs/"+s+"/users/"+e.userId)})(e,f),y(w.filter((s=>e.userId!==s.userId))),O()}})]})]})})})}},50641:(e,s,a)=>{a.d(s,{Z:()=>b});var t,r,i,n,l,o,d=a(68404),c=a(69783),h=a(57497),u=a(77058),m=a(98163),g=a(58170),x=a(8936),j=a(45916);const b=e=>{const{users:s,orgId:a,onRoleChange:b,onRemoveUser:p}=e,[v,f]=(0,d.useState)(null),[I,N]=(0,d.useState)([]),[w,y]=(0,d.useState)({});return(0,d.useEffect)((()=>{m.Vt.licensedAccessControlEnabled()&&async function(){try{if(m.Vt.hasPermission(g.bW.ActionRolesList)){let e=await(0,u.ul)(a);N(e)}if(m.Vt.accessControlBuiltInRoleAssignmentEnabled()&&m.Vt.hasPermission(g.bW.ActionBuiltinRolesList)){const e=await(0,u.fh)(a);y(e)}}catch(e){console.error("Error loading options")}}()}),[a]),(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("table",{className:"filter-table form-inline",children:[(0,j.jsx)("thead",{children:(0,j.jsxs)("tr",{children:[t||(t=(0,j.jsx)("th",{})),r||(r=(0,j.jsx)("th",{children:"Login"})),i||(i=(0,j.jsx)("th",{children:"Email"})),n||(n=(0,j.jsx)("th",{children:"Name"})),l||(l=(0,j.jsx)("th",{children:"Seen"})),o||(o=(0,j.jsx)("th",{children:"Role"})),(0,j.jsx)("th",{style:{width:"34px"}})]})}),(0,j.jsx)("tbody",{children:s.map(((e,s)=>(0,j.jsxs)("tr",{children:[(0,j.jsx)("td",{className:"width-2 text-center",children:(0,j.jsx)("img",{className:"filter-table__avatar",src:e.avatarUrl,alt:"User avatar"})}),(0,j.jsx)("td",{className:"max-width-6",children:(0,j.jsx)("span",{className:"ellipsis",title:e.login,children:e.login})}),(0,j.jsx)("td",{className:"max-width-5",children:(0,j.jsx)("span",{className:"ellipsis",title:e.email,children:e.email})}),(0,j.jsx)("td",{className:"max-width-5",children:(0,j.jsx)("span",{className:"ellipsis",title:e.name,children:e.name})}),(0,j.jsx)("td",{className:"width-1",children:e.lastSeenAtAge}),(0,j.jsx)("td",{className:"width-8",children:m.Vt.licensedAccessControlEnabled()?(0,j.jsx)(h.R,{userId:e.userId,orgId:a,builtInRole:e.role,onBuiltinRoleChange:s=>b(s,e),roleOptions:I,builtInRoles:w,disabled:!m.Vt.hasPermissionInMetadata(g.bW.OrgUsersWrite,e)}):(0,j.jsx)(x.A,{"aria-label":"Role",value:e.role,disabled:!m.Vt.hasPermissionInMetadata(g.bW.OrgUsersWrite,e),onChange:s=>b(s,e)})}),m.Vt.hasPermissionInMetadata(g.bW.OrgUsersRemove,e)&&(0,j.jsx)("td",{children:(0,j.jsx)(c.Button,{size:"sm",variant:"destructive",onClick:()=>{f(e)},icon:"times","aria-label":"Delete user"})})]},`${e.userId}-${s}`)))})]}),Boolean(v)&&(0,j.jsx)(c.ConfirmModal,{body:`Are you sure you want to delete user ${null==v?void 0:v.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>{f(null)},isOpen:!0,onConfirm:()=>{v&&(p(v),f(null))}})]})}}}]);
//# sourceMappingURL=AdminEditOrgPage.dad62b84d58c266c4c8e.js.map