domma-cms 1.48.1 → 1.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/CLAUDE.md +5 -0
- package/admin/js/lib/collection-editor-arrange.js +1 -1
- package/admin/js/templates/collection-editor.html +4 -0
- package/docs/api-reference.md +1 -1
- package/package.json +1 -1
- package/server/routes/api/collections.js +8 -1
- package/server/services/collectionAccess.js +19 -0
- package/server/services/collections.js +7 -0
- package/server/services/plugins.js +11 -2
- package/server/services/presetCollections.js +15 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.48.2] - 2026-11-09
|
|
4
|
+
|
|
5
|
+
- **Collections can opt out of users reading their own entries through `scope=mine`** (`api.mine: false` in the schema; Collections > API & Export, "Users can read their own entries"). A collection with it off answers 404 to `?scope=mine` on `/api/collections/:slug/public` and `/api/v1/:slug`, and a `[collection scope="mine"]` display of it is not filled in. Collections without the setting behave as before. The setting is kept by every schema save (including the collection editor and saves that send an `api` block without it) and by the boot-time rewrite of built-in collections, and a plugin whose collection schema sets it applies it to collections it already created.
|
|
6
|
+
|
|
3
7
|
## [1.48.1] - 2026-11-09
|
|
4
8
|
|
|
5
9
|
- Move "Show side admin menu" from Versions to Notifications for every signed-in user, including users without notification permissions. Keep each account's saved sidebar choice and the site default for new users.
|
package/CLAUDE.md
CHANGED
|
@@ -367,6 +367,11 @@ overlays, and Domma in the browser for the public navbar - so a change to one is
|
|
|
367
367
|
other. Bindings, highlighting, orientation, floating panels, structural items, and the
|
|
368
368
|
menu-data-driven admin sidebar all have non-obvious contracts: full detail in the
|
|
369
369
|
**`domma-menus` skill** (`.claude/skills/domma-menus/SKILL.md`) - load it before touching any of that.
|
|
370
|
+
|
|
371
|
+
**`scope=mine` bypasses `api.read`** (own rows, `meta.createdBy`) in two places - `publicListEntries` and
|
|
372
|
+
`POST /render-scope` - and both refuse (404, as an unknown slug) when the schema says `api.mine: false` (`mineAllowed()` in
|
|
373
|
+
`collectionAccess.js`); a new own-rows door must check it too. `updateCollection` and `seedAll()` keep the flag. (An admin-built owner row-level view is a
|
|
374
|
+
separate explicit grant and does not read it.)
|
|
370
375
|
## Form triggers
|
|
371
376
|
|
|
372
377
|
A trigger hangs off a field (`field.triggers[]`) and acts on the FORM when the answers meet a
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export const FIELD_TYPES=[{value:"string",label:"Text (single line)"},{value:"email",label:"Email"},{value:"tel",label:"Phone"},{value:"number",label:"Number"},{value:"textarea",label:"Textarea (multi-line)"},{value:"select",label:"Dropdown (select)"},{value:"radio",label:"Radio buttons"},{value:"checkbox",label:"Single checkbox"},{value:"checkbox-group",label:"Checkbox group"},{value:"date",label:"Date"},{value:"time",label:"Time"},{value:"url",label:"URL"},{value:"hidden",label:"Hidden field"},{value:"file",label:"Files (uploaded with a form)"}],OPTION_TYPES=new Set(["select","radio","checkbox-group"]),ADDON_TYPES=new Set(["string","email","tel","number","textarea","select","date","time","url"]);const f=/^[a-z0-9-]+$/i;export const EXTRA_TYPES={clear:new Set(["string","email","tel","url","textarea"]),stepper:new Set(["number"]),counter:new Set(["string","textarea"])};const m=24;function p(e){return e?typeof e=="string"?{icon:"",text:e}:{icon:e.icon||"",text:e.icon?"":String(e.text??"")}:{icon:"",text:""}}export function addonFromBoxes(e,r){const n=String(e??"").trim(),t=String(r??"").trim();return n&&f.test(n)?{icon:n}:t?{text:t.slice(0,m)}:null}export const OPERATIONS=["create","read","update","delete"],EXPORT_FORMATS=["csv","json"],FIELD_NAME_RE=/^[A-Za-z_][A-Za-z0-9_-]*$/;export function slugify(e){return String(e??"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}export const nameFromLabel=e=>slugify(e).replace(/-/g,"_"),typeLabel=e=>FIELD_TYPES.find(r=>r.value===e)?.label||e||"";export function optionsText(e){return(Array.isArray(e)?e:[]).map(r=>typeof r=="string"?`${r}: ${r}`:`${r?.value??""}: ${r?.label??r?.value??""}`).join(`
|
|
2
2
|
`)}export function parseOptions(e){return String(e??"").split(`
|
|
3
|
-
`).filter(r=>r.trim()).map(r=>{const[n,...t]=r.split(":");return{value:n.trim(),label:t.join(":").trim()||n.trim()}})}const g=()=>({create:{enabled:!1,access:"admin"},read:{enabled:!0,access:"public"},update:{enabled:!1,access:"admin"},delete:{enabled:!1,access:"admin"}}),b=e=>({enabled:!0,access:e||"",formats:["csv","json"]});export function roleLadder(e){return(Array.isArray(e)?e:e?.entries||[]).map(n=>({name:n?.data?.name,label:n?.data?.label||n?.data?.name,level:Number(n?.data?.level)})).filter(n=>typeof n.name=="string"&&n.name&&Number.isFinite(n.level)).sort((n,t)=>n.level-t.level||n.name.localeCompare(t.name))}export function accessOptions(e,r,{token:n=!0}={}){const t=[{value:"public",label:"Public - anyone"}];n&&t.push({value:"token",label:"API token"});for(const i of[...e||[]].reverse())t.push({value:i.name,label:i.level===0?`${i.label} only`:`${i.label} and above`});return typeof r=="string"&&r&&!t.some(i=>i.value===r)&&t.push(e?.length?{value:r,label:`${r} (role not found)`,missing:!0}:{value:r,label:r}),t}let x=0;export const fieldKey=()=>`f${Date.now().toString(36)}${(x++).toString(36)}`;export function formFromCollection(e=null,{project:r="",defaultRole:n=""}={}){const t=e||{},i={...g(),...t.api||{}},l={...b(n),...t.export||{}},s={title:String(t.title??""),slug:String(t.slug??""),description:String(t.description??""),layout:t.layout==="grid"?"grid":"stacked",columns:String(Number.parseInt(t.columns,10)||2),project:String(t.meta?.project??r??""),bundled:t.bundled===!0,storageAdapter:t.storage?.adapter==="mongodb"?"mongodb":"file",storageConnection:String(t.storage?.connection||"default"),fields:(Array.isArray(t.fields)?t.fields:[]).map(o=>({...o,_key:fieldKey()})),readFields:Array.isArray(i.read?.fields)?i.read.fields.join(", "):"",exportEnabled:l.enabled!==!1,exportAccess:typeof l.access=="string"&&l.access?l.access:String(n||""),exportCsv:(Array.isArray(l.formats)?l.formats:EXPORT_FORMATS).includes("csv"),exportJson:(Array.isArray(l.formats)?l.formats:EXPORT_FORMATS).includes("json")};for(const o of OPERATIONS){s[`${o}Enabled`]=i[o]?.enabled===!0;const a=i[o]?.access;s[`${o}Access`]=typeof a=="string"&&a?a:"admin"}return s}export function cleanField(e){const{_key:r,...n}=e||{};return n}export function payloadFromForm(e,{isNew:r=!1,meta:n={}}={}){const t=e||{},i={};for(const o of OPERATIONS)i[o]={enabled:t[`${o}Enabled`]===!0,access:t[`${o}Access`]||"admin"};const l=String(t.readFields??"").split(",").map(o=>o.trim()).filter(Boolean);l.length&&(i.read.fields=l);const s=Math.min(6,Math.max(1,Number.parseInt(t.columns,10)||2));return{title:String(t.title??"").trim(),...r&&{slug:slugify(t.slug||t.title)},description:String(t.description??"").trim(),layout:t.layout==="grid"?"grid":"stacked",columns:s,fields:(t.fields||[]).map(cleanField),api:i,export:{enabled:t.exportEnabled!==!1,...t.exportAccess&&{access:t.exportAccess},formats:EXPORT_FORMATS.filter(o=>o==="csv"?t.exportCsv:t.exportJson)},storage:t.storageAdapter==="mongodb"?{adapter:"mongodb",connection:t.storageConnection||"default"}:{adapter:"file"},meta:{...n||{},project:String(t.project??"")||null},bundled:t.bundled===!0}}export function snapshot(e){const{fields:r=[],...n}=e||{};return JSON.stringify({...n,fields:r.map(cleanField)})}export function checkForm(e,{isNew:r=!1,taken:n=[],original:t={}}={}){const i=e||{},l={};if(String(i.title??"").trim()||(l.title="A collection needs a title."),r){const c=slugify(i.slug||i.title);c?n.includes(c)&&(l.slug=`"${c}" is already a collection.`):l.slug="The slug needs a letter or a number."}const s=Number.parseInt(i.columns,10);i.layout==="grid"&&!(s>=1&&s<=6)&&(l.columns="Between 1 and 6 columns.");const o={},a=new Map;return(i.fields||[]).forEach(c=>{const d=fieldProblem(c,t[c._key]);d&&(o[c._key]=d);const u=String(c.name??"").trim();u&&(a.has(u)?o[c._key]=o[c._key]||`"${u}" is used by another field.`:a.set(u,c._key))}),Object.keys(o).length&&(l.fields=o),i.exportEnabled&&!i.exportCsv&&!i.exportJson&&(l.export="Pick at least one export format, or turn export off."),l}export function fieldProblem(e,r){const n=String(e?.name??"").trim();return n?n!==r&&!FIELD_NAME_RE.test(n)?"Names start with a letter or _, then letters, digits, _ or -.":OPTION_TYPES.has(e.type)&&!(Array.isArray(e.options)&&e.options.length)?`A ${typeLabel(e.type).toLowerCase()} needs at least one option.`:"":"A field needs a name - it is what each entry is keyed by."}export const errorCount=e=>Object.keys(e||{}).filter(r=>r!=="fields").length+Object.keys(e?.fields||{}).length;export function fieldRow(e,r={},{grid:n=!1}={}){const t=[e.name||"(no name)",typeLabel(e.type)];return OPTION_TYPES.has(e.type)&&t.push(`${(e.options||[]).length} options`),n&&t.push(e.fullWidth?"full width":`span ${e.span>1?e.span:1}`),{key:e._key,label:e.label||"(Untitled field)",meta:t.join(" \xB7 "),required:e.required===!0,hidden:e.type==="hidden",notInLists:e.listHidden===!0&&e.type!=="hidden",problem:r[e._key]||"",rowCls:r[e._key]?"is-bad":""}}export function moveField(e,r,n){const t=[...e];if(r<0||r>=t.length||n<0||n>=t.length||r===n)return t;const[i]=t.splice(r,1);return t.splice(n,0,i),t}export function duplicateField(e,r){const n=e[r];if(!n)return[...e];const t=new Set(e.map(a=>a.name)),i=`${n.name||"field"}_copy`;let l=i;for(let a=2;t.has(l);a++)l=`${i}_${a}`;const s={...JSON.parse(JSON.stringify(cleanField(n))),name:l,label:`${n.label||"Field"} (copy)`,_key:fieldKey()};delete s.id;const o=[...e];return o.splice(r+1,0,s),o}export const newField=()=>({id:`field-${Date.now()}`,name:"",label:"",type:"string",required:!1,placeholder:"",helper:"",options:[],validation:[],logic:null,_key:fieldKey()});export function panelForm(e){return{label:String(e.label??""),name:String(e.name??""),type:e.type||"string",required:e.required===!0,placeholder:String(e.placeholder??""),helper:String(e.helper??""),options:optionsText(e.options),span:String(e.span>1?e.span:1),fullWidth:e.fullWidth===!0,prefixIcon:p(e.prefix).icon,prefixText:p(e.prefix).text,suffixIcon:p(e.suffix).icon,suffixText:p(e.suffix).text,clear:e.clear===!0,stepper:e.stepper===!0,counter:e.counter===!0,inLists:e.listHidden!==!0}}export function fieldFromPanel(e,r){const n={...e,label:String(r.label??"").trim(),name:String(r.name??"").trim(),type:r.type||"string",required:r.required===!0,placeholder:String(r.placeholder??"").trim(),helper:String(r.helper??"").trim()};OPTION_TYPES.has(n.type)&&(n.options=parseOptions(r.options)),"inLists"in r&&(r.inLists===!1?n.listHidden=!0:delete n.listHidden);for(const[t,i]of Object.entries(EXTRA_TYPES)){if(!i.has(n.type)){delete n[t];continue}t in r&&(r[t]===!0?n[t]=!0:delete n[t])}for(const t of["prefix","suffix"]){const i=`${t}Icon`in r||`${t}Text`in r;if(!ADDON_TYPES.has(n.type)){delete n[t];continue}if(!i)continue;const l=addonFromBoxes(r[`${t}Icon`],r[`${t}Text`]);l?n[t]=l:delete n[t]}if(r.fullWidth)n.fullWidth=!0,delete n.span;else{delete n.fullWidth;const t=Number.parseInt(r.span,10);t>1?n.span=Math.min(6,t):delete n.span}return n}export function storageChange(e,r){const n=e||"file",t=r||"file";return n===t?"":`${n} \u2192 ${t}`}export function draftOf(e){const{fields:r=[],...n}=e||{};return{...n,fields:r.map(cleanField)}}export function formFromDraft(e,r){const n=e||{};return{...r,...n,fields:(Array.isArray(n.fields)?n.fields:r.fields).map(t=>({...cleanField(t),_key:fieldKey()}))}}
|
|
3
|
+
`).filter(r=>r.trim()).map(r=>{const[n,...t]=r.split(":");return{value:n.trim(),label:t.join(":").trim()||n.trim()}})}const g=()=>({create:{enabled:!1,access:"admin"},read:{enabled:!0,access:"public"},update:{enabled:!1,access:"admin"},delete:{enabled:!1,access:"admin"}}),b=e=>({enabled:!0,access:e||"",formats:["csv","json"]});export function roleLadder(e){return(Array.isArray(e)?e:e?.entries||[]).map(n=>({name:n?.data?.name,label:n?.data?.label||n?.data?.name,level:Number(n?.data?.level)})).filter(n=>typeof n.name=="string"&&n.name&&Number.isFinite(n.level)).sort((n,t)=>n.level-t.level||n.name.localeCompare(t.name))}export function accessOptions(e,r,{token:n=!0}={}){const t=[{value:"public",label:"Public - anyone"}];n&&t.push({value:"token",label:"API token"});for(const i of[...e||[]].reverse())t.push({value:i.name,label:i.level===0?`${i.label} only`:`${i.label} and above`});return typeof r=="string"&&r&&!t.some(i=>i.value===r)&&t.push(e?.length?{value:r,label:`${r} (role not found)`,missing:!0}:{value:r,label:r}),t}let x=0;export const fieldKey=()=>`f${Date.now().toString(36)}${(x++).toString(36)}`;export function formFromCollection(e=null,{project:r="",defaultRole:n=""}={}){const t=e||{},i={...g(),...t.api||{}},l={...b(n),...t.export||{}},s={title:String(t.title??""),slug:String(t.slug??""),description:String(t.description??""),layout:t.layout==="grid"?"grid":"stacked",columns:String(Number.parseInt(t.columns,10)||2),project:String(t.meta?.project??r??""),bundled:t.bundled===!0,storageAdapter:t.storage?.adapter==="mongodb"?"mongodb":"file",storageConnection:String(t.storage?.connection||"default"),fields:(Array.isArray(t.fields)?t.fields:[]).map(o=>({...o,_key:fieldKey()})),readFields:Array.isArray(i.read?.fields)?i.read.fields.join(", "):"",mineEnabled:i.mine===void 0||i.mine===!0,mineLocked:!!t.plugin&&!(i.mine===void 0||i.mine===!0),exportEnabled:l.enabled!==!1,exportAccess:typeof l.access=="string"&&l.access?l.access:String(n||""),exportCsv:(Array.isArray(l.formats)?l.formats:EXPORT_FORMATS).includes("csv"),exportJson:(Array.isArray(l.formats)?l.formats:EXPORT_FORMATS).includes("json")};for(const o of OPERATIONS){s[`${o}Enabled`]=i[o]?.enabled===!0;const a=i[o]?.access;s[`${o}Access`]=typeof a=="string"&&a?a:"admin"}return s}export function cleanField(e){const{_key:r,...n}=e||{};return n}export function payloadFromForm(e,{isNew:r=!1,meta:n={}}={}){const t=e||{},i={};for(const o of OPERATIONS)i[o]={enabled:t[`${o}Enabled`]===!0,access:t[`${o}Access`]||"admin"};const l=String(t.readFields??"").split(",").map(o=>o.trim()).filter(Boolean);l.length&&(i.read.fields=l),i.mine=t.mineLocked?!1:t.mineEnabled!==!1;const s=Math.min(6,Math.max(1,Number.parseInt(t.columns,10)||2));return{title:String(t.title??"").trim(),...r&&{slug:slugify(t.slug||t.title)},description:String(t.description??"").trim(),layout:t.layout==="grid"?"grid":"stacked",columns:s,fields:(t.fields||[]).map(cleanField),api:i,export:{enabled:t.exportEnabled!==!1,...t.exportAccess&&{access:t.exportAccess},formats:EXPORT_FORMATS.filter(o=>o==="csv"?t.exportCsv:t.exportJson)},storage:t.storageAdapter==="mongodb"?{adapter:"mongodb",connection:t.storageConnection||"default"}:{adapter:"file"},meta:{...n||{},project:String(t.project??"")||null},bundled:t.bundled===!0}}export function snapshot(e){const{fields:r=[],...n}=e||{};return JSON.stringify({...n,fields:r.map(cleanField)})}export function checkForm(e,{isNew:r=!1,taken:n=[],original:t={}}={}){const i=e||{},l={};if(String(i.title??"").trim()||(l.title="A collection needs a title."),r){const c=slugify(i.slug||i.title);c?n.includes(c)&&(l.slug=`"${c}" is already a collection.`):l.slug="The slug needs a letter or a number."}const s=Number.parseInt(i.columns,10);i.layout==="grid"&&!(s>=1&&s<=6)&&(l.columns="Between 1 and 6 columns.");const o={},a=new Map;return(i.fields||[]).forEach(c=>{const d=fieldProblem(c,t[c._key]);d&&(o[c._key]=d);const u=String(c.name??"").trim();u&&(a.has(u)?o[c._key]=o[c._key]||`"${u}" is used by another field.`:a.set(u,c._key))}),Object.keys(o).length&&(l.fields=o),i.exportEnabled&&!i.exportCsv&&!i.exportJson&&(l.export="Pick at least one export format, or turn export off."),l}export function fieldProblem(e,r){const n=String(e?.name??"").trim();return n?n!==r&&!FIELD_NAME_RE.test(n)?"Names start with a letter or _, then letters, digits, _ or -.":OPTION_TYPES.has(e.type)&&!(Array.isArray(e.options)&&e.options.length)?`A ${typeLabel(e.type).toLowerCase()} needs at least one option.`:"":"A field needs a name - it is what each entry is keyed by."}export const errorCount=e=>Object.keys(e||{}).filter(r=>r!=="fields").length+Object.keys(e?.fields||{}).length;export function fieldRow(e,r={},{grid:n=!1}={}){const t=[e.name||"(no name)",typeLabel(e.type)];return OPTION_TYPES.has(e.type)&&t.push(`${(e.options||[]).length} options`),n&&t.push(e.fullWidth?"full width":`span ${e.span>1?e.span:1}`),{key:e._key,label:e.label||"(Untitled field)",meta:t.join(" \xB7 "),required:e.required===!0,hidden:e.type==="hidden",notInLists:e.listHidden===!0&&e.type!=="hidden",problem:r[e._key]||"",rowCls:r[e._key]?"is-bad":""}}export function moveField(e,r,n){const t=[...e];if(r<0||r>=t.length||n<0||n>=t.length||r===n)return t;const[i]=t.splice(r,1);return t.splice(n,0,i),t}export function duplicateField(e,r){const n=e[r];if(!n)return[...e];const t=new Set(e.map(a=>a.name)),i=`${n.name||"field"}_copy`;let l=i;for(let a=2;t.has(l);a++)l=`${i}_${a}`;const s={...JSON.parse(JSON.stringify(cleanField(n))),name:l,label:`${n.label||"Field"} (copy)`,_key:fieldKey()};delete s.id;const o=[...e];return o.splice(r+1,0,s),o}export const newField=()=>({id:`field-${Date.now()}`,name:"",label:"",type:"string",required:!1,placeholder:"",helper:"",options:[],validation:[],logic:null,_key:fieldKey()});export function panelForm(e){return{label:String(e.label??""),name:String(e.name??""),type:e.type||"string",required:e.required===!0,placeholder:String(e.placeholder??""),helper:String(e.helper??""),options:optionsText(e.options),span:String(e.span>1?e.span:1),fullWidth:e.fullWidth===!0,prefixIcon:p(e.prefix).icon,prefixText:p(e.prefix).text,suffixIcon:p(e.suffix).icon,suffixText:p(e.suffix).text,clear:e.clear===!0,stepper:e.stepper===!0,counter:e.counter===!0,inLists:e.listHidden!==!0}}export function fieldFromPanel(e,r){const n={...e,label:String(r.label??"").trim(),name:String(r.name??"").trim(),type:r.type||"string",required:r.required===!0,placeholder:String(r.placeholder??"").trim(),helper:String(r.helper??"").trim()};OPTION_TYPES.has(n.type)&&(n.options=parseOptions(r.options)),"inLists"in r&&(r.inLists===!1?n.listHidden=!0:delete n.listHidden);for(const[t,i]of Object.entries(EXTRA_TYPES)){if(!i.has(n.type)){delete n[t];continue}t in r&&(r[t]===!0?n[t]=!0:delete n[t])}for(const t of["prefix","suffix"]){const i=`${t}Icon`in r||`${t}Text`in r;if(!ADDON_TYPES.has(n.type)){delete n[t];continue}if(!i)continue;const l=addonFromBoxes(r[`${t}Icon`],r[`${t}Text`]);l?n[t]=l:delete n[t]}if(r.fullWidth)n.fullWidth=!0,delete n.span;else{delete n.fullWidth;const t=Number.parseInt(r.span,10);t>1?n.span=Math.min(6,t):delete n.span}return n}export function storageChange(e,r){const n=e||"file",t=r||"file";return n===t?"":`${n} \u2192 ${t}`}export function draftOf(e){const{fields:r=[],...n}=e||{};return{...n,fields:r.map(cleanField)}}export function formFromDraft(e,r){const n=e||{};return{...r,...n,fields:(Array.isArray(n.fields)?n.fields:r.fields).map(t=>({...cleanField(t),_key:fieldKey()}))}}
|
|
@@ -110,6 +110,10 @@
|
|
|
110
110
|
<input id="api-read-fields" type="text" class="form-input" placeholder="Empty = every field" data-model="readFields.value">
|
|
111
111
|
<small class="cex-hint cex-wide" data-bind-hidden="!unknownReadFields.value" data-bind-text="unknownReadFields.value"></small>
|
|
112
112
|
</div>
|
|
113
|
+
<div class="cex-op cex-op-sub">
|
|
114
|
+
<label class="cex-check"><input type="checkbox" data-model="mineEnabled.value" data-bind-disabled="mineLocked.value"> Users can read their own entries (scope=mine)
|
|
115
|
+
<span data-help-title="Their own entries" data-help="A signed-in user may read the entries they created - [collection scope="mine"] and ?scope=mine - even when Read is off. Turn this off when entries hold something their creator must not see."></span></label>
|
|
116
|
+
</div>
|
|
113
117
|
<div class="cex-op"><strong>Update</strong>
|
|
114
118
|
<label class="cex-check"><input type="checkbox" data-model="updateEnabled.value"> Allowed</label>
|
|
115
119
|
<select class="form-input" aria-label="Who may update" data-model="updateAccess.value" data-bind-disabled="!updateEnabled.value"></select></div>
|
package/docs/api-reference.md
CHANGED
|
@@ -930,7 +930,7 @@ The public `GET` list endpoint accepts all the same query parameters as the admi
|
|
|
930
930
|
|
|
931
931
|
| Parameter | Description |
|
|
932
932
|
|---|---|
|
|
933
|
-
| `scope=mine` | Restrict to the current user's own entries (`createdBy = <user.id>`). Requires a JWT. Bypasses the `api.read` gate - users can
|
|
933
|
+
| `scope=mine` | Restrict to the current user's own entries (`createdBy = <user.id>`). Requires a JWT. Bypasses the `api.read` gate - users can view their own data unless the schema sets `api.mine: false` (then 404 as for an unknown collection, here and on `render-scope`). |
|
|
934
934
|
|
|
935
935
|
**`POST /api/collections/render-scope`** - renders a `[collection scope="mine"]` placeholder server-side with the
|
|
936
936
|
current user's id injected. Called by the public site JS when it encounters `.dm-collection-hydrate` placeholders.
|
package/package.json
CHANGED
|
@@ -129,6 +129,7 @@ import {
|
|
|
129
129
|
isRoot,
|
|
130
130
|
isUserDataPreset,
|
|
131
131
|
mayReadRow,
|
|
132
|
+
mineAllowed,
|
|
132
133
|
mayWriteRow,
|
|
133
134
|
ownRowsFilter,
|
|
134
135
|
pinOwner,
|
|
@@ -802,6 +803,7 @@ export async function collectionsRoutes(fastify) {
|
|
|
802
803
|
* JWT; returns 401 if unauthenticated. Used by the
|
|
803
804
|
* `[collection scope="mine"]` shortcode for per-user
|
|
804
805
|
* client-side hydration (e.g. "My Applications").
|
|
806
|
+
* 404 when the schema says `api.mine: false`.
|
|
805
807
|
*/
|
|
806
808
|
async function publicListEntries(request, reply) {
|
|
807
809
|
// Allowed in robots.txt so Google can render pages that read it; the JSON itself is never a search result.
|
|
@@ -827,6 +829,9 @@ export async function collectionsRoutes(fastify) {
|
|
|
827
829
|
} catch {
|
|
828
830
|
return reply.status(401).send({ error: 'Authentication required' });
|
|
829
831
|
}
|
|
832
|
+
// A collection that opts out (`api.mine: false`) is not there for this
|
|
833
|
+
// door at all: the unknown-slug answer, after the same 401 as any other.
|
|
834
|
+
if (!mineAllowed(schema)) return reply.status(404).send({ error: 'Collection not found' });
|
|
830
835
|
} else {
|
|
831
836
|
if (!(await checkPublicAccess(schema, 'read', request, reply))) return;
|
|
832
837
|
}
|
|
@@ -900,7 +905,7 @@ export async function collectionsRoutes(fastify) {
|
|
|
900
905
|
* Security: results are always scoped to `createdBy = <user.id>` -
|
|
901
906
|
* a caller can only ever render their own entries, regardless of the
|
|
902
907
|
* collection's `api.read` setting. This matches the security model
|
|
903
|
-
* of GET /:slug/public?scope=mine.
|
|
908
|
+
* of GET /:slug/public?scope=mine, `api.mine: false` (404) included.
|
|
904
909
|
*/
|
|
905
910
|
fastify.post('/collections/render-fragment', async (request, reply) => {
|
|
906
911
|
/*
|
|
@@ -980,6 +985,8 @@ export async function collectionsRoutes(fastify) {
|
|
|
980
985
|
|
|
981
986
|
const schema = await getCollection(attrs.slug);
|
|
982
987
|
if (!schema) return reply.status(404).send({ error: 'Collection not found' });
|
|
988
|
+
// Own rows without api.read: refused where the collection opts out (api.mine: false).
|
|
989
|
+
if (!mineAllowed(schema)) return reply.status(404).send({ error: 'Collection not found' });
|
|
983
990
|
|
|
984
991
|
// Interactive attrs come back as a Collection Browser shell scoped to
|
|
985
992
|
// this viewer (transitions included); the rest as a static fragment.
|
|
@@ -223,6 +223,25 @@ export function ownerOf(slug, entry) {
|
|
|
223
223
|
return entry?.[where.in]?.[where.field] ?? null;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Whether signed-in users may read the rows they created in this collection
|
|
228
|
+
* through `scope=mine` (`GET /:slug/public?scope=mine`, `/api/v1/:slug?scope=mine`
|
|
229
|
+
* and `POST /render-scope` for `[collection scope="mine"]`) - the one door that
|
|
230
|
+
* shows a user their own rows WITHOUT `api.read`. On unless the schema says
|
|
231
|
+
* `api.mine: false`: a collection whose rows carry fields the creator must not
|
|
232
|
+
* see (set by the owning plugin's routes after the user submitted) turns it off.
|
|
233
|
+
* Admin-built views with an owner row-level rule are a separate, explicit grant
|
|
234
|
+
* and do not read this flag.
|
|
235
|
+
*
|
|
236
|
+
* @param {object|null} schema
|
|
237
|
+
* @returns {boolean}
|
|
238
|
+
*/
|
|
239
|
+
export function mineAllowed(schema) {
|
|
240
|
+
// Only absent or `true` leaves it on: a typo ("false", null, 0) narrows rather than opens.
|
|
241
|
+
const mine = schema?.api?.mine;
|
|
242
|
+
return mine === undefined || mine === true;
|
|
243
|
+
}
|
|
244
|
+
|
|
226
245
|
/**
|
|
227
246
|
* The list filter that keeps a user-data preset to the caller's own rows, or
|
|
228
247
|
* null when no filter applies (not a user-data preset, root, or a preset whose
|
|
@@ -193,6 +193,13 @@ export async function updateCollection(slug, updates) {
|
|
|
193
193
|
updatedAt: new Date().toISOString()
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
+
// `api.mine` (see mineAllowed in collectionAccess.js) is kept when an
|
|
197
|
+
// update's api block does not mention it: clients that rebuild `api` from
|
|
198
|
+
// the four verbs would otherwise switch a collection's opt-out back on.
|
|
199
|
+
if (rest.api && typeof rest.api === 'object' && !('mine' in rest.api) && schema.api && 'mine' in schema.api) {
|
|
200
|
+
updated.api = {...rest.api, mine: schema.api.mine};
|
|
201
|
+
}
|
|
202
|
+
|
|
196
203
|
// Preserve the original plugin field (never overwrite)
|
|
197
204
|
if (schema.plugin) {
|
|
198
205
|
updated.plugin = schema.plugin;
|
|
@@ -42,7 +42,7 @@ import {disableInstantCalls, enableInstantCalls, grantInstantCallsOnce} from './
|
|
|
42
42
|
import {claimHosts} from './hostClaims.js';
|
|
43
43
|
import {pluginSafeFetch} from './outbound.js';
|
|
44
44
|
import {disableDashboardPro, enableDashboardPro, registerWidget, unregisterWidgetsFrom} from './widgets.js';
|
|
45
|
-
import {createCollection, getCollection} from './collections.js';
|
|
45
|
+
import {createCollection, getCollection, updateCollection} from './collections.js';
|
|
46
46
|
import * as defaultRolesService from './roles.js';
|
|
47
47
|
import {getAdminScope, normaliseAdminScope} from './roles.js';
|
|
48
48
|
import {pluginAuthGuards} from './pluginScope.js';
|
|
@@ -627,7 +627,7 @@ export async function registerPlugins(fastify) {
|
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
// Ensure plugin collections exist (idempotent - skips if already present)
|
|
630
|
-
await setupPlugin(manifest.name, {collections: {getCollection, createCollection}})
|
|
630
|
+
await setupPlugin(manifest.name, {collections: {getCollection, createCollection, updateCollection}})
|
|
631
631
|
.catch(err => fastify.log.warn(`[plugins] Collection setup for "${manifest.name}" failed: ${err.message}`));
|
|
632
632
|
|
|
633
633
|
// Permissions are held in memory, so they are registered on every
|
|
@@ -787,6 +787,15 @@ export async function setupPlugin(pluginName, services) {
|
|
|
787
787
|
if (!existing) {
|
|
788
788
|
await services.collections.createCollection(schema);
|
|
789
789
|
result.collections.push(schema.slug);
|
|
790
|
+
} else if (schema.api?.mine === false && existing.api?.mine !== false
|
|
791
|
+
&& existing.plugin === pluginName && services.collections.updateCollection) {
|
|
792
|
+
// The plugin's schema turns scope=mine off: an existing
|
|
793
|
+
// install gets that too (it only ever narrows - never the
|
|
794
|
+
// reverse, which stays the site's choice).
|
|
795
|
+
await services.collections.updateCollection(schema.slug, {
|
|
796
|
+
api: {...(existing.api || {}), mine: false},
|
|
797
|
+
...(existing.bundled && {bundled: true})
|
|
798
|
+
});
|
|
790
799
|
}
|
|
791
800
|
} catch {
|
|
792
801
|
// Skip missing or invalid schema files
|
|
@@ -562,6 +562,15 @@ async function keptStorage(schemaPath) {
|
|
|
562
562
|
return null;
|
|
563
563
|
}
|
|
564
564
|
|
|
565
|
+
/** Whether an existing schema.json switches scope=mine off (`api.mine: false`). */
|
|
566
|
+
async function keptMineOff(schemaPath) {
|
|
567
|
+
try {
|
|
568
|
+
return JSON.parse(await fs.readFile(schemaPath, 'utf8'))?.api?.mine === false;
|
|
569
|
+
} catch {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
565
574
|
/**
|
|
566
575
|
* Seed all preset collections at boot.
|
|
567
576
|
* Always overwrites schema.json; only creates data.json if absent.
|
|
@@ -578,7 +587,12 @@ export async function seedAll() {
|
|
|
578
587
|
// A user-data preset keeps the storage the site has (a move to or from
|
|
579
588
|
// MongoDB); rewriting it would flip the site to the other store.
|
|
580
589
|
const kept = USER_DATA.has(schema.slug) ? await keptStorage(schemaPath) : null;
|
|
581
|
-
|
|
590
|
+
let written = kept ? {...schema, storage: kept} : schema;
|
|
591
|
+
// A site's `api.mine: false` (own rows not readable through scope=mine)
|
|
592
|
+
// survives the rewrite; it only ever narrows access.
|
|
593
|
+
if (schema.api?.mine !== false && await keptMineOff(schemaPath)) {
|
|
594
|
+
written = {...written, api: {...(written.api || {}), mine: false}};
|
|
595
|
+
}
|
|
582
596
|
await fs.writeFile(schemaPath, JSON.stringify(written, null, 2) + '\n', 'utf8');
|
|
583
597
|
|
|
584
598
|
try {
|