@@ -1785,28 +1785,32 @@ var _ = Describe("linked schema", func() {
17851785 {
17861786 Kind : PathChainLinkedEntrance ,
17871787 TargetEntrance : & base.Entrance {
1788- Type : "department " ,
1789- Value : "dept_name " ,
1788+ Type : "company " ,
1789+ Value : "company_id " ,
17901790 },
17911791 TupleSetRelation : "" ,
17921792 PathChain : []* base.RelationReference {
17931793 {
17941794 Type : "employee" ,
17951795 Relation : "department" ,
17961796 },
1797+ {
1798+ Type : "department" ,
1799+ Relation : "company" ,
1800+ },
17971801 },
17981802 },
17991803 {
18001804 Kind : PathChainLinkedEntrance ,
18011805 TargetEntrance : & base.Entrance {
1802- Type : "company " ,
1803- Value : "company_id " ,
1806+ Type : "department " ,
1807+ Value : "dept_name " ,
18041808 },
18051809 TupleSetRelation : "" ,
18061810 PathChain : []* base.RelationReference {
18071811 {
1808- Type : "department " ,
1809- Relation : "company " ,
1812+ Type : "employee " ,
1813+ Relation : "department " ,
18101814 },
18111815 },
18121816 },
@@ -1821,6 +1825,65 @@ var _ = Describe("linked schema", func() {
18211825 },
18221826 }))
18231827 })
1828+
1829+ It ("Case 32: Nested PathChain preserves tuple-set relation" , func () {
1830+ sch , err := parser .NewParser (`
1831+ entity user {}
1832+
1833+ entity org {
1834+ attribute is_public boolean
1835+ permission view = is_public
1836+ }
1837+
1838+ entity folder {
1839+ relation parent @org
1840+ permission view = parent.view
1841+ }
1842+
1843+ entity resource {
1844+ relation parent @folder
1845+ relation alt @folder
1846+ permission view = parent.view
1847+ }
1848+ ` ).Parse ()
1849+
1850+ Expect (err ).ShouldNot (HaveOccurred ())
1851+
1852+ c := compiler .NewCompiler (true , sch )
1853+ a , _ , _ := c .Compile ()
1854+
1855+ g := NewLinkedGraph (NewSchemaFromEntityAndRuleDefinitions (a , nil ))
1856+
1857+ ent , err := g .LinkedEntrances (& base.Entrance {
1858+ Type : "resource" ,
1859+ Value : "view" ,
1860+ }, & base.Entrance {
1861+ Type : "user" ,
1862+ Value : "" ,
1863+ })
1864+
1865+ Expect (err ).ShouldNot (HaveOccurred ())
1866+ Expect (ent ).Should (Equal ([]* LinkedEntrance {
1867+ {
1868+ Kind : PathChainLinkedEntrance ,
1869+ TargetEntrance : & base.Entrance {
1870+ Type : "org" ,
1871+ Value : "is_public" ,
1872+ },
1873+ TupleSetRelation : "" ,
1874+ PathChain : []* base.RelationReference {
1875+ {
1876+ Type : "resource" ,
1877+ Relation : "parent" ,
1878+ },
1879+ {
1880+ Type : "folder" ,
1881+ Relation : "parent" ,
1882+ },
1883+ },
1884+ },
1885+ }))
1886+ })
18241887 })
18251888
18261889 Context ("BuildRelationPathChain" , func () {
0 commit comments