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

theme.keycloak.v2.admin.resources.assets.AddRoleMappingModal-Ds4yp8lg.js Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
import{jsxs as B,Fragment as T,jsx as l}from"react/jsx-runtime";import{useState as R}from"react";import{cq as O,u as _,a as J,f as W,B as z,j as X,a2 as D,bR as Y,h as x,bJ as Z,aC as V,bG as ee,b3 as te,s as se,M as ie,q as ne,J as le,K as oe,N as ae,D as re}from"./index-C1LIsRX7.js";import{L as G}from"./PaginatingTableToolbar-CpMLQtqt.js";import{K as H}from"./KeycloakDataTable-jyvvxdb8.js";import{u as ce}from"./ConfirmDialog-B5qjiAuo.js";import{F as de}from"./filter-icon-BVyMUArZ.js";import{T as pe}from"./Td-BwjBKSkH.js";const j={delete:["delClientRoleMappings","delRealmRoleMappings"],listEffective:["listRoleMappings","listCompositeRealmRoleMappings","listCompositeClientRoleMappings"],listAvailable:["listAvailableClientRoleMappings","listAvailableRealmRoleMappings"]},N={delete:["delClientScopeMappings","delRealmScopeMappings"],listEffective:["listScopeMappings","listCompositeRealmScopeMappings","listCompositeClientScopeMappings"],listAvailable:["listAvailableClientScopeMappings","listAvailableRealmScopeMappings"]},E={groups:j,users:j,clientScopes:N,clients:N,roles:{delete:["delCompositeRoles","delCompositeRoles"],listEffective:["getCompositeRoles","getCompositeRoles","getCompositeRolesForClient"],listAvailable:["listRoles","find"]}},me=(t,e)=>t[e],S=(t,e,i,...n)=>me(t,e)[i](...n),ge=(t,e,i,n)=>n.map(o=>{const a={id:o.role.id,name:o.role.name},s=E[e]?.delete[o.client?0:1];return S(t,e,s,{id:i,clientUniqueId:o.client?.id,client:o.client?.id,roles:[a]},[a])}),fe=async(t,e,i)=>{const n=E[e].listEffective[0],o=S(t,e,n,{id:i});if(e!=="roles")return o;const a=await o;return{clientMappings:await Promise.all(a.filter(p=>p.clientRole).map(async p=>{const r=await t.clients.findOne({id:p.containerId});return p.containerId=r?.clientId,{...r,mappings:[p]}})),realmMappings:a.filter(p=>!p.clientRole)}},ue=async(t,e,i)=>{const n=E[e].listEffective[1];if(e!=="roles")return(await S(t,e,n,{id:i})).map(s=>({role:s}));const o=await S(t,e,n,{id:i}),a=await Promise.all(o.filter(s=>s.composite).map(s=>S(t,e,n,{id:s.id})));return[...o,...a.flat()].map(s=>({role:s}))},Re=async(t,e,i)=>{const n=E[e].listAvailable[1];return(await S(t,e,n,i)).map(o=>({role:o}))},q=async(t,{id:e,type:i,first:n,max:o,search:a,endpoint:s})=>O(t,`/ui-ext/${s}/${i}/${e}`,{first:(n||0).toString(),max:(o||10).toString(),search:a||""}),he=(t,e)=>q(t,{...e,endpoint:"available-roles"}),ye=(t,e)=>q(t,{...e,endpoint:"effective-roles"}),Be=(t,e)=>O(t,"ui-ext/brute-force-user",e),Te=(t,e)=>q(t,{...e,endpoint:"authentication-management"}),Ce=(t,e,i)=>[...i?t.map(n=>({...n,role:{...n.role,isInherited:!1}})):e.map(n=>({...n,role:{...n.role,isInherited:t.find(o=>o.role.id===n.role.id)===void 0}}))],Q=({role:t,client:e})=>B(T,{children:[e?.clientId&&l(ee,{isRead:!0,className:"keycloak-admin--role-mapping__client-name",children:e.clientId}),t.name]}),De=({name:t,id:e,type:i,isManager:n=!0,save:o})=>{const{adminClient:a}=_(),{t:s}=J(),{addAlert:p,addError:r}=W(),[M,F]=R(0),u=()=>F(M+1),[y,f]=R(!0),[k,C]=R(!1),[b,h]=R([]),L=async d=>{await o(d),u()},K=async()=>{let d=[],v=[];y||(d=await ue(a,i,e),v=(await ye(a,{type:i,id:e})).map(c=>({client:{clientId:c.client,id:c.clientId},role:{id:c.id,name:c.role,description:c.description}})));const m=await fe(a,i,e),w=m.realmMappings?.map(c=>({role:c}))||[],A=Object.values(m.clientMappings||{}).map(c=>c.mappings.map(g=>({client:{clientId:c.client,...c},role:g}))).flat();return[...Ce([...w,...A],[...v,...d],y)]},[I,$]=ce({titleKey:"removeMappingTitle",messageKey:s("removeMappingConfirm",{count:b.length}),continueButtonLabel:"remove",continueButtonVariant:z.danger,onCancel:()=>{h([]),u()},onConfirm:async()=>{try{await Promise.all(ge(a,i,e,b)),p(s("clientScopeRemoveSuccess"),X.success),h([]),u()}catch(d){r("clientScopeRemoveError",d)}}});return B(T,{children:[k&&l(ve,{id:e,type:i,name:t,onAssign:L,onClose:()=>C(!1)}),l($,{}),l(H,{"data-testid":"assigned-roles",loader:K,canSelectAll:!0,onSelect:d=>h(d),searchPlaceholderKey:"searchByName",ariaLabelKey:"clientScopeList",isRowDisabled:d=>d.role.isInherited||!1,toolbarItem:B(T,{children:[l(D,{children:l(Y,{label:s("hideInheritedRoles"),id:"hideInheritedRoles","data-testid":"hideInheritedRoles",isChecked:y,onChange:(d,v)=>{f(v),u()}})}),n&&B(T,{children:[l(D,{children:l(x,{"data-testid":"assignRole",onClick:()=>C(!0),children:s("assignRole")})}),l(D,{children:l(x,{variant:"link","data-testid":"unAssignRole",onClick:I,isDisabled:b.length===0,children:s("unAssignRole")})})]})]}),actions:n?[{title:s("unAssignRole"),onRowClick:async d=>(h([d]),I(),!1)}]:[],columns:[{name:"role.name",displayKey:s("name"),transforms:[pe(30)],cellRenderer:Q},{name:"role.isInherited",displayKey:s("inherent"),cellFormatters:[Z(),V()]},{name:"role.description",displayKey:s("description"),cellFormatters:[V()]}],emptyState:l(G,{message:s(`noRoles-${i}`),instructions:s(`noRolesInstructions-${i}`),primaryActionText:s("assignRole"),onPrimaryAction:()=>C(!0),secondaryActions:[{text:s("showInheritedRoles"),onClick:()=>{f(!1),u()}}]})},`${e}${M}`)]})},ve=({id:t,name:e,type:i,isRadio:n=!1,isLDAPmapper:o,onAssign:a,onClose:s})=>{const{adminClient:p}=_(),{t:r}=J(),{hasAccess:M}=te(),F=M("view-realm")||M("query-users"),[u,y]=R(!1),[f,k]=R("clients"),[C,b]=R([]),[h,L]=R(0),K=()=>L(h+1),I=se(),$=({role:{name:m}})=>m?.toUpperCase(),d=async(m,w,A)=>{const c={first:m,max:w};A&&(c.search=A);const g=await Re(p,i,{...c,id:t});return I(g,$).map(U=>({role:U.role,id:U.role.id}))},v=async(m,w,A)=>{const c=await he(p,{id:t,type:i,first:m||0,max:w||10,search:A});return I(c.map(g=>({client:{clientId:g.client,id:g.clientId},role:{id:g.id,name:g.role,description:g.description},id:g.id})),({client:{clientId:g},role:{name:P}})=>`${g}${P}`)};return l(ie,{variant:ne.large,title:o?r("assignRole"):r("assignRolesTo",{client:e}),isOpen:!0,onClose:s,actions:[l(x,{"data-testid":"assign",isDisabled:C.length===0,variant:"primary",onClick:()=>{a(C),s()},children:r("assign")},"confirm"),l(x,{"data-testid":"cancel",variant:"link",onClick:s,children:r("cancel")},"cancel")],children:l(H,{onSelect:m=>b([...m]),searchPlaceholderKey:"searchByRoleName",isPaginated:!(f==="roles"&&i!=="roles"),searchTypeComponent:F&&l(D,{children:l(le,{onSelect:()=>{k(f==="roles"?"clients":"roles"),y(!1),K()},toggle:m=>l(oe,{"data-testid":"filter-type-dropdown",ref:m,onClick:()=>y(!u),icon:l(de,{}),children:r(f==="roles"?"filterByRoles":"filterByClients")}),isOpen:u,children:l(ae,{children:l(re,{"data-testid":f,children:r(f==="roles"?"filterByClients":"filterByRoles")},"filter-type")})})}),canSelectAll:!0,isRadio:n,loader:f==="roles"?d:v,ariaLabelKey:"roles",columns:[{name:"name",cellRenderer:Q},{name:"role.description",displayKey:"description"}],emptyState:l(G,{message:r("noRoles"),instructions:r("noRealmRolesToAssign"),secondaryActions:[{text:r("filterByClients"),onClick:()=>{k("clients"),K()}}]})},h)})};export{ve as A,De as R,Q as S,Be as a,Te as f};
//# sourceMappingURL=AddRoleMappingModal-Ds4yp8lg.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy