Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for fetching metadata for database and billing accounts #26

Open
akbertram opened this issue Oct 13, 2022 · 2 comments
Open

API for fetching metadata for database and billing accounts #26

akbertram opened this issue Oct 13, 2022 · 2 comments
Assignees
Milestone

Comments

@akbertram
Copy link
Member

The R package should expose a function for fetching metadata on the set of forms that belong to a database, or to a billing account. The results should include a list of forms, each with the metadata currently stored internally:

  • The form's label
  • The form's database
  • The number of records in the form
  • The time of the last update to the form
  • The form's version number
  • The form's schema version number
  • The visibility of the form (private, reference or public)

Additional permissions metadata that would be useful:

  • The number of users with read access
  • The number of users with write access
@nickdickinson nickdickinson added this to the Release 4.38 milestone Oct 16, 2024
@nickdickinson
Copy link
Collaborator

Dependencies

library(dplyr)
library(tidyr)
library(activityinfo)

Users with read access in a tibble dataframe

If you know the role id such as "readonly"

targetRole <- "readonly"
userRoles <- getDatabaseUsers(databaseId) %>% 
     as_tibble() %>% 
     unnest_wider(role, names_sep = "_") %>% 
     filter(role_id == targetRole)

If you are interested in a specific operation/expression like "VIEW"

tree <- getDatabaseTree(databaseId)

allRoleOperations <- tibble(roles = tree$roles) %>% 
     unnest_wider(roles) %>% 
     unnest_longer(grants) %>% 
     unnest_wider(grants) %>% 
     unnest_longer(operations) %>% 
     unnest_wider(operations)

viewOperations <- allRoleOperations %>% 
     filter(operation=="VIEW")

userRoles <- getDatabaseUsers(databaseId) %>% 
     as_tibble() %>% 
     unnest_wider(role, names_sep = "_")

userResourceWithView <- userRoles %>% 
     right_join(viewOperations, by=join_by(role_id==id)) %>% 
     filter(!is.na(databaseId))

usersWithView <- userResourceWithView %>% 
     select(userId, name, email) %>% 
     distinct()
n <- nrow(usersWithView)

All database roles and their definitions in a tibble dataframe

tibble(roles = tree$roles) %>% 
     unnest_wider(roles) %>% 
     unnest_longer(grants) %>% 
     unnest_wider(grants) %>% 
     unnest_longer(operations) %>% 
     unnest_wider(operations)

All users and their role ids for all databases in a tibble dataframe

lapply(getDatabases(asDataFrame = FALSE), function(x) {
     try(return(getDatabaseUsers(x$databaseId)))
     return(NULL)}
) %>% 
     bind_rows() %>% 
     as_tibble() %>% 
     unnest_wider(role, names_sep = "_")

Get all database roles and their definitions in a tibble dataframe

tibble(roles = tree$roles) %>% 
     unnest_wider(roles) %>% 
     unnest_longer(grants) %>% 
     unnest_wider(grants) %>% 
     unnest_longer(operations) %>% 
     unnest_wider(operations)

@nickdickinson
Copy link
Collaborator

These are relevant to #133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants