"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9119],{57582:(V,D,t)=>{t.r(D),t.d(D,{default:()=>F});var e=t(96540),y=t(49785),T=t(41053),p=t(42418),M=t(17408),L=t(88575),B=t(10354),W=t(55852),R=t(17205),g=t(10096),f=t(31678),K=t(69546),i=t(17172),S=t(80714);const b=30,x=async n=>await(0,i.AI)().get(`/api/orgs/${n}`),m=async(n,s)=>g.TP.hasPermission(f.AccessControlAction.OrgUsersRead)?(0,i.AI)().get(`/api/orgs/${n}/users/search`,(0,S.F)({perpage:b,page:s})):{orgUsers:[]},A=async(n,s)=>{const c=s.map(o=>o.userId),E=await(0,i.AI)().post("/api/access-control/users/roles/search",{userIds:c,orgId:n});s.forEach(o=>{o.roles=E?E[o.userId]||[]:[]})},N=(n,s)=>(0,i.AI)().patch(`/api/orgs/${s}/users/${n.userId}`,n),$=(n,s)=>(0,i.AI)().delete(`/api/orgs/${s}/users/${n.userId}`),U=(n,s)=>(0,i.AI)().put(`/api/orgs/${s}`,{name:n}),F=({match:n})=>{const s=parseInt(n.params.id,10),c=g.TP.hasPermission(f.AccessControlAction.OrgsWrite),E=g.TP.hasPermission(f.AccessControlAction.OrgUsersRead),[o,_]=(0,e.useState)([]),[u,z]=(0,e.useState)(1),[I,O]=(0,e.useState)(1),[P,h]=(0,T.A)(()=>x(s),[]),{handleSubmit:Y,register:j,formState:{errors:a}}=(0,y.mN)(),[,r]=(0,T.A)(async l=>{const d=await m(s,l);g.TP.licensedAccessControlEnabled()&&await A(s,d.orgUsers);const Z=d?.perPage!==0?Math.ceil(d.totalCount/d.perPage):0;return O(Z),_(d.orgUsers),d.orgUsers},[]);(0,e.useEffect)(()=>{h(),r(u)},[h,r,u]);const C=async({orgName:l})=>{await U(l,s)},v=()=>e.createElement(p.F,{severity:"info",title:"Access denied"},"You do not have permission to see users in this organization. To update this organization, contact your server administrator."),H=l=>{z(l)},J=async l=>{await $(l,s),r(u)},Q=async(l,d)=>{await N({...d,role:l},s),r(u)},X={text:P?.value?.name??"",icon:"shield",subTitle:"Manage settings and user roles for an organization."};return e.createElement(R.Y,{navId:"global-orgs",pageNav:X,subTitle:"Manage settings for this specific org."},e.createElement(R.Y.Contents,null,e.createElement(e.Fragment,null,e.createElement(M.s,null,"Edit organization"),P.value&&e.createElement("form",{onSubmit:Y(C),style:{maxWidth:"600px"}},e.createElement(L.D,{label:"Name",invalid:!!a.orgName,error:"Name is required",disabled:!c},e.createElement(B.p,{...j("orgName",{required:!0}),id:"org-name-input",defaultValue:P.value.name})),e.createElement(W.$n,{type:"submit",disabled:!c},"Update")),e.createElement("div",{style:{marginTop:"20px"}},e.createElement(M.s,null,"Organization users"),!E&&v(),E&&!!o.length&&e.createElement(K.b,{users:o,orgId:s,onRoleChange:Q,onRemoveUser:J,changePage:H,page:u,totalPages:I})))))}},69546:(V,D,t)=>{t.d(D,{b:()=>F});var e=t(96540),y=t(13544),T=t(12942),p=t(94753),M=t(90613),L=t(56034),B=t(14578),W=t(78369),R=t(55852),g=t(67061),f=t(48840),K=t(19384),i=t(96374),S=t(89062),b=t(85927),x=t(46334),m=t(10096),A=t(31678),N=t(5133);const $=`This user's role is not editable because it is synchronized from your auth provider.
Refer to the Grafana authentication docs for details.`,U=n=>{const s=n?.isExternallySynced;return!m.TP.hasPermissionInMetadata(A.AccessControlAction.OrgUsersWrite,n)||s},G=y.Tp.pages.UserListPage.UsersListPage,F=({users:n,orgId:s,onRoleChange:c,onRemoveUser:E,fetchData:o,changePage:_,page:u,totalPages:z,rolesLoading:I})=>{const[O,P]=(0,e.useState)(null),[h,Y]=(0,e.useState)([]);(0,e.useEffect)(()=>{async function a(){try{if(m.TP.hasPermission(A.AccessControlAction.ActionRolesList)){let r=await(0,b.RL)(s);Y(r)}}catch{console.error("Error loading options")}}m.TP.licensedAccessControlEnabled()&&a()},[s]);const j=(0,e.useMemo)(()=>[{id:"avatarUrl",header:"",cell:({cell:{value:a}})=>a&&e.createElement(T.e,{src:a,alt:"User avatar"})},{id:"login",header:"Login",cell:({cell:{value:a}})=>e.createElement("div",null,a),sortType:"string"},{id:"email",header:"Email",cell:({cell:{value:a}})=>a,sortType:"string"},{id:"name",header:"Name",cell:({cell:{value:a}})=>a,sortType:"string"},{id:"lastSeenAtAge",header:"Last active",cell:({cell:{value:a}})=>e.createElement(e.Fragment,null,a&&e.createElement(e.Fragment,null,a==="10 years"?e.createElement(p.E,{color:"disabled"},"Never"):a)),sortType:(a,r)=>new Date(a.original.lastSeenAt).getTime()-new Date(r.original.lastSeenAt).getTime()},{id:"role",header:"Role",cell:({cell:{value:a},row:{original:r}})=>{const C=U(r);return m.TP.licensedAccessControlEnabled()?e.createElement(S.y,{userId:r.userId,roles:r.roles||[],isLoading:I,orgId:s,roleOptions:h,basicRole:a,onBasicRoleChange:v=>c(v,r),basicRoleDisabled:C,basicRoleDisabledMessage:$,width:40}):e.createElement(N.r,{"aria-label":"Role",value:a,disabled:C,onChange:v=>c(v,r)})}},{id:"info",header:"",cell:({row:{original:a}})=>U(a)&&e.createElement(M.a,{display:"flex",alignItems:"center",marginLeft:1},e.createElement(L.m,{interactive:!0,content:e.createElement("div",null,"This user's role is not editable because it is synchronized from your auth provider. Refer to the\xA0",e.createElement("a",{href:"https://grafana.com/docs/grafana/latest/administration/user-management/manage-org-users/#change-a-users-organization-permissions",rel:"noreferrer",target:"_blank"},"Grafana authentication docs"),"\xA0for details.")},e.createElement(B.I,{name:"question-circle"})))},{id:"authLabels",header:"Origin",cell:({cell:{value:a}})=>e.createElement(e.Fragment,null,Array.isArray(a)&&a.length>0&&e.createElement(x.E,{label:a[0],removeIcon:!1,count:0}))},{id:"isDisabled",header:"",cell:({cell:{value:a}})=>e.createElement(e.Fragment,null,a&&e.createElement(W.v,{colorIndex:9,name:"Disabled"}))},{id:"delete",header:"",cell:({row:{original:a}})=>m.TP.hasPermissionInMetadata(A.AccessControlAction.OrgUsersRemove,a)&&e.createElement(R.$n,{size:"sm",variant:"destructive",onClick:()=>{P(a)},icon:"times","aria-label":`Delete user ${a.name}`})}],[I,s,h,c]);return e.createElement(g.B,{direction:"column",gap:2,"data-testid":G.container},e.createElement(f.j,{columns:j,data:n,getRowId:a=>String(a.userId),fetchData:o}),e.createElement(g.B,{justifyContent:"flex-end"},e.createElement(K.d,{onNavigate:_,currentPage:u,numberOfPages:z,hideWhenSinglePage:!0})),!!O&&e.createElement(i.u,{body:`Are you sure you want to delete user ${O?.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>{P(null)},isOpen:!0,onConfirm:()=>{O&&(E(O),P(null))}}))}}}]);

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