Finding Content Owned by a User

Problem

You need to identify all content owned by a user

This may be useful for auditing purposes, changing content ownership when an employee leaves the company, or creating a list of content that would be the input for another recipe in this guide.

Solution

These solutions assume that you have the username for the user in question.

Using the SDK to look up a user, you can directly access that user’s owned content.

from posit import connect

USERNAME = "publisher1"

client = connect.Client()

content = client.users.find_one(prefix = USERNAME).content.find()

The recipe produces a DataFrame containing all of the user’s owned content.

content_df = pl.DataFrame(content)
>>> content
shape: (3, 45)
            guid               name             title        description    access_type connection_timeout  read_timeout    init_timeout    idle_timeout    max_processes   min_processes   max_conns_per_process   load_factor memory_request  memory_limit    cpu_request cpu_limit   amd_gpu_limit   nvidia_gpu_limit    service_account_name    default_image_name      created_time    last_deployed_time  bundle_id          app_mode content_category    parameterized   cluster_name    image_name  r_version   py_version  quarto_version  r_environment_management    default_r_environment_management    py_environment_management   default_py_environment_management   run_as  run_as_current_user       owner_guid         content_url       dashboard_url    app_role      id                                                                                                                                      tags                                                                         owner
             str                str               str                str           str                null          null            null            null             null            null                    null          null           null          null           null      null            null               null                    null                  null               str                   str        str               str              str             bool            str          null       null          str             str                      null                                null                         bool                                null     null                 bool              str                 str                 str         str     str                                                                                                                           list[struct[5]]                                                                     struct[4]
"f55cdaed-c13e-…    "cgrndhmmpnsgp" "Literate Progr…    "An open-source…         "all"                null          null            null            null             null            null                    null          null           null          null           null      null            null               null                    null                  null  "2024-04-02T17:…      "2024-04-02T17:…       "11"   "quarto-static"               ""            false        "Local"          null       null     "3.11.6"       "1.4.549"                      null                                null                         true                                null     null                false "010b18bf-96b9-"https://wonder…    "https://wonder…     "owner"    "11"     [{"7","Python","1","2024-04-02T17:52:08Z","2024-04-02T17:52:08Z"}, {"12","Quarto","7","2024-04-02T17:55:25Z","2024-04-02T17:55:25Z"}]  {"010b18bf-96b9-499f-bb0f-7519a22ca870","publisher1","Publisher1","Account"}
"1c5278e5-a654-…    "cjbxgjmdaqodv" "Loan Risk Pred…    "An API serving…         "all"                null          null            null            null             null            null                    null          null           null          null           null      null            null               null                    null                  null  "2024-04-02T17:…      "2024-04-02T17:…       "10"   "python-fastapi…              ""            false        "Local"          null       null     "3.11.6"            null                      null                                null                         true                                null     null                false "010b18bf-96b9-…    "https://wonder…    "https://wonder…     "owner"    "10"    [{"7","Python","1","2024-04-02T17:52:08Z","2024-04-02T17:52:08Z"}, {"11","FastAPI","7","2024-04-02T17:54:39Z","2024-04-02T17:54:39Z"}]  {"010b18bf-96b9-499f-bb0f-7519a22ca870","publisher1","Publisher1","Account"}
"19afaa4e-e189-…    "ydcfowlsqtnow" "Interactive Da…    "Easy web apps …         "all"                null          null            null            null             null            null                    null          null           null          null           null      null            null               null                    null                  null  "2024-04-02T17:…      "2024-04-02T17:…        "9"    "python-shiny"               ""            false        "Local"          null       null     "3.11.6"            null                      null                                null                         true                                null     null                false "010b18bf-96b9-…    "https://wonder…    "https://wonder…     "owner"     "9"      [{"7","Python","1","2024-04-02T17:52:08Z","2024-04-02T17:52:08Z"}, {"10","Shiny","7","2024-04-02T17:53:54Z","2024-04-02T17:53:54Z"}]  {"010b18bf-96b9-499f-bb0f-7519a22ca870","publisher1","Publisher1","Account"}

Use the search_content() function to search for content owned by a user, specified by their username.

library(connectapi)

USERNAME <- "publisher1"

client <- connect()

content <- search_content(client, paste0("owner:", USERNAME))

This produces a list of Content objects.

> content
[[1]]
Posit Connect Content:
  Content GUID: 6e41cc4f-c2e5-40b8-96b2-0064638563c5
  Content URL: https://connect.example/connect/#/apps/6e41cc4f-c2e5-40b8-96b2-0064638563c5
  Content Title: Quarterly Revenue Trends

content_item(client, guid = "6e41cc4f-c2e5-40b8-96b2-0064638563c5")


[[2]]
Posit Connect Content:
  Content GUID: cdfd8c51-e177-442f-bc3a-093ca52c0b33
  Content URL: https://connect.example/connect/#/apps/cdfd8c51-e177-442f-bc3a-093ca52c0b33
  Content Title: Support Response Time Analysis

content_item(client, guid = "cdfd8c51-e177-442f-bc3a-093ca52c0b33")


[[3]]
Posit Connect Content:
  Content GUID: 73b812e7-a3df-4c71-ac99-815d5310fbe4
  Content URL: https://connect.example/connect/#/apps/73b812e7-a3df-4c71-ac99-815d5310fbe4
  Content Title: Operational Metrics Dashboard

content_item(client, guid = "73b812e7-a3df-4c71-ac99-815d5310fbe4")