Skip to content

Commit

Permalink
improve revoke and grant egs
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Feb 3, 2025
1 parent 977b9f4 commit aac9db2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
34 changes: 32 additions & 2 deletions R/privileges.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
#' if (!dbExistsTable(con, "passwd")) {
#' setup_example_table(con, "passwd")
#' }
#'
#' if (!rls_role_exists(con, "jane")) {
#' dbExecute(con, "CREATE ROLE jane")
#' }
#'
#' # NOTE: privileges construction doesn't make a change in the database
#' # unless you pass it to `rls_perform` or set `auto_pipe(TRUE)`
#' rls_tbl(con, "passwd") %>%
#' grant(update) %>%
#' to(jane)
Expand All @@ -24,7 +30,16 @@
#' grant(update, select, cols = c("real_name", "home_phone")) %>%
#' to(jane)
#'
#' # Execute a privilege and inspect the change to jane's details in the DB
#' rls_tbl(con, "passwd") %>%
#' grant(update, delete) %>%
#' to(jane) %>%
#' rls_perform()
#' rls_column_privileges(con, "passwd", "jane")
#'
#' # cleanup
#' dbExecute(con, "DROP OWNED BY jane")
#' dbExecute(con, "DROP ROLE jane")
#' dbDisconnect(con)
grant <- function(.data, ..., cols = NULL) {
pipe_autoexec(toggle = rls_env$auto_pipe)
Expand All @@ -50,16 +65,31 @@ grant <- function(.data, ..., cols = NULL) {
#' if (!dbExistsTable(con, "passwd")) {
#' setup_example_table(con, "passwd")
#' }
#'
#' if (!rls_role_exists(con, "jill")) {
#' dbExecute(con, "CREATE ROLE jill")
#' }
#'
#' # NOTE: privileges construction doesn't make a change in the database
#' # unless you pass it to `rls_perform` or set `auto_pipe(TRUE)`
#'
#' # Grant first
#' rls_tbl(con, "passwd") %>%
#' grant(update) %>%
#' from(jill)
#'
#' # Then revoke
#' rls_tbl(con, "passwd") %>%
#' revoke(update) %>%
#' from(jane)
#' from(jill)
#'
#' # Revoke on certain columns
#' rls_tbl(con, "passwd") %>%
#' revoke(update, cols = c("real_name", "home_phone")) %>%
#' from(jane)
#' from(jill)
#'
#' # cleanup
#' dbExecute(con, "DROP ROLE jill")
#' dbDisconnect(con)
revoke <- function(.data, ..., cols = NULL) {
pipe_autoexec(toggle = rls_env$auto_pipe)
Expand Down
15 changes: 15 additions & 0 deletions man/grant.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions man/revoke.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aac9db2

Please sign in to comment.