"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2721],{23010:(j,f,a)=>{a.r(f),a.d(f,{default:()=>T});var s=a(39953),t=a(65489),c=a(4148),A=a(33155),R=a(96276),y=a(85830),B=a(96227),v=a(38637),K=a(4919),U=a(13253),P=a(21308),S=a(26893),O=a(57721),N=a(27994);const x=30,b=async i=>await(0,c.i)().get(`/api/orgs/${i}`),V=async(i,o)=>P.Vt.hasPermission(O.AccessControlAction.OrgUsersRead)?(0,c.i)().get(`/api/orgs/${i}/users/search`,(0,S.y)({perpage:x,page:o})):{orgUsers:[]},E=(i,o)=>(0,c.i)().patch(`/api/orgs/${o}/users/${i.userId}`,i),u=(i,o)=>(0,c.i)().delete(`/api/orgs/${o}/users/${i.userId}`),T=({match:i})=>{const o=parseInt(i.params.id,10),h=P.Vt.hasPermission(O.AccessControlAction.OrgsWrite),C=P.Vt.hasPermission(O.AccessControlAction.OrgUsersRead),[D,l]=(0,s.useState)([]),[r,_]=(0,s.useState)(1),[L,z]=(0,s.useState)(1),[g,I]=(0,t.Z)(()=>b(o),[]),[,d]=(0,t.Z)(async e=>{const n=await V(o,e),W=n?.perPage!==0?Math.ceil(n.totalCount/n.perPage):0;return z(W),l(n.orgUsers),n.orgUsers},[]);(0,s.useEffect)(()=>{I(),d(r)},[I,d,r]);const m=async e=>await(0,c.i)().put(`/api/orgs/${o}`,{...g.value,name:e}),M=()=>s.createElement(A.b,{severity:"info",title:"Access denied"},"You do not have permission to see users in this organization. To update this organization, contact your server administrator."),p=e=>{_(e)},$=async e=>{await u(e,o),d(r)},F=async(e,n)=>{await E({...n,role:e},o),d(r)},X={text:g?.value?.name??"",icon:"shield",subTitle:"Manage settings and user roles for an organization."};return s.createElement(U.T,{navId:"global-orgs",pageNav:X,subTitle:"Manage settings for this specific org."},s.createElement(U.T.Contents,null,s.createElement(s.Fragment,null,s.createElement(R.D,null,"Edit organization"),g.value&&s.createElement(y.l,{defaultValues:{orgName:g.value.name},onSubmit:e=>m(e.orgName)},({register:e,errors:n})=>s.createElement(s.Fragment,null,s.createElement(B.g,{label:"Name",invalid:!!n.orgName,error:"Name is required",disabled:!h},s.createElement(v.I,{...e("orgName",{required:!0}),id:"org-name-input"})),s.createElement(K.zx,{type:"submit",disabled:!h},"Update"))),s.createElement("div",{style:{marginTop:"20px"}},s.createElement(R.D,null,"Organization users"),!C&&M(),C&&!!D.length&&s.createElement(N.q,{users:D,orgId:o,onRoleChange:F,onRemoveUser:$,changePage:p,page:r,totalPages:L})))))}},27994:(j,f,a)=>{a.d(f,{q:()=>h});var s=a(41407),t=a(39953),c=a(28888),A=a(82803),R=a(99503),y=a(51064),B=a(4919),v=a(12223),K=a(94696),U=a(39017),P=a(32840),S=a(69865),O=a(12190),N=a(10639),x=a(4171),b=a(90139),V=a(50820),E=a(21308),u=a(57721),Z=a(65741);const T=`This user's role is not editable because it is synchronized from your auth provider.
  Refer to the Grafana authentication docs for details.`,i=l=>{let r=!E.Vt.hasPermissionInMetadata(u.AccessControlAction.OrgUsersWrite,l);return((Array.isArray(l.authLabels)&&l.authLabels.length>0?l.authLabels[0]:"")!=="grafana.com"||V.default.featureToggles.gcomOnlyExternalOrgRoleSync)&&(r=l?.isExternallySynced||r),r},o=c.wl.pages.UserListPage.UsersListPage,h=({users:l,orgId:r,onRoleChange:_,onRemoveUser:L,fetchData:z,changePage:g,page:I,totalPages:d})=>{const[m,M]=(0,t.useState)(null),[p,$]=(0,t.useState)([]),F=(0,A.wW)(D);(0,t.useEffect)(()=>{async function e(){try{if(E.Vt.hasPermission(u.AccessControlAction.ActionRolesList)){let n=await(0,x.ul)(r);$(n)}}catch{console.error("Error loading options")}}E.Vt.licensedAccessControlEnabled()&&e()},[r]);const X=(0,t.useMemo)(()=>[{id:"avatarUrl",header:"",cell:({cell:{value:e}})=>e&&t.createElement(R.q,{src:e,alt:"User avatar"})},{id:"login",header:"Login",cell:({cell:{value:e}})=>t.createElement("div",null,e),sortType:"string"},{id:"email",header:"Email",cell:({cell:{value:e}})=>e,sortType:"string"},{id:"name",header:"Name",cell:({cell:{value:e}})=>e,sortType:"string"},{id:"lastSeenAtAge",header:"Last active",cell:({cell:{value:e}})=>e,sortType:(e,n)=>new Date(e.original.lastSeenAt).getTime()-new Date(n.original.lastSeenAt).getTime()},{id:"role",header:"Role",cell:({cell:{value:e},row:{original:n}})=>{const W=i(n);return E.Vt.licensedAccessControlEnabled()?t.createElement(N.R,{userId:n.userId,orgId:r,roleOptions:p,basicRole:e,onBasicRoleChange:Y=>_(Y,n),basicRoleDisabled:W,basicRoleDisabledMessage:T}):t.createElement(Z.A,{"aria-label":"Role",value:e,disabled:W,onChange:Y=>_(Y,n)})}},{id:"info",header:"",cell:C},{id:"authLabels",header:"Origin",cell:({cell:{value:e}})=>t.createElement(t.Fragment,null,Array.isArray(e)&&e.length>0&&t.createElement(b.e,{label:e[0],removeIcon:!1,count:0}))},{id:"isDisabled",header:"",cell:({cell:{value:e}})=>t.createElement(t.Fragment,null,e&&t.createElement(y.V,{colorIndex:9,name:"Disabled"}))},{id:"delete",header:"",cell:({row:{original:e}})=>E.Vt.hasPermissionInMetadata(u.AccessControlAction.OrgUsersRemove,e)&&t.createElement(B.zx,{size:"sm",variant:"destructive",onClick:()=>{M(e)},icon:"times","aria-label":`Delete user ${e.name}`})}],[r,p,_]);return t.createElement(v.wc,{spacing:"md","data-testid":o.container},t.createElement("div",{className:F.wrapper},t.createElement(K.e,{columns:X,data:l,getRowId:e=>String(e.userId),fetchData:z}),t.createElement(v.Lh,{justify:"flex-end"},t.createElement(U.t,{onNavigate:g,currentPage:I,numberOfPages:d,hideWhenSinglePage:!0}))),!!m&&t.createElement(P.s,{body:`Are you sure you want to delete user ${m?.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>{M(null)},isOpen:!0,onConfirm:()=>{m&&(L(m),M(null))}}))},C=({row:{original:l}})=>{const r=(0,A.wW)(D);return i(l)&&t.createElement("div",{className:r.row},t.createElement(S.u,{content:T},t.createElement(O.J,{name:"question-circle",className:r.icon})))},D=l=>({row:(0,s.css)({display:"flex",alignItems:"center"}),icon:(0,s.css)({marginLeft:l.spacing(1)}),wrapper:(0,s.css)({display:"flex",flexDirection:"column",overflowX:"auto",overflowY:"hidden",minHeight:"100vh",width:"100%","& > div":{overflowX:"unset",marginBottom:l.spacing(2)}})})}}]);

//# sourceMappingURL=AdminEditOrgPage.60446e4ff1a5b8d01d54.js.map