connect.permissions

connect.permissions

Permission resources.

Classes

Name Description
Permission
Permissions

Permission

connect.permissions.Permission(self, ctx, /, **kwargs)

Methods

Name Description
destroy Destroy the permission.
update Update the permission.
destroy
connect.permissions.Permission.destroy()

Destroy the permission.

update
connect.permissions.Permission.update(*args, **kwargs)

Update the permission.

Permissions

connect.permissions.Permissions(self, ctx, content_guid)

Attributes

Name Description
content_guid

Methods

Name Description
count Count the number of permissions.
create Create a permission.
destroy Remove supplied content item permission.
find Find permissions.
find_one Find a permission.
get Get a permission.
count
connect.permissions.Permissions.count()

Count the number of permissions.

Returns
Name Type Description
int
create
connect.permissions.Permissions.create(principal=None, /, **kwargs)

Create a permission.

Parameters
Name Type Description Default
principal User | Group The principal user or group to add. None
role str The principal role. Currently only "viewer" and "owner" are supported. required
principal_guid str User guid or Group guid. required
principal_type str The principal type. Either "user" or "group". required
role str The principal role. Currently only "viewer" and "owner" are supported required
Returns
Name Type Description
Permission The created permission.
Examples
from posit import connect

client = connect.Client()
content_item = client.content.get(content_guid)

# New permission role
role = "viewer"  # Or "owner"

# Example groups and users
groups = client.groups.find(prefix="GROUP_NAME_PREFIX_HERE")
group = groups[0]
user = client.users.get("USER_GUID_HERE")
users_and_groups = [user, *groups]

# Add a group permission
content_item.permissions.create(group, role=role)
# Add a user permission
content_item.permissions.create(user, role=role)

# Add many group and user permissions with the same role
for principal in users_and_groups:
    content_item.permissions.create(principal, role=role)

# Add a group permission manually
content_item.permissions.create(
    principal_guid=group["guid"],
    principal_type="group",
    role=role,
)
# Add a user permission manually
content_item.permissions.create(
    principal_guid=user["guid"],
    principal_type="user",
    role=role,
)

# Confirm new permissions
content_item.permissions.find()
destroy
connect.permissions.Permissions.destroy(permission, /)

Remove supplied content item permission.

Removes provided permission from the content item’s permissions.

Parameters
Name Type Description Default
permission str | Group | User | Permission The content item permission to remove. If a str is received, it is compared against the Permissions’s principal_guid. If a Group or User is received, the associated Permission will be removed. required
Examples
from posit import connect

#### User-defined inputs ####
# 1. specify the guid for the content item
content_guid = "CONTENT_GUID_HERE"
# 2. specify either the principal_guid or group name prefix
principal_guid = "USER_OR_GROUP_GUID_HERE"
group_name_prefix = "GROUP_NAME_PREFIX_HERE"
############################

client = connect.Client()
content_item = client.content.get(content_guid)

# Remove a single permission by principal_guid
content_item.permissions.destroy(principal_guid)

# Remove by user (if principal_guid is a user)
user = client.users.get(principal_guid)
content_item.permissions.destroy(user)

# Remove by group (if principal_guid is a group)
group = client.groups.get(principal_guid)
content_item.permissions.destroy(group)

# Remove all groups with a matching prefix name
groups = client.groups.find(prefix=group_name_prefix)
for group in groups:
    content_item.permissions.destroy(group)

# Confirm new permissions
content_item.permissions.find()
find
connect.permissions.Permissions.find(**kwargs)

Find permissions.

Returns
Name Type Description
List[Permission]
find_one
connect.permissions.Permissions.find_one(**kwargs)

Find a permission.

Returns
Name Type Description
Permission | None
get
connect.permissions.Permissions.get(uid)

Get a permission.

Parameters
Name Type Description Default
uid str The permission id. required
Returns
Name Type Description
Permission