import{r as s,p as r,q as u,w as o,z as l,R as t}from"./vendor.3d5b4206.js";const i=l("div",{class:"markdown-body"},[l("blockquote",null,[l("p",null,[t("Permissions, validation, and the API\u2019s "),l("code",null,"filter"),t(" parameter all rely on a specific JSON structure to define their rules. This page describes the syntax for creating flat, relational, or complex filter rules.")])]),l("p",null,[l("div",{class:"table-of-contents"},[l("ul",null,[l("li",null,[l("a",{href:"#syntax"},"Syntax")]),l("li",null,[l("a",{href:"#filter-operators"},"Filter Operators")]),l("li",null,[l("a",{href:"#relational"},"Relational")]),l("li",null,[l("a",{href:"#logical-operators"},"Logical Operators")]),l("li",null,[l("a",{href:"#dynamic-variables"},"Dynamic Variables")])])])]),l("h2",{id:"syntax"},[t("Syntax "),l("a",{class:"header-anchor",href:"#syntax"},"#")]),l("ul",null,[l("li",null,[l("strong",null,"Field"),t(" \u2014 Any valid root field, "),l("a",{href:"#relational"},"relational field"),t(", or "),l("a",{href:"#logical-operators"},"logical operator")]),l("li",null,[l("strong",null,"Operator"),t(" \u2014 Any valid "),l("a",{href:"#filter-operators"},"filter operator")]),l("li",null,[l("strong",null,"Value"),t(" \u2014 Any valid static value, or "),l("a",{href:"#dynamic-variables"},"dynamic variable")])]),l("pre",null,[l("code",null,`{
	<field>: {
		<operator>: <value>
	}
}
`)]),l("h3",{id:"examples"},[t("Examples "),l("a",{class:"header-anchor",href:"#examples"},"#")]),l("pre",null,[l("code",{class:"language-json"},[t(`{
	`),l("span",{class:"hljs-attr"},'"title"'),t(`: {
		`),l("span",{class:"hljs-attr"},'"_contains"'),t(": "),l("span",{class:"hljs-string"},'"Directus"'),t(`
	}
}
`)])]),l("pre",null,[l("code",{class:"language-json"},[t(`{
	`),l("span",{class:"hljs-attr"},'"owner"'),t(`: {
		`),l("span",{class:"hljs-attr"},'"_eq"'),t(": "),l("span",{class:"hljs-string"},'"$CURRENT_USER"'),t(`
	}
}
`)])]),l("pre",null,[l("code",{class:"language-json"},[t(`{
	`),l("span",{class:"hljs-attr"},'"datetime"'),t(`: {
		`),l("span",{class:"hljs-attr"},'"_lte"'),t(": "),l("span",{class:"hljs-string"},'"$NOW"'),t(`
	}
}
`)])]),l("h2",{id:"filter-operators"},[t("Filter Operators "),l("a",{class:"header-anchor",href:"#filter-operators"},"#")]),l("table",null,[l("thead",null,[l("tr",null,[l("th",null,"Operator"),l("th",null,"Description")])]),l("tbody",null,[l("tr",null,[l("td",null,[l("code",null,"_eq")]),l("td",null,"Equal to")]),l("tr",null,[l("td",null,[l("code",null,"_neq")]),l("td",null,"Not equal to")]),l("tr",null,[l("td",null,[l("code",null,"_lt")]),l("td",null,"Less than")]),l("tr",null,[l("td",null,[l("code",null,"_lte")]),l("td",null,"Less than or equal to")]),l("tr",null,[l("td",null,[l("code",null,"_gt")]),l("td",null,"Greater than")]),l("tr",null,[l("td",null,[l("code",null,"_gte")]),l("td",null,"Greater than or equal to")]),l("tr",null,[l("td",null,[l("code",null,"_in")]),l("td",null,"Matches any of the values")]),l("tr",null,[l("td",null,[l("code",null,"_nin")]),l("td",null,"Doesn\u2019t match any of the values")]),l("tr",null,[l("td",null,[l("code",null,"_null")]),l("td",null,[t("Is "),l("code",null,"null")])]),l("tr",null,[l("td",null,[l("code",null,"_nnull")]),l("td",null,[t("Is not "),l("code",null,"null")])]),l("tr",null,[l("td",null,[l("code",null,"_contains")]),l("td",null,"Contains the substring")]),l("tr",null,[l("td",null,[l("code",null,"_ncontains")]),l("td",null,"Doesn\u2019t contain the substring")]),l("tr",null,[l("td",null,[l("code",null,"_starts_with")]),l("td",null,"Starts with")]),l("tr",null,[l("td",null,[l("code",null,"_nstarts_with")]),l("td",null,"Doesn\u2019t start with")]),l("tr",null,[l("td",null,[l("code",null,"_ends_with")]),l("td",null,"Ends with")]),l("tr",null,[l("td",null,[l("code",null,"_nends_with")]),l("td",null,"Doesn\u2019t end with")]),l("tr",null,[l("td",null,[l("code",null,"_between")]),l("td",null,"Is between two values (inclusive)")]),l("tr",null,[l("td",null,[l("code",null,"_nbetween")]),l("td",null,"Is not between two values (inclusive)")]),l("tr",null,[l("td",null,[l("code",null,"_empty")]),l("td",null,[t("Is empty ("),l("code",null,"null"),t(" or falsy)")])]),l("tr",null,[l("td",null,[l("code",null,"_nempty")]),l("td",null,[t("Is not empty ("),l("code",null,"null"),t(" or falsy)")])]),l("tr",null,[l("td",null,[l("code",null,"_intersects"),t(),l("sup",null,"[1]")]),l("td",null,"Value intersects a given point")]),l("tr",null,[l("td",null,[l("code",null,"_nintersects"),t(),l("sup",null,"[1]")]),l("td",null,"Value does not intersect a given point")]),l("tr",null,[l("td",null,[l("code",null,"_intersects_bbox"),t(),l("sup",null,"[1]")]),l("td",null,"Value is in a bounding box")]),l("tr",null,[l("td",null,[l("code",null,"_nintersects_bbox"),t(),l("sup",null,"[1]")]),l("td",null,"Value is not in a bounding box")])])]),l("p",null,[t("The following operators are "),l("strong",null,"only available in validation permissions"),t(":")]),l("table",null,[l("thead",null,[l("tr",null,[l("th",null,"Operator"),l("th",null,"Description")])]),l("tbody",null,[l("tr",null,[l("td",null,[l("code",null,"_submitted")]),l("td",null,"Field has to be submitted")]),l("tr",null,[l("td",null,[l("code",null,"_regex"),t(),l("sup",null,"[2]")]),l("td",null,"Field has to match regex")])])]),l("p",null,[l("sup",null,"[1]"),t(" Only available on Geometry types."),l("br"),l("sup",null,"[2]"),t(" JavaScript \u201Cflavor\u201D regex. Make sure to escape backslashes.")]),l("h2",{id:"relational"},[t("Relational "),l("a",{class:"header-anchor",href:"#relational"},"#")]),l("p",null,[t("You can target related values by nesting field names. For example, if you have a relational Many-to-One "),l("code",null,"author"),t(" field, you can set a rule for the "),l("code",null,"author.name"),t(" field using the following syntax.")]),l("pre",null,[l("code",{class:"language-json"},[t(`{
	`),l("span",{class:"hljs-attr"},'"author"'),t(`: {
		`),l("span",{class:"hljs-attr"},'"name"'),t(`: {
			`),l("span",{class:"hljs-attr"},'"_eq"'),t(": "),l("span",{class:"hljs-string"},'"Rijk van Zanten"'),t(`
		}
	}
}
`)])]),l("h2",{id:"logical-operators"},[t("Logical Operators "),l("a",{class:"header-anchor",href:"#logical-operators"},"#")]),l("p",null,[t("You can nest or group multiple rules using the "),l("code",null,"_and"),t(" or "),l("code",null,"_or"),t(" logical operators. Each operator holds an array of rules, allowing for more complex filtering.")]),l("pre",null,[l("code",{class:"language-json"},[t(`{
	`),l("span",{class:"hljs-attr"},'"_or"'),t(`: [
		{
			`),l("span",{class:"hljs-attr"},'"_and"'),t(`: [
				{
					`),l("span",{class:"hljs-attr"},'"user_created"'),t(`: {
						`),l("span",{class:"hljs-attr"},'"_eq"'),t(": "),l("span",{class:"hljs-string"},'"$CURRENT_USER"'),t(`
					}
				},
				{
					`),l("span",{class:"hljs-attr"},'"status"'),t(`: {
						`),l("span",{class:"hljs-attr"},'"_in"'),t(": ["),l("span",{class:"hljs-string"},'"published"'),t(", "),l("span",{class:"hljs-string"},'"draft"'),t(`]
					}
				}
			]
		},
		{
			`),l("span",{class:"hljs-attr"},'"_and"'),t(`: [
				{
					`),l("span",{class:"hljs-attr"},'"user_created"'),t(`: {
						`),l("span",{class:"hljs-attr"},'"_neq"'),t(": "),l("span",{class:"hljs-string"},'"$CURRENT_USER"'),t(`
					}
				},
				{
					`),l("span",{class:"hljs-attr"},'"status"'),t(`: {
						`),l("span",{class:"hljs-attr"},'"_in"'),t(": ["),l("span",{class:"hljs-string"},'"published"'),t(`]
					}
				}
			]
		}
	]
}
`)])]),l("h2",{id:"dynamic-variables"},[t("Dynamic Variables "),l("a",{class:"header-anchor",href:"#dynamic-variables"},"#")]),l("p",null,[t("In addition to static values, you can also filter against "),l("em",null,"dynamic"),t(" values using the following variables.")]),l("ul",null,[l("li",null,[l("code",null,"$CURRENT_USER"),t(" \u2014 The primary key of the currently authenticated user")]),l("li",null,[l("code",null,"$CURRENT_ROLE"),t(" \u2014 The primary key of the role for the currently authenticated user")]),l("li",null,[l("code",null,"$NOW"),t(" \u2014 The current timestamp")]),l("li",null,[l("code",null,"$NOW(<adjustment>)"),t(" - The current timestamp plus/minus a given distance, for example "),l("code",null,"$NOW(-1 year)"),t(", "),l("code",null,"$NOW(+2 hours)")])]),l("div",{class:"tip hint"},[l("div",{class:"hint-title"},"Nested User / Role variables in Permissions"),l("p",null,[t("When configuring permissions, "),l("code",null,"$CURRENT_USER"),t(" and "),l("code",null,"$CURRENT_ROLE"),t(" allow you to specify any (nested) field under the current user/role as well as the root ID. For example: "),l("code",null,"$CURRENT_ROLE.name"),t(" or "),l("code",null,"$CURRENT_USER.avatar.filesize"),t(". This includes custom fields that were added to the directus_users/directus_roles tables.")]),l("p",null,"Note: This feature is only available for permissions, validation, and presets. Regular filters and conditional fields currently only support the root ID.")])],-1),_={setup(d,{expose:e}){const n={title:"Filter Rules",modularExtension:!1};return e({frontmatter:n}),(c,h)=>{const a=s("DocsWrapper");return r(),u(a,{frontmatter:n},{default:o(()=>[i]),_:1})}}};export{_ as default};
