PageSourceSearch

https://cfes-fceg.ca/assets/EmailDelegations-Dy5fKjI-.js

js cfes-fceg.ca collected 2026-10-07 00:42:34 UTC 11,301 bytes, 1 lines download raw bytes

1import{P as A,j as e,y as R}from"./index-DIjT-SAT.js";import{r as s}from"./react-vendor-HKQAQU4_.js";import{C as ae}from"./ConfirmModal-F06FeQCv.js";import{Y as le,w as se,u as oe}from"./platformApi-DlaIEvGM.js";import{P as re}from"./PageShell-CnagczLb.js";import{W as z}from"./WorkspaceUserPicker-BcFnXCna.js";import{u as ne}from"./platformEntitlements-Yk_lBZiP.js";import"./i18n-vendor-Dt0ofUAt.js";import"./iconRegistry-CII8vZNQ.js";function ie(u){const n=u.lastIndexOf("@");return n===-1?"(unknown)":u.slice(n+1).toLowerCase()}function de(u,n){const o=[...u];return o.sort((r,d)=>{const c=r.delegateEmail.toLowerCase(),x=d.delegateEmail.toLowerCase(),l=r.delegatorEmail.toLowerCase(),i=d.delegatorEmail.toLowerCase();return n==="delegate-mailbox"?c.localeCompare(x)||l.localeCompare(i):l.localeCompare(i)||c.localeCompare(x)}),o}const ce=8;function ge(u,n){const o=n.trim().toLowerCase();if(!o)return[];const r=new Map,d=new Set,c=new Map;for(const l of u){const i=l.delegatorEmail.toLowerCase();i.includes(o)&&r.set(i,l.delegatorEmail),l.delegateEmail.toLowerCase().includes(o)&&d.add(l.delegateEmail),l.delegatorFullName&&l.delegatorFullName.toLowerCase().includes(o)&&c.set(l.delegatorFullName.toLowerCase(),l.delegatorFullName)}const x=[];for(const l of r.values())x.push({kind:"mailbox",value:l,label:l});for(const l of d)x.push({kind:"delegate",value:l,label:l});for(const l of c.values())x.push({kind:"name",value:l,label:l});return x.slice(0,ce)}const me={mailbox:"Mailbox",delegate:"Delegate",name:"Name"};function ue(u,n){const o=new Map;for(const r of u){const d=n==="by-delegator"?r.delegatorEmail:n==="by-delegate"?r.delegateEmail:ie(r.delegateEmail),c=o.get(d);c?c.push(r):o.set(d,[r])}return[...o.entries()].sort(([r],[d])=>r.localeCompare(d))}function Ne(){const{can:u}=ne(),n=u("delegations:manage"),[o,r]=s.useState([]),[d,c]=s.useState(!0),[x,l]=s.useState(null),[i,E]=s.useState(""),[f,C]=s.useState("by-delegator"),[H,W]=s.useState({}),X="delegate-mailbox",[Y,F]=s.useState(0),[S,w]=s.useState(!1),[$,v]=s.useState(0),G=s.useRef(null),[J,j]=s.useState(!1),[k,O]=s.useState(""),[D,P]=s.useState(""),[y,K]=s.useState(!1),[_,N]=s.useState(null),[b,L]=s.useState(null),[Q,I]=s.useState(!1);s.useEffect(()=>{const t=new AbortController;return c(!0),l(null),le({},t.signal).then(a=>r(a.delegations)).catch(a=>{t.signal.aborted||l(a instanceof A?a.message:"Failed to load delegations")}).finally(()=>{t.signal.aborted||c(!1)}),()=>t.abort()},[Y]);const T=s.useMemo(()=>{const t=i.trim().toLowerCase();return t?o.filter(a=>a.delegatorEmail.toLowerCase().includes(t)||a.delegateEmail.toLowerCase().includes(t)||(a.delegatorFullName??"").toLowerCase().includes(t)):o},[o,i]),B=s.useMemo(()=>ue(T,f),[T,f]),h=s.useMemo(()=>ge(o,i),[o,i]);s.useEffect(()=>{v(0)},[i,h.length]),s.useEffect(()=>{function t(a){var g;(g=G.current)!=null&&g.contains(a.target)||w(!1)}return document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[]);const U=t=>{E(t.value),w(!1)},V=t=>{if(!(!S||h.length===0))if(t.key==="ArrowDown")t.preventDefault(),v(a=>Math.min(a+1,h.length-1));else if(t.key==="ArrowUp")t.preventDefault(),v(a=>Math.max(a-1,0));else if(t.key==="Enter"){const a=h[$];a&&(t.preventDefault(),U(a))}else t.key==="Escape"&&w(!1)};async function Z(t){t.preventDefault(),N(null);const a=k.trim().toLowerCase(),g=D.trim().toLowerCase();if(!a||!g){N("Both emails are required");return}K(!0);try{await se({delegatorEmail:a,delegateEmail:g}),R.success(`${g} can now access ${a}`),j(!1),O(""),P(""),F(p=>p+1)}catch(p){N(p instanceof A?p.message:"Failed to add delegate")}finally{K(!1)}}async function ee(){if(b){I(!0);try{await oe(b.delegatorEmail,b.delegateEmail),R.success(`Removed ${b.delegateEmail} from ${b.delegatorEmail}`),L(null),F(t=>t+1)}catch(t){R.error(t instanceof A?t.message:"Failed to remove delegate")}finally{I(!1)}}}return e.jsxs(re,{title:"Email delegations",width:"wide",description:n?"Gmail mailbox delegations across the org. Synced daily at 03:15. Reads come from the local cache; writes hit the Gmail API and refresh the affected delegator.":"Gmail mailbox delegations across the org. Synced daily at 03:15. Read-only view — granting or revoking a delegation needs the delegations:manage permission.",actions:n?e.jsx("button",{type:"button",onClick:()=>{N(null),j(!0)},className:"px-3 py-2 text-sm rounded bg-gray-900 hover:bg-gray-800 text-white whitespace-nowrap",children:"Add delegation"}):null,children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3",children:[e.jsxs("div",{ref:G,className:"relative flex-1 min-w-[240px]",children:[e.jsx("input",{type:"search",value:i,onChange:t=>{E(t.target.value),w(!0)},onFocus:()=>w(!0),onKeyDown:V,placeholder:"Filter by mailbox, delegate, or name…",autoComplete:"off",className:"w-full border border-gray-300 rounded px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"}),S&&i.trim()&&h.length>0&&e.jsx("div",{className:"absolute z-10 mt-1 w-full bg-white border border-gray-200 rounded-lg shadow-lg max-h-72 overflow-y-auto",children:h.map((t,a)=>e.jsxs("button",{type:"button",onMouseDown:g=>{g.preventDefault(),U(t)},onMouseEnter:()=>v(a),className:`w-full text-left px-3 py-2 text-sm border-b border-gray-100 last:border-b-0 flex items-center justify-between gap-3 ${a===$?"bg-blue-50":"hover:bg-gray-50"}`,children:[e.jsx("span",{className:"truncate text-gray-900",children:t.label}),e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-gray-500 shrink-0",children:me[t.kind]})]},`${t.kind}:${t.value}`))}),S&&i.trim()&&h.length===0&&o.length>0&&e.jsx("div",{className:"absolute z-10 mt-1 w-full bg-white border border-gray-200 rounded-lg shadow-lg px-3 py-2 text-xs text-gray-500",children:"No matches in loaded delegations."})]}),e.jsxs("div",{className:"inline-flex rounded border border-gray-300 overflow-hidden",children:[e.jsx("button",{type:"button",onClick:()=>C("by-delegator"),className:`px-3 py-2 text-sm ${f==="by-delegator"?"bg-gray-900 text-white":"bg-white text-gray-700"}`,children:"Group by mailbox"}),e.jsx("button",{type:"button",onClick:()=>C("by-delegate"),className:`px-3 py-2 text-sm border-l border-gray-300 ${f==="by-delegate"?"bg-gray-900 text-white":"bg-white text-gray-700"}`,children:"Group by delegate"}),e.jsx("button",{type:"button",onClick:()=>C("by-delegate-domain"),className:`px-3 py-2 text-sm border-l border-gray-300 ${f==="by-delegate-domain"?"bg-gray-900 text-white":"bg-white text-gray-700"}`,children:"Group by delegate domain"})]})]}),x&&e.jsx("div",{className:"mb-4 p-3 border border-red-300 bg-red-50 text-sm text-red-800 rounded",children:x}),d?e.jsx("p",{className:"text-sm text-gray-500",children:"Loading…"}):B.length===0?e.jsx("p",{className:"text-sm text-gray-500",children:"No delegations foun
1d."}):e.jsx("div",{className:"space-y-4",children:B.map(([t,a])=>{const g=f==="by-delegate-domain",p=H[t]??X,M=g?de(a,p):a,q=m=>W(te=>({...te,[t]:m}));return e.jsxs("section",{className:"border border-gray-200 rounded bg-white overflow-hidden",children:[e.jsxs("header",{className:"px-4 py-2 bg-gray-50 border-b border-gray-200 flex items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-gray-900 truncate",children:t}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[g&&e.jsxs("div",{className:"inline-flex rounded border border-gray-300 overflow-hidden text-xs",role:"group","aria-label":"Sort order",children:[e.jsx("button",{type:"button",onClick:()=>q("delegate-mailbox"),className:`px-2 py-0.5 ${p==="delegate-mailbox"?"bg-gray-900 text-white":"bg-white text-gray-700 hover:bg-gray-100"}`,title:"Sort by delegate, then mailbox",children:"delegate → mailbox"}),e.jsx("button",{type:"button",onClick:()=>q("mailbox-delegate"),className:`px-2 py-0.5 border-l border-gray-300 ${p==="mailbox-delegate"?"bg-gray-900 text-white":"bg-white text-gray-700 hover:bg-gray-100"}`,title:"Sort by mailbox, then delegate",children:"mailbox → delegate"})]}),e.jsxs("span",{className:"text-xs text-gray-500",children:[M.length," ",M.length===1?"entry":"entries"]})]})]}),e.jsx("ul",{className:"divide-y divide-gray-100",children:M.map(m=>e.jsxs("li",{className:"px-4 py-2 flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"min-w-0 flex flex-wrap items-baseline gap-x-2",children:[f==="by-delegate-domain"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono text-gray-800",children:m.delegateEmail}),e.jsx("span",{className:"text-xs text-gray-500",children:"→"}),e.jsx("span",{className:"font-mono text-xs text-gray-600",children:m.delegatorEmail})]}):e.jsx("span",{className:"font-mono text-gray-800",children:f==="by-delegator"?m.delegateEmail:m.delegatorEmail}),e.jsx("span",{className:"inline-block text-xs px-1.5 py-0.5 rounded bg-gray-100 text-gray-600",children:m.verificationStatus})]}),n&&e.jsx("button",{type:"button",onClick:()=>L({delegatorEmail:m.delegatorEmail,delegateEmail:m.delegateEmail}),className:"text-xs px-2 py-1 rounded border border-gray-300 hover:bg-gray-50 text-gray-700",children:"Remove"})]},`${m.delegatorEmail}|${m.delegateEmail}`))})]},t)})}),J&&n&&e.jsx("div",{className:"fixed inset-0 z-40 flex items-center justify-center p-4 bg-black bg-opacity-50",onClick:t=>{t.target===t.currentTarget&&!y&&j(!1)},role:"dialog","aria-modal":"true",children:e.jsxs("form",{onSubmit:Z,className:"bg-white rounded-lg shadow-xl w-full max-w-2xl",children:[e.jsxs("div",{className:"px-5 py-4 border-b border-gray-200",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-900",children:"Add email delegation"}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"The delegate (left) will be able to send and read mail on behalf of the mailbox (right)."})]}),e.jsxs("div",{className:"px-5 py-4 text-sm",children:[e.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] items-end gap-3",children:[e.jsx(z,{id:"add-delegate",label:"Delegate (person with access)",value:D,onChange:P,placeholder:"[email protected]",disabled:y,excludeEmail:k}),e.jsx("div",{className:"pb-2 text-gray-400 text-2xl select-none leading-none","aria-hidden":"true",title:"gets access to",children:"→"}),e.jsx(z,{id:"add-delegator",label:"Mailbox (delegator)",value:k,onChange:O,placeholder:"[email protected]",disabled:y,excludeEmail:D})]}),_&&e.jsx("p",{className:"mt-3 text-sm text-red-700 bg-red-50 border border-red-200 rounded px-2 py-1",children:_})]}),e.jsxs("div",{className:"px-5 py-3 border-t border-gray-200 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>j(!1),disabled:y,className:"px-3 py-1.5 text-sm rounded border border-gray-300 bg-white hover:bg-gray-50 disabled:opacity-50",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:y,className:"px-3 py-1.5 text-sm rounded bg-gray-900 hover:bg-gray-800 text-white disabled:opacity-50",children:y?"Adding…":"Add"})]})]})}),e.jsx(ae,{open:b!==null,title:"Remove delegation",message:b?e.jsxs("span",{children:["Remove"," ",e.jsx("span",{className:"font-mono",children:b.delegateEmail})," as a delegate of ",e.jsx("span",{className:"font-mono",children:b.delegatorEmail}),"?"]}):null,confirmLabel:"Remove",variant:"danger",busy:Q,onConfirm:ee,onCancel:()=>L(null)})]})}export{Ne as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.