Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role to OrganizationMembership class #236

Merged
merged 9 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/utils/fixtures/mock_organization_membership.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def __init__(self, id):
self.user_id = "user_12345"
self.organization_id = "org_67890"
self.status = "active"
self.role = {"slug": "member"}
self.created_at = datetime.datetime.now()
self.updated_at = datetime.datetime.now()

Expand All @@ -16,6 +17,7 @@ def __init__(self, id):
"user_id",
"organization_id",
"status",
"role",
"created_at",
"updated_at",
]
1 change: 1 addition & 0 deletions workos/resources/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class WorkOSOrganizationMembership(WorkOSBaseResource):
"status",
"created_at",
"updated_at",
"role",
]


Expand Down
10 changes: 8 additions & 2 deletions workos/user_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,25 @@ def delete_user(self, user_id):
token=workos.api_key,
)

def create_organization_membership(self, user_id, organization_id):
def create_organization_membership(self, user_id, organization_id, role_slug=None):
"""Create a new OrganizationMembership for the given Organization and User.

Args:
user_id: The Unique ID of the User.
organization_id: The Unique ID of the Organization to which the user belongs to.
role_slug: The Unique Slug of the Role to which to grant to this membership.
If no slug is passed in, the default role will be granted.(Optional)

Returns:
dict: Created OrganizationMembership response from WorkOS.
"""
headers = {}

params = {"user_id": user_id, "organization_id": organization_id}
params = {
"user_id": user_id,
"organization_id": organization_id,
"role_slug": role_slug,
}

response = self.request_helper.request(
ORGANIZATION_MEMBERSHIP_PATH,
Expand Down
Loading