Granting Access to a User
Problem
You need to grant a user access to a content item.
Solution
from posit import connect
= "c92da1ad-9c48-420f-8e2a-dcd2d58f9723"
CONTENT_GUID = "20a79ce3-6e87-4522-9faf-be24228800a4"
USER_GUID # Valid values are "viewer" and "owner" (collaborator)
= "viewer"
ACCESS_TYPE
= connect.Client()
client
# Add a user permission directly
= client.users.get(USER_GUID)
user =ACCESS_TYPE)
client.content.get(CONTENT_GUID).permissions.create(user, role
# Add a user permission manually
client.content.get(CONTENT_GUID).permissions.create(=USER_GUID,
principal_guid="user",
principal_type=ACCESS_TYPE,
role
)
# Confirm new permissions
client.content.get(CONTENT_GUID).permissions.find()
library(connectapi)
<- "c92da1ad-9c48-420f-8e2a-dcd2d58f9723"
CONTENT_GUID <- "20a79ce3-6e87-4522-9faf-be24228800a4"
USER_GUID # Valid values are "viewer" and "owner" (collaborator)
<- "viewer"
ACCESS_TYPE
<- connect()
client
# For the specified content item add the desired user
<- content_item(client, CONTENT_GUID)
content content_add_user(content, USER_GUID, role = ACCESS_TYPE)
# Confirm new permissions
get_content_permissions(content)