[英]Filter data dynamically based on a hierarchical user id in cube.js
I have two tables called Writers and Publications where there is a foreign key publications.writer_id = writers.id
我有两个名为 Writers 和 Publications 的表,其中有一个外键
publications.writer_id = writers.id
id (int)![]() |
parent_id (int) ![]() |
role (varchar)![]() |
name (varchar)![]() |
path (ltree)![]() |
---|---|---|---|---|
1 ![]() |
ADMIN![]() |
Firstname Lastname![]() |
||
2 ![]() |
1 ![]() |
EDITOR![]() |
Anon Anon![]() |
1.2 ![]() |
3 ![]() |
2 ![]() |
WEB EDITOR ![]() |
Maisy Tickles ![]() |
1.2.3 ![]() |
4 ![]() |
2 ![]() |
WEB EDITOR ![]() |
Jack Beanstalk![]() |
1.2.4 ![]() |
5 ![]() |
3 ![]() |
WEB PROOFREADER ![]() |
Sunny Ray![]() |
1.2.3.5 ![]() |
id (int)![]() |
writer_id (FK) ![]() |
publication_name (varchar) ![]() |
word_length (int)![]() |
published (datetime)![]() |
---|---|---|---|---|
1 ![]() |
2 ![]() |
My First Magazine![]() |
6000 ![]() |
2019-09-09 09:00:00 ![]() |
2 ![]() |
2 ![]() |
My Second Magazine![]() |
6000 ![]() |
2019-09-16 09:00:00 ![]() |
3 ![]() |
3 ![]() |
My First Article![]() |
1000 ![]() |
2019-09-23 09:00:00 ![]() |
4 ![]() |
4 ![]() |
My First Article![]() |
1500 ![]() |
2019-09-23 09:00:00 ![]() |
5 ![]() |
4 ![]() |
My Second Article![]() |
600 ![]() |
2019-10-01 09:00:00 ![]() |
6 ![]() |
5 ![]() |
My First Piece![]() |
600 ![]() |
2020-10-01 09:00:00 ![]() |
I want to do a proof of concept in cube.js
Developer Playground to show various charts.我想在
cube.js
Developer Playground 中进行概念验证以显示各种图表。 Is it possible to filter dynamically based on the user_id so that they can only access content that is equal to or in their subtree ie是否可以根据 user_id 动态过滤,以便他们只能访问等于或在其子树中的内容,即
writers.id=4
) is using the application, they can only see their own articles ( publications.id in (4,5)
)writers.id=4
) 正在使用该应用程序,他们只能看到自己的文章 ( publications.id in (4,5)
)writers.id=3
) is using the application, they can see their publication and the WEB PROOFREADER's one ( publications.id in (3,6)
)writers.id=3
) 正在使用该应用程序,他们可以看到他们的出版物和 WEB PROOFREADER 的出版物 ( publications.id in (3,6)
)publications.id=6
) publications.id=6
) These are the models I have set up so far这些是我到目前为止建立的模型
cube(`Writers`, {
sql: `SELECT * FROM public.writers`,
preAggregations: {},
joins: {
Publications:{
sql: `${CUBE}.id = ${Publication}.writer_id`,
relationship: `hasMany`
}
},
measures: {
count: {
type: `count`,
drillMembers: [id, name, created]
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primaryKey: true
},
role: {
sql: `role`,
type: `string`,
},
};
cube(`Publications`, {
sql: `SELECT * FROM public.publications`,
preAggregations: {},
joins: {
Writer:{
sql: `${CUBE}.writer_id = ${Writers}.id`,
relationship: `hasOne`
}
},
measures: {
count: {
type: `count`,
drillMembers: [id, name, created]
}
},
dimensions: {
id: {
sql: `id`,
type: `number`,
primaryKey: true
},
wordLength: {
sql: `word_length`,
type: `number`,
},
};
I know there are filters
and segments
but these appear to be static. Is there any way to pass a writer_id to filter the relevant data dynamically?我知道有
filters
和segments
,但这些似乎是 static。有什么方法可以传递 writer_id 来动态过滤相关数据吗? (I have no previous knowledge of JS) (我以前对JS一无所知)
I think these recipes can help you:我认为这些食谱可以帮助您:
I think you can query the cube from your front-end application with a filter of id.我认为您可以使用 id 过滤器从前端应用程序查询多维数据集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.