You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frompositimportconnect# 1. specify the guid for the content itemcontent_guid="CONTENT_GUID_HERE"# 2. specify either the guid or name for the group to be added (group_name will be used if group_guid is blank)group_guid=""group_name="GROUP_NAME_HERE"# 3. specify if the group should be added as a "viewer" or "owner" (collaborator)access_type="viewer"client=connect.Client()
# search by group_name to find the group_guid if blankifnotgroup_guidandgroup_name:
group_match=client.get("/v1/groups", params={"prefix": group_name}).json()
ifnotgroup_match["results"]:
raiseException("Invalid group name")
eliflen(group_match["results"]) !=1:
raiseException("More than one group name found, ensure you enter a unique name")
else:
group_guid=group_match["results"][0]["guid"]
elifnotgroup_name:
raiseException("Either group_guid or group_name must be specified")
# For the specified content item add the desired groupclient.content.get(content_guid).permissions.create(
principal_guid=group_guid,
principal_type="group",
role=access_type,
)
# Confirm new permissionsclient.content.get(content_guid).permissions.find()
Current User recipe:
frompositimportconnect# 1. specify the guid for the content itemcontent_guid="CONTENT_GUID_HERE"# 2. specify either the guid or username for the user being added (username will be used if user_guid is blank)user_guid=""username="USERNAME_HERE"# 3. specify if the user should be added as a "viewer" or "owner" (collaborator)access_type="viewer"client=connect.Client()
# search by username to find the user_guid if blankifnotuser_guidandusername:
user_match=client.users.find(prefix=username)
ifnotuser_match:
raiseException("Invalid username")
eliflen(user_match) !=1:
raiseException("More than one username found, ensure you enter a unique name")
else:
user_guid=user_match[0]["guid"]
elifnotusername:
raiseException("Either user_guid or username must be specified")
# For the specified content item add the desired userclient.content.get(content_guid).permissions.create(
principal_guid=user_guid,
principal_type="user",
role=access_type,
)
# Confirm new permissionsclient.content.get(content_guid).permissions.find()
The text was updated successfully, but these errors were encountered:
frompositimportconnect#### User-defined inputs ##### 1. specify the guid for the content itemcontent_guid="CONTENT_GUID_HERE"# 2. specify the group prefix namegroup_name_prefix="GROUP_NAME_PREFIX_HERE"# 3. specify if the group should be added as a "viewer" or "owner" (collaborator)access_type="viewer"#############################client=connect.Client()
groups=client.groups.find(prefix=group_name_prefix)
# Add many group permissions with the same roleclient.content.get(content_guid).permissions.create(*groups, role=access_type)
# Add a group permissiongroup=groups[0]
client.content.get(content_guid).permissions.create(group, role=access_type)
# Add a group permission manuallyclient.content.get(content_guid).permissions.create(
principal_guid=group["guid"],
principal_type="group",
role=access_type
)
# Confirm new permissionsclient.content.get(content_guid).permissions.find()
User
frompositimportconnect#### User-defined inputs ##### 1. specify the guid for the content itemcontent_guid="CONTENT_GUID_HERE"# 2. specify the user guiduser_guid="USER_GUID_HERE"# 3. specify if the group should be added as a "viewer" or "owner" (collaborator)access_type="viewer"#############################client=connect.Client()
user=client.users.get(user_guid)
users= [user]
# Add many user permissions with the same roleclient.content.get(content_guid).permissions.create(*users, role=access_type)
# Add a user permissionclient.content.get(content_guid).permissions.create(user, role=access_type)
# Add a group permission manuallyclient.content.get(content_guid).permissions.create(
principal_guid=user_guid,
principal_type="user",
role=access_type
)
Related: https://github.com/rstudio/connect/issues/28825 ; https://docs.posit.co/connect/cookbook/content-access-controls/granting-access-to-a-group/
Related: Granting Access to a User: https://docs.posit.co/connect/cookbook/content-access-controls/granting-access-to-a-user/
Current Group recipe:
Current User recipe:
The text was updated successfully, but these errors were encountered: