"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2721],{28911:(b,u,t)=>{t.r(u),t.d(u,{default:()=>a});var e=t(27702),D=t(26811),i=t(73289),R=t(63439),M=t(12375),U=t(23839),C=t(22209),p=t(1128),T=t(66670),o=t(64022),_=t(50852),h=t(44644),E=t(66574),L=t(92317),g=t(18771),d=t(56071);const A=30,I=async s=>await(0,i.i)().get(`/api/orgs/${s}`),m=async(s,n)=>E.Vt.hasPermission(g.AccessControlAction.OrgUsersRead)?(0,i.i)().get(`/api/orgs/${s}/users/search`,(0,L.y)({perpage:A,page:n})):{orgUsers:[]},P=(s,n)=>(0,i.i)().patch(`/api/orgs/${n}/users/${s.userId}`,s),y=(s,n)=>(0,i.i)().delete(`/api/orgs/${n}/users/${s.userId}`),a=({match:s})=>{const n=parseInt(s.params.id,10),W=E.Vt.hasPermission(g.AccessControlAction.OrgsWrite),c=E.Vt.hasPermission(g.AccessControlAction.OrgUsersRead),[K,x]=(0,e.useState)([]),[O,S]=(0,e.useState)(1),[$,z]=(0,e.useState)(1),[f,N]=(0,D.Z)(()=>I(n),[]),[,v]=(0,D.Z)(async l=>{const r=await m(n,l),X=r?.perPage!==0?Math.ceil(r.totalCount/r.perPage):0;return z(X),x(r.orgUsers),r.orgUsers},[]);(0,e.useEffect)(()=>{N(),v(O)},[N,v,O]);const V=async l=>await(0,i.i)().put(`/api/orgs/${n}`,{...f.value,name:l}),F=()=>e.createElement(R.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."),Z=l=>{S(l)},j=async l=>{await y(l,n),v(O)},G=async(l,r)=>{await P({...r,role:l},n),v(O)},J={text:f?.value?.name??"",icon:"shield",subTitle:"Manage settings and user roles for an organization."};return e.createElement(h.T,{navId:"global-orgs",pageNav:J,subTitle:"Manage settings for this specific org."},e.createElement(h.T.Contents,null,e.createElement(e.Fragment,null,e.createElement(M.D,null,"Edit organization"),f.value&&e.createElement(U.l,{defaultValues:{orgName:f.value.name},onSubmit:l=>V(l.orgName)},({register:l,errors:r})=>e.createElement(e.Fragment,null,e.createElement(C.g,{label:"Name",invalid:!!r.orgName,error:"Name is required",disabled:!W},e.createElement(p.I,{...l("orgName",{required:!0}),id:"org-name-input"})),e.createElement(T.zx,{type:"submit",disabled:!W},"Update"))),e.createElement("div",{style:{marginTop:"20px"}},e.createElement(M.D,null,"Organization users"),!c&&F(),c&&!!K.length&&e.createElement(o.wc,{spacing:"md"},e.createElement(d.P,{users:K,orgId:n,onRoleChange:G,onRemoveUser:j}),e.createElement(o.Lh,{justify:"flex-end"},e.createElement(_.t,{onNavigate:Z,currentPage:O,numberOfPages:$,hideWhenSinglePage:!0})))))))}},56071:(b,u,t)=>{t.d(u,{P:()=>L});var e=t(27702),D=t(80011),i=t(73453),R=t(66670),M=t(3613),U=t(75574),C=t(11349),p=t(8311),T=t(12308),o=t(66574),_=t(18771),h=t(8237);const E=`This user's role is not editable because it is synchronized from your auth provider.
  Refer to the Grafana authentication docs for details.`,L=({users:g,orgId:d,onRoleChange:A,onRemoveUser:I})=>{const[m,P]=(0,e.useState)(null),[y,B]=(0,e.useState)([]);return(0,e.useEffect)(()=>{async function a(){try{if(o.Vt.hasPermission(_.AccessControlAction.ActionRolesList)){let s=await(0,C.ul)(d);B(s)}}catch{console.error("Error loading options")}}o.Vt.licensedAccessControlEnabled()&&a()},[d]),e.createElement(e.Fragment,null,e.createElement("table",{className:"filter-table form-inline"},e.createElement("thead",null,e.createElement("tr",null,e.createElement("th",null),e.createElement("th",null,"Login"),e.createElement("th",null,"Email"),e.createElement("th",null,"Name"),e.createElement("th",null,"Seen"),e.createElement("th",null,"Role"),e.createElement("th",null),e.createElement("th",{style:{width:"34px"}}),e.createElement("th",null,"Origin"),e.createElement("th",null))),e.createElement("tbody",null,g.map((a,s)=>{let n=!o.Vt.hasPermissionInMetadata(_.AccessControlAction.OrgUsersWrite,a);return((Array.isArray(a.authLabels)&&a.authLabels.length>0?a.authLabels[0]:"")!=="grafana.com"||T.default.featureToggles.gcomOnlyExternalOrgRoleSync)&&(n=a?.isExternallySynced||n),e.createElement("tr",{key:`${a.userId}-${s}`},e.createElement("td",{className:"width-2 text-center"},e.createElement("img",{className:"filter-table__avatar",src:a.avatarUrl,alt:"User avatar"})),e.createElement("td",{className:"max-width-6"},e.createElement("span",{className:"ellipsis",title:a.login},a.login)),e.createElement("td",{className:"max-width-5"},e.createElement("span",{className:"ellipsis",title:a.email},a.email)),e.createElement("td",{className:"max-width-5"},e.createElement("span",{className:"ellipsis",title:a.name},a.name)),e.createElement("td",{className:"width-1"},a.lastSeenAtAge),e.createElement("td",{className:"width-8"},o.Vt.licensedAccessControlEnabled()?e.createElement(U.R,{userId:a.userId,orgId:d,roleOptions:y,basicRole:a.role,onBasicRoleChange:c=>A(c,a),basicRoleDisabled:n,basicRoleDisabledMessage:E}):e.createElement(h.A,{"aria-label":"Role",value:a.role,disabled:n,onChange:c=>A(c,a)})),e.createElement("td",null,n&&e.createElement("div",{style:{display:"flex",alignItems:"center"}},e.createElement(D.u,{content:E},e.createElement(i.J,{name:"question-circle",style:{marginLeft:"8px"}})))),e.createElement("td",{className:"width-1 text-center"},a.isDisabled&&e.createElement("span",{className:"label label-tag label-tag--gray"},"Disabled")),e.createElement("td",{className:"width-1"},Array.isArray(a.authLabels)&&a.authLabels.length>0&&e.createElement(p.e,{label:a.authLabels[0],removeIcon:!1,count:0})),o.Vt.hasPermissionInMetadata(_.AccessControlAction.OrgUsersRemove,a)&&e.createElement("td",{className:"text-right"},e.createElement(R.zx,{size:"sm",variant:"destructive",onClick:()=>{P(a)},icon:"times","aria-label":"Delete user"})))}))),!!m&&e.createElement(M.s,{body:`Are you sure you want to delete user ${m?.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>{P(null)},isOpen:!0,onConfirm:()=>{m&&(I(m),P(null))}}))}}}]);

//# sourceMappingURL=AdminEditOrgPage.b8e0886b6ec0a42fa1a6.js.map