1+ use crate :: db:: datastore:: locking_tx_datastore:: state_view:: StateView ;
12use crate :: db:: datastore:: locking_tx_datastore:: MutTxId ;
23use crate :: sql:: ast:: SchemaViewer ;
34use spacetimedb_expr:: check:: parse_and_type_sub;
4- use spacetimedb_expr:: errors:: TypingError ;
55use spacetimedb_expr:: expr:: ProjectName ;
6+ use spacetimedb_lib:: db:: auth:: StAccess ;
67use spacetimedb_lib:: db:: raw_def:: v9:: RawRowLevelSecurityDefV9 ;
78use spacetimedb_lib:: identity:: AuthCtx ;
89use spacetimedb_schema:: schema:: RowLevelSecuritySchema ;
@@ -17,15 +18,26 @@ impl RowLevelExpr {
1718 tx : & mut MutTxId ,
1819 auth_ctx : & AuthCtx ,
1920 rls : & RawRowLevelSecurityDefV9 ,
20- ) -> Result < Self , TypingError > {
21+ ) -> anyhow :: Result < Self > {
2122 let ( sql, _) = parse_and_type_sub ( & rls. sql , & SchemaViewer :: new ( tx, auth_ctx) , auth_ctx) ?;
23+ let table_id = sql. return_table_id ( ) . unwrap ( ) ;
24+ let schema = tx. schema_for_table ( table_id) ?;
2225
23- Ok ( Self {
24- def : RowLevelSecuritySchema {
25- table_id : sql. return_table_id ( ) . unwrap ( ) ,
26- sql : rls. sql . clone ( ) ,
27- } ,
28- sql,
29- } )
26+ match schema. table_access {
27+ StAccess :: Private => {
28+ anyhow:: bail!(
29+ "Cannot define RLS rule on private table: {}. \
30+ Please make table public if you wish to restrict access using RLS.",
31+ schema. table_name
32+ )
33+ }
34+ StAccess :: Public => Ok ( Self {
35+ def : RowLevelSecuritySchema {
36+ table_id,
37+ sql : rls. sql . clone ( ) ,
38+ } ,
39+ sql,
40+ } ) ,
41+ }
3042 }
3143}
0 commit comments