theme.keycloak.v2.admin.resources.assets.EditUser-Ad2pc0MX.js Maven / Gradle / Ivy
import{jsx as e,jsxs as f,Fragment as W}from"react/jsx-runtime";import{cK as rt,cL as pt,cM as ht,cO as ze,cN as gt,cj as ft,cJ as bt,cA as yt,eq as Ct,er as wt,c$ as vt,es as kt,et as It,eu as Pt,aj as Tt,P as me,cn as Re,u as $,a as K,f as ee,B as le,k as G,aC as fe,ag as Dt,ah as At,M as st,q as Oe,s as Lt,i as N,J as St,K as Rt,aB as xt,N as Ut,D as xe,g as be,r as Te,ac as Ie,am as at,e1 as Et,c3 as Nt,ab as Mt,F as De,ev as Bt,bp as We,aq as $e,w as Ue,a3 as nt,ar as Ft,ad as Kt,b2 as Je,at as Ot,b3 as Ge,bS as Gt,a9 as Vt,cp as jt,y as Qe,c as Ve,b as qt,bt as Xe,aa as ve,Z as ke,bK as Ht,p as Ee,L as _t,cx as zt,d as Wt,dv as $t,I as Jt,bw as Qt,bx as Xt,em as Yt,en as Ye}from"./main-C7ps2lmX.js";import{useState as P,useMemo as it,useRef as Zt,Fragment as er}from"react";import{u as ue,C as ot}from"./ConfirmDialog-hx7XKLbN.js";import{R as tr,u as rr}from"./RoutableTabs-T8JTILEW.js";import{V as sr}from"./ViewHeader-B7eeFzFA.js";import{U as ar}from"./UserProfileContext-BkGsi2EQ.js";import{u as je}from"./useParams-B67lSY02.js";import{A as nr}from"./AttributeForm-CdFbESi6.js";import{a as Ne,R as ir,F as or,U as dr,t as lr,f as cr}from"./UserForm-PSfSn7pK.js";import{U as mr}from"./userProfileMetadata-CFgHgJ2w.js";import{L as qe}from"./PaginatingTableToolbar-Cjsz5Jh4.js";import{i as ur,l as Ze,K as Pe}from"./KeycloakDataTable-DbY4la1D.js";import{u as dt}from"./useFormatDate-X7HJ5iYO.js";import{s as lt}from"./sortBy-DtY8l0cj.js";import{T as F,U as Me,a1 as pr,V as Be,W as ce,X as O,Y as Fe,Z as U,$ as Se}from"./Td-D2hVFK0Z.js";import{C as hr,S as gr,i as fr}from"./SessionsTable-7Bmc2htq.js";import{u as Ke}from"./useToggle-K3Kx99tM.js";import{P as br}from"./pencil-alt-icon-BJd8WcEw.js";import{T as yr}from"./TimeSelectorControl-BxG2OWnt.js";import{D as Cr}from"./SwitchControl-C_9Y74oV.js";import{G as wr,a as vr}from"./GroupPickerDialog-C09EjRTA.js";import{b as kr}from"./_baseFlatten-eIEJR-AJ.js";import{Q as Ir}from"./question-circle-icon-dDThmv9d.js";import{c as pe}from"./capitalize-Dxqk2Vco.js";import{R as Pr}from"./AddRoleMappingModal-DW8o4W0z.js";/* empty css */import{a as oe,b as de}from"./Tabs-CMdqT4Cg.js";import"react-dom";import"./PageHandler-P2CRgucq.js";import"./DynamicComponents-DvaX3FJx.js";import"./ClientSelect-B9UqjyP6.js";import"./FileUpload-CumNwlWc.js";import"./CodeEditor-C-nZkUJx.js";import"./copy-icon-ACZmDH8e.js";import"./EmptyStateFooter-DqmBOP2I.js";import"./EmptyStateActions-DWNUFByn.js";import"./FlexItem-BzZfUnQ1.js";import"./KeySelect-jKxsKqdI.js";import"./MultiLineInput-DiPNQ1LE.js";import"./PageList-s9OtSlkz.js";import"./grip-vertical-icon-BxF7V59o.js";import"./FormAccess-DyLNkc18.js";import"./KeyValueInput-B0tpVTv9.js";import"./ListItem-CHzEhhky.js";import"./TimeSelector-DcQmr_f3.js";import"./DataListItemRow-BC0LurDd.js";import"./_baseSlice-F8doVSIJ.js";import"./filter-icon-DO0QNij3.js";var Tr=Math.min;function Dr(t,r,a){for(var n=gt,p=t[0].length,o=t.length,i=o,g=Array(o),m=1/0,h=[];i--;){var u=t[i];i&&r&&(u=rt(u,pt(r))),m=Tr(u.length,m),g[i]=r||p>=120&&u.length>=120?new ht(i&&u):void 0}u=t[0];var c=-1,d=g[0];e:for(;++c{const n=Tt();return e(me,{variant:Re.light,children:e(nr,{form:n,save:r,fineGrainedAccess:t.access?.manage,reset:()=>n.reset({...n.getValues(),attributes:Ne(t).attributes}),name:"unmanagedAttributes",isDisabled:mr.AdminView==a?.unmanagedAttributePolicy})})},Nr=()=>{const{adminClient:t}=$(),[r,a]=P(),{t:n}=K(),{addAlert:p,addError:o}=ee(),i=dt(),[g,m]=P(0),{id:h}=je(),u=k=>lt(k,M=>M.clientId?.toUpperCase()),c=()=>m(new Date().getTime()),d=async()=>{const k=await t.users.listConsents({id:h});return u(k)},y=({grantedClientScopes:k})=>e(Dt,{className:"kc-consents-chip-group",children:k.map(M=>e(At,{isReadOnly:!0,className:"kc-consents-chip",children:M},M))}),[D,v]=ue({titleKey:"revokeClientScopesTitle",messageKey:n("revokeClientScopes",{clientId:r?.clientId}),continueButtonLabel:"revoke",continueButtonVariant:le.danger,onConfirm:async()=>{try{await t.users.revokeConsent({id:h,clientId:r.clientId}),c(),p(n("deleteGrantsSuccess"),G.success)}catch(k){o("deleteGrantsError",k)}}});return f(W,{children:[e(v,{}),e(Pe,{loader:d,ariaLabelKey:"roleList",searchPlaceholderKey:" ",columns:[{name:"clientId",displayKey:"Client",cellFormatters:[fe()],transforms:[F(20)]},{name:"grantedClientScopes",displayKey:"grantedClientScopes",cellFormatters:[fe()],cellRenderer:y,transforms:[F(30)]},{name:"createDate",displayKey:"created",transforms:[F(20)],cellRenderer:({createDate:k})=>k?i(new Date(k)):"—"},{name:"lastUpdatedDate",displayKey:"lastUpdated",transforms:[F(10)],cellRenderer:({lastUpdatedDate:k})=>k?i(new Date(k)):"—"}],actions:[{title:n("revoke"),onRowClick:k=>{a(k),D()}}],emptyState:e(qe,{hasIcon:!0,icon:hr,message:n("noConsents"),instructions:n("noConsentsText")})},g)]})},Mr=({credentialData:t,onClose:r})=>{const{t:a}=K();return e(st,{variant:Oe.medium,title:a("passwordDataTitle"),"data-testid":"passwordDataDialog",isOpen:!0,onClose:r,children:f(Me,{"aria-label":a("passwordDataTitle"),"data-testid":"password-data-dialog",variant:pr.compact,children:[e(Be,{children:f(ce,{children:[e(O,{children:a("showPasswordDataName")}),e(O,{children:a("showPasswordDataValue")})]})}),e(Fe,{children:t.map((n,p)=>f(ce,{children:[e(U,{children:n[0]}),e(U,{children:n[1]})]},p))})]})})},Br=({credential:t,resetPassword:r,toggleDelete:a,children:n})=>{const p=dt(),{t:o}=K(),[i,g]=Ke(),[m,h]=Ke(),u=Lt(),c=it(()=>{if(!t.credentialData)return[];const d=JSON.parse(t.credentialData);return u(Object.entries(d),([y])=>y).map(([y,D])=>typeof D=="string"?[y,D]:[y,JSON.stringify(D)])},[t.credentialData]);return f(W,{children:[i&&Object.keys(t).length!==0&&e(Mr,{credentialData:c,onClose:()=>{g()}}),e(U,{children:n}),e(U,{children:p(new Date(t.createdDate))}),e(U,{children:e(N,{className:"kc-showData-btn",variant:"link","data-testid":"showDataBtn",onClick:g,children:o("showDataBtn")})}),t.type==="password"?e(U,{isActionCell:!0,children:e(N,{variant:"secondary","data-testid":"resetPasswordBtn",onClick:r,children:o("resetPasswordBtn")})}):e(U,{}),e(U,{isActionCell:!0,children:e(St,{popperProps:{position:"right"},onOpenChange:h,toggle:d=>e(Rt,{ref:d,isExpanded:m,onClick:h,variant:"plain","aria-label":"Kebab toggle",children:e(xt,{})}),isOpen:m,children:e(Ut,{children:e(xe,{"data-testid":"deleteDropdownItem",component:"button",onClick:()=>{a(),h()},children:o("deleteBtn")},t.id)})})})]})},Fr=({userId:t,credential:r,isEditable:a,toggle:n})=>{const{adminClient:p}=$(),{t:o}=K(),{register:i,handleSubmit:g}=be(),{addAlert:m,addError:h}=ee();return e(Te,{isHorizontal:!0,className:"kc-form-userLabel",onSubmit:g(async c=>{try{await p.users.updateCredentialLabel({id:t,credentialId:r.id},c.userLabel||""),m(o("updateCredentialUserLabelSuccess"),G.success),n()}catch(d){h("updateCredentialUserLabelError",d)}}),children:e(Ie,{fieldId:"kc-userLabel",className:"kc-userLabel-row",children:e("div",{className:"kc-form-group-userLabel",children:a?f(W,{children:[e(at,{"data-testid":"userLabelFld",defaultValue:r.userLabel,className:"kc-userLabel","aria-label":o("userLabel"),...i("userLabel")}),f("div",{className:"kc-userLabel-actionBtns",children:[e(N,{"data-testid":"editUserLabelAcceptBtn",variant:"link",className:"kc-editUserLabelAcceptBtn","aria-label":o("acceptBtn"),type:"submit",icon:e(Et,{})}),e(N,{"data-testid":"editUserLabelCancelBtn",variant:"link",className:"kc-editUserLabel-cancelBtn","aria-label":o("cancelBtn"),onClick:n,icon:e(Nt,{})})]})]}):f(W,{children:[r.userLabel,e(N,{"aria-label":o("editUserLabel"),variant:"link",className:"kc-editUserLabel-btn",onClick:n,"data-testid":"editUserLabelBtn",icon:e(br,{})})]})})})})},Kr=()=>{const{t}=K();return e(yr,{name:"lifespan",label:t("lifespan"),labelIcon:t("lifespanHelp"),units:["minute","hour","day"],menuAppendTo:"parent",controller:{defaultValue:ct.lifespan}})},ct={actions:[],lifespan:43200},Or=({userId:t,onClose:r})=>{const{adminClient:a}=$(),{t:n}=K(),p=be({defaultValues:ct}),{handleSubmit:o,control:i}=p,g=Mt({control:i,name:"actions"}),m=!et(g),{addAlert:h,addError:u}=ee(),c=async({actions:d,lifespan:y})=>{if(!et(d))try{await a.users.executeActionsEmail({id:t,actions:d,lifespan:y}),h(n("credentialResetEmailSuccess"),G.success),r()}catch(D){u("credentialResetEmailError",D)}};return e(ot,{variant:Oe.medium,titleKey:"credentialReset",open:!0,onCancel:r,toggleDialog:r,continueButtonLabel:"credentialResetConfirm",onConfirm:()=>{o(c)()},confirmButtonDisabled:!m,children:e(Te,{id:"userCredentialsReset-form",isHorizontal:!0,"data-testid":"credential-reset-modal",children:f(De,{...p,children:[e(ir,{name:"actions",label:"resetAction",help:"resetActions"}),e(Kr,{})]})})})},Gr={password:"",passwordConfirmation:"",temporaryPassword:!0},Vr=({user:t,isResetPassword:r,onAddRequiredActions:a,refresh:n,onClose:p})=>{const{adminClient:o}=$(),{t:i}=K(),g=be({defaultValues:Gr,mode:"onChange"}),{register:m,formState:{isValid:h,errors:u},watch:c,handleSubmit:d,clearErrors:y,setError:D}=g,[v,k]=Ke(!0),M=c("password",""),J=c("passwordConfirmation",""),{addAlert:te,addError:re}=ee(),[_,z]=ue({titleKey:r?"resetPasswordConfirm":"setPasswordConfirm",messageKey:r?i("resetPasswordConfirmText",{username:t.username}):i("setPasswordConfirmText",{username:t.username}),continueButtonLabel:r?"resetPassword":"savePassword",continueButtonVariant:le.danger,onConfirm:()=>d(x)()}),x=async({password:l,temporaryPassword:A})=>{try{await o.users.resetPassword({id:t.id,credential:{temporary:A,type:"password",value:l}}),A&&a?.([Bt.UPDATE_PASSWORD]);const j=(await o.users.getCredentials({id:t.id})).find(b=>b.type==="password");j&&await o.users.updateCredentialLabel({id:t.id,credentialId:j.id},i("defaultPasswordLabel")),te(i(r?"resetCredentialsSuccess":"savePasswordSuccess"),G.success),n()}catch(V){re(r?"resetPasswordError":"savePasswordError",V)}p()},{onChange:R,...B}=m("password",{required:!0});return f(W,{children:[e(z,{}),e(ot,{titleKey:r?i("resetPasswordFor",{username:t.username}):i("setPasswordFor",{username:t.username}),open:v,onCancel:p,toggleDialog:k,onConfirm:_,confirmButtonDisabled:!h,continueButtonLabel:"save",children:f(Te,{id:"userCredentials-form",isHorizontal:!0,className:"keycloak__user-credentials__reset-form",children:[f(Ie,{name:"password",label:i("password"),fieldId:"password",isRequired:!0,children:[e(We,{"data-testid":"passwordField",id:"password",onChange:l=>{R(l),J!==l.currentTarget.value?D("passwordConfirmation",{message:i("confirmPasswordDoesNotMatch").toString()}):y("passwordConfirmation")},...B}),u.password&&e($e,{message:i("required")})]}),f(Ie,{name:"passwordConfirmation",label:i(r?"resetPasswordConfirmation":"passwordConfirmation"),fieldId:"passwordConfirmation",isRequired:!0,children:[e(We,{"data-testid":"passwordConfirmationField",id:"passwordConfirmation",...m("passwordConfirmation",{required:!0,validate:l=>l===M||i("confirmPasswordDoesNotMatch").toString()})}),u.passwordConfirmation&&e($e,{message:u.passwordConfirmation.message})]}),e(De,{...g,children:e(Cr,{name:"temporaryPassword",label:i("temporaryPassword"),labelIcon:i("temporaryPasswordHelpText"),defaultValue:"true"})})]})})]})},tt=({credential:t,userId:r,toggleDelete:a,resetPassword:n,isUserLabelEdit:p,setIsUserLabelEdit:o,refresh:i})=>e(Br,{credential:t,toggleDelete:()=>a(t),resetPassword:n,children:e(Fr,{credential:t,userId:r,isEditable:p?.status&&p.rowKey===t.id||!1,toggle:()=>{o({status:!p?.status,rowKey:t.id}),p?.status&&i()}})},t.id),jr=({user:t,setUser:r})=>{const{adminClient:a}=$(),{t:n}=K(),{addAlert:p,addError:o}=ee(),[i,g]=P(0),m=()=>g(i+1),[h,u]=P(!1),[c,d]=P(!1),[y,D]=P([]),[v,k]=P([]),[M,J]=P({}),[te,re]=P(!1),[_,z]=P(),x=Zt(null),[R,B]=P({draggedItemId:"",draggingToItemIndex:-1,dragging:!1,tempItemOrder:[""]});Ue(()=>a.users.getCredentials({id:t.id}),s=>{D(s);const I=s.reduce((T,S)=>(T[S.type]=T[S.type]||[],T[S.type].push(S),T),Object.create(null)),w=Object.keys(I).map(T=>({key:T,value:I[T]}));k(w.map(T=>({...T,isExpanded:!1})))},[i]);const l=y.find(s=>s.type==="password"),A=()=>u(!h),V=()=>{d(!c)},j=()=>{re(!0),A()},[b,L]=ue({titleKey:n("deleteCredentialsConfirmTitle"),messageKey:n("deleteCredentialsConfirm"),continueButtonLabel:n("delete"),continueButtonVariant:le.danger,onConfirm:async()=>{try{await a.users.deleteCredential({id:t.id,credentialId:M.id}),p(n("deleteCredentialsSuccess"),G.success),g(s=>s+1)}catch(s){o("deleteCredentialsError",s)}}}),E=it(()=>v.flatMap(s=>[s.value.map(({id:I})=>I).toString(),...s.isExpanded?s.value.map(I=>I.id):[]]),[v]),Q=s=>{s.dataTransfer.effectAllowed="move",s.dataTransfer.setData("text/plain",s.currentTarget.id);const I=s.currentTarget.id;s.currentTarget.classList.add(Se.modifiers.ghostRow),s.currentTarget.setAttribute("aria-pressed","true"),B({...R,draggedItemId:I,dragging:!0})},he=(s,I,w)=>{const T=s.indexOf(I);if(T===w)return s;const S=[...s];return S.splice(w,0,S.splice(T,1)[0]),S},X=s=>{if(!x.current)return;const I=x.current,w=Array.from(I.children);w.every(({id:T},S)=>T===s[S])||(I.replaceChildren(),s.forEach(T=>{I.appendChild(w.find(({id:S})=>S===T))}))},Ae=()=>{x.current&&(Array.from(x.current.children).forEach(s=>{s.classList.remove(Se.modifiers.ghostRow),s.setAttribute("aria-pressed","false")}),B({...R,draggedItemId:"",draggingToItemIndex:-1,dragging:!1}))},Le=s=>{ye(s)||(X(E),B({...R,draggingToItemIndex:-1}))},ye=s=>{if(!x.current)return!1;const I=x.current.getBoundingClientRect();return s.clientX>I.x&&s.clientXI.y&&s.clientY{ye(s)?ae(R.draggedItemId,R.tempItemOrder):Ae()},C=s=>{s.preventDefault();const w=s.target.closest("tr");if(!(!w||x.current&&!x.current.contains(w)||w.id===R.draggedItemId)){const T=w.id,S=Array.from(x.current?.children||[]).findIndex(H=>H.id===T);if(S===R.draggingToItemIndex)return;const ie=he(E,R.draggedItemId,S);X(ie),B({...R,draggingToItemIndex:S,tempItemOrder:ie})}},se=s=>{r({...t,requiredActions:[...t.requiredActions??[],...s]})},Y=({target:s})=>{s instanceof HTMLTableRowElement&&(s.classList.remove(Se.modifiers.ghostRow),s.setAttribute("aria-pressed","false"),B({...R,draggedItemId:"",draggingToItemIndex:-1,dragging:!1}))},ae=async(s,I)=>{const w=E.findIndex(H=>H===s),T=I.findIndex(H=>H===s),S=T-w,ie=s.split(",");try{for(const H of ie)for(let _e=0;_e0?await a.users.moveCredentialPositionDown({id:t.id,credentialId:H,newPreviousCredentialId:E[T]}):await a.users.moveCredentialPositionUp({id:t.id,credentialId:H});m(),p(n("updatedCredentialMoveSuccess"),G.success)}catch(H){o("updatedCredentialMoveError",H)}},Z=s=>{J(s),b()},q=t.federationLink||t.origin,[ne,ge]=P([]);if(Ue(()=>a.users.getUserStorageCredentialTypes({id:t.id}),ge,[]),!ne)return e(nt,{});const we=ne.length>0,mt=v.length===0,ut=!t.credentials||t.credentials.length===0,He=mt&&ut&&!we;return f(W,{children:[h&&e(Vr,{user:t,isResetPassword:te,onAddRequiredActions:se,refresh:m,onClose:()=>u(!1)}),c&&e(Or,{userId:t.id,onClose:()=>d(!1)}),e(L,{}),t.email&&!He&&e(N,{className:"kc-resetCredentialBtn-header",variant:"primary","data-testid":"credentialResetBtn",onClick:()=>d(!0),children:n("credentialResetBtn")}),y.length!==0&&l===void 0&&f(W,{children:[e(N,{className:"kc-setPasswordBtn-tbl","data-testid":"setPasswordBtn-table",variant:"primary",form:"userCredentials-form",onClick:()=>{u(!0)},children:n("setPassword")}),e(Ft,{})]}),v.length!==0&&e(me,{variant:Re.light,children:f(Me,{variant:"compact",children:[e(Be,{children:f(ce,{className:"kc-table-header",children:[e(O,{children:e(Kt,{helpText:n("userCredentialsHelpText"),fieldLabelId:"userCredentialsHelpTextLabel"})}),e(O,{"aria-hidden":"true"}),e(O,{children:n("type")}),e(O,{children:n("userLabel")}),e(O,{children:n("createdAt")}),e(O,{children:n("data")}),e(O,{"aria-hidden":"true"}),e(O,{"aria-hidden":"true"})]})}),e(Fe,{ref:x,onDragOver:C,onDrop:C,onDragLeave:Le,children:v.map((s,I)=>f(er,{children:[f(ce,{id:s.value.map(({id:w})=>w).toString(),draggable:v.length>1,onDrop:Ce,onDragEnd:Y,onDragStart:Q,children:[e(U,{className:v.length===1?"one-row":"",draggableRow:{id:`draggable-row-${s.value.map(({id:w})=>w)}`}}),s.value.length>1?e(U,{className:"kc-expandRow-btn",expand:{rowIndex:I,isExpanded:s.isExpanded,onToggle:(w,T)=>{const S=v.map((ie,H)=>H===T?{...ie,isExpanded:!ie.isExpanded}:ie);k(S)}}}):e(U,{}),e(U,{dataLabel:`columns-${s.key}`,className:"kc-notExpandableRow-credentialType","data-testid":"credentialType",children:Je(s.key)}),s.value.length<=1&&s.value.map(w=>e(tt,{credential:w,userId:t.id,toggleDelete:Z,resetPassword:j,isUserLabelEdit:_,setIsUserLabelEdit:z,refresh:m},w.id))]}),s.isExpanded&&s.value.map(w=>f(ce,{id:w.id,draggable:!0,onDrop:Ce,onDragEnd:Y,onDragStart:Q,children:[e(U,{}),e(U,{className:"kc-draggable-dropdown-type-icon",draggableRow:{id:`draggable-row-${s.value.map(({id:T})=>T)}`}}),e(U,{dataLabel:`child-columns-${w.id}`,className:"kc-expandableRow-credentialType",children:Je(w.type)}),e(tt,{credential:w,userId:t.id,toggleDelete:Z,resetPassword:j,isUserLabelEdit:_,setIsUserLabelEdit:z,refresh:m})]},w.id))]},s.key))})]})}),q&&we&&e(me,{variant:Re.light,children:f(Me,{variant:"compact",children:[e(Be,{children:f(ce,{children:[e(O,{children:n("type")}),e(O,{children:n("providedBy")}),e(O,{"aria-hidden":"true"})]})}),e(Fe,{children:ne.map(s=>f(ce,{children:[e(U,{children:e("b",{children:s})}),e(U,{children:e(or,{user:t})}),s==="password"&&e(U,{modifier:"fitContent",children:e(N,{variant:"secondary",onClick:A,children:n("setPassword")})})]},s))})]})}),He&&e(qe,{hasIcon:!0,message:n("noCredentials"),instructions:n("noCredentialsText"),primaryActionText:n("setPassword"),onPrimaryAction:A,secondaryActions:t.email?[{text:n("credentialResetBtn"),onClick:V,type:le.link}]:void 0})]})},qr=({user:t})=>{const{adminClient:r}=$(),{t:a}=K(),{addAlert:n,addError:p}=ee(),[o,i]=P(0),g=()=>i(o+1),[m,h]=P([]),[u,c]=P(!0),[d,y]=P([]),[D,v]=P(!1),{enabled:k}=Ot(),{hasAccess:M}=Ge(),J=M("manage-users"),te=l=>lt(l,A=>A.path?.toUpperCase()),re=async(l,A,V)=>{const j={first:l,max:A},b=V||"";b&&(j.search=b);const L=await r.users.listGroups({...j,id:t.id});y([...L]);const E=[];return u||L.forEach(Q=>{const he=(Q.path?.substring(1).match(/((~\/)|[^/])+/g)||[]).slice(0,-1);E.push(...he.map(X=>({name:X,path:Q.path?.substring(0,Q.path.indexOf(X)+X.length)})))}),te(jt([...L,...E],"path"))},_=()=>{v(!D)},[z,x]=ue({titleKey:a("leaveGroup",{count:m.length,name:m[0]?.name}),messageKey:a("leaveGroupConfirmDialog",{count:m.length,groupname:m[0]?.name,username:t.username}),continueButtonLabel:"leave",continueButtonVariant:le.danger,onConfirm:async()=>{try{await Promise.all(m.map(l=>r.users.delFromGroup({id:t.id,groupId:l.id}))),h([]),n(a("removedGroupMembership"),G.success)}catch(l){p("removedGroupMembershipError",l)}g()}}),R=l=>{h(l),z()},B=async l=>{try{await Promise.all(l.map(A=>r.users.addToGroup({id:t.id,groupId:A.id}))),n(a("addedGroupMembership"),G.success)}catch(A){p("addedGroupMembershipError",A)}g()};return f(W,{children:[e(x,{}),D&&e(wr,{id:t.id,type:"selectMany",text:{title:a("joinGroupsFor",{username:t.username}),ok:"join"},canBrowse:J,onClose:()=>v(!1),onConfirm:async(l=[])=>{await B(l),v(!1)}}),e(Pe,{loader:re,className:"keycloak_user-section_groups-table",isPaginated:!0,ariaLabelKey:"roleList",searchPlaceholderKey:"searchGroup",canSelectAll:!0,onSelect:l=>h(u?l:Lr(l,d,"id")),isRowDisabled:l=>!u&&d.every(A=>A.id!==l.id),toolbarItem:f(W,{children:[e(N,{className:"kc-join-group-button",onClick:_,"data-testid":"add-group-button",isDisabled:!t.access?.manageGroupMembership,children:a("joinGroup")}),e(Gt,{label:a("directMembership"),id:"kc-direct-membership-checkbox",onChange:()=>{c(!u),g()},isChecked:u,className:"direct-membership-check"},"direct-membership-check"),e(N,{onClick:()=>R(m),"data-testid":"leave-group-button",variant:"link",isDisabled:m.length===0,children:a("leave")}),k&&e(Vt,{"aria-label":"Basic popover",position:"bottom",bodyContent:e("div",{children:a("whoWillAppearPopoverTextUsers")}),children:e(N,{variant:"link",className:"kc-who-will-appear-button",icon:e(Ir,{}),children:a("whoWillAppearLinkTextUsers")},"who-will-appear-button")})]}),columns:[{name:"groupMembership",displayKey:"groupMembership",cellRenderer:l=>l.name||"-",transforms:[F(40)]},{name:"path",displayKey:"path",cellRenderer:l=>e(vr,{group:l}),transforms:[F(45)]},{name:"",cellRenderer:l=>d.some(V=>V.id===l.id)||d.length===0||u?e(N,{"data-testid":`leave-${l.name}`,onClick:()=>R([l]),variant:"link",isDisabled:!t.access?.manageGroupMembership,children:a("leave")}):"-",transforms:[F(20)]}],emptyState:e(qe,{hasIcon:!0,message:a("noGroups"),instructions:a("noGroupsText"),primaryActionText:a("joinGroup"),onPrimaryAction:_})},o)]})},Hr=({userId:t,federatedId:r,onClose:a,onRefresh:n})=>{const{adminClient:p}=$(),{t:o}=K(),{addAlert:i,addError:g}=ee(),m=be({mode:"onChange"}),{handleSubmit:h,formState:{isValid:u}}=m,c=async d=>{try{await p.users.addToFederatedIdentity({id:t,federatedIdentityId:r,federatedIdentity:d}),i(o("idpLinkSuccess"),G.success),a(),n()}catch(y){g("couldNotLinkIdP",y)}};return e(st,{variant:Oe.small,title:o("linkAccountTitle",{provider:pe(r)}),onClose:a,actions:[e(N,{"data-testid":"confirm",variant:"primary",type:"submit",form:"group-form",isDisabled:!u,children:o("link")},"confirm"),e(N,{"data-testid":"cancel",variant:le.link,onClick:a,children:o("cancel")},"cancel")],isOpen:!0,children:e(Te,{id:"group-form",onSubmit:h(c),children:f(De,{...m,children:[e(Ie,{label:o("identityProvider"),fieldId:"identityProvider",children:e(at,{id:"identityProvider","data-testid":"idpNameInput",value:pe(r),readOnly:!0})}),e(Qe,{name:"userId",label:o("userID"),helperText:o("userIdHelperText"),autoFocus:!0,rules:{required:o("required")}}),e(Qe,{name:"userName",label:o("username"),helperText:o("usernameHelperText"),rules:{required:o("required")}})]})})})},_r=({userId:t})=>{const{adminClient:r}=$(),[a,n]=P(0),[p,o]=P(""),[i,g]=P(!1),{realm:m,realmRepresentation:h}=Ve(),{addAlert:u,addError:c}=ee(),{t:d}=K(),{hasAccess:y,hasSomeAccess:D}=Ge(),v=D("manage-identity-providers","view-identity-providers"),k=()=>n(new Date().getTime()),M=qt().identityProviders,J=async()=>{const b=await r.users.listFederatedIdentities({id:t});if(v){const L=await r.identityProviders.find();for(const E of b)E.providerId=L.find(Q=>Q.alias===E.identityProvider)?.providerId}return b},te=()=>h?.identityProviders,re=async()=>J(),_=async()=>{const b=(await J()).map(L=>L.identityProvider);return te()?.filter(L=>!b.includes(L.alias))},[z,x]=ue({titleKey:d("unlinkAccountTitle",{provider:pe(p)}),messageKey:d("unlinkAccountConfirm",{provider:pe(p)}),continueButtonLabel:"unlink",continueButtonVariant:le.primary,onConfirm:async()=>{try{await r.users.delFromFederatedIdentity({id:t,federatedIdentityId:p}),u(d("idpUnlinkSuccess"),G.success),k()}catch(b){c("mappingDeletedError",b)}}}),R=b=>v?e(_t,{to:zt({realm:m,providerId:b.providerId,alias:b.identityProvider,tab:"settings"}),children:pe(b.identityProvider)}):e("span",{children:pe(b.identityProvider)}),B=b=>{const L=M?.find(E=>E.id===b.identityProvider)?.groupName;return e(Ee,{color:L==="Social"?"blue":"orange",children:d(L==="Social"?"idpType.social":"idpType.custom")})},l=b=>{const L=M?.find(E=>E.id===b.providerId)?.groupName;return e(Ee,{color:L==="User-defined"?"orange":"blue",children:L==="User-defined"?"Custom":L==="Social"?d("idpType.social"):L})},A=b=>y("manage-users")?e(N,{variant:"link",onClick:()=>{o(b.identityProvider),z()},children:d("unlinkAccount")}):e("span",{}),V=b=>e(N,{variant:"link",onClick:()=>{o(b.alias),g(!0)},children:d("linkAccount")}),j=()=>{const b=[{name:"identityProvider",displayKey:"name",cellRenderer:R,transforms:[F(20)]},{name:"userId",displayKey:"userID",cellFormatters:[fe()],transforms:[F(30)]},{name:"userName",displayKey:"username",cellFormatters:[fe()],transforms:[F(20)]},{name:"",cellRenderer:A,transforms:[F(20)]}];return v&&b.splice(1,0,{name:"type",displayKey:"type",cellRenderer:B,transforms:[F(10)]}),b};return f(W,{children:[i&&e(Hr,{userId:t,federatedId:p,onClose:()=>g(!1),onRefresh:k}),e(x,{}),f(me,{variant:"light",className:"pf-v5-u-p-0",children:[f(Xe,{title:d("linkedIdPs"),className:"kc-linked-idps",children:[e(ve,{children:e(ke,{className:"kc-available-idps-text",children:d("linkedIdPsText")})}),e(Pe,{loader:re,isPaginated:!1,ariaLabelKey:"LinkedIdPs",className:"kc-linked-IdPs-table",columns:j(),emptyState:e(ve,{className:"kc-no-providers-text",children:e(ke,{children:d("noProvidersLinked")})})},a)]}),y("manage-users")&&v&&f(Xe,{className:"kc-available-idps",title:d("availableIdPs"),children:[e(ve,{children:e(ke,{className:"kc-available-idps-text",children:d("availableIdPsText")})}),e(Pe,{loader:_,isPaginated:!1,ariaLabelKey:"LinkedIdPs",className:"kc-linked-IdPs-table",columns:[{name:"alias",displayKey:"name",cellFormatters:[fe(),Ht()],transforms:[F(20)]},{name:"type",displayKey:"type",cellRenderer:l,transforms:[F(60)]},{name:"",cellRenderer:V}],emptyState:e(ve,{className:"kc-no-providers-text",children:e(ke,{children:d("noAvailableIdentityProviders")})})},a)]})]})]})},zr=({id:t,name:r})=>{const{adminClient:a}=$(),{t:n}=K(),{addAlert:p,addError:o}=ee();return e(Pr,{name:r,id:t,type:"users",save:async g=>{try{const m=g.filter(h=>h.client===void 0).map(h=>h.role).flat();await a.users.addRealmRoleMappings({id:t,roles:m}),await Promise.all(g.filter(h=>h.client!==void 0).map(h=>a.users.addClientRoleMappings({id:t,clientUniqueId:h.client.id,roles:[h.role]}))),p(n("userRoleMappingUpdatedSuccess"),G.success)}catch(m){o("roleMappingUpdatedError",m)}}})},Wr=()=>{const{adminClient:t}=$(),{id:r}=je(),{realm:a}=Ve(),{t:n}=K();return e(me,{variant:"light",className:"pf-v5-u-p-0",children:e(gr,{loader:()=>t.users.listSessions({id:r,realm:a}),hiddenColumns:["username","type"],emptyInstructions:n("noSessionsForUser"),logoutUser:r})})};function qs(){const{adminClient:t}=$(),{t:r}=K(),{addAlert:a,addError:n}=ee(),p=Wt(),{hasAccess:o}=Ge(),{id:i}=je(),{realm:g,realmRepresentation:m}=Ve(),u=be({mode:"onChange",resolver:async C=>({values:C,errors:{}})}),[c,d]=P(),[y,D]=P(),[v,k]=P(),[M,J]=P(),[te,re]=P(0),_=()=>re(C=>C+1),z=fr(c?.id),[x,R]=P(),B=C=>Xt({realm:g,id:c?.id||"",tab:C}),l=C=>rr(B(C)),A=l("settings"),V=l("attributes"),j=l("credentials"),b=l("role-mapping"),L=l("groups"),E=l("consents"),Q=l("identity-provider-links"),he=l("sessions");Ue(async()=>Promise.all([t.users.findOne({id:i,userProfileMetadata:!0}),t.attackDetection.findOne({id:i}),t.users.getUnmanagedAttributes({id:i}),t.users.getProfile({realm:g})]),([C,se,Y,ae])=>{if(!C||!m||!se)throw new Error(r("notFound"));const{userProfileMetadata:Z,...q}=C;J(Z),q.unmanagedAttributes=Y,q.attributes=cr(q.attributes,Y),ae.unmanagedAttributePolicy!==void 0&&k(!0),d(q),R(ae);const ne=m.bruteForceProtected,ge=ne&&se.disabled;D({isBruteForceProtected:ne,isLocked:ge}),u.reset(Ne(q))},[te]);const X=async C=>{try{await t.users.update({id:c.id},lr(C)),a(r("userSaved"),G.success),_()}catch(se){if(Yt(se)){if(v&&Array.isArray(C.unmanagedAttributes)){const Y=new Array(C.unmanagedAttributes.length);let ae=!1;Ye(se,(Z,q)=>{if(Z.startsWith("attributes.")){const ne=Z.substring(11);C.unmanagedAttributes.forEach((ge,we)=>{ge.key===ne&&(Y[we]=q,ae=!0)})}else u.setError(Z,q)},(Z,q)=>r(Z,q)),ae&&u.setError("unmanagedAttributes",Y)}else Ye(se,u.setError,(Y,ae)=>r(Y,ae));n("userNotSaved","")}else n("userCreateError",se)}},[Ae,Le]=ue({titleKey:"deleteConfirm",messageKey:"deleteConfirmCurrentUser",continueButtonLabel:"delete",continueButtonVariant:le.danger,onConfirm:async()=>{try{z?await t.users.logout({id:c.id}):await t.users.del({id:c.id}),a(r("userDeletedSuccess"),G.success),p($t({realm:g}))}catch(C){n("userDeletedError",C)}}}),[ye,Ce]=ue({titleKey:"impersonateConfirm",messageKey:"impersonateConfirmDialog",continueButtonLabel:"impersonate",onConfirm:async()=>{try{const C=await t.users.impersonation({id:c.id},{user:c.id,realm:g});C.sameRealm?window.location=C.redirect:window.open(C.redirect,"_blank")}catch(C){n("impersonateError",C)}}});return!c||!y?e(nt,{}):f(W,{children:[e(Ce,{}),e(Le,{}),e(sr,{titleKey:c.username,className:"kc-username-view-header",divider:!1,badges:z?[{text:e(Jt,{content:r("transientUserTooltip"),children:e(Ee,{"data-testid":"user-details-label-transient-user",icon:e(Qt,{}),children:r("transientUser")})})}]:[],dropdownItems:[e(xe,{isDisabled:!c.access?.impersonate,onClick:()=>ye(),children:r("impersonate")},"impersonate"),e(xe,{isDisabled:!c.access?.manage,onClick:()=>Ae(),children:r("delete")},"delete")],onToggle:C=>X({...Ne(c),enabled:C}),isEnabled:c.enabled}),e(me,{variant:"light",className:"pf-v5-u-p-0",children:e(ar,{children:e(De,{...u,children:f(tr,{isBox:!0,mountOnEnter:!0,defaultLocation:B("settings"),children:[e(oe,{"data-testid":"user-details-tab",title:e(de,{children:r("details")}),...A,children:e(me,{variant:"light",children:e(dr,{form:u,realm:m,user:c,bruteForce:y,userProfileMetadata:M,save:X})})}),v&&e(oe,{"data-testid":"attributes",title:e(de,{children:r("attributes")}),...V,children:e(Er,{user:c,save:X,upConfig:x})}),e(oe,{"data-testid":"credentials",isHidden:!c.access?.view,title:e(de,{children:r("credentials")}),...j,children:e(jr,{user:c,setUser:d})}),e(oe,{"data-testid":"role-mapping-tab",isHidden:!c.access?.view,title:e(de,{children:r("roleMapping")}),...b,children:e(zr,{id:c.id,name:c.username})}),o("query-groups")&&e(oe,{"data-testid":"user-groups-tab",title:e(de,{children:r("groups")}),...L,children:e(qr,{user:c})}),e(oe,{"data-testid":"user-consents-tab",title:e(de,{children:r("consents")}),...E,children:e(Nr,{})}),e(oe,{"data-testid":"identity-provider-links-tab",title:e(de,{children:r("identityProviderLinks")}),...Q,children:e(_r,{userId:c.id})}),e(oe,{"data-testid":"user-sessions-tab",title:e(de,{children:r("sessions")}),...he,children:e(Wr,{})})]})})})})]})}export{qs as default};
//# sourceMappingURL=EditUser-Ad2pc0MX.js.map