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
= connect.Client()
client = client.content.get(content_guid)
content_item
# New permission role
= "viewer" # Or "owner"
role
# Example groups and users
= client.groups.find(prefix="GROUP_NAME_PREFIX_HERE")
groups = groups[0]
group = client.users.get("USER_GUID_HERE")
user = [user, *groups]
users_and_groups
# Add a group permission
=role)
content_item.permissions.create(group, role# Add a user permission
=role)
content_item.permissions.create(user, role
# Add many group and user permissions with the same role
for principal in users_and_groups:
=role)
content_item.permissions.create(principal, role
# Add a group permission manually
content_item.permissions.create(=group["guid"],
principal_guid="group",
principal_type=role,
role
)# Add a user permission manually
content_item.permissions.create(=user["guid"],
principal_guid="user",
principal_type=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_HERE"
content_guid # 2. specify either the principal_guid or group name prefix
= "USER_OR_GROUP_GUID_HERE"
principal_guid = "GROUP_NAME_PREFIX_HERE"
group_name_prefix ############################
= connect.Client()
client = client.content.get(content_guid)
content_item
# Remove a single permission by principal_guid
content_item.permissions.destroy(principal_guid)
# Remove by user (if principal_guid is a user)
= client.users.get(principal_guid)
user
content_item.permissions.destroy(user)
# Remove by group (if principal_guid is a group)
= client.groups.get(principal_guid)
group
content_item.permissions.destroy(group)
# Remove all groups with a matching prefix name
= client.groups.find(prefix=group_name_prefix)
groups 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 |