Revoking Access from a Group
Problem
You need to revoke a group’s access to a content item.
Solution
Use the Python or R SDKs to revoke access. You need to specify the following information:
- The
content_guid
for the content item from which you want to remove permissions. - Either the
group_guid
orgroup_name
for the group whose access is being revoked. Thegroup_name
is used ifgroup_guid
is blank.
from posit import connect
#### User-defined inputs ####
# 1. specify the guid for the content item
= "CONTENT_GUID_HERE"
content_guid # 2. specify either the guid or name for the group to be removed (group_name will be used if group_guid is blank)
= ""
group_guid = "GROUP_NAME_HERE"
group_name ############################
= connect.Client()
client
# search by group_name to find the group_guid if blank
if not group_guid and group_name:
= client.get("/v1/groups", params={"prefix": group_name}).json()
group_match if not group_match["results"]:
raise Exception("Invalid group name")
elif len(group_match["results"]) != 1:
raise Exception("More than one group name found, ensure you enter a unique name")
else:
= group_match["results"][0]["guid"]
group_guid elif not group_name:
raise Exception("Either group_guid or group_name must be specified")
# For the specified content item remove the desired user
for perm in client.content.get(content_guid).permissions.find():
if perm.principal_guid == group_guid:
perm.delete()
# Confirm new permissions
client.content.get(content_guid).permissions.find()
library(connectapi)
# 1. specify the guid for the content item
= "CONTENT_GUID_HERE"
content_guid # 2. specify either the guid or name for the group to be removed (group_name will be used if group_guid is blank)
= ""
group_guid = "GROUP_NAME_HERE"
group_name
<- connect()
client
# search by group_name to find the group_guid if blank
if (group_guid == "" && group_name != "") {
<- get_groups(client, prefix = group_name)
group_match if (nrow(group_match) == 0) {
stop("Invalid group name")
else if (length(unique(group_match$name)) != 1) {
} stop("More than one group name found, ensure you enter a unique name")
else {
} <- unique(group_match$guid)
group_guid
}else if (group_name == "") {
} stop("Either group_guid or group_name must be specified")
}
# For the specified content item remove the desired group
<- content_item(client, content_guid)
content content_delete_group(content, group_guid)
# Confirm new permissions
get_content_permissions(content)