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

theme.keycloak.v2.admin.resources.assets.PermissionDetails-51dd66cb.js Maven / Gradle / Ivy

There is a newer version: 25.0.1
Show newest version
import{u as M,a as G,r as y,q as U,j as e,C as z,g as d,e as _,b as H,d as $,l as V,A as K,aS as O,Q,K as W,at as J,G as X,P as Y,f as Z,F as p,h as m,S as ee,B as k,L as se,ax as ie}from"./index-0cda761d.js";import{a as N}from"./policyRepresentation-618c0846.js";import{u as te}from"./ConfirmDialog-100e6a40.js";import{F as oe}from"./FormAccess-835af982.js";import{K as ae}from"./KeycloakTextArea-9049d04c.js";import{K as B}from"./KeycloakTextInput-ada01047.js";import{V as re}from"./ViewHeader-ff389f8e.js";import{u as ne}from"./useParams-bc47a968.js";import{R as E}from"./ResourcesPolicySelect-7e343dcc.js";import{S as le,a as w,b as ce}from"./Select-68736f55.js";import{R as de}from"./Radio-a79edd45.js";import{A as pe}from"./Form-4087ddae.js";import"./Modal-ea09312d.js";import"./copy-icon-b8d617db.js";import"./GridItem-1535d986.js";import"./Text-b9444fb8.js";import"./ToolbarContent-fee3570e.js";import"./check-fc57dbe1.js";import"./star-icon-2ee5dfa7.js";const me=({clientId:s,resourceId:u,preSelected:f})=>{const{t:S}=M("clients"),{control:L,getValues:c,setValue:D,formState:{errors:R}}=G(),[a,j]=y.useState([]),[o,r]=y.useState([]),[h,g]=y.useState(""),[F,b]=y.useState(!1),P=y.useRef(!0),C=c("scopes"),T=n=>n.map(l=>e.jsx(ce,{value:l,children:l.name},l.id));return U(async()=>u?(u&&!P.current&&D("scopes",[]),P.current=!1,d.clients.listScopesByResource({id:s,resourceName:u})):d.clients.listAllScopes(Object.assign({id:s,deep:!1},h===""?null:{name:h})),n=>{j(n),h||r(n.filter(l=>C?.includes(l.id)))},[u,h]),e.jsx(z,{name:"scopes",defaultValue:f?[f]:[],control:L,rules:{validate:n=>n.length>0},render:({field:n})=>e.jsx(le,{toggleId:"scopes",variant:w.typeaheadMulti,onToggle:b,onFilter:(l,x)=>(g(x),T(a)),onClear:()=>{n.onChange([]),g("")},selections:o.map(l=>l.name),onSelect:(l,x)=>{const I=typeof x=="string"?o.find(i=>i.name===x):x,t=o.find(i=>i.id===I.id)?o.filter(i=>i.id!==I.id):[...o,I];n.onChange(t.map(i=>i.id)),r(t),g("")},isOpen:F,"aria-labelledby":S("scopes"),validated:R.scopes?"error":"default",isDisabled:!!f,typeAheadAriaLabel:S("scopes"),children:T(a)})})};function qe(){const{t:s}=M("clients"),u=_({mode:"onChange"}),{register:f,control:S,reset:L,formState:{errors:c},handleSubmit:D}=u,R=H(),{id:a,realm:j,permissionType:o,permissionId:r,selectedId:h}=ne(),{addAlert:g,addError:F}=$(),[b,P]=y.useState(),[C,T]=y.useState(!1);U(async()=>{if(!r)return{};const[t,i,A,q]=await Promise.all([d.clients.findOnePermission({id:a,type:o,permissionId:r}),d.clients.getAssociatedResources({id:a,permissionId:r}),d.clients.getAssociatedPolicies({id:a,permissionId:r}),d.clients.getAssociatedScopes({id:a,permissionId:r})]);if(!t)throw new Error(s("common:notFound"));return{permission:t,resources:i.map(v=>v._id),policies:A.map(v=>v.id),scopes:q.map(v=>v.id)}},({permission:t,resources:i,policies:A,scopes:q})=>{L({...t,resources:i,policies:A,scopes:q}),t&&"resourceType"in t&&T(!!t.resourceType),P({...t,resources:i,policies:A})},[]);const n=async t=>{try{if(r)await d.clients.updatePermission({id:a,type:o,permissionId:r},t);else{const i=await d.clients.createPermission({id:a,type:o},t);R(ie({realm:j,id:a,permissionType:o,permissionId:i.id}))}g(s((r?"update":"create")+"PermissionSuccess"),K.success)}catch(i){F("clients:permissionSaveError",i)}},[l,x]=te({titleKey:"clients:deletePermission",messageKey:s("deletePermissionConfirm",{permission:b?.name}),continueButtonVariant:V.danger,continueButtonLabel:"clients:confirm",onConfirm:async()=>{try{await d.clients.delPermission({id:a,type:o,permissionId:r}),g(s("permissionDeletedSuccess"),K.success),R(O({realm:j,clientId:a,tab:"permissions"}))}catch(t){F("clients:permissionDeletedError",t)}}}),I=Q({control:S,name:"resources",defaultValue:[]});return b?e.jsxs(e.Fragment,{children:[e.jsx(x,{}),e.jsx(re,{titleKey:r?b.name:`clients:create${J(o)}BasedPermission`,dropdownItems:r?[e.jsx(X,{"data-testid":"delete-resource",onClick:()=>l(),children:s("common:delete")},"delete")]:void 0}),e.jsx(Y,{variant:"light",children:e.jsx(oe,{isHorizontal:!0,role:"view-clients",onSubmit:D(n),children:e.jsxs(Z,{...u,children:[e.jsx(p,{label:s("common:name"),isRequired:!0,helperTextInvalid:s("common:required"),validated:c.name?"error":"default",fieldId:"name",labelIcon:e.jsx(m,{helpText:s("clients-help:permissionName"),fieldLabelId:"name"}),children:e.jsx(B,{id:"name",validated:c.name?"error":"default",...f("name",{required:!0})})}),e.jsx(p,{label:s("common:description"),fieldId:"description",labelIcon:e.jsx(m,{helpText:s("clients-help:permissionDescription"),fieldLabelId:"description"}),validated:c.description?"error":"default",helperTextInvalid:c.description?.message,children:e.jsx(ae,{id:"description",validated:c.description?"error":"default",...f("description",{maxLength:{value:255,message:s("common:maxLength",{length:255})}})})}),e.jsx(p,{label:s("applyToResourceTypeFlag"),fieldId:"applyToResourceTypeFlag",labelIcon:e.jsx(m,{helpText:s("clients-help:applyToResourceTypeFlag"),fieldLabelId:"clients:applyToResourceTypeFlag"}),children:e.jsx(ee,{id:"applyToResourceTypeFlag",name:"applyToResourceTypeFlag",label:s("common:on"),labelOff:s("common:off"),isChecked:C,onChange:T,"aria-label":s("applyToResourceTypeFlag")})}),C?e.jsx(p,{label:s("resourceType"),fieldId:"name",labelIcon:e.jsx(m,{helpText:s("clients-help:resourceType"),fieldLabelId:"resourceType"}),isRequired:o==="scope",children:e.jsx(B,{id:"resourceType",...f("resourceType",{required:o==="scope"})})}):e.jsx(p,{label:s("resources"),fieldId:"resources",labelIcon:e.jsx(m,{helpText:s("clients-help:permissionResources"),fieldLabelId:"clients:resources"}),helperTextInvalid:s("common:required"),validated:c.resources?"error":"default",isRequired:o!=="scope",children:e.jsx(E,{name:"resources",clientId:a,permissionId:r,preSelected:o==="scope"?void 0:h,variant:o==="scope"?w.typeahead:w.typeaheadMulti,isRequired:o!=="scope"})}),o==="scope"&&e.jsx(p,{label:s("authorizationScopes"),fieldId:"scopes",labelIcon:e.jsx(m,{helpText:s("clients-help:permissionScopes"),fieldLabelId:"clients:scopesSelect"}),helperTextInvalid:s("common:required"),validated:c.scopes?"error":"default",isRequired:!0,children:e.jsx(me,{clientId:a,resourceId:I?.[0],preSelected:h})}),e.jsx(p,{label:s("policies"),fieldId:"policies",labelIcon:e.jsx(m,{helpText:s("clients-help:permissionPolicies"),fieldLabelId:"clients:policies"}),children:e.jsx(E,{name:"policies",clientId:a,permissionId:r})}),e.jsx(p,{label:s("decisionStrategy"),labelIcon:e.jsx(m,{helpText:s("clients-help:permissionDecisionStrategy"),fieldLabelId:"clients:decisionStrategy"}),fieldId:"policyEnforcementMode",hasNoPaddingTop:!0,children:e.jsx(z,{name:"decisionStrategy","data-testid":"decisionStrategy",defaultValue:N.UNANIMOUS,control:S,render:({field:t})=>e.jsx(e.Fragment,{children:Object.values(N).map(i=>e.jsx(de,{id:i,"data-testid":i,isChecked:t.value===i,name:"decisionStrategies",onChange:()=>t.onChange(i),label:s(`decisionStrategies.${i}`),className:"pf-u-mb-md"},i))})})}),e.jsx(pe,{children:e.jsxs("div",{className:"pf-u-mt-md",children:[e.jsx(k,{variant:V.primary,type:"submit","data-testid":"save",children:s("common:save")}),e.jsx(k,{variant:"link","data-testid":"cancel",component:t=>e.jsx(se,{...t,to:O({realm:j,clientId:a,tab:"permissions"})}),children:s("common:cancel")})]})})]})})})]}):e.jsx(W,{})}export{qe as default};
//# sourceMappingURL=PermissionDetails-51dd66cb.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy