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

//# sourceMappingURL=AdminEditOrgPage.29e6825870b2d17dcbc6.js.map