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 organization membership deactivate and reactivate API methods #226

Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/main/kotlin/com/workos/usermanagement/UserManagementApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,20 @@ class UserManagementApi(private val workos: WorkOS) {
workos.delete("/user_management/organization_memberships/$id")
}

/**
* Deactivate an organization membership.
*/
fun deactivateOrganizationMembership(id: String): OrganizationMembership {
return workos.put("/user_management/organization_memberships/$id/deactivate", OrganizationMembership::class.java)
}

/**
* Reactivate an organization membership.
*/
fun reactivateOrganizationMembership(id: String): OrganizationMembership {
return workos.put("/user_management/organization_memberships/$id/reactivate", OrganizationMembership::class.java)
}

/**
* Get the details of an existing invitation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.workos.usermanagement.builders

import com.workos.common.models.Order
import com.workos.usermanagement.types.ListOrganizationMembershipsOptions
import com.workos.usermanagement.types.OrganizationMembershipStatusEnumType

/**
* Builder for options when listing organization memberships.
*
* @param userId Filter organization memberships by their id.
* @param organizationId Filter organization memberships by the organization they are members of.
* @param statuses Filter organization memberships by the membership status.
* @param limit Maximum number of records to return.
* @param before Pagination cursor to receive records before a provided organization membership ID.
* @param after Pagination cursor to receive records after a provided organization membership ID.
Expand All @@ -16,6 +18,7 @@ import com.workos.usermanagement.types.ListOrganizationMembershipsOptions
class ListOrganizationMembershipsOptionsBuilder @JvmOverloads constructor(
private var userId: String? = null,
private var organizationId: String? = null,
private var statuses: List<OrganizationMembershipStatusEnumType>? = null,
private var limit: Int? = null,
private var before: String? = null,
private var after: String? = null,
Expand All @@ -31,6 +34,11 @@ class ListOrganizationMembershipsOptionsBuilder @JvmOverloads constructor(
*/
fun organizationId(value: String) = apply { organizationId = value }

/**
* Statuses
*/
fun statuses(value: List<OrganizationMembershipStatusEnumType>) = apply { statuses = value }

/**
* Limit
*/
Expand Down Expand Up @@ -58,6 +66,7 @@ class ListOrganizationMembershipsOptionsBuilder @JvmOverloads constructor(
return ListOrganizationMembershipsOptions(
userId = this.userId,
organizationId = this.organizationId,
statuses = this.statuses,
limit = this.limit,
before = this.before,
after = this.after,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class ListOrganizationMembershipsOptions @JvmOverloads constructor(
@JsonProperty("organization_id")
val organizationId: String? = null,

@JsonProperty("statuses")
val statuses: List<OrganizationMembershipStatusEnumType>? = null,

@JsonProperty("limit")
val limit: Int? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ enum class OrganizationMembershipStatusEnumType(val type: String) {
@JsonProperty("active")
Active("active"),

/**
* Inactive
*/
@JsonProperty("inactive")
Inactive("inactive"),

/**
* Pending
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,12 @@ class UserManagementApiTest : TestBase() {
val options = ListOrganizationMembershipsOptionsBuilder()
.userId("id_456")
.organizationId("org_789")
.statuses(
listOf<OrganizationMembershipStatusEnumType>(
OrganizationMembershipStatusEnumType.Active,
OrganizationMembershipStatusEnumType.Inactive
)
)
.order(Order.Desc)
.limit(10)
.after("someAfterId")
Expand Down Expand Up @@ -1137,6 +1143,74 @@ class UserManagementApiTest : TestBase() {
}
}

@Test
fun deactivateOrganizationMembershipShouldReturnValidOrganizationMembershipObject() {
stubResponse(
"/user_management/organization_memberships/om_123/deactivate",
"""{
"object": "organization_membership",
"id": "om_123",
"user_id": "user_456",
"organization_id": "org_789",
"role": {
"slug": "admin"
},
"status": "inactive",
"created_at": "2021-06-25T19:07:33.155Z",
"updated_at": "2021-06-25T19:07:33.155Z"
}"""
)

val organizationMembership = workos.userManagement.deactivateOrganizationMembership("om_123")

assertEquals(
OrganizationMembership(
"om_123",
"user_456",
"org_789",
OrganizationMembershipRole("admin"),
OrganizationMembershipStatusEnumType.Inactive,
"2021-06-25T19:07:33.155Z",
"2021-06-25T19:07:33.155Z",
),
organizationMembership
)
}

@Test
fun reactivateOrganizationMembershipShouldReturnValidOrganizationMembershipObject() {
stubResponse(
"/user_management/organization_memberships/om_123/reactivate",
"""{
"object": "organization_membership",
"id": "om_123",
"user_id": "user_456",
"organization_id": "org_789",
"role": {
"slug": "admin"
},
"status": "active",
"created_at": "2021-06-25T19:07:33.155Z",
"updated_at": "2021-06-25T19:07:33.155Z"
}"""
)

val organizationMembership = workos.userManagement.reactivateOrganizationMembership("om_123")

assertEquals(
OrganizationMembership(
"om_123",
"user_456",
"org_789",
OrganizationMembershipRole("admin"),
OrganizationMembershipStatusEnumType.Active,
"2021-06-25T19:07:33.155Z",
"2021-06-25T19:07:33.155Z",
),
organizationMembership
)
}

@Test
fun getInvitationShouldReturnValidUserObject() {
stubResponse(
Expand Down