All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.EditUser-c3171d23.js Maven / Gradle / Ivy

There is a newer version: 25.0.1
Show newest version
import{bp as qe,c3 as is,c4 as os,c7 as Ee,c6 as ds,c5 as ls,bk as cs,bz as Ae,bj as ms,cw as us,bh as ps,dq as hs,dr as fs,ds as gs,dt as xs,du as bs,dv as ys,a as He,j as e,P as se,bG as ye,r as w,u as R,d as z,l as Z,g as b,A as U,a8 as O,a1 as ze,B as L,D as js,bJ as ws,a7 as Cs,G as je,e as oe,F as J,dw as Is,dx as vs,h as Ce,C as _e,Q as ks,f as We,V as G,S as Ps,q as ue,K as $e,X as Ts,at as Ne,Y as Ss,au as Qe,M as Ds,bH as Ls,c as he,W as Fs,N as de,a$ as Rs,L as Es,bN as As,o as Ue,b as Ns,dy as Us,aO as Ms}from"./index-831988f6.js";import{u as te,C as Xe}from"./ConfirmDialog-927d61dd.js";import{R as Bs,u as Ks}from"./RoutableTabs-8afbc312.js";import{V as Os}from"./ViewHeader-2b1ad3ef.js";import{U as Gs}from"./UserProfileContext-32e12bef.js";import{u as Vs,F as qs}from"./useIsFeatureEnabled-d2f044ea.js";import{u as Ie}from"./useParams-6d64d61e.js";import{u as Hs}from"./useUpdateEffect-f4b10551.js";import{A as zs}from"./AttributeForm-022c18f3.js";import{a as ce,R as _s,F as Ws,U as $s,t as Qs,i as Xs,u as Ys}from"./form-state-bdbf39d3.js";import{L as ve}from"./PaginatingTableToolbar-c55a17f1.js";import{K as pe,T as Js,m as Zs,n as et,P as st}from"./KeycloakDataTable-2267a354.js";import{u as tt}from"./useFormatDate-abfcb505.js";import{X as rt,N,Y as at,S as F,T as Me,O as Be,P as ne,Q as H,R as Ke,V as be}from"./Td-bb613d18.js";import{C as nt,S as it}from"./SessionsTable-fafa2640.js";import{C as ot,c as dt}from"./Select-9c61d949.js";import{u as we}from"./useToggle-039c9b34.js";import{u as lt}from"./useLocaleSort-6d6b4eec.js";import{M as Ye,a as ke}from"./Modal-5d8a3df4.js";import{K as me}from"./KeycloakTextInput-ead44014.js";import{F as fe}from"./Form-bd3cf98e.js";import{T as ct}from"./TimeSelector-8c03a95f.js";import{P as Oe}from"./PasswordInput-8b14c85c.js";import{G as mt,a as ut}from"./GroupPickerDialog-71e86661.js";import{C as pt}from"./Checkbox-d44d2684.js";import{Q as ht}from"./question-circle-icon-b8a84e76.js";import{F as Ge}from"./FormPanel-c74fde48.js";import{c as ie}from"./capitalize-9cb33771.js";import{T as le}from"./Text-2a2c2dcc.js";import{R as ft}from"./AddRoleMappingModal-e0605cd7.js";import"./user-section-9e42f5e8.js";import{a as X,b as Y}from"./Tabs-f8972b46.js";import"./ToolbarContent-186be8fd.js";import"./FormAccess-589a8032.js";import"./copy-icon-476b0d6d.js";import"./GridItem-2c75fd83.js";import"./KeyValueInput-edcd33df.js";import"./minus-icon-9c8a6df2.js";import"./minus-circle-icon-d374d13f.js";import"./ActionListItem-90f0e72b.js";import"./plus-circle-icon-3c14c705.js";import"./EmptyStateBody-dd392e69.js";import"./ScrollForm-4efa2caf.js";import"./Radio-94b05d7e.js";import"./KeycloakTextArea-3e2614e3.js";import"./EmptyStateSecondaryActions-3d9f7969.js";import"./TableToolbar-af5dff6f.js";import"./star-icon-f5649401.js";import"./check-fc57dbe1.js";import"./grip-vertical-icon-0333850c.js";import"./ListItem-dbf5a2d8.js";import"./admin-ui-endpoint-cc06c193.js";import"./getAuthorizationHeaders-f2376d1a.js";import"./DataListItemRow-e4e4ea8b.js";import"./data-list-7d55714c.js";import"./CardHeader-e4f1d51b.js";import"./Card-f255349a.js";import"./CardTitle-234a430a.js";import"./CardBody-7b8c88cd.js";import"./resource-edcf6e4d.js";import"./filter-icon-5bbef384.js";import"./plus-icon-1b237b1a.js";import"./MenuList-d75eeee8.js";var gt=Math.min;function xt(s,t,n){for(var o=n?ds:ls,a=s[0].length,x=s.length,l=x,m=Array(x),c=1/0,f=[];l--;){var i=s[l];l&&t&&(i=qe(i,is(t))),c=gt(i.length,c),m[l]=!n&&(t||a>=120&&i.length>=120)?new os(l&&i):void 0}i=s[0];var g=-1,y=m[0];e:for(;++g{const n=He();return e.jsx(se,{variant:ye.light,children:e.jsx(zs,{form:n,save:t,fineGrainedAccess:s.access?.manage,reset:()=>n.reset({...n.getValues(),attributes:ce(s).attributes})})})},Pt=()=>{const[s,t]=w.useState(),{t:n}=R("roles"),{addAlert:o,addError:a}=z(),x=tt(),[l,m]=w.useState(0),{id:c}=Ie(),f=p=>ze(p,E=>E.clientId?.toUpperCase()),i=()=>m(new Date().getTime()),g=async()=>{const p=await b.users.listConsents({id:c});return f(p)},y=({grantedClientScopes:p})=>e.jsx(ot,{className:"kc-consents-chip-group",children:p.map(E=>e.jsx(dt,{isReadOnly:!0,className:"kc-consents-chip",children:E},E))}),[u,k]=te({titleKey:"users:revokeClientScopesTitle",messageKey:n("users:revokeClientScopes",{clientId:s?.clientId}),continueButtonLabel:"common:revoke",continueButtonVariant:Z.danger,onConfirm:async()=>{try{await b.users.revokeConsent({id:c,clientId:s.clientId}),i(),o(n("deleteGrantsSuccess"),U.success)}catch(p){a("roles:deleteGrantsError",p)}}});return e.jsxs(e.Fragment,{children:[e.jsx(k,{}),e.jsx(pe,{loader:g,ariaLabelKey:"roles:roleList",searchPlaceholderKey:" ",columns:[{name:"clientId",displayKey:"clients:Client",cellFormatters:[O()],transforms:[N(20)]},{name:"grantedClientScopes",displayKey:"client-scopes:grantedClientScopes",cellFormatters:[O()],cellRenderer:y,transforms:[N(30)]},{name:"createDate",displayKey:"clients:created",transforms:[N(20)],cellRenderer:({createDate:p})=>p?x(new Date(p)):"—"},{name:"lastUpdatedDate",displayKey:"clients:lastUpdated",transforms:[N(10)],cellRenderer:({lastUpdatedDate:p})=>p?x(new Date(p)):"—"}],actions:[{title:n("users:revoke"),onRowClick:p=>{t(p),u()}}],emptyState:e.jsx(ve,{hasIcon:!0,icon:nt,message:n("users:noConsents"),instructions:n("users:noConsentsText")})},l)]})},Tt=({credentialData:s,onClose:t})=>{const{t:n}=R("users");return e.jsx(Ye,{variant:ke.medium,title:n("passwordDataTitle"),"data-testid":"passwordDataDialog",isOpen:!0,onClose:t,children:e.jsxs(Js,{"aria-label":n("passwordDataTitle"),"data-testid":"password-data-dialog",variant:at.compact,cells:[n("showPasswordDataName"),n("showPasswordDataValue")],rows:s,children:[e.jsx(Zs,{}),e.jsx(et,{})]})})},St=({credential:s,resetPassword:t,toggleDelete:n,children:o})=>{const{t:a}=R("users"),[x,l]=we(),[m,c]=we(),f=lt(),i=w.useMemo(()=>{if(!s.credentialData)return[];const g=JSON.parse(s.credentialData);return f(Object.entries(g),([y])=>y).map(([y,u])=>typeof u=="string"?[y,u]:[y,JSON.stringify(u)])},[s.credentialData]);return e.jsxs(e.Fragment,{children:[x&&Object.keys(s).length!==0&&e.jsx(Tt,{credentialData:i,onClose:()=>{l()}}),e.jsx(F,{children:o}),e.jsx(F,{children:e.jsx(L,{className:"kc-showData-btn",variant:"link","data-testid":"showDataBtn",onClick:l,children:a("showDataBtn")})}),s.type==="password"?e.jsx(F,{isActionCell:!0,children:e.jsx(L,{variant:"secondary","data-testid":"resetPasswordBtn",onClick:t,children:a("resetPasswordBtn")})}):e.jsx(F,{}),e.jsx(F,{isActionCell:!0,children:e.jsx(js,{isPlain:!0,position:ws.right,toggle:e.jsx(Cs,{onToggle:c}),isOpen:m,dropdownItems:[e.jsx(je,{"data-testid":"deleteDropdownItem",component:"button",onClick:()=>{n(),c()},children:a("deleteBtn")},s.id)]})})]})},Dt=({userId:s,credential:t,isEditable:n,toggle:o})=>{const{t:a}=R("users"),{register:x,handleSubmit:l}=oe(),{addAlert:m,addError:c}=z(),f=async i=>{try{await b.users.updateCredentialLabel({id:s,credentialId:t.id},i.userLabel||""),m(a("updateCredentialUserLabelSuccess"),U.success),o()}catch(g){c("users:updateCredentialUserLabelError",g)}};return e.jsx(fe,{isHorizontal:!0,className:"kc-form-userLabel",onSubmit:l(f),children:e.jsx(J,{fieldId:"kc-userLabel",className:"kc-userLabel-row",children:e.jsx("div",{className:"kc-form-group-userLabel",children:n?e.jsxs(e.Fragment,{children:[e.jsx(me,{"data-testid":"userLabelFld",defaultValue:t.userLabel,className:"kc-userLabel","aria-label":a("userLabel"),...x("userLabel")}),e.jsxs("div",{className:"kc-userLabel-actionBtns",children:[e.jsx(L,{"data-testid":"editUserLabelAcceptBtn",variant:"link",className:"kc-editUserLabelAcceptBtn",type:"submit",icon:e.jsx(Is,{})}),e.jsx(L,{"data-testid":"editUserLabelCancelBtn",variant:"link",className:"kc-editUserLabel-cancelBtn",onClick:o,icon:e.jsx(vs,{})})]})]}):e.jsxs(e.Fragment,{children:[t.userLabel,e.jsx(L,{"aria-label":a("editUserLabel"),variant:"link",className:"kc-editUserLabel-btn",onClick:o,"data-testid":"editUserLabelBtn",icon:e.jsx(st,{})})]})})})})},Lt=()=>{const{t:s}=R("users"),{control:t}=He();return e.jsx(J,{fieldId:"lifespan",label:s("lifespan"),isStack:!0,labelIcon:e.jsx(Ce,{helpText:s("clients-help:lifespan"),fieldLabelId:"lifespan"}),children:e.jsx(_e,{name:"lifespan",defaultValue:Je.lifespan,control:t,render:({field:n})=>e.jsx(ct,{value:n.value,units:["minute","hour","day"],onChange:n.onChange,menuAppendTo:"parent"})})})},Je={actions:[],lifespan:43200},Ft=({userId:s,onClose:t})=>{const{t:n}=R("users"),o=oe({defaultValues:Je}),{handleSubmit:a,control:x}=o,l=ks({control:x,name:"actions"}),m=!Ve(l),{addAlert:c,addError:f}=z(),i=async({actions:g,lifespan:y})=>{if(!Ve(g))try{await b.users.executeActionsEmail({id:s,actions:g,lifespan:y}),c(n("credentialResetEmailSuccess"),U.success),t()}catch(u){f("users:credentialResetEmailError",u)}};return e.jsx(Xe,{variant:ke.medium,titleKey:"users:credentialReset",open:!0,onCancel:t,toggleDialog:t,continueButtonLabel:"users:credentialResetConfirm",onConfirm:()=>{a(i)()},confirmButtonDisabled:!m,children:e.jsx(fe,{id:"userCredentialsReset-form",isHorizontal:!0,"data-testid":"credential-reset-modal",children:e.jsxs(We,{...o,children:[e.jsx(_s,{name:"actions",label:"resetActions",help:"clients-help:resetActions"}),e.jsx(Lt,{})]})})})},Rt={password:"",passwordConfirmation:"",temporaryPassword:!0},Et=({user:s,isResetPassword:t,refresh:n,onClose:o})=>{const{t:a}=R("users"),{register:x,control:l,formState:{isValid:m,errors:c},watch:f,handleSubmit:i,clearErrors:g,setError:y}=oe({defaultValues:Rt,mode:"onChange"}),[u,k]=we(!0),p=f("password",""),E=f("passwordConfirmation",""),{addAlert:_,addError:W}=z(),[M,q]=te({titleKey:t?"users:resetPasswordConfirm":"users:setPasswordConfirm",messageKey:t?a("resetPasswordConfirmText",{username:s.username}):a("setPasswordConfirmText",{username:s.username}),continueButtonLabel:t?"users:resetPassword":"users:savePassword",continueButtonVariant:Z.danger,onConfirm:()=>i(S)()}),S=async({password:h,temporaryPassword:d})=>{try{await b.users.resetPassword({id:s.id,credential:{temporary:d,type:"password",value:h}});const B=(await b.users.getCredentials({id:s.id})).find($=>$.type==="password");B&&await b.users.updateCredentialLabel({id:s.id,credentialId:B.id},a("defaultPasswordLabel")),_(a(t?"resetCredentialsSuccess":"savePasswordSuccess"),U.success),n()}catch(v){W(t?"users:resetPasswordError":"users:savePasswordError",v)}o()},{onChange:D,...A}=x("password",{required:!0});return e.jsxs(e.Fragment,{children:[e.jsx(q,{}),e.jsx(Xe,{titleKey:t?a("resetPasswordFor",{username:s.username}):a("setPasswordFor",{username:s.username}),open:u,onCancel:o,toggleDialog:k,onConfirm:M,confirmButtonDisabled:!m,continueButtonLabel:"common:save",children:e.jsxs(fe,{id:"userCredentials-form",isHorizontal:!0,className:"keycloak__user-credentials__reset-form",children:[e.jsx(J,{name:"password",label:a("password"),fieldId:"password",helperTextInvalid:a("common:required"),validated:c.password?G.error:G.default,isRequired:!0,children:e.jsx(Oe,{"data-testid":"passwordField",id:"password",onChange:h=>{D(h),E!==h.currentTarget.value?y("passwordConfirmation",{message:a("confirmPasswordDoesNotMatch").toString()}):g("passwordConfirmation")},...A})}),e.jsx(J,{name:"passwordConfirmation",label:a(t?"resetPasswordConfirmation":"passwordConfirmation"),fieldId:"passwordConfirmation",helperTextInvalid:c.passwordConfirmation?.message,validated:c.passwordConfirmation?G.error:G.default,isRequired:!0,children:e.jsx(Oe,{"data-testid":"passwordConfirmationField",id:"passwordConfirmation",...x("passwordConfirmation",{required:!0,validate:h=>h===p||a("confirmPasswordDoesNotMatch").toString()})})}),e.jsx(J,{label:a("common:temporaryPassword"),labelIcon:e.jsx(Ce,{helpText:a("common:temporaryPasswordHelpText"),fieldLabelId:"temporaryPassword"}),fieldId:"kc-temporaryPassword",children:e.jsx(_e,{name:"temporaryPassword",defaultValue:!0,control:l,render:({field:h})=>e.jsx(Ps,{className:"kc-temporaryPassword",onChange:h.onChange,isChecked:h.value,label:a("common:on"),labelOff:a("common:off"),"aria-label":a("common:temporaryPassword")})})})]})})]})};const At=({user:s})=>{const{t}=R("users"),{addAlert:n,addError:o}=z(),[a,x]=w.useState(0),l=()=>x(a+1),[m,c]=w.useState(!1),[f,i]=w.useState(!1),[g,y]=w.useState([]),[u,k]=w.useState([]),[p,E]=w.useState({}),[_,W]=w.useState(!1),[M,q]=w.useState(),S=w.useRef(null),[D,A]=w.useState({draggedItemId:"",draggingToItemIndex:-1,dragging:!1,tempItemOrder:[""]});ue(()=>b.users.getCredentials({id:s.id}),r=>{y(r);const C=r.reduce((I,T)=>(I[T.type]=I[T.type]||[],I[T.type].push(T),I),Object.create(null)),j=Object.keys(C).map(I=>({key:I,value:C[I]}));k(j.map(I=>({...I,isExpanded:!1})))},[a]);const h=g.find(r=>r.type==="password"),d=()=>c(!m),v=()=>{i(!f)},B=()=>{W(!0),d()},[$,P]=te({titleKey:t("deleteCredentialsConfirmTitle"),messageKey:t("deleteCredentialsConfirm"),continueButtonLabel:t("common:delete"),continueButtonVariant:Z.danger,onConfirm:async()=>{try{await b.users.deleteCredential({id:s.id,credentialId:p.id}),n(t("deleteCredentialsSuccess"),U.success),x(r=>r+1)}catch(r){o("users:deleteCredentialsError",r)}}}),V=({credential:r})=>e.jsx(St,{credential:r,toggleDelete:()=>{E(r),$()},resetPassword:B,children:e.jsx(Dt,{credential:r,userId:s.id,isEditable:M?.status&&M.rowKey===r.id||!1,toggle:()=>{q({status:!M?.status,rowKey:r.id}),M?.status&&l()}})},r.id),ee=w.useMemo(()=>u.flatMap(r=>[r.value.map(({id:C})=>C).toString(),...r.isExpanded?r.value.map(C=>C.id):[]]),[u]),re=r=>{r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",r.currentTarget.id);const C=r.currentTarget.id;r.currentTarget.classList.add(be.modifiers.ghostRow),r.currentTarget.setAttribute("aria-pressed","true"),A({...D,draggedItemId:C,dragging:!0})},ge=(r,C,j)=>{const I=r.indexOf(C);if(I===j)return r;const T=[...r];return T.splice(j,0,T.splice(I,1)[0]),T},ae=r=>{if(!S.current)return;const C=S.current,j=Array.from(C.children);j.every(({id:I},T)=>I===r[T])||(C.replaceChildren(),r.forEach(I=>{C.appendChild(j.find(({id:T})=>T===I))}))},Ze=()=>{S.current&&(Array.from(S.current.children).forEach(r=>{r.classList.remove(be.modifiers.ghostRow),r.setAttribute("aria-pressed","false")}),A({...D,draggedItemId:"",draggingToItemIndex:-1,dragging:!1}))},es=r=>{Pe(r)||(ae(ee),A({...D,draggingToItemIndex:-1}))},Pe=r=>{if(!S.current)return!1;const C=S.current.getBoundingClientRect();return r.clientX>C.x&&r.clientXC.y&&r.clientY{Pe(r)?ss(D.draggedItemId,D.tempItemOrder):Ze()},Se=r=>{r.preventDefault();const j=r.target.closest("tr");if(!(!j||S.current&&!S.current.contains(j)||j.id===D.draggedItemId)){const I=j.id,T=Array.from(S.current?.children||[]).findIndex(K=>K.id===I);if(T===D.draggingToItemIndex)return;const Q=ge(ee,D.draggedItemId,T);ae(Q),A({...D,draggingToItemIndex:T,tempItemOrder:Q})}},De=({target:r})=>{r instanceof HTMLTableRowElement&&(r.classList.remove(be.modifiers.ghostRow),r.setAttribute("aria-pressed","false"),A({...D,draggedItemId:"",draggingToItemIndex:-1,dragging:!1}))},ss=async(r,C)=>{const j=ee.findIndex(K=>K===r),I=C.findIndex(K=>K===r),T=I-j,Q=r.split(",");try{for(const K of Q)for(let Re=0;Re0?await b.users.moveCredentialPositionDown({id:s.id,credentialId:K,newPreviousCredentialId:ee[I]}):await b.users.moveCredentialPositionUp({id:s.id,credentialId:K});l(),n(t("users:updatedCredentialMoveSuccess"),U.success)}catch(K){o("users:updatedCredentialMoveError",K)}},ts=s.federationLink||s.origin,[xe,rs]=w.useState([]);if(ue(()=>b.users.getUserStorageCredentialTypes({id:s.id}),rs,[]),!xe)return e.jsx($e,{});const Le=xe.length>0,as=u.length===0,ns=!s.credentials||s.credentials.length===0,Fe=as&&ns&&!Le;return e.jsxs(e.Fragment,{children:[m&&e.jsx(Et,{user:s,isResetPassword:_,refresh:l,onClose:()=>c(!1)}),f&&e.jsx(Ft,{userId:s.id,onClose:()=>i(!1)}),e.jsx(P,{}),s.email&&!Fe&&e.jsx(L,{className:"kc-resetCredentialBtn-header",variant:"primary","data-testid":"credentialResetBtn",onClick:()=>i(!0),children:t("credentialResetBtn")}),g.length!==0&&h===void 0&&e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"kc-setPasswordBtn-tbl","data-testid":"setPasswordBtn-table",variant:"primary",form:"userCredentials-form",onClick:()=>{c(!0)},children:t("setPassword")}),e.jsx(Ts,{})]}),u.length!==0&&e.jsx(se,{variant:ye.light,children:e.jsxs(Me,{variant:"compact",children:[e.jsx(Be,{children:e.jsxs(ne,{className:"kc-table-header",children:[e.jsx(H,{children:e.jsx(Ce,{helpText:t("users:userCredentialsHelpText"),fieldLabelId:"users:userCredentialsHelpTextLabel"})}),e.jsx(H,{"aria-hidden":"true"}),e.jsx(H,{children:t("type")}),e.jsx(H,{children:t("userLabel")}),e.jsx(H,{children:t("data")}),e.jsx(H,{"aria-hidden":"true"}),e.jsx(H,{"aria-hidden":"true"})]})}),e.jsx(Ke,{ref:S,onDragOver:Se,onDrop:Se,onDragLeave:es,children:u.map((r,C)=>e.jsxs(w.Fragment,{children:[e.jsxs(ne,{id:r.value.map(({id:j})=>j).toString(),draggable:u.length>1,onDrop:Te,onDragEnd:De,onDragStart:re,children:[e.jsx(F,{className:u.length===1?"one-row":"",draggableRow:{id:`draggable-row-${r.value.map(({id:j})=>j)}`}}),r.value.length>1?e.jsx(F,{className:"kc-expandRow-btn",expand:{rowIndex:C,isExpanded:r.isExpanded,onToggle:(j,I)=>{const T=u.map((Q,K)=>K===I?{...Q,isExpanded:!Q.isExpanded}:Q);k(T)}}}):e.jsx(F,{}),e.jsx(F,{dataLabel:`columns-${r.key}`,className:"kc-notExpandableRow-credentialType","data-testid":"credentialType",children:Ne(r.key)}),r.value.length<=1&&r.value.map(j=>e.jsx(V,{credential:j},j.id))]}),r.isExpanded&&r.value.map(j=>e.jsxs(ne,{id:j.id,draggable:!0,onDrop:Te,onDragEnd:De,onDragStart:re,children:[e.jsx(F,{}),e.jsx(F,{className:"kc-draggable-dropdown-type-icon",draggableRow:{id:`draggable-row-${r.value.map(({id:I})=>I)}`}}),e.jsx(F,{dataLabel:`child-columns-${j.id}`,className:"kc-expandableRow-credentialType",children:Ne(j.type)}),e.jsx(V,{credential:j})]},j.id))]},r.key))})]})}),ts&&Le&&e.jsx(se,{variant:ye.light,children:e.jsxs(Me,{variant:"compact",children:[e.jsx(Be,{children:e.jsxs(ne,{children:[e.jsx(H,{children:t("type")}),e.jsx(H,{children:t("providedBy")}),e.jsx(H,{"aria-hidden":"true"})]})}),e.jsx(Ke,{children:xe.map(r=>e.jsxs(ne,{children:[e.jsx(F,{children:e.jsx("b",{children:r})}),e.jsx(F,{children:e.jsx(Ws,{user:s})}),r==="password"&&e.jsx(F,{modifier:"fitContent",children:e.jsx(L,{variant:"secondary",onClick:d,children:t("setPassword")})})]},r))})]})}),Fe&&e.jsx(ve,{hasIcon:!0,message:t("noCredentials"),instructions:t("noCredentialsText"),primaryActionText:t("setPassword"),onPrimaryAction:d,secondaryActions:s.email?[{text:t("credentialResetBtn"),onClick:v,type:Z.link}]:void 0})]})},Nt=({user:s})=>{const{t}=R("users"),{addAlert:n,addError:o}=z(),[a,x]=w.useState(0),l=()=>x(a+1),[m,c]=w.useState([]),[f,i]=w.useState(!0),[g,y]=w.useState([]),[u,k]=w.useState(!1),{enabled:p}=Ss(),{hasAccess:E}=Qe(),_=E("manage-users"),W=d=>ze(d,v=>v.path?.toUpperCase()),M=async(d,v,B)=>{const $={first:d,max:v},P=B||"";P&&($.search=P);const V=await b.users.listGroups({...$,id:s.id});y([...V]);const ee=[];return f||V.forEach(re=>{const ge=re.path?.substring(1).split("/").slice(0,-1)||[];ee.push(...ge.map(ae=>({name:ae,path:re.path?.substring(0,re.path.indexOf(ae)+ae.length)})))}),W(Ls([...V,...ee],"path"))},q=()=>{k(!u)},[S,D]=te({titleKey:t("leaveGroup",{count:m.length,name:m[0]?.name}),messageKey:t("leaveGroupConfirmDialog",{count:m.length,groupname:m[0]?.name,username:s.username}),continueButtonLabel:"leave",continueButtonVariant:Z.danger,onConfirm:async()=>{try{await Promise.all(m.map(d=>b.users.delFromGroup({id:s.id,groupId:d.id}))),n(t("removedGroupMembership"),U.success)}catch(d){o("users:removedGroupMembershipError",d)}l()}}),A=d=>{c(d),S()},h=async d=>{try{await Promise.all(d.map(v=>b.users.addToGroup({id:s.id,groupId:v.id}))),n(t("addedGroupMembership"),U.success)}catch(v){o("users:addedGroupMembershipError",v)}l()};return e.jsxs(e.Fragment,{children:[e.jsx(D,{}),u&&e.jsx(mt,{id:s.id,type:"selectMany",text:{title:t("joinGroupsFor",{username:s.username}),ok:"users:join"},canBrowse:_,onClose:()=>k(!1),onConfirm:async(d=[])=>{await h(d),k(!1)}}),e.jsx(pe,{loader:M,className:"keycloak_user-section_groups-table",isPaginated:!0,ariaLabelKey:"roles:roleList",searchPlaceholderKey:"groups:searchGroup",canSelectAll:!0,onSelect:d=>c(f?d:jt(d,g,"id")),isRowDisabled:d=>!f&&g.every(v=>v.id!==d.id),toolbarItem:e.jsxs(e.Fragment,{children:[e.jsx(L,{className:"kc-join-group-button",onClick:q,"data-testid":"add-group-button",isDisabled:!s.access?.manageGroupMembership,children:t("joinGroup")}),e.jsx(pt,{label:t("directMembership"),id:"kc-direct-membership-checkbox",onChange:()=>{i(!f),l()},isChecked:f,className:"direct-membership-check"},"direct-membership-check"),e.jsx(L,{onClick:()=>A(m),"data-testid":"leave-group-button",variant:"link",isDisabled:m.length===0,children:t("leave")}),p&&e.jsx(Ds,{"aria-label":"Basic popover",position:"bottom",bodyContent:e.jsx("div",{children:t("whoWillAppearPopoverText")}),children:e.jsx(L,{variant:"link",className:"kc-who-will-appear-button",icon:e.jsx(ht,{}),children:t("whoWillAppearLinkText")},"who-will-appear-button")})]}),columns:[{name:"groupMembership",displayKey:"users:groupMembership",cellRenderer:d=>d.name||"",cellFormatters:[O()],transforms:[N(40)]},{name:"path",displayKey:"users:path",cellRenderer:d=>e.jsx(ut,{group:d}),transforms:[N(45)]},{name:"",cellRenderer:d=>g.some(B=>B.id===d.id)||g.length===0||f?e.jsx(L,{"data-testid":`leave-${d.name}`,onClick:()=>A([d]),variant:"link",isDisabled:!s.access?.manageGroupMembership,children:t("leave")}):"",cellFormatters:[O()],transforms:[N(20)]}],emptyState:e.jsx(ve,{hasIcon:!0,message:t("noGroups"),instructions:t("noGroupsText"),primaryActionText:t("joinGroup"),onPrimaryAction:q})},a)]})},Ut=({userId:s,federatedId:t,onClose:n,onRefresh:o})=>{const{t:a}=R("users"),{addAlert:x,addError:l}=z(),{register:m,handleSubmit:c,formState:{isValid:f,errors:i}}=oe({mode:"onChange"}),g=async y=>{try{await b.users.addToFederatedIdentity({id:s,federatedIdentityId:t,federatedIdentity:y}),x(a("users:idpLinkSuccess"),U.success),n(),o()}catch(u){l("users:couldNotLinkIdP",u)}};return e.jsx(Ye,{variant:ke.small,title:a("users:linkAccountTitle",{provider:ie(t)}),onClose:n,actions:[e.jsx(L,{"data-testid":"confirm",variant:"primary",type:"submit",form:"group-form",isDisabled:!f,children:a("link")},"confirm"),e.jsx(L,{"data-testid":"cancel",variant:Z.link,onClick:n,children:a("common:cancel")},"cancel")],isOpen:!0,children:e.jsxs(fe,{id:"group-form",onSubmit:c(g),children:[e.jsx(J,{label:a("users:identityProvider"),fieldId:"identityProvider",children:e.jsx(me,{id:"identityProvider","data-testid":"idpNameInput",value:ie(t),isReadOnly:!0})}),e.jsx(J,{label:a("users:userID"),fieldId:"userID",helperText:a("users-help:userIdHelperText"),helperTextInvalid:a("common:required"),validated:i.userId?G.error:G.default,isRequired:!0,children:e.jsx(me,{id:"userID","data-testid":"userIdInput",validated:i.userId?G.error:G.default,autoFocus:!0,...m("userId",{required:!0})})}),e.jsx(J,{label:a("users:username"),fieldId:"username",helperText:a("users-help:usernameHelperText"),helperTextInvalid:a("common:required"),validated:i.userName?G.error:G.default,isRequired:!0,children:e.jsx(me,{id:"username","data-testid":"usernameInput",validated:i.userName?G.error:G.default,...m("userName",{required:!0})})})]})})},Mt=({userId:s})=>{const[t,n]=w.useState(0),[o,a]=w.useState(""),[x,l]=w.useState(!1),{realm:m}=he(),{addAlert:c,addError:f}=z(),{t:i}=R("users"),g=()=>n(new Date().getTime()),y=Fs().identityProviders,u=async()=>{const h=await b.identityProviders.find(),d=await b.users.listFederatedIdentities({id:s});for(const v of d)v.providerId=h.find(B=>B.alias===v.identityProvider)?.providerId;return d},k=async()=>(await b.realms.findOne({realm:m})).identityProviders,p=async()=>u(),E=async()=>{const h=(await u()).map(d=>d.identityProvider);return(await k())?.filter(d=>!h.includes(d.alias))},[_,W]=te({titleKey:i("users:unlinkAccountTitle",{provider:ie(o)}),messageKey:i("users:unlinkAccountConfirm",{provider:ie(o)}),continueButtonLabel:"users:unlink",continueButtonVariant:Z.primary,onConfirm:async()=>{try{await b.users.delFromFederatedIdentity({id:s,federatedIdentityId:o}),c(i("users:idpUnlinkSuccess"),U.success),g()}catch(h){f("common:mappingDeletedError",h)}}}),M=h=>e.jsx(Es,{to:As({realm:m,providerId:h.providerId,alias:h.identityProvider,tab:"settings"}),children:ie(h.identityProvider)}),q=h=>{const d=y?.find(v=>v.id===h.identityProvider)?.groupName;return e.jsx(Ue,{color:d==="Social"?"blue":"orange",children:i(d==="Social"?"users:idpType.social":"users:idpType.custom")})},S=h=>{const d=y?.find(v=>v.id===h.providerId)?.groupName;return e.jsx(Ue,{color:d==="User-defined"?"orange":"blue",children:d==="User-defined"?"Custom":d==="Social"?i("users:idpType.social"):d})},D=h=>e.jsx(L,{variant:"link",onClick:()=>{a(h.identityProvider),_()},children:i("unlinkAccount")}),A=h=>e.jsx(L,{variant:"link",onClick:()=>{a(h.alias),l(!0)},children:i("linkAccount")});return e.jsxs(e.Fragment,{children:[x&&e.jsx(Ut,{userId:s,federatedId:o,onClose:()=>l(!1),onRefresh:g}),e.jsx(W,{}),e.jsxs(se,{variant:"light",className:"pf-u-p-0",children:[e.jsxs(Ge,{title:i("linkedIdPs"),className:"kc-linked-idps",children:[e.jsx(de,{children:e.jsx(le,{className:"kc-available-idps-text",children:i("linkedIdPsText")})}),e.jsx(pe,{loader:p,isPaginated:!1,ariaLabelKey:"users:LinkedIdPs",className:"kc-linked-IdPs-table",columns:[{name:"identityProvider",displayKey:"common:name",cellFormatters:[O()],cellRenderer:M,transforms:[N(20)]},{name:"type",displayKey:"common:type",cellFormatters:[O()],cellRenderer:q,transforms:[N(10)]},{name:"userId",displayKey:"users:userID",cellFormatters:[O()],transforms:[N(30)]},{name:"userName",displayKey:"users:username",cellFormatters:[O()],transforms:[N(20)]},{name:"",cellFormatters:[O()],cellRenderer:D,transforms:[N(20)]}],emptyState:e.jsx(de,{className:"kc-no-providers-text",children:e.jsx(le,{children:i("users:noProvidersLinked")})})},t)]}),e.jsxs(Ge,{className:"kc-available-idps",title:i("availableIdPs"),children:[e.jsx(de,{children:e.jsx(le,{className:"kc-available-idps-text",children:i("availableIdPsText")})}),e.jsx(pe,{loader:E,isPaginated:!1,ariaLabelKey:"users:LinkedIdPs",className:"kc-linked-IdPs-table",columns:[{name:"alias",displayKey:"common:name",cellFormatters:[O(),Rs()],transforms:[N(20)]},{name:"type",displayKey:"common:type",cellFormatters:[O()],cellRenderer:S,transforms:[N(60)]},{name:"",cellFormatters:[O()],cellRenderer:A}],emptyState:e.jsx(de,{className:"kc-no-providers-text",children:e.jsx(le,{children:i("users:noAvailableIdentityProviders")})})},t)]})]})]})},Bt=({id:s,name:t})=>{const{t:n}=R("users"),{addAlert:o,addError:a}=z(),x=async l=>{try{const m=l.filter(c=>c.client===void 0).map(c=>c.role).flat();await b.users.addRealmRoleMappings({id:s,roles:m}),await Promise.all(l.filter(c=>c.client!==void 0).map(c=>b.users.addClientRoleMappings({id:s,clientUniqueId:c.client.id,roles:[c.role]}))),o(n("roleMappingUpdatedSuccess"),U.success)}catch(m){a("clients:roleMappingUpdatedError",m)}};return e.jsx(ft,{name:t,id:s,type:"users",save:x})},Kt=()=>{const{id:s}=Ie(),{realm:t}=he(),{t:n}=R("sessions"),o=()=>b.users.listSessions({id:s,realm:t});return e.jsx(se,{variant:"light",className:"pf-u-p-0",children:e.jsx(it,{loader:o,hiddenColumns:["username","type"],emptyInstructions:n("noSessionsForUser"),logoutUser:s})})};function Xr(){const{realm:s}=he(),{id:t}=Ie(),{t:n}=R("users"),[o,a]=w.useState(),[x,l]=w.useState(),[m,c]=w.useState(0),f=()=>c(i=>i+1);return ue(async()=>{const[i,g,y]=await Promise.all([b.users.findOne({id:t,userProfileMetadata:!0}),b.realms.findOne({realm:s}),b.attackDetection.findOne({id:t})]);if(!i||!g||!y)throw new Error(n("common:notFound"));const u=g.bruteForceProtected,k=u&&y.disabled;return{user:i,bruteForced:{isBruteForceProtected:u,isLocked:k}}},({user:i,bruteForced:g})=>{a(i),l(g)},[m]),!o||!x?e.jsx($e,{}):e.jsx(Ot,{user:o,bruteForced:x,refresh:f})}const Ot=({user:s,bruteForced:t,refresh:n})=>{const{t:o}=R("users"),{realm:a}=he(),{addAlert:x,addError:l}=z(),m=Ns(),{hasAccess:c}=Qe(),f=oe({mode:"onChange",defaultValues:ce(s)}),[i,g]=w.useState();ue(()=>b.realms.findOne({realm:a}),P=>{if(!P)throw new Error(o("common:notFound"));g(P)},[]);const u=Vs()(qs.DeclarativeUserProfile)&&i?.attributes?.userProfileEnabled==="true",k=P=>Ms({realm:a,id:s.id,tab:P}),p=P=>Ks(k(P)),E=p("settings"),_=p("attributes"),W=p("credentials"),M=p("role-mapping"),q=p("groups"),S=p("consents"),D=p("identity-provider-links"),A=p("sessions");Hs(()=>f.reset(ce(s)),[s]);const h=async P=>{try{await b.users.update({id:s.id},Qs(P)),x(o("userSaved"),U.success),n()}catch(V){Xs(V)?l(Ys(V),V):l("users:userCreateError",V)}},[d,v]=te({titleKey:"users:deleteConfirm",messageKey:"users:deleteConfirmCurrentUser",continueButtonLabel:"common:delete",continueButtonVariant:Z.danger,onConfirm:async()=>{try{await b.users.del({id:s.id}),x(o("userDeletedSuccess"),U.success),m(Us({realm:a}))}catch(P){l("users:userDeletedError",P)}}}),[B,$]=te({titleKey:"users:impersonateConfirm",messageKey:"users:impersonateConfirmDialog",continueButtonLabel:"users:impersonate",onConfirm:async()=>{try{const P=await b.users.impersonation({id:s.id},{user:s.id,realm:a});P.sameRealm?window.location=P.redirect:window.open(P.redirect,"_blank")}catch(P){l("users:impersonateError",P)}}});return e.jsxs(e.Fragment,{children:[e.jsx($,{}),e.jsx(v,{}),e.jsx(Os,{titleKey:s.username,className:"kc-username-view-header",divider:!1,dropdownItems:[e.jsx(je,{isDisabled:!s.access?.impersonate,onClick:()=>B(),children:o("impersonate")},"impersonate"),e.jsx(je,{isDisabled:!s.access?.manage,onClick:()=>d(),children:o("common:delete")},"delete")],onToggle:P=>h({...ce(s),enabled:P}),isEnabled:s.enabled}),e.jsx(se,{variant:"light",className:"pf-u-p-0",children:e.jsx(Gs,{children:e.jsx(We,{...f,children:e.jsxs(Bs,{isBox:!0,mountOnEnter:!0,defaultLocation:k("settings"),children:[e.jsx(X,{"data-testid":"user-details-tab",title:e.jsx(Y,{children:o("common:details")}),...E,children:e.jsx(se,{variant:"light",children:e.jsx($s,{save:h,user:s,bruteForce:t,realm:i})})}),!u&&e.jsx(X,{"data-testid":"attributes",title:e.jsx(Y,{children:o("common:attributes")}),..._,children:e.jsx(kt,{user:s,save:h})}),e.jsx(X,{"data-testid":"credentials",isHidden:!s.access?.view,title:e.jsx(Y,{children:o("common:credentials")}),...W,children:e.jsx(At,{user:s})}),e.jsx(X,{"data-testid":"role-mapping-tab",isHidden:!s.access?.mapRoles,title:e.jsx(Y,{children:o("roleMapping")}),...M,children:e.jsx(Bt,{id:s.id,name:s.username})}),c("query-groups")&&e.jsx(X,{"data-testid":"user-groups-tab",title:e.jsx(Y,{children:o("common:groups")}),...q,children:e.jsx(Nt,{user:s})}),e.jsx(X,{"data-testid":"user-consents-tab",title:e.jsx(Y,{children:o("consents")}),...S,children:e.jsx(Pt,{})}),c("view-identity-providers")&&e.jsx(X,{"data-testid":"identity-provider-links-tab",title:e.jsx(Y,{children:o("identityProviderLinks")}),...D,children:e.jsx(Mt,{userId:s.id})}),e.jsx(X,{"data-testid":"user-sessions-tab",title:e.jsx(Y,{children:o("sessions")}),...A,children:e.jsx(Kt,{})})]})})})})]})};export{Xr as default};
//# sourceMappingURL=EditUser-c3171d23.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy