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

theme.keycloak.v2.admin.resources.assets.PolicyDetails-63e32b3b.js Maven / Gradle / Ivy

There is a newer version: 25.0.1
Show newest version
import{b9 as Qe,ba as ce,bb as Xe,r as x,ak as A,_ as Ze,bc as et,aA as tt,k as Y,bd as st,O as nt,be as it,n as rt,u as O,a as P,q as H,g as D,j as e,F as y,h as b,C as R,B as F,l as X,D as se,bf as ot,E as ne,ah as ve,G as de,V as M,R as Ne,U as G,b as at,e as lt,d as ct,K as dt,P as ut,f as pt,L as mt,aS as Ce,ay as ht,A as ye}from"./index-0cda761d.js";import{u as ft}from"./ConfirmDialog-100e6a40.js";import{F as gt}from"./FormAccess-835af982.js";import{V as xt}from"./ViewHeader-ff389f8e.js";import{u as we}from"./useParams-bc47a968.js";import{R as Z}from"./Radio-a79edd45.js";import{R as St}from"./ResourcesPolicySelect-7e343dcc.js";import{a as K,S as me,b as B}from"./Select-68736f55.js";import{u as jt,m as It}from"./useLocaleSort-ef2c79ac.js";import{h as Tt}from"./ClientScopeTypes-d24d11d6.js";import{L as vt}from"./PaginatingTableToolbar-11bdf18a.js";import{K as Ct}from"./KeycloakDataTable-a1a2bfca.js";import{u as ue}from"./useToggle-3764a2a4.js";import{g as yt}from"./utils-49fe564a.js";import{M as bt,a as Ot}from"./Modal-ea09312d.js";import{F as be}from"./filter-icon-56a9cd24.js";import{T as he,O as fe,P as U,Q as _,R as ge,S as q}from"./Td-d9b96677.js";import{C as xe}from"./Checkbox-3affa1d3.js";import{M as Se}from"./minus-circle-icon-ac3563ca.js";import{G as kt}from"./GroupPickerDialog-9d38b823.js";import{K as ee}from"./KeycloakTextInput-ada01047.js";import{C as $t,L as Dt}from"./CodeEditor-781232a0.js";import{K as Rt}from"./KeycloakTextArea-9049d04c.js";import{A as Pt,S as Mt}from"./AddRoleMappingModal-71c36ce9.js";import{d as J,D as Et}from"./DatePicker-66178c4a.js";import{m as ie,M as At,a as Ft,b as Nt,c as wt}from"./MenuList-7fad6760.js";import{F as Lt}from"./Flex-a3793595.js";import{F as Oe}from"./FlexItem-742749b8.js";import{N as Vt}from"./NumberInput-1d7f57ff.js";import{A as _t}from"./Form-4087ddae.js";var qt=/\s/;function Ut(t){for(var r=t.length;r--&&qt.test(t.charAt(r)););return r}var Ht=/^\s+/;function Gt(t){return t&&t.slice(0,Ut(t)+1).replace(Ht,"")}var ke=0/0,Kt=/^[-+]0x[0-9a-f]+$/i,Bt=/^0b[01]+$/i,Wt=/^0o[0-7]+$/i,zt=parseInt;function $e(t){if(typeof t=="number")return t;if(Qe(t))return ke;if(ce(t)){var r=typeof t.valueOf=="function"?t.valueOf():t;t=ce(r)?r+"":r}if(typeof t!="string")return t===0?t:+t;t=Gt(t);var n=Bt.test(t);return n||Wt.test(t)?zt(t.slice(2),n?2:8):Kt.test(t)?ke:+t}var Yt=function(){return Xe.Date.now()};const re=Yt;var Jt="Expected a function",Qt=Math.max,Xt=Math.min;function Zt(t,r,n){var d,l,c,u,p,f,m=0,s=!1,o=!1,i=!0;if(typeof t!="function")throw new TypeError(Jt);r=$e(r)||0,ce(n)&&(s=!!n.leading,o="maxWait"in n,c=o?Qt($e(n.maxWait)||0,r):c,i="trailing"in n?!!n.trailing:i);function a(v){var $=d,I=l;return d=l=void 0,m=v,u=t.apply(I,$),u}function h(v){return m=v,p=setTimeout(C,r),s?a(v):u}function S(v){var $=v-f,I=v-m,N=r-$;return o?Xt(N,c-I):N}function T(v){var $=v-f,I=v-m;return f===void 0||$>=r||$<0||o&&I>=c}function C(){var v=re();if(T(v))return k(v);p=setTimeout(C,S(v))}function k(v){return p=void 0,i&&d?a(v):(d=l=void 0,u)}function g(){p!==void 0&&clearTimeout(p),m=0,d=f=l=p=void 0}function j(){return p===void 0?u:k(re())}function E(){var v=re(),$=T(v);if(d=arguments,l=this,f=v,$){if(p===void 0)return h(f);if(o)return clearTimeout(p),p=setTimeout(C,r),a(f)}return p===void 0&&(p=setTimeout(C,r)),u}return E.cancel=g,E.flush=j,E}const L=" AM",V=" PM",es=(t,r,n,d,l,c)=>{const u=[],p=new Date(new Date().setHours(0,0,0,0)),f=p.getDay();for(;p.getDay()===f;){let m=p.getHours(),s=L;r&&(m===0?m=12:m>=12&&(s=V),m>12&&(m%=12)),m=r?m.toString():m.toString().padStart(2,"0");const o=p.getMinutes().toString().padStart(2,"0"),i=`${m}${n}${o}${r?s:""}`;Ve(d,l,i,n,c)&&u.push(i),p.setMinutes(p.getMinutes()+t)}return u},w=(t,r,n,d,l)=>{const c=new Date(t);if(!isNaN(c.getDate())&&(t instanceof Date||t.includes("T"))){const u=d?`${c.getHours()>12?c.getHours()-12:c.getHours()}`:`${c.getHours()}`.padStart(2,"0"),p=`${c.getMinutes()}`.padStart(2,"0"),f=l?`${c.getSeconds()}`.padStart(2,"0"):"",m=f?`${n}${f}`:"";let s="";return d&&c.getHours()>11?s=V:d&&(s=L),`${u}${n}${p}${m}${s}`}else if(typeof t=="string"&&(t=t.trim(),t!==""&&Le(t,r,n,d))){const[,u,p,f,m=""]=r.exec(t),s=l?`${n}${f??"00"}`:"";let o="";if(d){const i=m.toUpperCase();i===L.toUpperCase().trim()?o=L:i===V.toUpperCase().trim()?o=V:o=new Date().getHours()>11?V:L}return`${u}${n}${p}${s}${o}`}return t.toString()},Le=(t,r,n,d)=>{const l=new Date(t);if(!isNaN(l.getDate())&&t.includes("T"))return!0;const c=parseInt(t.split(n)[0]),u=c>=(d?1:0)&&c<=(d?12:23);return t===""||r.test(t)&&u},De=(t,r)=>{const n=t.match(r);return n&&n.length?/pm/i.test(n[4])?parseInt(n[1])===12?parseInt(n[1]):parseInt(n[1])+12:/am/i.test(n[4])&&parseInt(n[1])===12?0:parseInt(n[1]):null},Re=(t,r)=>{const n=t.match(r);return n&&n.length?parseInt(n[2]):null},Pe=(t,r)=>{var n;const d=(n=t.match(r))===null||n===void 0?void 0:n[3];return d?parseInt(d):null},Ve=(t,r,n,d,l)=>{if(n.trim()==="")return!0;const c=oe(t,d,l),u=oe(n,d,l),p=oe(r,d,l);return c<=u&&u<=p},oe=(t,r,n)=>{const l=new RegExp(`^\\s*(\\d\\d?)${r}([0-5]\\d)${r}?([0-5]\\d)?\\s*([AaPp][Mm])?\\s*$`).exec(t);if(!l||!l.length)return;let c=l[1].padStart(2,"0");const u=l[2];let p=l[3]?`${r}${l[3]}`:"";!p&&n&&(p=`${r}00`);const f=l[4]||"";return f.toUpperCase()==="PM"&&c!=="12"?c=`${parseInt(c)+12}`:f.toUpperCase()==="AM"&&c==="12"&&(c="00"),`${c}${r}${u}${p}`};class je extends x.Component{constructor(r){super(r),this.baseComponentRef=x.createRef(),this.toggleRef=x.createRef(),this.inputRef=x.createRef(),this.menuRef=x.createRef(),this.onDocClick=s=>{var o,i,a,h;const S=(i=(o=this.toggleRef)===null||o===void 0?void 0:o.current)===null||i===void 0?void 0:i.contains(s.target),T=(h=(a=this.menuRef)===null||a===void 0?void 0:a.current)===null||h===void 0?void 0:h.contains(s.target);this.state.isTimeOptionsOpen&&!(S||T)&&this.onToggle(!1)},this.handleGlobalKeys=s=>{var o,i,a,h;const{isTimeOptionsOpen:S,focusedIndex:T,scrollIndex:C}=this.state;!((i=(o=this.inputRef)===null||o===void 0?void 0:o.current)===null||i===void 0)&&i.contains(s.target)?!S&&s.key!==A.Tab&&s.key!==A.Escape?this.onToggle(!0):S&&(s.key===A.Escape||s.key===A.Tab?this.onToggle(!1):s.key===A.Enter?T!==null?(this.focusSelection(T),s.stopPropagation()):this.onToggle(!1):(s.key===A.ArrowDown||s.key===A.ArrowUp)&&(this.focusSelection(C),this.updateFocusedIndex(0),s.preventDefault())):!((h=(a=this.menuRef)===null||a===void 0?void 0:a.current)===null||h===void 0)&&h.contains(s.target)&&(s.key===A.ArrowDown?(this.updateFocusedIndex(1),s.preventDefault()):s.key===A.ArrowUp?(this.updateFocusedIndex(-1),s.preventDefault()):(s.key===A.Escape||s.key===A.Tab)&&(this.inputRef.current.focus(),this.onToggle(!1)))},this.updateFocusedIndex=s=>{this.setState(o=>{const i=this.getOptions().length-1;let a=o.focusedIndex!==null?o.focusedIndex+s:o.scrollIndex+s;return a<0?a=i:a>i&&(a=0),this.scrollToIndex(a),{focusedIndex:a}})},this.getIndexToScroll=s=>this.props.menuAppendTo==="inline"?s>0?s-1:0:s,this.scrollToIndex=s=>{this.getOptions()[s].closest(`.${ie.menuContent}`).scrollTop=this.getOptions()[this.getIndexToScroll(s)].offsetTop},this.focusSelection=s=>{var o;const i=s!==-1?s:0;!((o=this.menuRef)===null||o===void 0)&&o.current&&this.getOptions()[i].querySelector(`.${ie.menuItem}`).focus()},this.scrollToSelection=s=>{const{delimiter:o,is24Hour:i}=this.props;let a=s.split(this.props.delimiter),h=null;if(a.length<2?(s=`${s}${o}00`,a=s.split(o)):a.length>2&&(s=w(s,this.state.timeRegex,o,!i,!1),a=s.split(o)),!i&&a.length>1&&a[1].length<2){const T=a[1].length===0?"00":a[1]+"0";s=`${a[0]}${o}${T}${new Date().getHours()>11?V:L}`}else!i&&a.length>1&&a[1].length===2&&!s.toUpperCase().includes(L.toUpperCase().trim())&&!s.toUpperCase().includes(V.toUpperCase().trim())&&(s=`${s}${new Date().getHours()>11?V:L}`);let S=this.getOptions().findIndex(T=>T.textContent===s);if(S!==-1)this.scrollToIndex(S),h=S;else if(a.length===2){let T="";i||(a[1].toUpperCase().includes("P")?T=V:a[1].toUpperCase().includes("A")&&(T=L)),s=`${a[0]}${o}00${T}`,S=this.getOptions().findIndex(C=>C.textContent===s),S!==-1&&this.scrollToIndex(S)}this.setState({focusedIndex:h,scrollIndex:S})},this.getRegExp=(s=!0)=>{const{is24Hour:o,delimiter:i}=this.props;let a=`\\s*(\\d\\d?)${i}([0-5]\\d)`;return s&&(a+=`${i}?([0-5]\\d)?`),new RegExp(`^${a}${o?"":"\\s*([AaPp][Mm])?"}\\s*$`)},this.getOptions=()=>{var s;return!((s=this.menuRef)===null||s===void 0)&&s.current?Array.from(this.menuRef.current.querySelectorAll(`.${ie.menuListItem}`)):[]},this.isValidFormat=s=>{if(this.props.validateTime)return this.props.validateTime(s);const{delimiter:o,is24Hour:i,includeSeconds:a}=this.props;return Le(s,this.getRegExp(a),o,!i)},this.isValidTime=s=>{const{delimiter:o,includeSeconds:i}=this.props,{minTimeState:a,maxTimeState:h}=this.state;return Ve(a,h,s,o,i)},this.isValid=s=>this.isValidFormat(s)&&this.isValidTime(s),this.onToggle=s=>{this.setState(o=>{const{timeRegex:i,isInvalid:a,timeState:h}=o,{delimiter:S,is24Hour:T,includeSeconds:C,onChange:k}=this.props,g=w(h,i,S,!T,C);return k&&!s&&g!==h&&k(null,g,De(g,i),Re(g,i),Pe(g,i),this.isValid(g)),{isTimeOptionsOpen:s,timeState:g,isInvalid:s?a:!this.isValid(g)}}),this.props.setIsOpen(s),s||this.inputRef.current.focus()},this.onSelect=s=>{const{timeRegex:o,timeState:i}=this.state,{delimiter:a,is24Hour:h,includeSeconds:S,setIsOpen:T}=this.props,C=w(s.target.textContent,o,a,!h,S);C!==i&&this.onInputChange(C,s),this.inputRef.current.focus(),this.setState({isTimeOptionsOpen:!1,isInvalid:!1}),T(!1)},this.onInputClick=s=>{this.state.isTimeOptionsOpen||this.onToggle(!0),s.stopPropagation()},this.onInputChange=(s,o)=>{const{onChange:i}=this.props,{timeRegex:a}=this.state;i&&i(o,s,De(s,a),Re(s,a),Pe(s,a),this.isValid(s)),this.scrollToSelection(s),this.setState({timeState:s})};const{is24Hour:n,delimiter:d,time:l,includeSeconds:c,isOpen:u}=this.props;let{minTime:p,maxTime:f}=this.props;if(p===""){const s=c?`${d}00`:"";p=n?`00${d}00${s}`:`12${d}00${s} AM`}if(f===""){const s=c?`${d}59`:"";f=n?`23${d}59${s}`:`11${d}59${s} PM`}const m=this.getRegExp();this.state={isInvalid:!1,isTimeOptionsOpen:u,timeState:w(l,m,d,!n,c),focusedIndex:null,scrollIndex:0,timeRegex:m,minTimeState:w(p,m,d,!n,c),maxTimeState:w(f,m,d,!n,c)}}componentDidMount(){document.addEventListener("mousedown",this.onDocClick),document.addEventListener("touchstart",this.onDocClick),document.addEventListener("keydown",this.handleGlobalKeys),this.setState({isInvalid:!this.isValid(this.state.timeState)})}componentWillUnmount(){document.removeEventListener("mousedown",this.onDocClick),document.removeEventListener("touchstart",this.onDocClick),document.removeEventListener("keydown",this.handleGlobalKeys)}componentDidUpdate(r,n){const{timeState:d,isTimeOptionsOpen:l,isInvalid:c,timeRegex:u}=this.state,{time:p,is24Hour:f,delimiter:m,includeSeconds:s,isOpen:o,minTime:i,maxTime:a}=this.props;if(r.isOpen!==o&&this.onToggle(o),l&&!n.isTimeOptionsOpen&&d&&!c&&this.scrollToSelection(d),m!==r.delimiter&&this.setState({timeRegex:this.getRegExp()}),p!==""&&p!==r.time){const h=w(p,u,m,!f,s);this.setState({timeState:h,isInvalid:!this.isValid(h)})}i!==""&&i!==r.minTime&&this.setState({minTimeState:w(i,u,m,!f,s)}),a!==""&&a!==r.maxTime&&this.setState({maxTimeState:w(a,u,m,!f,s)})}render(){const r=this.props,{"aria-label":n,isDisabled:d,className:l,placeholder:c,id:u,menuAppendTo:p,is24Hour:f,invalidFormatErrorMessage:m,invalidMinMaxErrorMessage:s,stepMinutes:o,width:i,delimiter:a,inputProps:h,onChange:S,setIsOpen:T,isOpen:C,time:k,validateTime:g,minTime:j,maxTime:E,includeSeconds:v,removeFindDomNode:$,zIndex:I}=r,N=Ze(r,["aria-label","isDisabled","className","placeholder","id","menuAppendTo","is24Hour","invalidFormatErrorMessage","invalidMinMaxErrorMessage","stepMinutes","width","delimiter","inputProps","onChange","setIsOpen","isOpen","time","validateTime","minTime","maxTime","includeSeconds","removeFindDomNode","zIndex"]),{timeState:W,isTimeOptionsOpen:qe,isInvalid:Ie,minTimeState:Ue,maxTimeState:He}=this.state,Ge={"--pf-c-date-picker__input--c-form-control--Width":i},Ke=es(o,!f,a,Ue,He,v),Be=this.isValidFormat(W),te=u||et("time-picker"),We=()=>this.baseComponentRef&&this.baseComponentRef.current?this.baseComponentRef.current.parentElement:null,ze=x.createElement(At,{ref:this.menuRef,isScrollable:!0},x.createElement(Ft,{maxMenuHeight:"200px"},x.createElement(Nt,{"aria-label":n},Ke.map((Te,Je)=>x.createElement(wt,{onClick:this.onSelect,key:Te,id:`${te}-option-${Je}`},Te))))),Ye=x.createElement(tt,Object.assign({"aria-haspopup":"menu",className:Y(st.formControl),id:`${te}-input`,"aria-label":n,validated:Ie?"error":"default",placeholder:c,value:W||"",type:"text",iconVariant:"clock",onClick:this.onInputClick,onChange:this.onInputChange,autoComplete:"off",isDisabled:d,ref:this.inputRef},h));let z;switch(p){case"inline":z=()=>this.toggleRef.current;break;case"parent":z=We;break;default:z=p}return x.createElement("div",{ref:this.baseComponentRef,className:Y(J.datePicker,l)},x.createElement("div",Object.assign({className:Y(J.datePickerInput),style:Ge},N),x.createElement(nt,null,x.createElement("div",{id:te},x.createElement("div",{ref:this.toggleRef,style:{paddingLeft:"0"}},x.createElement(it,{appendTo:z,trigger:Ye,popper:ze,isVisible:qe,removeFindDomNode:$,zIndex:I})))),Ie&&x.createElement("div",{className:Y(J.datePickerHelperText,J.modifiers.error)},Be?s:m)))}}je.displayName="TimePicker";je.defaultProps={className:"",isDisabled:!1,time:"",is24Hour:!1,invalidFormatErrorMessage:"Invalid time format",invalidMinMaxErrorMessage:"Invalid time entered",placeholder:"hh:mm",delimiter:":","aria-label":"Time picker",width:"150px",menuAppendTo:"inline",stepMinutes:30,inputProps:{},minTime:"",maxTime:"",isOpen:!1,setIsOpen:()=>{},removeFindDomNode:!1,zIndex:9999};const ts={name:"CaretUpIcon",height:512,width:320,svgPath:"M288.662 352H31.338c-17.818 0-26.741-21.543-14.142-34.142l128.662-128.662c7.81-7.81 20.474-7.81 28.284 0l128.662 128.662c12.6 12.599 3.676 34.142-14.142 34.142z",yOffset:0,xOffset:0},ss=rt(ts),ns=({name:t,label:r,helpText:n,defaultValue:d,isRequired:l,variant:c=K.typeaheadMulti})=>{const{t:u}=O("clients"),{control:p,getValues:f,formState:{errors:m}}=P(),s=f(t),[o,i]=ue(),[a,h]=x.useState([]),[S,T]=x.useState(""),C=x.useCallback(Zt(T,1e3),[]);H(()=>{const g={max:20};return S&&(g.username=S),s?.length&&!S?Promise.all(s.map(j=>D.users.findOne({id:j}))):D.users.find(g)},h,[S]);const k=g=>g.filter(j=>j!==void 0).map(j=>e.jsx(B,{value:j.id,selected:s?.includes(j.id),children:j.username},j.id));return e.jsx(y,{label:u(r),isRequired:l,labelIcon:e.jsx(b,{helpText:n,fieldLabelId:`clients:${r}`}),fieldId:t,validated:m[t]?"error":"default",helperTextInvalid:u("common:required"),children:e.jsx(R,{name:t,defaultValue:d,control:p,rules:l&&c===K.typeaheadMulti?{validate:g=>g.length>0}:{required:l},render:({field:g})=>e.jsx(me,{toggleId:t,variant:c,placeholderText:u("selectAUser"),onToggle:i,isOpen:o,selections:g.value,onFilter:(j,E)=>(C(E),k(a)),onSelect:(j,E)=>{const v=E.toString();if(c!==K.typeaheadMulti)g.value.includes(v)?g.onChange([]):g.onChange([v]);else{const $=g.value.find(I=>I===v)?g.value.filter(I=>I!==v):[...g.value,v];g.onChange($)}i()},"aria-label":u(t),children:k(a)})})})},ae=["UNANIMOUS","AFFIRMATIVE","CONSENSUS"],is=({helpLabel:t,isLimited:r=!1})=>{const{t:n}=O("clients"),{control:d}=P();return e.jsx(y,{label:n("decisionStrategy"),labelIcon:e.jsx(b,{helpText:n(`clients-help:${t||"decisionStrategy"}`),fieldLabelId:"clients:decisionStrategy"}),fieldId:"decisionStrategy",hasNoPaddingTop:!0,children:e.jsx(R,{name:"decisionStrategy","data-testid":"decisionStrategy",defaultValue:ae[0],control:d,render:({field:l})=>e.jsx(e.Fragment,{children:(r?ae.slice(0,2):ae).map(c=>e.jsx(Z,{id:c,"data-testid":c,isChecked:l.value===c,name:"decisionStrategy",onChange:()=>l.onChange(c),label:n(`decisionStrategies.${c}`),className:"pf-u-mb-md"},c))})})})},rs=()=>{const{t}=O("clients"),{id:r}=we();return e.jsxs(e.Fragment,{children:[e.jsx(y,{label:t("applyPolicy"),fieldId:"policies",labelIcon:e.jsx(b,{helpText:t("clients-help:applyPolicy"),fieldLabelId:"clients:policies"}),children:e.jsx(St,{name:"policies",clientId:r})}),e.jsx(is,{helpLabel:"policyDecisionStagey"})]})},os=()=>{const{t}=O("clients"),{control:r,getValues:n,formState:{errors:d}}=P(),l=n("clients"),[c,u]=x.useState(!1),[p,f]=x.useState([]),[m,s]=x.useState("");H(async()=>{const i={max:20};return m&&(i.clientId=m,i.search=!0),l?.length&&!m?await Promise.all(l.map(a=>D.clients.findOne({id:a}))):await D.clients.find(i)},f,[m]);const o=i=>i.map(a=>e.jsx(B,{value:a.id,selected:l?.includes(a.id),children:a.clientId},a.id));return e.jsx(y,{label:t("clients"),labelIcon:e.jsx(b,{helpText:t("clients-help:policyClient"),fieldLabelId:"clients:client"}),fieldId:"clients",helperTextInvalid:t("requiredClient"),validated:d.clients?"error":"default",isRequired:!0,children:e.jsx(R,{name:"clients",defaultValue:[],control:r,rules:{validate:i=>i.length>0},render:({field:i})=>e.jsx(me,{toggleId:"clients",variant:K.typeaheadMulti,onToggle:a=>u(a),isOpen:c,selections:i.value,onFilter:(a,h)=>(s(h),o(p)),onSelect:(a,h)=>{const S=h.toString();i.value.includes(S)?i.onChange(i.value.filter(T=>T!==S)):i.onChange([...i.value,S]),u(!1)},"aria-label":t("clients"),children:o(p)})})})};const as=({clientScopes:t,clientName:r,open:n,toggleDialog:d,onAdd:l,isClientScopesConditionType:c})=>{const{t:u}=O("clients"),[p,f]=x.useState(!1),[m,s]=x.useState([]),[o,i]=x.useState("Name"),[a,h]=x.useState("All"),[S,T]=ue(),[C,k]=ue(!1),g=x.useMemo(()=>a==="OpenID Connect"?t.filter(I=>I.protocol==="openid-connect"):a==="SAML"?t.filter(I=>I.protocol==="saml"):t,[t,o,a]),j=I=>{const N=m.map(W=>({scope:W,type:I}));l(N),f(!1),d()},E=I=>{I==="Name"?i("Protocol"):I==="Protocol"&&(i("Name"),h("All")),T()},v=I=>{I==="SAML"?h("SAML"):I==="OpenID Connect"?h("OpenID Connect"):I==="All"&&h("All"),k()},$=[e.jsx(B,{value:"SAML",children:u("protocolTypes.saml")},1),e.jsx(B,{value:"OpenID Connect",children:u("protocolTypes.openIdConnect")},2),e.jsx(B,{value:"All",isPlaceholder:!0,children:u("protocolTypes.all")},3)];return e.jsx(bt,{variant:Ot.medium,title:c?u("addClientScope"):u("addClientScopesTo",{clientName:r}),isOpen:n,onClose:d,actions:c?[e.jsx(F,{id:"modal-add","data-testid":"confirm",variant:X.primary,onClick:()=>{const I=m.map(N=>({scope:N}));l(I),d()},isDisabled:m.length===0,children:u("common:add")},"add"),e.jsx(F,{id:"modal-cancel","data-testid":"cancel",variant:X.link,onClick:()=>{s([]),d()},children:u("common:cancel")},"cancel")]:[e.jsx(se,{className:"keycloak__client-scopes-add__add-dropdown",id:"add-dropdown",direction:ot.up,isOpen:p,toggle:e.jsx(ne,{isDisabled:m.length===0,onToggle:()=>f(!p),isPrimary:!0,toggleIndicator:ss,id:"add-scope-toggle",children:u("common:add")}),dropdownItems:Tt(u,j)},"add-dropdown"),e.jsx(F,{id:"modal-cancel",variant:X.link,onClick:()=>{s([]),d()},children:u("common:cancel")},"cancel")],children:e.jsx(Ct,{loader:g,ariaLabelKey:"client-scopes:chooseAMapperType",searchPlaceholderKey:o==="Name"?"client-scopes:searchFor":void 0,isSearching:o!=="Name",searchTypeComponent:e.jsx(se,{onSelect:()=>{E(o)},"data-testid":"filter-type-dropdown",toggle:e.jsx(ne,{id:"toggle-id-9",onToggle:T,toggleIndicator:ve,icon:e.jsx(be,{}),children:o}),isOpen:S,dropdownItems:[e.jsx(de,{"data-testid":"filter-type-dropdown-item",children:u(o==="Name"?"protocol":"common:name")},"filter-type")]}),toolbarItem:o==="Protocol"&&e.jsxs(e.Fragment,{children:[e.jsx(se,{onSelect:()=>{E(o)},"data-testid":"filter-type-dropdown",toggle:e.jsx(ne,{id:"toggle-id-9",onToggle:T,toggleIndicator:ve,icon:e.jsx(be,{}),children:o}),isOpen:S,dropdownItems:[e.jsx(de,{"data-testid":"filter-type-dropdown-item",children:u("common:name")},"filter-type")]}),e.jsx(me,{variant:K.single,className:"kc-protocolType-select","aria-label":u("common:selectOne"),onToggle:k,onSelect:(I,N)=>v(N.toString()),selections:a,isOpen:C,children:$})]}),canSelectAll:!0,onSelect:I=>s(I),columns:[{name:"name"},{name:"protocol",displayKey:"clients:protocol",cellRenderer:I=>yt(u,I.protocol??"openid-connect")},{name:"description"}],emptyState:e.jsx(vt,{message:u("emptyAddClientScopes"),instructions:u("emptyAddClientScopesInstructions")})})})},ls=()=>{const{t}=O("clients"),{control:r,getValues:n,setValue:d,formState:{errors:l}}=P(),[c,u]=x.useState(!1),[p,f]=x.useState([]),[m,s]=x.useState([]),o=jt();return H(()=>D.clientScopes.find(),i=>{s(n("clientScopes").map(a=>i.find(h=>h.id===a.id))),f(o(i,It("name")))},[]),e.jsxs(y,{label:t("clientScopes"),labelIcon:e.jsx(b,{helpText:t("clients-help:clientScopes"),fieldLabelId:"clients:clientScopes"}),fieldId:"clientScopes",helperTextInvalid:t("requiredClientScope"),validated:l.clientScopes?"error":"default",isRequired:!0,children:[e.jsx(R,{name:"clientScopes",control:r,defaultValue:[],rules:{validate:i=>i.filter(a=>a.id).length>0},render:({field:i})=>e.jsxs(e.Fragment,{children:[c&&e.jsx(as,{clientScopes:p.filter(a=>!i.value.map(h=>h.id).includes(a.id)),isClientScopesConditionType:!0,open:c,toggleDialog:()=>u(!c),onAdd:a=>{s([...m,...a.map(h=>h.scope)]),i.onChange([...i.value,...a.map(h=>h.scope).map(h=>({id:h.id,required:!1}))])}}),e.jsx(F,{"data-testid":"select-scope-button",variant:"secondary",onClick:()=>{u(!0)},children:t("addClientScopes")})]})}),m.length>0&&e.jsxs(he,{variant:"compact",children:[e.jsx(fe,{children:e.jsxs(U,{children:[e.jsx(_,{children:t("clientScope")}),e.jsx(_,{children:t("required")}),e.jsx(_,{"aria-hidden":"true"})]})}),e.jsx(ge,{children:m.map((i,a)=>e.jsxs(U,{children:[e.jsx(q,{children:i.name}),e.jsx(q,{children:e.jsx(R,{name:`clientScopes.${a}.required`,defaultValue:!1,control:r,render:({field:h})=>e.jsx(xe,{id:"required","data-testid":"standard",name:"required",isChecked:h.value,onChange:h.onChange})})}),e.jsx(q,{children:e.jsx(F,{variant:"link",className:"keycloak__client-authorization__policy-row-remove",icon:e.jsx(Se,{}),onClick:()=>{d("clientScopes",[...n("clientScopes").filter(h=>h.id!==i.id)]),s([...m.filter(h=>h.id!==i.id)])}})})]},i.id))})]})]})},cs=()=>{const{t}=O("clients"),{control:r,register:n,getValues:d,setValue:l,formState:{errors:c}}=P(),u=d("groups"),[p,f]=x.useState(!1),[m,s]=x.useState([]);return H(()=>u&&u.length>0?Promise.all(u.map(o=>D.groups.findOne({id:o.id}))):Promise.resolve([]),o=>{const i=o.filter(a=>a);s(i)},[]),e.jsxs(e.Fragment,{children:[e.jsx(y,{label:t("groupsClaim"),labelIcon:e.jsx(b,{helpText:t("clients-help:groupsClaim"),fieldLabelId:"clients:groupsClaim"}),fieldId:"groups",children:e.jsx(ee,{type:"text",id:"groupsClaim","data-testid":"groupsClaim",...n("groupsClaim")})}),e.jsxs(y,{label:t("groups"),labelIcon:e.jsx(b,{helpText:t("clients-help:policyGroups"),fieldLabelId:"clients:groups"}),fieldId:"groups",helperTextInvalid:t("requiredGroups"),validated:c.groups?"error":"default",isRequired:!0,children:[e.jsx(R,{name:"groups",control:r,defaultValue:[],rules:{validate:o=>o&&o.filter(({id:i})=>i).length>0},render:({field:o})=>e.jsxs(e.Fragment,{children:[p&&e.jsx(kt,{type:"selectMany",text:{title:"clients:addGroupsToGroupPolicy",ok:"common:add"},onConfirm:i=>{o.onChange([...o.value||[],...(i||[]).map(({id:a})=>({id:a}))]),s([...m,...i||[]]),f(!1)},onClose:()=>{f(!1)},filterGroups:m}),e.jsx(F,{"data-testid":"select-group-button",variant:"secondary",onClick:()=>{f(!0)},children:t("addGroups")})]})}),m.length>0&&e.jsxs(he,{variant:"compact",children:[e.jsx(fe,{children:e.jsxs(U,{children:[e.jsx(_,{children:t("groups")}),e.jsx(_,{children:t("extendToChildren")}),e.jsx(_,{"aria-hidden":"true"})]})}),e.jsx(ge,{children:m.map((o,i)=>e.jsxs(U,{children:[e.jsx(q,{children:o.path}),e.jsx(q,{children:e.jsx(R,{name:`groups.${i}.extendChildren`,defaultValue:!1,control:r,render:({field:a})=>e.jsx(xe,{id:"extendChildren","data-testid":"standard",name:"extendChildren",isChecked:a.value,onChange:a.onChange,isDisabled:o.subGroups?.length===0})})}),e.jsx(q,{children:e.jsx(F,{variant:"link",className:"keycloak__client-authorization__policy-row-remove",icon:e.jsx(Se,{}),onClick:()=>{l("groups",[...(u||[]).filter(({id:a})=>a!==o.id)]),s([...m.filter(({id:a})=>a!==o.id)])}})})]},o.id))})]})]})]})},ds=()=>{const{t}=O("clients"),{control:r}=P();return e.jsx(y,{label:t("code"),labelIcon:e.jsx(b,{helpText:t("clients-help:policyCode"),fieldLabelId:"clients:code"}),fieldId:"code",isRequired:!0,children:e.jsx(R,{name:"code",defaultValue:"",control:r,render:({field:n})=>e.jsx($t,{id:"code","data-testid":"code",onChange:n.onChange,code:n.value,height:"600px",language:Dt.javascript,isReadOnly:!0})})})},Me=["POSITIVE","NEGATIVE"],us=({isDisabled:t})=>{const{t:r}=O("clients"),{control:n}=P();return e.jsx(y,{label:r("logic"),labelIcon:e.jsx(b,{helpText:r("clients-help:logic"),fieldLabelId:"clients:logic"}),fieldId:"logic",hasNoPaddingTop:!0,children:e.jsx(R,{name:"logic","data-testid":"logic",defaultValue:Me[0],control:n,render:({field:d})=>e.jsx(e.Fragment,{children:Me.map(l=>e.jsx(Z,{id:l,"data-testid":l,isChecked:d.value===l,name:"logic",onChange:()=>d.onChange(l),label:r(`logicType.${l.toLowerCase()}`),className:"pf-u-mb-md",isDisabled:t},l))})})})},ps=({prefix:t,isDisabled:r})=>{const{t:n}=O("clients"),{register:d,formState:{errors:l}}=P();return e.jsxs(e.Fragment,{children:[e.jsx(y,{label:n("common:name"),fieldId:"kc-name",helperTextInvalid:n("common:required"),validated:l.name?M.error:M.default,isRequired:!0,labelIcon:e.jsx(b,{helpText:n(`clients-help:${t}-name`),fieldLabelId:"name"}),children:e.jsx(ee,{isDisabled:r,id:"kc-name","data-testid":"name",validated:l.name?M.error:M.default,...d("name",{required:!0})})}),e.jsx(y,{label:n("common:description"),fieldId:"kc-description",labelIcon:e.jsx(b,{helpText:n(`clients-help:${t}-description`),fieldLabelId:"description"}),validated:l.description?M.error:M.default,helperTextInvalid:n("common:maxLength",{length:255}),children:e.jsx(Rt,{isDisabled:r,id:"kc-description","data-testid":"description",validated:l.description?M.error:M.default,...d("description",{maxLength:255})})})]})},ms=()=>{const{t}=O("clients"),{register:r,formState:{errors:n}}=P();return e.jsxs(e.Fragment,{children:[e.jsx(y,{label:t("targetClaim"),fieldId:"targetClaim",helperTextInvalid:t("common:required"),validated:n.targetClaim?"error":"default",isRequired:!0,labelIcon:e.jsx(b,{helpText:t("clients-help:targetClaim"),fieldLabelId:"clients:targetClaim"}),children:e.jsx(ee,{id:"targetClaim","data-testid":"targetClaim",validated:n.targetClaim?"error":"default",...r("targetClaim",{required:!0})})}),e.jsx(y,{label:t("regexPattern"),fieldId:"pattern",labelIcon:e.jsx(b,{helpText:t("clients-help:regexPattern"),fieldLabelId:"clients:regexPattern"}),isRequired:!0,validated:n.pattern?"error":"default",helperTextInvalid:t("common:required"),children:e.jsx(ee,{id:"pattern","data-testid":"regexPattern",validated:n.pattern?"error":"default",...r("pattern",{required:!0})})})]})},hs=()=>{const{t}=O("clients"),{control:r,getValues:n,setValue:d,formState:{errors:l}}=P(),c=n("roles"),[u,p]=x.useState(!1),[f,m]=x.useState([]);return H(async()=>{if(c&&c.length>0){const s=await Promise.all(c.map(o=>D.roles.findOneById({id:o.id})));return Promise.all(s.map(async o=>({role:o,client:o.clientRole?await D.clients.findOne({id:o?.containerId}):void 0})))}return Promise.resolve([])},m,[]),e.jsxs(y,{label:t("roles"),labelIcon:e.jsx(b,{helpText:t("clients-help:policyRoles"),fieldLabelId:"clients:roles"}),fieldId:"roles",helperTextInvalid:t("requiredRoles"),validated:l.roles?"error":"default",isRequired:!0,children:[e.jsx(R,{name:"roles",control:r,defaultValue:[],rules:{validate:s=>s&&s.filter(o=>o.id).length>0},render:({field:s})=>e.jsxs(e.Fragment,{children:[u&&e.jsx(Pt,{id:"role",type:"roles",onAssign:o=>{s.onChange([...s.value||[],...o.map(i=>({id:i.role.id}))]),m([...f,...o]),p(!1)},onClose:()=>{p(!1)},isLDAPmapper:!0}),e.jsx(F,{"data-testid":"select-role-button",variant:"secondary",onClick:()=>{p(!0)},children:t("addRoles")})]})}),f.length>0&&e.jsxs(he,{variant:"compact",children:[e.jsx(fe,{children:e.jsxs(U,{children:[e.jsx(_,{children:t("roles")}),e.jsx(_,{children:t("required")}),e.jsx(_,{"aria-hidden":"true"})]})}),e.jsx(ge,{children:f.map((s,o)=>e.jsxs(U,{children:[e.jsx(q,{children:e.jsx(Mt,{role:s.role,client:s.client})}),e.jsx(q,{children:e.jsx(R,{name:`roles.${o}.required`,defaultValue:!1,control:r,render:({field:i})=>e.jsx(xe,{id:"required","data-testid":"standard",name:"required",isChecked:i.value,onChange:i.onChange})})}),e.jsx(q,{children:e.jsx(F,{variant:"link",className:"keycloak__client-authorization__policy-row-remove",icon:e.jsx(Se,{}),onClick:()=>{d("roles",[...(c||[]).filter(i=>i.id!==s.role.id)]),m([...f.filter(i=>i.role.id!==s.role.id)])}})})]},s.role.id))})]})]})},le=/(\d\d\d\d-\d\d-\d\d)? (\d\d?):(\d\d?)/,Ee=t=>t.toString().padStart(2,"0"),Ae=({name:t})=>{const{control:r}=P(),n=(l,c)=>{if(!c)return l;const u=l.match(le);return`${[c.getFullYear(),Ee(c.getMonth()+1),Ee(c.getDate())].join("-")} ${u?u[2]:"00"}:${u?u[3]:"00"}:00`},d=(l,c,u)=>{const p=l.match(le);return u!=null?`${p?p[1]:""} ${c}:${u<10?`0${u}`:u}:00`:l};return e.jsx(R,{name:t,defaultValue:"",control:r,rules:{required:!0},render:({field:l})=>{const c=l.value.match(le)||["","","0","00"];return e.jsxs(Ne,{hasGutter:!0,id:t,children:[e.jsx(G,{children:e.jsx(Et,{value:c[1],onChange:(u,p,f)=>{l.onChange(n(l.value,f))}})}),e.jsx(G,{children:e.jsx(je,{time:`${c[2]}:${c[3]}`,onChange:(u,p,f,m)=>l.onChange(d(l.value,f,m)),is24Hour:!0})})]})}})},Fe=({name:t,min:r,max:n})=>{const{control:d}=P(),l=c=>Math.min(c,n);return e.jsx(R,{name:t,defaultValue:"",control:d,render:({field:c})=>e.jsx(Vt,{id:t,value:c.value,min:r,max:n,onPlus:()=>c.onChange(Number(c.value)+1),onMinus:()=>c.onChange(Number(c.value)-1),onChange:u=>{const p=Number(u.currentTarget.value);c.onChange(l(isNaN(p)?0:p))}})})},Q=({name:t,...r})=>{const{t:n}=O("clients");return e.jsx(y,{label:n(t),fieldId:t,labelIcon:e.jsx(b,{helpText:n(`clients-help:${t}`),fieldLabelId:`clients:${t}`}),children:e.jsxs(Ne,{hasGutter:!0,children:[e.jsx(G,{children:e.jsx(Fe,{name:t,...r})}),e.jsx(G,{children:n("common:to")}),e.jsx(G,{children:e.jsx(Fe,{name:`${t}End`,...r})})]})})},fs=()=>{const{t}=O("clients"),{getValues:r,formState:{errors:n}}=P(),[d,l]=x.useState(r("month"));return e.jsxs(e.Fragment,{children:[e.jsx(y,{label:t("repeat"),fieldId:"repeat",labelIcon:e.jsx(b,{helpText:t("clients-help:repeat"),fieldLabelId:"clients:repeat"}),children:e.jsxs(Lt,{children:[e.jsx(Oe,{children:e.jsx(Z,{id:"notRepeat","data-testid":"notRepeat",isChecked:!d,name:"repeat",onChange:()=>l(!1),label:t("notRepeat"),className:"pf-u-mb-md"})}),e.jsx(Oe,{children:e.jsx(Z,{id:"repeat","data-testid":"repeat",isChecked:d,name:"repeat",onChange:()=>l(!0),label:t("repeat"),className:"pf-u-mb-md"})})]})}),d&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{name:"month",min:1,max:12}),e.jsx(Q,{name:"dayMonth",min:1,max:31}),e.jsx(Q,{name:"hour",min:0,max:23}),e.jsx(Q,{name:"minute",min:0,max:59})]}),e.jsx(y,{label:t("startTime"),fieldId:"notBefore",labelIcon:e.jsx(b,{helpText:t("clients-help:startTime"),fieldLabelId:"clients:startTime"}),isRequired:!0,helperTextInvalid:t("common:required"),validated:n.notBefore?M.error:M.default,children:e.jsx(Ae,{name:"notBefore"})}),e.jsx(y,{label:t("expireTime"),fieldId:"notOnOrAfter",labelIcon:e.jsx(b,{helpText:t("clients-help:expireTime"),fieldLabelId:"clients:expireTime"}),isRequired:!0,helperTextInvalid:t("common:required"),validated:n.notOnOrAfter?M.error:M.default,children:e.jsx(Ae,{name:"notOnOrAfter"})})]})},gs=()=>{const{t}=O();return e.jsx(ns,{name:"users",label:"users",helpText:t("clients-help:policyUsers"),defaultValue:[],isRequired:!0})};const pe={aggregate:rs,client:os,user:gs,"client-scope":ls,group:cs,regex:ms,role:hs,time:fs,js:ds},_e=t=>t in pe;function xs(){const{t}=O("clients"),{id:r,realm:n,policyId:d,policyType:l}=we(),c=at(),u=lt(),{reset:p,handleSubmit:f}=u,{addAlert:m,addError:s}=ct(),[o,i]=x.useState(),a=l==="js";H(async()=>{if(d){const g=await Promise.all([D.clients.findOnePolicy({id:r,type:l,policyId:d}),D.clients.getAssociatedPolicies({id:r,permissionId:d})]);if(!g[0])throw new Error(t("common:notFound"));return{policy:g[0],policies:g[1].map(j=>j.id)}}return{}},({policy:g,policies:j})=>{p({...g,policies:j}),i(g)},[r,l,d]);const h=async g=>{g.groups=g.groups?.filter(j=>j.id),g.clientScopes=g.clientScopes?.filter(j=>j.id),g.roles=g.roles?.filter(j=>j.id).map(j=>({...j,required:j.required||!1}));try{if(d)await D.clients.updatePolicy({id:r,type:l,policyId:d},g);else{const j=await D.clients.createPolicy({id:r,type:l},g);c(ht({realm:n,id:r,policyType:l,policyId:j.id}))}m(t((d?"update":"create")+"PolicySuccess"),ye.success)}catch(j){s("clients:policySaveError",j)}},[S,T]=ft({titleKey:"clients:deletePolicy",messageKey:"clients:deletePolicyConfirm",continueButtonLabel:"clients:confirm",onConfirm:async()=>{try{await D.clients.delPolicy({id:r,policyId:d}),m(t("policyDeletedSuccess"),ye.success),c(Ce({realm:n,clientId:r,tab:"policies"}))}catch(g){s("clients:policyDeletedError",g)}}});if(d&&!o)return e.jsx(dt,{});function C(){return _e(l)?pe[l]:pe.js}const k=C();return e.jsxs(e.Fragment,{children:[e.jsx(T,{}),e.jsx(xt,{titleKey:d?o?.name:t("clients:createPolicyOfType",{policyType:l}),dropdownItems:d?[e.jsx(de,{"data-testid":"delete-policy",onClick:()=>S(),children:t("common:delete")},"delete")]:void 0}),e.jsx(ut,{variant:"light",children:e.jsxs(gt,{isHorizontal:!0,onSubmit:f(h),role:"view-clients",children:[e.jsxs(pt,{...u,children:[e.jsx(ps,{isDisabled:a,prefix:"policy"}),e.jsx(k,{}),e.jsx(us,{isDisabled:a})]}),e.jsx(_t,{children:e.jsxs("div",{className:"pf-u-mt-md",children:[e.jsx(F,{isDisabled:a,variant:X.primary,className:"pf-u-mr-md",type:"submit","data-testid":"save",children:t("common:save")}),e.jsx(F,{variant:"link","data-testid":"cancel",component:g=>e.jsx(mt,{...g,to:Ce({realm:n,clientId:r,tab:"policies"})}),children:t("common:cancel")})]})})]})})]})}const zs=Object.freeze(Object.defineProperty({__proto__:null,default:xs,isValidComponentType:_e},Symbol.toStringTag,{value:"Module"}));export{as as A,is as D,zs as P,ns as U,_e as i};
//# sourceMappingURL=PolicyDetails-63e32b3b.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy