rshinyrstudioposit-connect

Write pins with specific list of users with access (acl)


I would like to write pins to my Posit Connect board with acl, by that I mean a list of specific users that get access.

I need to do this via code instead of Posit Connect GUI because I have thousands of pins (that get updated regularly).

The following code uploads mtcars as a pin to my Posit Connect board with access_type "logged_in" ("All users - login required").

library(pins)
board <- board_connect(auth = "envvar")

mtcars %>% pins::pin_write(board = board, name = "my_mtcars_pin",
                               force_identical_write = T, access_type = "logged_in")

Other options are "all" and "acl". With "acl" I would have to supply a list of users or groups. I don't know how to to that, I can't find any documentation on this. Could someone please provide me with an example? Thank you very much!

I wonder if I could use connectapi::get_acl_user() or connectapi::get_acl() for my purposes but for that I would need the GUID for the content item to be retrieved. The GUID is not provided with functions from the pins library (as far as I can tell).


Solution

  • I found a solution. Not sure if this is the best way to do it - probably not - but it does work at least.

    library(dplyr)
    library(connectapi)
    
    # connect object to Posit board
    connect <- connectapi::connect(
      server = Sys.getenv("CONNECT_SERVER"),
      api_key = Sys.getenv("CONNECT_API_KEY"))
    
    # get all content
    myguids <- connectapi::get_content(connect, limit = Inf)
    # filter for specific content by name
    # (here: use an object that has the specific acl set that I'd like elsewhere)
    # probably could also just search for user GUIDS via connectapi
    content <- myguids %>% dplyr::filter(name == "report_a")
    # create a R6 content object
    content_r6 <- connectapi::content_item(
      connect = connect, guid = content$guid)
    
    # get user permission
    users_guid <- connectapi::get_content_permissions(
      content_r6, add_owner = FALSE) %>% dplyr::pull(principal_guid)
    
    # get the content I want to update
    content2 <- myguids %>% dplyr::filter(name == "my_mtcars_pin")
    # create a R6 content object
    content2_r6 <- connectapi::content_item(
      connect = connect, guid = content2$guid)
    
    # update access_type to acl if not set like this anyway yet
    connectapi::content_update_access_type(
      content = content2_r6, access_type = "acl")
    # set new owners
    connectapi::content_add_user(
      content = content2_r6, guid = users_guid, role = "owner")