1.4. Teams

Teams were introduced to simplify securely sharing your assets across projects. All assets are owned by teams, including projects.

1.4.1. Basic Team Use

In the following examples, citrine is the name of your Citrine client object.

After connecting to the Citrine Platform, you’ll most likely want to find a specific team. To list all teams of which you are a member, use the list method.

citrine.teams.list()

There are a few ways to find a specific team in this list.

# 1. Use a helper method from citrine.seeding.find_or_create, such as find_or_create_team.
from citrine.seeding.find_or_create import find_or_create_team
team_name = "Team A"
team_a = find_or_create_team(team_collection=citrine.teams, team_name=team_name)

# 2. If you have its unique ID, retrieve it directly.
team_a = citrine.teams.get("baaa467e-1758-43a8-97c7-76e569d0dcab")

Note that you can only retrieve a Team of which you are a member.

1.4.2. Managing Users

Admins can manage user permissions in teams. Permissions replace the previous concept of roles.

There are three types of access permissions a user can have on a team: READ, SHARE, and WRITE.

  • READ allows a user to view resources in a team.

  • WRITE allows them to modify those resources.

  • SHARE allows them to publish those resources to other teams.

There are several methods for managing teams, users, and user membership in teams.

1.4.2.1. Listing Users in a Team

Users in a team can be listed using the list_members() method, which returns a TeamMember array. Each TeamMember contains the user’s access permissions, a copy of the User object, and a copy of the Team object.

team = citrine.teams.register(name="Your Team")

# List Members of a team
team_members = team.list_members()

# See their actions
[(m.user.screen_name, m.actions) for m in team_members]
# or
[str(m) for m in team_members]

1.4.2.2. Add User to a Team

Users can be added to a team. They will be granted READ access to resources in the team. This is accomplished with the add_user() method.

# Get the UUID of the user you'd like to add
user_id = "bed6f207-f15e-4aef-932d-87d99b2d6203"
team = citrine.teams.get("baaa467e-1758-43a8-97c7-76e569d0dcab")

# Add them to your team
team.add_user(user_id)

When adding a user to a team, you can specify the actions that user should have:

from citrine.resources.team import READ, WRITE, SHARE
# Add user to your team and give them read, write, and share permissions
team.add_user(user_id, actions=[READ, WRITE, SHARE])

1.4.2.3. Remove User from a Team

Users can also be removed from a team. This is achieved with the remove_user() method.

# Get the UUID of the user you'd like to delete
user_id = "bed6f207-f15e-4aef-932d-87d99b2d6203"
team = citrine.teams.get("baaa467e-1758-43a8-97c7-76e569d0dcab")

# Remove them from the team
team.remove_user(user_id)

1.4.2.4. Update User’s Actions in a Team

A user’s actions in a team can be updated. The method update_user_actions() facilitates changing a user’s actions.

from citrine.resources.team import READ, WRITE
user_id = "bed6f207-f15e-4aef-932d-87d99b2d6203"
team = citrine.teams.get("baaa467e-1758-43a8-97c7-76e569d0dcab")

# Make the user a member with read and write access
team.update_user_actions(user_uid=user_id, actions=[READ, WRITE])

1.4.2.5. Listing Publish Resources in a Team

Teams can list the published IDs for datasets, modules, tables and table definitions available in a team. Using the list_readable, list_writeable, or list_shareable methods to list IDs with these permissions. Note: these calls return a list of string uids, not the complete resource objects.

dataset_ids(), module_ids(), table_ids(), table_definition_ids().

team = citrine.teams.get("baaa467e-1758-43a8-97c7-76e569d0dcab")
project1 = team.projects.get("8ad2f784-5c49-45ad-b525-6af859651acf")

dataset_ids = team.dataset_ids.list_readable()

# Use one of the IDs to get a handle to the resource from it's origin project:
dataset = project1.datasets.get(dataset_ids[0])

# Pull this published resource into another project:
project2 = team.projects.get("9ecb5610-6f69-4175-a1f8-bbfd7d711826")
project2.pull_in_resource(resource=dataset)