Access Control#

In UI, you can manage access control to a project under the Manage -> Access Control tab. The SDK provides functionality to interact with the access control API.

This includes operations such as:
  • Listing project collaborators

  • Adding project collaborators

  • Updating project collaborators’ roles

  • Removing project collaborators

Listing Collaborators#

In the UI, you can see the list of project collaborators under the Manage -> Access Control tab.

Screenshot of access control window in a project

In the SDK, project collaborators can be retrieved using the Project.collaborators property. This property returns a ProjectCollaborators object.

>>> project.collaborators
[...ProjectCollaborator(...)...]

>>> project.collaborators.get_all()
[...ProjectCollaborator(...)...]

>>> collaborator = project.collaborators[0]
>>> collaborator
ProjectCollaborator(...)

You can also retrieve a specific project collaborator by using the ProjectCollaborators.get() method and passing in a user_name.

>>> project.collaborators.get(user_name='myuser@ibm.com')
ProjectCollaborator(user_name='myuser@ibm.com', ...)

Adding Collaborators#

In the UI, to add a collaborator you can press the Add collaborators button, where it will prompt you on which type of collaborator you would like to add.

Add collaborator 1
There are four types of collaborators you can add to a project:

Once you select the type of collaborator you would like to add, you can search for the appropriate collaborators to add.

Add collaborator 2

In the SDK, you can add collaborator(s) using either the Project.add_collaborator() Project.add_collaborators() depending on how many collaborators you would like to add. These functions accept a variety of collaborator types as well the parameter role which specifies their privileges.

You can add the following type of collaborator types:
>>> user
UserProfile(...)

>>> project.add_collaborator(user, role=CollaboratorRole.ADMIN)
ProjectCollaborator(user_name='myuser@ibm.com', role='admin', ...)

>>> access_group
AccessGroup(access_group_id='access_group_id', ...)

>>> service_id
AccessGroup(service_id='service_id', ...)

>>> project.add_collaborators([access_group, service_id], role=CollaboratorRole.EDITOR)
[ProjectCollaborator(user_name='access_group_id', role='editor', ...), ProjectCollaborator(user_name='service_id', role='editor', ...)]

Updating Project Collaborators’ Roles#

In the UI, you can edit a collaborator’s role by clicking on the edit icon next to their current role. From here, a modal will appear which will allow you to set the new role for the collaborator.

Screenshot of updating a collaborator's role

In the SDK, you can edit collaborator(s) roles by using the ProjectCollaborator.role property and then either using the Project.update_collaborator() Project.update_collaborators() method depending on how many collaborators you would like to update.

>>> collaborator
ProjectCollaborator(...)

>>> collaborator.role = ProjectRole.EDITOR
>>> project.update_collaborator(collaborator)
ProjectCollaborator(user_name='myuser@ibm.com', role='editor', ...)

>>> collaborator1
ProjectCollaborator(user_name='myuser1@ibm.com', role='editor', ...)

>>> collaborator2
ProjectCollaborator(user_name='myuser2@ibm.com', role='editor', ...)

>>> collaborator1.role = ProjectRole.VIEWER
>>> collaborator2.role = ProjectRole.VIEWER
>>> project.update_collaborators([collaborator1, collaborator2])
[ProjectCollaborator(user_name='myuser1@ibm.com', role='viewer', ...), ProjectCollaborator(user_name='myuser2@ibm.com', role='viewer', ...)]

Removing Project Collaborators#

In the UI, you can remove a collaborator by pressing the remove icon to the right of their entry in the collaborator table.

Screenshot of removing a collaborator

In the SDK, you can remove collaborator(s) using either the Project.remove_collaborator() Project.remove_collaborators() depending on how many collaborators you would like to remove.

>>> project.remove_collaborator(collaborator)
<Response [204]>

>>> project.remove_collaborators([collaborator1, collaborator2])
<Response [204]>