Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69ed8c742a | ||
|
|
258c25efe1 | ||
|
|
a378fdf345 | ||
|
|
96e3fead0a |
No files matched your search
@@ -21,4 +21,4 @@ between lil-koneko.com, CarsHub, iriks-it.nl and bouwbedrijf.iriks-it.nl, as one
|
||||
|
||||
1. Frontend: decided and built: the screens are in the package (`ui/`, built into `resources/dist`, committed; PR CI checks it is up to date). Still open: a theme editor in the manager, and a `host` mode that publishes the sources for a site to build itself.
|
||||
2. Moving the rest from bouwbedrijf.iriks-it.nl: real pages and reviews (now skeletons) and revisions. Users, media, posts, audit log and statistics are done, with their screens. Leave out what is site-specific (the IriksIT API disk, the owner's simple screens, client names): this repo is public.
|
||||
3. How the host's own `User` and a package `Group` relate when the host has its own roles.
|
||||
3. Decided in 0.5.0: groups stay the default and the host's roles are added next to them (`manager.permissions`: `mode` groups, host or merge; `roles` or a `PermissionResolver`). A host that wants to replace the groups screens entirely is not planned.
|
||||
@@ -31,6 +31,10 @@ the section is the text of the release in Gitea.
|
||||
- Editor: Markdown fields get a toolbar, photos from the media library and a server-rendered preview (`POST /manager/markdown`); the media
|
||||
library gets a click-to-set focus point with a square preview. (No cropping or rotating: the file stays as uploaded.)
|
||||
- Statistics: `<x-manager::pulse />` puts the counting script (`/pulse/pulse.js`, no cookies, honours Do Not Track) in the public pages of a site.
|
||||
- Login checks: `manager.login.checks` (contract `LoginCheck`, base class `BaseLoginCheck`) adds fields and checks before and after the password;
|
||||
Cloudflare Turnstile is built in (two env keys). No two-factor login in the package itself.
|
||||
- Roles of the host: `manager.permissions` (`mode` groups/host/merge, `roles` map or a `resolver` implementing `PermissionResolver`) lets a site
|
||||
with its own roles say what an account may do; groups stay the default.
|
||||
|
||||
## v0.4.0 - 2026-12-04
|
||||
|
||||
|
||||
@@ -112,9 +112,25 @@ php artisan manager:create-user # the only way to make a super admin
|
||||
- `groups.manage` is a gate for super admins only, not a permission of a group.
|
||||
- The package defines one gate per permission and **no `Gate::before`**: it never answers for the
|
||||
abilities of your own app.
|
||||
- **A site with roles of its own** (decided in 0.5.0: groups stay the default, the site's roles are added next to them).
|
||||
`manager.permissions.mode` is `groups` (default), `host` (the groups are ignored) or `merge` (both). The site says what a role may do
|
||||
with `roles` (`['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]`, read from the attribute `role_attribute`: a string, a
|
||||
list or a relation with a `name`) or with a `resolver` class that implements `IriksIT\Manager\Contracts\PermissionResolver`. Values
|
||||
that are no permission of an active module are ignored and what a permission needs is added. A super admin may always do everything.
|
||||
The group screens still work in `host` mode but give nothing.
|
||||
- The migration adds `is_super_admin` to your users table (the table of `manager.user_model`). It
|
||||
promotes nobody.
|
||||
|
||||
## Checks on the login
|
||||
|
||||
The login of the screens can ask for more. Write a class that extends `IriksIT\Manager\Support\Login\BaseLoginCheck` (the contract is `IriksIT\Manager\Contracts\LoginCheck`) and list it in `manager.login.checks`:
|
||||
|
||||
- `fields()`: extra inputs on the form (`['name' => 'code', 'type' => 'text', 'label' => 'Code', 'autocomplete' => 'one-time-code']`);
|
||||
- `before($request)`: runs before the password is looked at: a captcha;
|
||||
- `after($request, $user)`: runs when the email and password are right and before anyone is logged in: a second factor. Refuse by throwing a `ValidationException`; the attempt then counts as a failed login, so the audit log and the bans see it.
|
||||
|
||||
**Cloudflare Turnstile** is built in: set `MANAGER_TURNSTILE_SITE_KEY` and `MANAGER_TURNSTILE_SECRET` and the widget appears and is checked (a token that cannot be checked refuses the login). The widget loads a script from `challenges.cloudflare.com`; a strict Content-Security-Policy has to allow it. **There is no two-factor login in the package itself**: `after()` is the place for it, the code to make and keep the secrets is the site's. These checks belong to the login of the screens (`MANAGER_UI=package`); an app with its own login keeps its own.
|
||||
|
||||
## Media module
|
||||
|
||||
Files live on a Laravel filesystem disk (`manager.media.disk`); each row remembers its own disk.
|
||||
|
||||
@@ -41,3 +41,5 @@ Per stuk werk een rij; zie `dev/token-usage.py`.
|
||||
| 2026-12-04 | Revisies: geschiedenis van berichten en pagina's, met terugzetten | - | claude-sonnet-5-5 | 6 | 12.423 | 12 | 14.609 | 1.461.419 | 0,03 |
|
||||
| 2026-12-04 | De editor: opmaakknoppen, foto's in de tekst, voorbeeld en een scherpstelpunt in de bibliotheek | - | claude-sonnet-5-5 | 15 | 18.397 | 30 | 28.742 | 3.931.230 | 0,07 |
|
||||
| 2026-12-04 | Het telscript en de Blade-component voor de publieke pagina's van de statistieken | - | claude-sonnet-5-5 | 8 | 9.037 | 16 | 15.948 | 2.254.948 | 0,04 |
|
||||
| 2026-12-04 | Loginhaken: eigen velden en controles, en Turnstile | - | claude-sonnet-5-5 | 4 | 9.009 | 8 | 9.515 | 1.178.544 | 0,02 |
|
||||
| 2026-12-04 | Rollen van de site naast de groepen van het pakket | - | claude-sonnet-5-5 | 3 | 5.308 | 6 | 8.235 | 921.246 | 0,01 |
|
||||
@@ -184,6 +184,26 @@ return [
|
||||
*/
|
||||
'revisions' => ['keep' => 50, 'types' => [], 'skip' => []],
|
||||
|
||||
/*
|
||||
| More a login asks for. `checks`: classes that implement IriksIT\Manager\Contracts\LoginCheck (extend
|
||||
| IriksIT\Manager\Support\Login\BaseLoginCheck): a field of the form, something to check before the password is
|
||||
| tried (a captcha) or after it was right (a second factor). Cloudflare Turnstile is built in and turns itself on
|
||||
| when both of its keys are set. These apply to the login of the manager's own screens.
|
||||
*/
|
||||
'login' => [
|
||||
'checks' => [],
|
||||
'turnstile' => ['site_key' => env('MANAGER_TURNSTILE_SITE_KEY'), 'secret' => env('MANAGER_TURNSTILE_SECRET')],
|
||||
],
|
||||
|
||||
/*
|
||||
| Who may do what. `groups` (default): the groups of the package. A site that has roles of its own can say it itself:
|
||||
| `host` takes the permissions only from the site, `merge` adds them to what the groups give. The site's side is a
|
||||
| `resolver` class (IriksIT\Manager\Contracts\PermissionResolver), or, simpler, `roles` per role name (`*` is
|
||||
| everything) read from the attribute `role_attribute` of the account (a string, a list or a relation with a `name`).
|
||||
| 'roles' => ['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]. A super admin may always do everything.
|
||||
*/
|
||||
'permissions' => ['mode' => env('MANAGER_PERMISSIONS', 'groups'), 'resolver' => null, 'roles' => [], 'role_attribute' => 'role'],
|
||||
|
||||
/*
|
||||
| The menu. `items` changes what a module gives, by the route name without the prefix:
|
||||
| 'posts.index' => ['order' => 10, 'section' => 'Content', 'icon' => 'file', 'simple' => true, 'hidden' => false].
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
var e=Object.defineProperty,t=(t,n)=>{let r=Object.setPrototypeOf({},null);for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&1||e(r,Symbol.toStringTag,{value:`Module`}),n&2?r:Object.preventExtensions(r)};function n(e){let t=Object.create(null);for(let n of e.split(`,`))t[n]=1;return e=>e in t}var r={},i=[],a=()=>{},o=()=>!1,s=e=>e.charCodeAt(0)===111&&e.charCodeAt(1)===110&&(e.charCodeAt(2)>122||e.charCodeAt(2)<97),c=e=>e.startsWith(`onUpdate:`),l=Object.assign,u=(e,t)=>{let n=e.indexOf(t);n>-1&&e.splice(n,1)},d=Object.prototype.hasOwnProperty,f=(e,t)=>d.call(e,t),p=Array.isArray,m=e=>C(e)===`[object Map]`,h=e=>C(e)===`[object Set]`,g=e=>C(e)===`[object Date]`,_=e=>C(e)===`[object RegExp]`,v=e=>typeof e==`function`,y=e=>typeof e==`string`,b=e=>typeof e==`symbol`,x=e=>typeof e==`object`&&!!e,S=e=>(x(e)||v(e))&&v(e.then)&&v(e.catch),ee=Object.prototype.toString,C=e=>ee.call(e),te=e=>C(e).slice(8,-1),w=e=>C(e)===`[object Object]`,T=e=>y(e)&&e!==`NaN`&&e[0]!==`-`&&``+parseInt(e,10)===e,ne=n(`,key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted`),re=1e4,ie=e=>{let t=Object.create(null),n=0;return(r=>{let i=t[r];return i===void 0?(++n>re&&(t=Object.create(null),n=1),t[r]=e(r)):i})},ae=/-\w/g,E=ie(e=>e.replace(ae,e=>e.slice(1).toUpperCase())),oe=/\B([A-Z])/g,se=ie(e=>e.replace(oe,`-$1`).toLowerCase()),ce=ie(e=>e.charAt(0).toUpperCase()+e.slice(1)),le=ie(e=>e?`on${ce(e)}`:``),D=(e,t)=>!Object.is(e,t),ue=(e,...t)=>{for(let n=0;n<e.length;n++)e[n](...t)},de=(e,t,n,r=!1)=>{Object.defineProperty(e,t,{configurable:!0,enumerable:!1,writable:r,value:n})},fe=e=>{let t=parseFloat(e);return isNaN(t)?e:t},pe=e=>{let t=y(e)?Number(e):NaN;return isNaN(t)?e:t},me,he=()=>me||=typeof globalThis<`u`?globalThis:typeof self<`u`?self:typeof window<`u`?window:typeof global<`u`?global:{},ge=n(`Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol`);function _e(e){if(p(e)){let t={};for(let n=0;n<e.length;n++){let r=e[n],i=y(r)?xe(r):_e(r);if(i)for(let e in i)t[e]=i[e]}return t}if(y(e)||x(e))return e}var ve=/;(?![^(]*\))/g,ye=/:([^]+)/,be=/"(?:[^"\\]|\\[^])*"|'(?:[^'\\]|\\[^])*'|\\[^]|\/\*[^]*?\*\//g;function xe(e){let t={};return e.replace(be,e=>e.startsWith(`/*`)?``:e).split(ve).forEach(e=>{if(e){let n=e.split(ye);n.length>1&&(t[n[0].trim()]=n[1].trim())}}),t}function O(e){let t=``;if(y(e))t=e;else if(p(e))for(let n=0;n<e.length;n++){let r=O(e[n]);r&&(t+=r+` `)}else if(x(e))for(let n in e)e[n]&&(t+=n+` `);return t.trim()}function Se(e){if(!e)return null;let{class:t,style:n}=e;return t&&!y(t)&&(e.class=O(t)),n&&(e.style=_e(n)),e}var Ce=`itemscope,allowfullscreen,disablepictureinpicture,disableremoteplayback,formnovalidate,ismap,nomodule,novalidate,playsinline,readonly`,we=n(Ce);Ce+``;function Te(e){return!!e||e===``}function Ee(e,t,n){if(e.length!==t.length)return!1;let r=!0;for(let i=0;r&&i<e.length;i++)r=Ae(e[i],t[i],n);return r}function De(e,t,n){if(e.size!==t.size)return!1;let r=Array.from(t),i=new Uint8Array(r.length);for(let t of e){let e=-1;for(let a=0;a<r.length;a++)if(!i[a]&&Ae(t,r[a],n)){e=a;break}if(e<0)return!1;i[e]=1}return!0}function Oe(e,t,n){let r=m(e),i=m(t);if(r||i||(r=h(e),i=h(t),r||i))return r&&i?De(e,t,n):!1;if(Object.keys(e).length!==Object.keys(t).length)return!1;for(let r in e){let i=f(e,r),a=f(t,r);if(i&&!a||!i&&a||!Ae(e[r],t[r],n))return!1}return Me(e)===Me(t)}function ke(e,t,n,r){n||=[new Map,new Map];let[i,a]=n;if(i.has(e)||a.has(t))return i.get(e)===t&&a.get(t)===e;i.set(e,t),a.set(t,e);let o=r(e,t,n);return i.delete(e),a.delete(t),o}function Ae(e,t,n){if(e===t)return!0;let r=g(e),i=g(t);return r||i?r&&i?e.getTime()===t.getTime():!1:(r=b(e),i=b(t),r||i?e===t:(r=p(e),i=p(t),r||i?r&&i?ke(e,t,n,Ee):!1:(r=x(e),i=x(t),r||i?!r||!i?!1:ke(e,t,n,Oe):String(e)===String(t))))}function je(e,t){return e.findIndex(e=>Ae(e,t))}function Me(e){return Object.getPrototypeOf(e)===null&&e[Symbol.toPrimitive]==null&&typeof e.toString!=`function`&&typeof e.valueOf!=`function`?C(e):String(e)}var Ne=e=>!!(e&&e.__v_isRef===!0),k=e=>y(e)?e:e==null?``:p(e)||x(e)&&(e.toString===ee||!v(e.toString))?Ne(e)?k(e.value):JSON.stringify(e,Pe,2):String(e),Pe=(e,t)=>Ne(t)?Pe(e,t.value):m(t)?{[`Map(${t.size})`]:[...t.entries()].reduce((e,[t,n],r)=>(e[Fe(t,r)+` =>`]=n,e),{})}:h(t)?{[`Set(${t.size})`]:[...t.values()].map(e=>Fe(e))}:b(t)?Fe(t):x(t)&&!p(t)&&!w(t)?String(t):t,Fe=(e,t=``)=>b(e)?`Symbol(${e.description??t})`:e;function Ie(e){return e==null?`initial`:typeof e==`string`?e===``?` `:e:String(e)}var Le,Re=class{constructor(e=!1){this.detached=e,this._active=!0,this._on=0,this.effects=[],this.cleanups=[],this._isPaused=!1,this._warnOnRun=!0,this.__v_skip=!0,!e&&Le&&(Le.active?(this.parent=Le,this.index=(Le.scopes||(Le.scopes=[])).push(this)-1):(this._active=!1,this._warnOnRun=!1))}get active(){return thLine truncated
|
||||
`&&(e.tagName===`PRE`||e.tagName===`TEXTAREA`)&&(n=n.slice(1));let{textContent:r}=e;r!==n&&r!==n.replace(/\r\n|\r/g,`
|
||||
`)&&(Ai(e,0)||bi(),e.textContent=t.children)}if(d){if(_||b||!o||f&48){let t=e.tagName.includes(`-`),i=e.namespaceURI.includes(`svg`)?`svg`:e.namespaceURI.includes(`MathML`)?`mathml`:void 0;for(let a in d)if(_&&(a.endsWith(`value`)||a===`indeterminate`)||s(a)&&!ne(a)||a[0]===`.`||t&&!ne(a)||u&&u.includes(a)){if(Di(e,a,d[a]))continue;r(e,a,null,d[a],i,n)}}else if(d.onClick)r(e,`onClick`,null,d.onClick,void 0,n);else if(f&4&&ln(d.style))for(let e in d.style)d.style[e]}let x;(x=d&&d.onVnodeBeforeMount)&&Rs(x,n,t),h&&wr(t,null,n,`beforeMount`),((x=d&&d.onVnodeMounted)||h||l)&&ms(()=>{x&&Rs(x,n,t),l&&g.enter(e),h&&wr(t,null,n,`mounted`)},i)}return e.nextSibling},m=(e,t,r,o,s,c,u,d)=>{u||=!!t.dynamicChildren;let p=t.children,m=p.length,h=t.type===B,g=!1;for(let t=0;t<m;t++){let _=u?p[t]:p[t]=Ps(p[t]),v=_.type===_s;h&&e&&wi(e)&&e.data===`]`&&(d=e),e&&e!==d?(v&&!u&&t+1<m&&Ps(p[t+1]).type===_s&&(l(i(e.data.slice(_.children.length)),r,a(e)),e.data=_.children),e=f(e,_,o,s,c,u)):v&&!_.children?l(_.el=i(``),r,d):(g||(g=!0,Ai(r,1)||bi()),n(null,_,r,d,o,s,Ci(r),c))}return e},h=(e,t,n,r,i,s)=>{let{slotScopeIds:c}=t;c&&(i=i?i.concat(c):c);let d=o(e),f=m(a(e),t,d,n,r,i,s);return f&&wi(f)&&f.data===`]`?a(t.anchor=f):(bi(),l(t.anchor=u(`]`),d,f),f)},g=(e,t,r,i,s,l)=>{if(Mi(e,t)||bi(),t.el=null,l){let t=_(e);for(;;){let n=a(e);if(n&&n!==t)c(n);else break}}let u=a(e),d=o(e);return c(e),n(null,t,d,u,r,i,Ci(d),s),r&&r.vnode.el===e&&(r.vnode.el=t.el,wo(r,t.el)),u},_=(e,t=`[`,n=`]`)=>{let r=0;for(;e;)if(e=a(e),e&&wi(e)&&(e.data===t&&r++,e.data===n)){if(r===0)return a(e);r--}return e},v=(e,t,n)=>{let r=t.parentNode;r&&r.replaceChild(e,t);let i=n;for(;i;)i.vnode.el===t&&(i.vnode.el=i.subTree.el=e),i=i.parent},y=e=>e.nodeType===1&&e.tagName===`TEMPLATE`;return[d,f]}var Ei=new Set([`src`,`srcset`,`href`,`poster`]);function Di(e,t,n){return Ei.has(t)?e.getAttribute(t)===(n==null?null:`${n}`):!1}var Oi=`data-allow-mismatch`,ki={0:`text`,1:`children`,2:`class`,3:`style`,4:`attribute`};function Ai(e,t){if(t===0||t===1)for(;e&&!e.hasAttribute(Oi);)e=e.parentElement;return ji(e&&e.getAttribute(Oi),t)}function ji(e,t){if(e==null)return!1;if(e===``)return!0;{let n=e.split(`,`);return t===0&&n.includes(`children`)?!0:n.includes(ki[t])}}function Mi(e,t){return Ai(e.parentElement,1)||Ni(e)||Pi(t)}function Ni(e){return e.nodeType===1&&ji(e.getAttribute(Oi),1)}function Pi({props:e}){let t=e&&e[Oi];return typeof t==`string`&&ji(t,1)}var Fi=he().requestIdleCallback||(e=>setTimeout(e,1)),Ii=he().cancelIdleCallback||(e=>clearTimeout(e)),Li=(e=1e4)=>t=>{let n=Fi(t,{timeout:e});return()=>Ii(n)};function Ri(e){let{top:t,left:n,bottom:r,right:i}=e.getBoundingClientRect(),{innerHeight:a,innerWidth:o}=window;return(t>0&&t<a||r>0&&r<a)&&(n>0&&n<o||i>0&&i<o)}var zi=e=>(t,n)=>{let r=new IntersectionObserver(e=>{for(let n of e)if(n.isIntersecting){r.disconnect(),t();break}},e),i=e=>{if(Ri(e))return t(),r.disconnect(),!1;if(getComputedStyle(e).display===`contents`){for(let t=0;t<e.children.length;t++)if(i(e.children[t])===!1)return!1}r.observe(e)};return n(e=>{if(e instanceof Element)return i(e)}),()=>r.disconnect()},Bi=e=>t=>{if(e){let n=matchMedia(e);if(n.matches)t();else return n.addEventListener(`change`,t,{once:!0}),()=>n.removeEventListener(`change`,t)}},Vi=(e=[])=>(t,n)=>{y(e)&&(e=[e]);let r=!1,i=e=>{r||(r=!0,a(),t(),e.target.dispatchEvent(new e.constructor(e.type,e)))},a=()=>{n(t=>{for(let n of e)t.removeEventListener(n,i)})};return n(t=>{for(let n of e)t.addEventListener(n,i,{once:!0})}),a};function Hi(e,t){if(wi(e)&&e.data===`[`){let n=1,r=e.nextSibling;for(;r;){if(r.nodeType===1){if(t(r)===!1)break}else if(wi(r)){if(r.data===`]`){if(--n===0)break}else r.data===`[`&&n++}r=r.nextSibling}}else t(e)}var Ui=e=>!!e.type.__asyncLoader;function Wi(e){v(e)&&(e={loader:e});let{loader:t,loadingComponent:n,errorComponent:r,delay:i=200,hydrate:a,timeout:o,suspensible:s=!0,onError:c}=e,l=null,u,d=0,f=()=>(d++,l=null,p()),p=()=>{let e;return l||(e=l=t().catch(e=>{if(e=e instanceof Error?e:Error(String(e)),c)return new Promise((t,n)=>{c(e,()=>t(f()),()=>n(e),d+1)});throw e}).then(t=>e!==l&&l?l:(t&&(t.__esModule||t[Symbol.toStringTag]===`Module`)&&(t=t.default),u=t,t)))};return L({name:`AsyncComponentWrapper`,__asyncLoader:p,__asyncHydrate(e,t,n){let r=e.isConnected,i=!1;(t.bu||=[]).push(()=>i=!0);let o=()=>{i||!e.parentNode||r&&!e.isConnected||n()},s=a?()=>{let n=a(o,t=>Hi(e,t));n&&(t.bum||=[]).push(n)}:o;u?s():p().then(()=>!t.isUnmounted&&s())},get __asyncResolved(){return u},setup(){let e=Us;if(pi(e),u)return()=>Gi(u,e);let t=t=>{l=null,Yn(t,e,13,!r,!0)};if(s&&e.suspense||Xs)return p().then(t=>()=>Gi(t,e)).catch(e=>(t(e),()=>r?K(r,{error:e}):null));let a=N(!1),c=N(),d=N(!!i),f,m;return Ve(()=>{f!=null&&clearTimeout(f),m!=null&&clearTimeout(m)}),i&&(m=setTimeout(()=>{e.isUnmounted||(d.value=!1)},i)),o!=null&&(f=setTimeout(()=>{if(!e.isUnmounted&&!a.value&&!c.value){let e=Error(`Async component timed out after ${o}ms.`);t(e),c.value=e}},o)),p().then(()=>{e.isUnmounted|
Line truncated
|
||||
`))),e[cu]=au(i);let a=r||i.props&&i.props.type===`number`;xl(e,t?`change`:`input`,t=>{t.target.composing||e[cu](uu(e.value,n,a))}),(n||a)&&xl(e,`change`,()=>{e.value=uu(e.value,n,a)}),t||(xl(e,`compositionstart`,ou),xl(e,`compositionend`,su),xl(e,`change`,su))},mounted(e,{value:t,modifiers:{trim:n,number:r}}){let i=t??``,a=e[lu];delete e[lu],a!==void 0&&(e.type===`text`||e.type===`textarea`)&&e.value!==a?e[cu](uu(e.value,n,r)):e.value=i},beforeUpdate(e,{value:t,oldValue:n,modifiers:{lazy:r,trim:i,number:a}},o){if(e[cu]=au(o),e.composing)return;let s=(a||e.type===`number`)&&!/^0\d/.test(e.value)?fe(e.value):e.value,c=t??``;if(s===c)return;let l=e.getRootNode();(l instanceof Document||l instanceof ShadowRoot)&&l.activeElement===e&&e.type!==`range`&&(r&&t===n||i&&e.value.trim()===c)||(e.value=c)}},du={deep:!0,created(e,t,n){e[cu]=au(n),xl(e,`change`,()=>{let t=e._modelValue,n=_u(e),r=e.checked,i=e[cu];if(p(t)){let e=je(t,n),a=e!==-1;if(r&&!a)i(t.concat(n));else if(!r&&a){let n=[...t];n.splice(e,1),i(n)}}else if(h(t)){let e=new Set(t);r?e.add(n):e.delete(n),i(e)}else i(vu(e,r))})},mounted:fu,beforeUpdate(e,t,n){e[cu]=au(n),fu(e,t,n)}};function fu(e,{value:t,oldValue:n},r){e._modelValue=t;let i;if(p(t))i=je(t,r.props.value)>-1;else if(h(t))i=t.has(r.props.value);else{if(t===n)return;i=Ae(t,vu(e,!0))}e.checked!==i&&(e.checked=i)}var pu={created(e,{value:t},n){e.checked=Ae(t,n.props.value),e[cu]=au(n),xl(e,`change`,()=>{e[cu](_u(e))})},beforeUpdate(e,{value:t,oldValue:n},r){e[cu]=au(r),t!==n&&(e.checked=Ae(t,r.props.value))}},mu={deep:!0,created(e,{value:t,modifiers:{number:n}},r){e._modelValue=t,xl(e,`change`,()=>{let t=Array.prototype.filter.call(e.options,e=>e.selected).map(e=>n?fe(_u(e)):_u(e)),r=e.multiple,i=r?h(e._modelValue)?new Set(t):t:t[0],a=e._pendingValue=[r,r?p(i)?t.slice():t:i];try{e[cu](i)}finally{ir(()=>{e._pendingValue===a&&(e._pendingValue=void 0)})}}),e[cu]=au(r)},mounted(e,{value:t,modifiers:{number:n}}){gu(e,t,n)},beforeUpdate(e,{value:t},n){e._modelValue=t,e[cu]=au(n)},updated(e,{value:t,modifiers:{number:n}}){let r=e._pendingValue;e._pendingValue=void 0,r&&r[0]===e.multiple&&hu(t,r[1],r[0])||gu(e,t,n)}};function hu(e,t,n){if(!n||p(e))return Ae(e,t);if(h(e)){if(e.size!==t.length)return!1;for(let n of t)if(!e.has(n))return!1;return!0}return!1}function gu(e,t,n=!1){let r=e.multiple,i=p(t);if(!r||i||h(t)){for(let a=0,o=e.options.length;a<o;a++){let o=e.options[a],s=_u(o);if(r){if(i){let e=typeof s;o.selected=e===`string`||e===`number`?t.some(e=>String(e)===String(s)):je(t,s)>-1}else o.selected=t.has(s)||n&&typeof s==`string`&&t.has(fe(s))}else if(Ae(_u(o),t)){e.selectedIndex!==a&&(e.selectedIndex=a);return}}!r&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function _u(e){return`_value`in e?e._value:e.value}function vu(e,t){let n=t?`_trueValue`:`_falseValue`;return n in e?e[n]:t}var yu={created(e,t,n){xu(e,t,n,null,`created`)},mounted(e,t,n){xu(e,t,n,null,`mounted`)},beforeUpdate(e,t,n,r){xu(e,t,n,r,`beforeUpdate`)},updated(e,t,n,r){xu(e,t,n,r,`updated`)}};function bu(e,t){switch(e){case`SELECT`:return mu;case`TEXTAREA`:return Y;default:switch(t){case`checkbox`:return du;case`radio`:return pu;default:return Y}}}function xu(e,t,n,r,i){let a=bu(e.tagName,n.props&&n.props.type)[i];a&&a(e,t,n,r)}function Su(){Y.getSSRProps=({value:e})=>({value:e}),pu.getSSRProps=({value:e},t)=>{if(t.props&&Ae(t.props.value,e))return{checked:!0}},du.getSSRProps=({value:e},t)=>{if(p(e)){if(t.props&&je(e,t.props.value)>-1)return{checked:!0}}else if(h(e)){if(t.props&&e.has(t.props.value))return{checked:!0}}else if(e)return{checked:!0}},yu.getSSRProps=(e,t)=>{if(typeof t.type!=`string`)return;let n=bu(t.type.toUpperCase(),t.props&&t.props.type);if(n.getSSRProps)return n.getSSRProps(e,t)}}var Cu=[`ctrl`,`shift`,`alt`,`meta`],wu={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>`button`in e&&e.button!==0,middle:e=>`button`in e&&e.button!==1,right:e=>`button`in e&&e.button!==2,exact:(e,t)=>Cu.some(n=>e[`${n}Key`]&&!t.includes(n))},Tu=(e,t)=>{if(!e)return e;let n=e._withMods||={},r=t.join(`.`);return n[r]||(n[r]=((n,...r)=>{for(let e=0;e<t.length;e++){let r=wu[t[e]];if(r&&r(n,t))return}return e(n,...r)}))},Eu={esc:`escape`,space:` `,up:`arrow-up`,left:`arrow-left`,right:`arrow-right`,down:`arrow-down`,delete:`backspace`},Du=(e,t)=>{let n=e._withKeys||={},r=t.join(`.`),i=n[r];if(i)return i;let a=t.some(e=>e===`left`||e===`right`);return n[r]=(n=>{if(!(`key`in n))return a?e(n):void 0;let r=se(n.key);if(t.some(e=>e===r||Eu[e]===r))return e(n)})},Ou=l({patchProp:Nl},kc),ku,Au=!1;function ju(){return ku||=Uo(Ou)}function Mu(){return ku=Au?ku:Wo(Ou),Au=!0,ku}var Nu=((...e)=>{ju().render(...e)}),Pu=((...e)=>{Mu().hydrate(...e)}),Fu=((...e)=>{let t=ju().createApp(...e),{mount:n}=t;return t.mount=e=>{let r=Ru(e);if(!r)return;let i=t._component;v(i)||i.render||i.template||(i.template=r.innerHTML),r.nodeType===
Line truncated
|
||||
`))),e[cu]=au(i);let a=r||i.props&&i.props.type===`number`;xl(e,t?`change`:`input`,t=>{t.target.composing||e[cu](uu(e.value,n,a))}),(n||a)&&xl(e,`change`,()=>{e.value=uu(e.value,n,a)}),t||(xl(e,`compositionstart`,ou),xl(e,`compositionend`,su),xl(e,`change`,su))},mounted(e,{value:t,modifiers:{trim:n,number:r}}){let i=t??``,a=e[lu];delete e[lu],a!==void 0&&(e.type===`text`||e.type===`textarea`)&&e.value!==a?e[cu](uu(e.value,n,r)):e.value=i},beforeUpdate(e,{value:t,oldValue:n,modifiers:{lazy:r,trim:i,number:a}},o){if(e[cu]=au(o),e.composing)return;let s=(a||e.type===`number`)&&!/^0\d/.test(e.value)?fe(e.value):e.value,c=t??``;if(s===c)return;let l=e.getRootNode();(l instanceof Document||l instanceof ShadowRoot)&&l.activeElement===e&&e.type!==`range`&&(r&&t===n||i&&e.value.trim()===c)||(e.value=c)}},du={deep:!0,created(e,t,n){e[cu]=au(n),xl(e,`change`,()=>{let t=e._modelValue,n=_u(e),r=e.checked,i=e[cu];if(p(t)){let e=je(t,n),a=e!==-1;if(r&&!a)i(t.concat(n));else if(!r&&a){let n=[...t];n.splice(e,1),i(n)}}else if(h(t)){let e=new Set(t);r?e.add(n):e.delete(n),i(e)}else i(vu(e,r))})},mounted:fu,beforeUpdate(e,t,n){e[cu]=au(n),fu(e,t,n)}};function fu(e,{value:t,oldValue:n},r){e._modelValue=t;let i;if(p(t))i=je(t,r.props.value)>-1;else if(h(t))i=t.has(r.props.value);else{if(t===n)return;i=Ae(t,vu(e,!0))}e.checked!==i&&(e.checked=i)}var pu={created(e,{value:t},n){e.checked=Ae(t,n.props.value),e[cu]=au(n),xl(e,`change`,()=>{e[cu](_u(e))})},beforeUpdate(e,{value:t,oldValue:n},r){e[cu]=au(r),t!==n&&(e.checked=Ae(t,r.props.value))}},mu={deep:!0,created(e,{value:t,modifiers:{number:n}},r){e._modelValue=t,xl(e,`change`,()=>{let t=Array.prototype.filter.call(e.options,e=>e.selected).map(e=>n?fe(_u(e)):_u(e)),r=e.multiple,i=r?h(e._modelValue)?new Set(t):t:t[0],a=e._pendingValue=[r,r?p(i)?t.slice():t:i];try{e[cu](i)}finally{ir(()=>{e._pendingValue===a&&(e._pendingValue=void 0)})}}),e[cu]=au(r)},mounted(e,{value:t,modifiers:{number:n}}){gu(e,t,n)},beforeUpdate(e,{value:t},n){e._modelValue=t,e[cu]=au(n)},updated(e,{value:t,modifiers:{number:n}}){let r=e._pendingValue;e._pendingValue=void 0,r&&r[0]===e.multiple&&hu(t,r[1],r[0])||gu(e,t,n)}};function hu(e,t,n){if(!n||p(e))return Ae(e,t);if(h(e)){if(e.size!==t.length)return!1;for(let n of t)if(!e.has(n))return!1;return!0}return!1}function gu(e,t,n=!1){let r=e.multiple,i=p(t);if(!r||i||h(t)){for(let a=0,o=e.options.length;a<o;a++){let o=e.options[a],s=_u(o);if(r){if(i){let e=typeof s;o.selected=e===`string`||e===`number`?t.some(e=>String(e)===String(s)):je(t,s)>-1}else o.selected=t.has(s)||n&&typeof s==`string`&&t.has(fe(s))}else if(Ae(_u(o),t)){e.selectedIndex!==a&&(e.selectedIndex=a);return}}!r&&e.selectedIndex!==-1&&(e.selectedIndex=-1)}}function _u(e){return`_value`in e?e._value:e.value}function vu(e,t){let n=t?`_trueValue`:`_falseValue`;return n in e?e[n]:t}var yu={created(e,t,n){xu(e,t,n,null,`created`)},mounted(e,t,n){xu(e,t,n,null,`mounted`)},beforeUpdate(e,t,n,r){xu(e,t,n,r,`beforeUpdate`)},updated(e,t,n,r){xu(e,t,n,r,`updated`)}};function bu(e,t){switch(e){case`SELECT`:return mu;case`TEXTAREA`:return Y;default:switch(t){case`checkbox`:return du;case`radio`:return pu;default:return Y}}}function xu(e,t,n,r,i){let a=bu(e.tagName,n.props&&n.props.type)[i];a&&a(e,t,n,r)}function Su(){Y.getSSRProps=({value:e})=>({value:e}),pu.getSSRProps=({value:e},t)=>{if(t.props&&Ae(t.props.value,e))return{checked:!0}},du.getSSRProps=({value:e},t)=>{if(p(e)){if(t.props&&je(e,t.props.value)>-1)return{checked:!0}}else if(h(e)){if(t.props&&e.has(t.props.value))return{checked:!0}}else if(e)return{checked:!0}},yu.getSSRProps=(e,t)=>{if(typeof t.type!=`string`)return;let n=bu(t.type.toUpperCase(),t.props&&t.props.type);if(n.getSSRProps)return n.getSSRProps(e,t)}}var Cu=[`ctrl`,`shift`,`alt`,`meta`],wu={stop:e=>e.stopPropagation(),prevent:e=>e.preventDefault(),self:e=>e.target!==e.currentTarget,ctrl:e=>!e.ctrlKey,shift:e=>!e.shiftKey,alt:e=>!e.altKey,meta:e=>!e.metaKey,left:e=>`button`in e&&e.button!==0,middle:e=>`button`in e&&e.button!==1,right:e=>`button`in e&&e.button!==2,exact:(e,t)=>Cu.some(n=>e[`${n}Key`]&&!t.includes(n))},Tu=(e,t)=>{if(!e)return e;let n=e._withMods||={},r=t.join(`.`);return n[r]||(n[r]=((n,...r)=>{for(let e=0;e<t.length;e++){let r=wu[t[e]];if(r&&r(n,t))return}return e(n,...r)}))},Eu={esc:`escape`,space:` `,up:`arrow-up`,left:`arrow-left`,right:`arrow-right`,down:`arrow-down`,delete:`backspace`},Du=(e,t)=>{let n=e._withKeys||={},r=t.join(`.`),i=n[r];if(i)return i;let a=t.some(e=>e===`left`||e===`right`);return n[r]=(n=>{if(!(`key`in n))return a?e(n):void 0;let r=se(n.key);if(t.some(e=>e===r||Eu[e]===r))return e(n)})},Ou=l({patchProp:Nl},kc),ku,Au=!1;function ju(){return ku||=Uo(Ou)}function Mu(){return ku=Au?ku:Wo(Ou),Au=!0,ku}var Nu=((...e)=>{ju().render(...e)}),Pu=((...e)=>{Mu().hydrate(...e)}),Fu=((...e)=>{let t=ju().createApp(...e),{mount:n}=t;return t.mount=e=>{let r=Ru(e);if(!r)return;let i=t._component;v(i)||i.render||i.template||(i.template=r.innerHTML),r.nodeType===
Line truncated
|
||||
`,t.selectionStart-1)+1,o=t.selectionEnd,s=n.modelValue.slice(a,o).split(`
|
||||
`).map(t=>e+t).join(`
|
||||
`);r(`update:modelValue`,n.modelValue.slice(0,a)+s+n.modelValue.slice(o)),requestAnimationFrame(()=>t.focus())}function f(e,t){c.value=!1;let a=(t?.alt||t?.name||``).replace(/[[\]]/g,``),o=i.value,s=o.selectionStart,l=``;r(`update:modelValue`,n.modelValue.slice(0,s)+l+n.modelValue.slice(o.selectionEnd)),requestAnimationFrame(()=>{o.focus(),o.setSelectionRange(s+l.length,s+l.length)})}async function p(e){if(a.value=e,e===`preview`){s.value=!0;try{o.value=(await qu.post(`${X.base}/markdown`,{text:n.modelValue})).html}finally{s.value=!1}}}return(t,n)=>(H(),U(`div`,null,[G(`div`,{class:`mb-2 flex flex-wrap items-center gap-1`,role:`toolbar`,"aria-label":P(Z)(`Formatting`)},[G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1 font-bold`,disabled:a.value===`preview`,title:P(Z)(`Bold`),onClick:n[0]||=e=>u(`**`,`**`,P(Z)(`bold`))},`B`,8,jd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1 italic`,disabled:a.value===`preview`,title:P(Z)(`Italic`),onClick:n[1]||=e=>u(`*`,`*`,P(Z)(`italic`))},`I`,8,Md),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`Heading`),onClick:n[2]||=e=>d(`## `)},`H`,8,Nd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`List`),onClick:n[3]||=e=>d(`- `)},`•`,8,Pd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`Quote`),onClick:n[4]||=e=>d(`> `)},`”`,8,Fd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`Link`),onClick:n[5]||=e=>u(`[`,`](https://)`,P(Z)(`text`))},`🔗`,8,Id),P(l)?(H(),U(`button`,{key:0,type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,onClick:n[6]||=e=>c.value=!0},k(P(Z)(`Photo`)),9,Ld)):J(``,!0),G(`span`,Rd,[G(`button`,{type:`button`,class:O([`m-btn !px-3 !py-1`,a.value===`write`?`m-btn-primary`:`m-btn-secondary`]),onClick:n[7]||=e=>p(`write`)},k(P(Z)(`Write`)),3),G(`button`,{type:`button`,class:O([`m-btn !px-3 !py-1`,a.value===`preview`?`m-btn-primary`:`m-btn-secondary`]),onClick:n[8]||=e=>p(`preview`)},k(P(Z)(`Preview`)),3)])],8,Ad),I(G(`textarea`,{id:e.id,ref_key:`area`,ref:i,value:e.modelValue,rows:e.rows??14,required:e.required,maxlength:e.maxlength,class:`m-input font-mono`,onInput:n[9]||=e=>r(`update:modelValue`,e.target.value)},null,40,zd),[[$c,a.value===`write`]]),a.value===`preview`?(H(),U(`div`,Bd,[s.value?(H(),U(`p`,Vd,k(P(Z)(`Loading…`)),1)):(H(),U(`div`,{key:1,class:`m-prose`,innerHTML:o.value},null,8,Hd))])):J(``,!0),c.value?(H(),W(kd,{key:1,onPick:f,onClose:n[10]||=e=>c.value=!1})):J(``,!0)]))}}),Wd={class:`m-card mt-6 max-w-3xl p-5`},Gd={class:`font-display text-lg font-bold`},Kd={key:0,class:`mt-2 text-sm text-muted`},qd={key:1,class:`mt-2 text-sm text-muted`},Jd={key:2,class:`mt-3 divide-y divide-line`},Yd={class:`flex flex-wrap items-center justify-between gap-2`},Xd=[`aria-expanded`,`onClick`],Zd={class:`font-semibold`},Qd={key:0,class:`text-muted`},$d={key:1,class:`m-badge ml-2`},ef={class:`block text-xs text-muted`},tf=[`onClick`],nf={key:0,class:`mt-2 space-y-2 text-sm`},rf={class:`text-xs font-semibold uppercase tracking-wide text-muted`},af={class:`whitespace-pre-wrap break-words`},of=L({__name:`RevisionsPanel`,props:{type:{},id:{}},setup(e){let t=e,n=N([]),r=N(!1),i=N(null),a=N(!0),o=`${X.base}/revisions/${t.type}/${t.id}`;ia(async()=>{try{let e=await qu.get(o);n.value=e.revisions,r.value=e.can_restore}finally{a.value=!1}});async function s(e){window.confirm(Z(`Put this version back? The text now is kept in the history.`))&&(await qu.post(`${o}/${e.id}/restore`),$(Z(`The earlier version is back.`)),await h1())}let c=e=>new Date(e).toLocaleString(X.locale||void 0);return(e,t)=>(H(),U(`section`,Wd,[G(`h2`,Gd,k(P(Z)(`History`)),1),a.value?(H(),U(`p`,Kd,k(P(Z)(`Loading…`)),1)):n.value.length?(H(),U(`ul`,Jd,[(H(!0),U(B,null,R(n.value,e=>(H(),U(`li`,{key:e.id,class:`py-3`},[G(`div`,Yd,[G(`button`,{type:`button`,class:`text-left text-sm`,"aria-expanded":i.value===e.id,onClick:t=>i.value=i.value===e.id?null:e.id},[G(`span`,Zd,k(c(e.created_at)),1),e.user?(H(),U(`span`,Qd,` · `+k(e.user),1)):J(``,!0),e.current?(H(),U(`span`,$d,k(P(Z)(`Now`)),1)):J(``,!0),G(`span`,ef,k(e.changed.join(`, `)),1)],8,Xd),r.value&&!e.current?(H(),U(`button`,{key:0,type:`button`,class:`m-btn m-btn-secondary`,onClick:t=>s(e)},k(P(Z)(`Put back`)),9,tf)):J(``,!0)]),i.value===e.id?(H(),U(`dl`,nf,[(H(!0),U(B,null,R(e.values,(e,t)=>(H(),U(`div`,{key:t},[G(`dt`,rf,k(t),1),G(`dd`,af,k(e),1)]))),128))])):J(``,!0)]))),128))])):(H(),U(`p`,qd,k(P(Z)(`Nothing here yet.`)),1))]))}}),sf={class:`mb-6 flex items-center justify-between gap-3`},cf={class:`font-display text-2xl font-bold`},lf={for:`title`,class:`m-label`},uf={key:0,class:`m-error`},df={class:`grid gap-5 sm:grid-cols-2`},ff={for:`slug`,class:`m-label`},pf={key:0,class:`m-error`},mf={for:`category`,class:`m-lab
Line truncated
|
||||
`);r(`update:modelValue`,n.modelValue.slice(0,a)+s+n.modelValue.slice(o)),requestAnimationFrame(()=>t.focus())}function f(e,t){c.value=!1;let a=(t?.alt||t?.name||``).replace(/[[\]]/g,``),o=i.value,s=o.selectionStart,l=``;r(`update:modelValue`,n.modelValue.slice(0,s)+l+n.modelValue.slice(o.selectionEnd)),requestAnimationFrame(()=>{o.focus(),o.setSelectionRange(s+l.length,s+l.length)})}async function p(e){if(a.value=e,e===`preview`){s.value=!0;try{o.value=(await qu.post(`${X.base}/markdown`,{text:n.modelValue})).html}finally{s.value=!1}}}return(t,n)=>(H(),U(`div`,null,[G(`div`,{class:`mb-2 flex flex-wrap items-center gap-1`,role:`toolbar`,"aria-label":P(Z)(`Formatting`)},[G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1 font-bold`,disabled:a.value===`preview`,title:P(Z)(`Bold`),onClick:n[0]||=e=>u(`**`,`**`,P(Z)(`bold`))},`B`,8,Ld),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1 italic`,disabled:a.value===`preview`,title:P(Z)(`Italic`),onClick:n[1]||=e=>u(`*`,`*`,P(Z)(`italic`))},`I`,8,Rd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`Heading`),onClick:n[2]||=e=>d(`## `)},`H`,8,zd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`List`),onClick:n[3]||=e=>d(`- `)},`•`,8,Bd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`Quote`),onClick:n[4]||=e=>d(`> `)},`”`,8,Vd),G(`button`,{type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,title:P(Z)(`Link`),onClick:n[5]||=e=>u(`[`,`](https://)`,P(Z)(`text`))},`🔗`,8,Hd),P(l)?(H(),U(`button`,{key:0,type:`button`,class:`m-btn m-btn-secondary !px-2 !py-1`,disabled:a.value===`preview`,onClick:n[6]||=e=>c.value=!0},k(P(Z)(`Photo`)),9,Ud)):J(``,!0),G(`span`,Wd,[G(`button`,{type:`button`,class:O([`m-btn !px-3 !py-1`,a.value===`write`?`m-btn-primary`:`m-btn-secondary`]),onClick:n[7]||=e=>p(`write`)},k(P(Z)(`Write`)),3),G(`button`,{type:`button`,class:O([`m-btn !px-3 !py-1`,a.value===`preview`?`m-btn-primary`:`m-btn-secondary`]),onClick:n[8]||=e=>p(`preview`)},k(P(Z)(`Preview`)),3)])],8,Id),I(G(`textarea`,{id:e.id,ref_key:`area`,ref:i,value:e.modelValue,rows:e.rows??14,required:e.required,maxlength:e.maxlength,class:`m-input font-mono`,onInput:n[9]||=e=>r(`update:modelValue`,e.target.value)},null,40,Gd),[[$c,a.value===`write`]]),a.value===`preview`?(H(),U(`div`,Kd,[s.value?(H(),U(`p`,qd,k(P(Z)(`Loading…`)),1)):(H(),U(`div`,{key:1,class:`m-prose`,innerHTML:o.value},null,8,Jd))])):J(``,!0),c.value?(H(),W(Fd,{key:1,onPick:f,onClose:n[10]||=e=>c.value=!1})):J(``,!0)]))}}),Xd={class:`m-card mt-6 max-w-3xl p-5`},Zd={class:`font-display text-lg font-bold`},Qd={key:0,class:`mt-2 text-sm text-muted`},$d={key:1,class:`mt-2 text-sm text-muted`},ef={key:2,class:`mt-3 divide-y divide-line`},tf={class:`flex flex-wrap items-center justify-between gap-2`},nf=[`aria-expanded`,`onClick`],rf={class:`font-semibold`},af={key:0,class:`text-muted`},of={key:1,class:`m-badge ml-2`},sf={class:`block text-xs text-muted`},cf=[`onClick`],lf={key:0,class:`mt-2 space-y-2 text-sm`},uf={class:`text-xs font-semibold uppercase tracking-wide text-muted`},df={class:`whitespace-pre-wrap break-words`},ff=L({__name:`RevisionsPanel`,props:{type:{},id:{}},setup(e){let t=e,n=N([]),r=N(!1),i=N(null),a=N(!0),o=`${X.base}/revisions/${t.type}/${t.id}`;ia(async()=>{try{let e=await qu.get(o);n.value=e.revisions,r.value=e.can_restore}finally{a.value=!1}});async function s(e){window.confirm(Z(`Put this version back? The text now is kept in the history.`))&&(await qu.post(`${o}/${e.id}/restore`),$(Z(`The earlier version is back.`)),await x1())}let c=e=>new Date(e).toLocaleString(X.locale||void 0);return(e,t)=>(H(),U(`section`,Xd,[G(`h2`,Zd,k(P(Z)(`History`)),1),a.value?(H(),U(`p`,Qd,k(P(Z)(`Loading…`)),1)):n.value.length?(H(),U(`ul`,ef,[(H(!0),U(B,null,R(n.value,e=>(H(),U(`li`,{key:e.id,class:`py-3`},[G(`div`,tf,[G(`button`,{type:`button`,class:`text-left text-sm`,"aria-expanded":i.value===e.id,onClick:t=>i.value=i.value===e.id?null:e.id},[G(`span`,rf,k(c(e.created_at)),1),e.user?(H(),U(`span`,af,` · `+k(e.user),1)):J(``,!0),e.current?(H(),U(`span`,of,k(P(Z)(`Now`)),1)):J(``,!0),G(`span`,sf,k(e.changed.join(`, `)),1)],8,nf),r.value&&!e.current?(H(),U(`button`,{key:0,type:`button`,class:`m-btn m-btn-secondary`,onClick:t=>s(e)},k(P(Z)(`Put back`)),9,cf)):J(``,!0)]),i.value===e.id?(H(),U(`dl`,lf,[(H(!0),U(B,null,R(e.values,(e,t)=>(H(),U(`div`,{key:t},[G(`dt`,uf,k(t),1),G(`dd`,df,k(e),1)]))),128))])):J(``,!0)]))),128))])):(H(),U(`p`,$d,k(P(Z)(`Nothing here yet.`)),1))]))}}),pf={class:`mb-6 flex items-center justify-between gap-3`},mf={class:`font-display text-2xl font-bold`},hf={for:`title`,class:`m-label`},gf={key:0,class:`m-error`},_f={class:`grid gap-5 sm:grid-cols-2`},vf={for:`slug`,class:`m-label`},yf={key:0,class:`m-error`},bf={for:`category`,class:`m-lab
Line truncated
|
||||
@@ -111,5 +111,6 @@
|
||||
"See the history of posts and pages": "De geschiedenis van berichten en pagina's zien",
|
||||
"Put an earlier version of a post or page back": "Een eerdere versie van een bericht of pagina terugzetten",
|
||||
"Put an earlier version back": "Een eerdere versie teruggezet",
|
||||
"Opened the history of a text": "De geschiedenis van een tekst geopend"
|
||||
"Opened the history of a text": "De geschiedenis van een tekst geopend",
|
||||
"Prove you are not a program, then log in again.": "Laat zien dat je geen programma bent en log dan opnieuw in."
|
||||
}
|
||||
@@ -6,12 +6,13 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use IriksIT\Manager\Models\Group;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
use IriksIT\Manager\Support\Names;
|
||||
use IriksIT\Manager\Support\Permissions\Sources;
|
||||
|
||||
/**
|
||||
* Put this on the User model of the host app (needs the Users module).
|
||||
*
|
||||
* A super admin may do everything of the manager. Everyone else may do what any of their
|
||||
* groups allows. `is_super_admin` is never fillable and no form sets it: only
|
||||
* groups allows, or (config `manager.permissions`) what the roles of the site say. `is_super_admin` is never fillable and no form sets it: only
|
||||
* `manager:create-user` makes one. Keep it out of `$fillable` in the host model.
|
||||
*/
|
||||
trait HasManagerAccess
|
||||
@@ -40,7 +41,9 @@ trait HasManagerAccess
|
||||
return $registry->permissionValues();
|
||||
}
|
||||
|
||||
return $registry->complete($this->managerGroups->flatMap(fn (Group $group) => $group->allowed())->all());
|
||||
$fromGroups = Sources::usesGroups() ? $this->managerGroups->flatMap(fn (Group $group) => $group->allowed())->all() : [];
|
||||
|
||||
return $registry->complete([...$fromGroups, ...Sources::fromHost($this)]);
|
||||
}
|
||||
|
||||
public function hasManagerPermission(string $permission): bool
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Something more a login asks for: a captcha, a code from an authenticator app, a field of the site's own. List the class in
|
||||
* `manager.login.checks`. A check fails a login by throwing `Illuminate\Validation\ValidationException`.
|
||||
*/
|
||||
interface LoginCheck
|
||||
{
|
||||
/**
|
||||
* What the login form shows besides the email and the password. Each entry has a `name` (the key in the request) and a `type`:
|
||||
* `text`, `password`, `number` or `turnstile` (with a `site_key`); and optionally a `label`, `autocomplete` and `required`.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function fields(): array;
|
||||
|
||||
/** Runs first, before the password is looked at: a captcha belongs here. */
|
||||
public function before(Request $request): void;
|
||||
|
||||
/**
|
||||
* Runs when the email and password are right, before anyone is logged in: a second factor belongs here. When it refuses, the
|
||||
* attempt counts as a failed login (the audit log and the bans see it).
|
||||
*/
|
||||
public function after(Request $request, Authenticatable $user): void;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
/**
|
||||
* Where a site that has roles of its own says what an account may do in the manager (config `manager.permissions.resolver`).
|
||||
* Values that are no permission of an active module are ignored, and what a permission needs is added.
|
||||
*/
|
||||
interface PermissionResolver
|
||||
{
|
||||
/** @return list<string> permission values such as `posts.write` */
|
||||
public function permissions(Authenticatable $user): array;
|
||||
}
|
||||
@@ -7,20 +7,38 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use IriksIT\Manager\Support\LoginChecks;
|
||||
use IriksIT\Manager\Support\Names;
|
||||
|
||||
/** The manager's own login, for an app that has none. Failed attempts reach the audit log through Laravel's `Failed` event. */
|
||||
class LoginController
|
||||
{
|
||||
public function store(Request $request): JsonResponse
|
||||
public function store(Request $request, LoginChecks $checks): JsonResponse
|
||||
{
|
||||
$checks->before($request);
|
||||
|
||||
$credentials = $request->validate([
|
||||
'email' => ['required', 'string', 'email', 'max:255'],
|
||||
'password' => ['required', 'string', 'max:200'],
|
||||
]);
|
||||
|
||||
if (! Auth::attempt($credentials, $request->boolean('remember'))) {
|
||||
throw ValidationException::withMessages(['email' => trans('auth.failed')]);
|
||||
$refused = null;
|
||||
|
||||
// `attemptWhen` runs the second checks after the password is right and before the login begins; a refusal is a failed login.
|
||||
$loggedIn = Auth::attemptWhen($credentials, function ($user) use ($checks, $request, &$refused) {
|
||||
try {
|
||||
$checks->after($request, $user);
|
||||
} catch (ValidationException $e) {
|
||||
$refused = $e;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, $request->boolean('remember'));
|
||||
|
||||
if (! $loggedIn) {
|
||||
throw $refused ?? ValidationException::withMessages(['email' => trans('auth.failed')]);
|
||||
}
|
||||
|
||||
$request->session()->regenerate();
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support\Login;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Request;
|
||||
use IriksIT\Manager\Contracts\LoginCheck;
|
||||
|
||||
/** Extend this and override what the check needs. */
|
||||
abstract class BaseLoginCheck implements LoginCheck
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function before(Request $request): void {}
|
||||
|
||||
public function after(Request $request, Authenticatable $user): void {}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support\Login;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Cloudflare Turnstile on the login. On by itself when `MANAGER_TURNSTILE_SITE_KEY` and `MANAGER_TURNSTILE_SECRET` are set. A token that
|
||||
* cannot be checked (Cloudflare does not answer) refuses the login: a captcha that lets everyone in when it is down protects nothing.
|
||||
*/
|
||||
final class Turnstile extends BaseLoginCheck
|
||||
{
|
||||
private const VERIFY = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';
|
||||
|
||||
public static function configured(): bool
|
||||
{
|
||||
return (string) config('manager.login.turnstile.site_key') !== '' && (string) config('manager.login.turnstile.secret') !== '';
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [['name' => 'turnstile', 'type' => 'turnstile', 'site_key' => (string) config('manager.login.turnstile.site_key')]];
|
||||
}
|
||||
|
||||
public function before(Request $request): void
|
||||
{
|
||||
$token = $request->string('turnstile')->limit(2048, '')->toString();
|
||||
|
||||
if ($token === '' || ! $this->valid($token, (string) $request->ip())) {
|
||||
throw ValidationException::withMessages(['turnstile' => __('Prove you are not a program, then log in again.')]);
|
||||
}
|
||||
}
|
||||
|
||||
private function valid(string $token, string $ip): bool
|
||||
{
|
||||
try {
|
||||
$answer = Http::asForm()->timeout(5)->post(self::VERIFY, ['secret' => config('manager.login.turnstile.secret'), 'response' => $token, 'remoteip' => $ip]);
|
||||
|
||||
return $answer->ok() && $answer->json('success') === true;
|
||||
} catch (Throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Request;
|
||||
use IriksIT\Manager\Contracts\LoginCheck;
|
||||
use IriksIT\Manager\Support\Login\Turnstile;
|
||||
|
||||
/** The checks a login runs, from config `manager.login.checks` (and Turnstile when it is set up). */
|
||||
final class LoginChecks
|
||||
{
|
||||
/** @return list<LoginCheck> */
|
||||
public function all(): array
|
||||
{
|
||||
$classes = array_values(array_unique([...(array) config('manager.login.checks', []), ...(Turnstile::configured() ? [Turnstile::class] : [])]));
|
||||
$checks = [];
|
||||
|
||||
foreach ($classes as $class) {
|
||||
if (is_string($class) && is_subclass_of($class, LoginCheck::class)) {
|
||||
$checks[] = app($class);
|
||||
}
|
||||
}
|
||||
|
||||
return $checks;
|
||||
}
|
||||
|
||||
/** @return list<array<string, mixed>> */
|
||||
public function fields(): array
|
||||
{
|
||||
return array_merge(...array_map(fn (LoginCheck $check) => $check->fields(), $this->all()) ?: [[]]);
|
||||
}
|
||||
|
||||
public function before(Request $request): void
|
||||
{
|
||||
foreach ($this->all() as $check) {
|
||||
$check->before($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function after(Request $request, Authenticatable $user): void
|
||||
{
|
||||
foreach ($this->all() as $check) {
|
||||
$check->after($request, $user);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support\Permissions;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Collection;
|
||||
use IriksIT\Manager\Contracts\PermissionResolver;
|
||||
|
||||
/**
|
||||
* For a site whose accounts have a role (a `role` column, or a `roles` list or relation): config `manager.permissions.roles` says
|
||||
* what each role may do, e.g. `['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]` (`*` is everything). The attribute is
|
||||
* `manager.permissions.role_attribute`.
|
||||
*/
|
||||
final class RoleMap implements PermissionResolver
|
||||
{
|
||||
public function permissions(Authenticatable $user): array
|
||||
{
|
||||
$roles = $user->{(string) config('manager.permissions.role_attribute', 'role')} ?? [];
|
||||
$roles = $roles instanceof Collection ? $roles->all() : (array) $roles;
|
||||
$map = (array) config('manager.permissions.roles', []);
|
||||
$out = [];
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$name = is_object($role) ? (string) ($role->name ?? '') : (string) (is_scalar($role) ? $role : '');
|
||||
|
||||
foreach ((array) ($map[$name] ?? []) as $permission) {
|
||||
$out[] = (string) $permission;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($out));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support\Permissions;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use IriksIT\Manager\Contracts\PermissionResolver;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
|
||||
/**
|
||||
* What an account may do comes from the groups of the package (the default), from the roles of the site, or from both:
|
||||
* `manager.permissions.mode` is `groups`, `host` or `merge`. A site's side is its own `resolver` class, or the built-in `RoleMap`
|
||||
* when `roles` is filled. A super admin always may everything.
|
||||
*/
|
||||
final class Sources
|
||||
{
|
||||
public static function usesGroups(): bool
|
||||
{
|
||||
return self::mode() !== 'host';
|
||||
}
|
||||
|
||||
/** @return list<string> what the roles of the site allow (empty in `groups` mode) */
|
||||
public static function fromHost(Authenticatable $user): array
|
||||
{
|
||||
if (self::mode() === 'groups') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$class = config('manager.permissions.resolver');
|
||||
$resolver = is_string($class) && is_subclass_of($class, PermissionResolver::class) ? app($class) : (config('manager.permissions.roles') ? new RoleMap : null);
|
||||
|
||||
if ($resolver === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$known = app(ModuleRegistry::class)->permissionValues();
|
||||
$given = $resolver->permissions($user);
|
||||
|
||||
return in_array('*', $given, true) ? $known : array_values(array_filter($given, fn ($value) => is_string($value) && in_array($value, $known, true)));
|
||||
}
|
||||
|
||||
private static function mode(): string
|
||||
{
|
||||
return in_array(config('manager.permissions.mode'), ['groups', 'host', 'merge'], true) ? config('manager.permissions.mode') : 'groups';
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use IriksIT\Manager\ManagerServiceProvider;
|
||||
/** What the first page of the screens needs to know: who, what they may do, the menu and the look. */
|
||||
class Shell
|
||||
{
|
||||
public function __construct(private readonly ModuleRegistry $modules, private readonly Themes $themes, private readonly Menu $menu) {}
|
||||
public function __construct(private readonly ModuleRegistry $modules, private readonly Themes $themes, private readonly Menu $menu, private readonly LoginChecks $loginChecks) {}
|
||||
|
||||
/** @return array{boot: array<string, mixed>, css: string, scripts: string, styles: string} */
|
||||
public function data(Request $request): array
|
||||
@@ -54,6 +54,7 @@ class Shell
|
||||
'can_switch' => $this->menu->maySwitch($user),
|
||||
'theme' => $key,
|
||||
'can_login' => Route::has(Names::route('login')),
|
||||
'login_fields' => $user === null ? $this->loginChecks->fields() : [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Auth\Events\Failed;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use IriksIT\Manager\Support\Login\BaseLoginCheck;
|
||||
use IriksIT\Manager\Tests\TestCase;
|
||||
|
||||
uses(TestCase::class);
|
||||
|
||||
class NeedsCode extends BaseLoginCheck
|
||||
{
|
||||
public function fields(): array
|
||||
{
|
||||
return [['name' => 'code', 'type' => 'text', 'label' => 'Code', 'autocomplete' => 'one-time-code']];
|
||||
}
|
||||
|
||||
public function after(Request $request, Authenticatable $user): void
|
||||
{
|
||||
if ($request->input('code') !== '123456') {
|
||||
throw ValidationException::withMessages(['code' => 'The code is not right.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
$this->user = makeUser(superAdmin: true);
|
||||
$this->user->forceFill(['password' => Hash::make('a-long-enough-password')])->save();
|
||||
$this->login = fn (array $extra = []) => $this->postJson('/manager/login', ['email' => $this->user->email, 'password' => 'a-long-enough-password'] + $extra);
|
||||
});
|
||||
|
||||
it('logs in as before when no check is set', function () {
|
||||
($this->login)()->assertOk()->assertJsonPath('redirect', '/manager');
|
||||
$this->assertAuthenticated();
|
||||
});
|
||||
|
||||
it('asks a second factor of the site after the password, and counts a refusal as a failed login', function () {
|
||||
config(['manager.login.checks' => [NeedsCode::class]]);
|
||||
$failed = 0;
|
||||
Event::listen(Failed::class, function () use (&$failed) {
|
||||
$failed++;
|
||||
});
|
||||
|
||||
($this->login)(['code' => '000000'])->assertJsonValidationErrors(['code']);
|
||||
$this->assertGuest();
|
||||
expect($failed)->toBe(1);
|
||||
|
||||
($this->login)(['code' => '123456'])->assertOk();
|
||||
$this->assertAuthenticated();
|
||||
});
|
||||
|
||||
it('shows the fields of the checks on the form', function () {
|
||||
config(['manager.login.checks' => [NeedsCode::class, 'Not\\A\\Check']]);
|
||||
|
||||
$this->get('/manager/login')->assertOk()->assertSee('"login_fields":[{"name":"code"', false);
|
||||
});
|
||||
|
||||
describe('turnstile', function () {
|
||||
beforeEach(fn () => config(['manager.login.turnstile' => ['site_key' => 'site-key', 'secret' => 'secret-key']]));
|
||||
|
||||
it('needs a token that Cloudflare accepts, and checks before the password', function () {
|
||||
Http::fake(['challenges.cloudflare.com/*' => Http::response(['success' => true])]);
|
||||
|
||||
($this->login)()->assertJsonValidationErrors(['turnstile']);
|
||||
($this->login)(['turnstile' => 'token'])->assertOk();
|
||||
|
||||
Http::assertSent(fn ($request) => $request['secret'] === 'secret-key' && $request['response'] === 'token');
|
||||
});
|
||||
|
||||
it('refuses a token Cloudflare does not accept, and everything when Cloudflare is unreachable', function () {
|
||||
Http::fake(['challenges.cloudflare.com/*' => Http::response(['success' => false])]);
|
||||
($this->login)(['turnstile' => 'bad'])->assertJsonValidationErrors(['turnstile']);
|
||||
|
||||
Http::fake(['challenges.cloudflare.com/*' => Http::response('', 500)]);
|
||||
($this->login)(['turnstile' => 'token'])->assertJsonValidationErrors(['turnstile']);
|
||||
|
||||
Http::fake(fn () => throw new ConnectionException('down'));
|
||||
($this->login)(['turnstile' => 'token'])->assertJsonValidationErrors(['turnstile']);
|
||||
$this->assertGuest();
|
||||
});
|
||||
|
||||
it('puts the widget on the form', function () {
|
||||
$this->get('/manager/login')->assertSee('"type":"turnstile","site_key":"site-key"', false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use IriksIT\Manager\Contracts\PermissionResolver;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
use IriksIT\Manager\Tests\Fixtures\User;
|
||||
use IriksIT\Manager\Tests\TestCase;
|
||||
|
||||
uses(TestCase::class);
|
||||
|
||||
class FromTheSite implements PermissionResolver
|
||||
{
|
||||
public function permissions(Authenticatable $user): array
|
||||
{
|
||||
return str_starts_with($user->email, 'editor') ? ['posts.write', 'posts.view', 'nonsense.thing'] : [];
|
||||
}
|
||||
}
|
||||
|
||||
function editor(string $role = 'editor', array $groups = []): User
|
||||
{
|
||||
$user = makeUser($groups);
|
||||
$user->setAttribute('role', $role);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
it('uses the groups only, as before', function () {
|
||||
config(['manager.permissions.roles' => ['editor' => ['posts.view']]]);
|
||||
|
||||
expect(editor('editor', ['media.view'])->managerPermissions())->toBe(['media.view']);
|
||||
});
|
||||
|
||||
it('takes the permissions from the roles of the site in host mode, and not from the groups', function () {
|
||||
config(['manager.permissions' => ['mode' => 'host', 'roles' => ['editor' => ['posts.write', 'unknown.thing'], 'owner' => ['*']]] + config('manager.permissions')]);
|
||||
|
||||
expect(editor('editor', ['media.view'])->managerPermissions())->toBe(['posts.view', 'posts.write'])
|
||||
->and(editor('owner')->managerPermissions())->toBe(app(ModuleRegistry::class)->permissionValues())
|
||||
->and(editor('nobody')->managerPermissions())->toBe([]);
|
||||
|
||||
$this->actingAs(editor('editor'));
|
||||
$this->getJson('/manager/posts')->assertOk();
|
||||
$this->getJson('/manager/media/items')->assertForbidden();
|
||||
});
|
||||
|
||||
it('adds the roles to the groups in merge mode, and reads a list of roles', function () {
|
||||
config(['manager.permissions' => ['mode' => 'merge', 'roles' => ['editor' => ['posts.view'], 'writer' => ['posts.write']]] + config('manager.permissions')]);
|
||||
|
||||
$user = editor('editor', ['media.view']);
|
||||
$user->setAttribute('role', ['editor', 'writer']);
|
||||
|
||||
expect($user->managerPermissions())->toEqualCanonicalizing(['posts.view', 'posts.write', 'media.view']);
|
||||
});
|
||||
|
||||
it('asks a resolver of the site, which can only give permissions that exist', function () {
|
||||
config(['manager.permissions' => ['mode' => 'host', 'resolver' => FromTheSite::class] + config('manager.permissions')]);
|
||||
|
||||
$user = makeUser();
|
||||
$user->forceFill(['email' => '[email protected]'])->save();
|
||||
|
||||
expect($user->managerPermissions())->toBe(['posts.view', 'posts.write'])
|
||||
->and(makeUser()->managerPermissions())->toBe([]);
|
||||
});
|
||||
|
||||
it('keeps a super admin all-powerful in every mode', function () {
|
||||
config(['manager.permissions.mode' => 'host']);
|
||||
|
||||
expect(makeUser(superAdmin: true)->managerPermissions())->toContain('posts.view', 'media.view');
|
||||
});
|
||||
@@ -30,6 +30,7 @@ export interface Boot {
|
||||
navigation: NavItem[];
|
||||
view: 'full' | 'simple';
|
||||
extensions: string[];
|
||||
login_fields: { name: string; type: string; label?: string; autocomplete?: string; required?: boolean; site_key?: string }[];
|
||||
can_switch: boolean;
|
||||
theme: string;
|
||||
can_login: boolean;
|
||||
|
||||
+49
-1
@@ -1,8 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { boot, useForm } from '../api';
|
||||
import { t } from '../i18n';
|
||||
|
||||
const form = useForm({ email: '', password: '', remember: false });
|
||||
// What a check of the site adds to the form (config `manager.login.checks`): fields, and the Turnstile captcha.
|
||||
const extra = boot.login_fields ?? [];
|
||||
const form = useForm({ email: '', password: '', remember: false, ...Object.fromEntries(extra.map((field) => [field.name, ''])) } as Record<string, any>);
|
||||
const widget = ref<HTMLElement | null>(null);
|
||||
let widgetId: string | undefined;
|
||||
|
||||
onMounted(() => {
|
||||
const captcha = extra.find((field) => field.type === 'turnstile');
|
||||
|
||||
if (!captcha) {
|
||||
return;
|
||||
}
|
||||
|
||||
const draw = () => {
|
||||
widgetId = (window as any).turnstile.render(widget.value, { sitekey: captcha.site_key, callback: (token: string) => (form.values[captcha.name] = token) });
|
||||
};
|
||||
|
||||
if ((window as any).turnstile) {
|
||||
draw();
|
||||
} else {
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit';
|
||||
script.async = true;
|
||||
script.onload = draw;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
});
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
const done = await form.send<{ redirect: string }>('post', boot.base + '/login');
|
||||
@@ -11,6 +38,9 @@ async function submit(): Promise<void> {
|
||||
window.location.assign(done.redirect);
|
||||
} else {
|
||||
form.values.password = '';
|
||||
// A token works once.
|
||||
widgetId !== undefined && (window as any).turnstile.reset(widgetId);
|
||||
extra.filter((field) => field.type === 'turnstile').forEach((field) => (form.values[field.name] = ''));
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -31,6 +61,24 @@ async function submit(): Promise<void> {
|
||||
<input id="password" v-model="form.values.password" type="password" autocomplete="current-password" required class="m-input" />
|
||||
<p v-if="form.errors.password" class="m-error">{{ form.errors.password }}</p>
|
||||
</div>
|
||||
<template v-for="field in extra" :key="field.name">
|
||||
<div v-if="field.type === 'turnstile'" class="mt-4">
|
||||
<div :ref="(el: any) => (widget = el)" />
|
||||
<p v-if="form.errors[field.name]" class="m-error">{{ form.errors[field.name] }}</p>
|
||||
</div>
|
||||
<div v-else class="mt-4">
|
||||
<label :for="'login-' + field.name" class="m-label">{{ t(field.label ?? field.name) }}</label>
|
||||
<input
|
||||
:id="'login-' + field.name"
|
||||
v-model="form.values[field.name]"
|
||||
:type="field.type === 'password' || field.type === 'number' ? field.type : 'text'"
|
||||
:autocomplete="field.autocomplete"
|
||||
:required="field.required"
|
||||
class="m-input"
|
||||
/>
|
||||
<p v-if="form.errors[field.name]" class="m-error">{{ form.errors[field.name] }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<label class="mt-4 flex items-center gap-2 text-sm text-muted">
|
||||
<input v-model="form.values.remember" type="checkbox" />
|
||||
{{ t('Keep me logged in') }}
|
||||
|
||||
Reference in new issue
Block a user