Skip to content

Commit fa1ce82

Browse files
authored
Add organization membership deactivate and reactivate API methods (#295)
* Add organization membership deactivate and reactivate API methods.
1 parent cdf473b commit fa1ce82

File tree

5 files changed

+303
-1
lines changed

5 files changed

+303
-1
lines changed

lib/workos/user_management.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,8 @@ def get_organization_membership(id:)
748748
#
749749
# @param [Hash] options
750750
# @option options [String] user_id The ID of the User.
751-
# @option options [String] organization_id Filter Users by the organization they are members of.
751+
# @option options [String] organization_id Filter memberships by the organization they are members of.
752+
# @option options [Array<String>] statuses Filter memberships by status.
752753
# @option options [String] limit Maximum number of records to return.
753754
# @option options [String] order The order in which to paginate records
754755
# @option options [String] before Pagination cursor to receive records
@@ -816,6 +817,38 @@ def delete_organization_membership(id:)
816817
response.is_a? Net::HTTPSuccess
817818
end
818819

820+
# Deactivate an Organization Membership
821+
#
822+
# @param [String] id The unique ID of the Organization Membership.
823+
#
824+
# @return WorkOS::OrganizationMembership
825+
def deactivate_organization_membership(id:)
826+
response = execute_request(
827+
request: put_request(
828+
path: "/user_management/organization_memberships/#{id}/deactivate",
829+
auth: true,
830+
),
831+
)
832+
833+
WorkOS::OrganizationMembership.new(response.body)
834+
end
835+
836+
# Reactivate an Organization Membership
837+
#
838+
# @param [String] id The unique ID of the Organization Membership.
839+
#
840+
# @return WorkOS::OrganizationMembership
841+
def reactivate_organization_membership(id:)
842+
response = execute_request(
843+
request: put_request(
844+
path: "/user_management/organization_memberships/#{id}/reactivate",
845+
auth: true,
846+
),
847+
)
848+
849+
WorkOS::OrganizationMembership.new(response.body)
850+
end
851+
819852
# Gets an Invitation
820853
#
821854
# @param [String] id The unique ID of the Invitation.

spec/lib/workos/user_management_spec.rb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,33 @@
933933
end
934934
end
935935
end
936+
937+
context 'with statuses option' do
938+
it 'returns a list of matching users' do
939+
request_args = [
940+
'/user_management/organization_memberships?user_id=user_01HXYSZBKQE2N3NHBKZHDP1X5X&'\
941+
'statuses=active&statuses=inactive&order=desc&limit=5',
942+
'Content-Type' => 'application/json'
943+
]
944+
945+
expected_request = Net::HTTP::Get.new(*request_args)
946+
947+
expect(Net::HTTP::Get).to receive(:new).with(*request_args).
948+
and_return(expected_request)
949+
950+
VCR.use_cassette 'user_management/list_organization_memberships/with_statuses_option' do
951+
organization_memberships = described_class.list_organization_memberships(
952+
user_id: 'user_01HXYSZBKQE2N3NHBKZHDP1X5X',
953+
statuses: %w[active inactive],
954+
order: 'desc',
955+
limit: '5',
956+
)
957+
958+
expect(organization_memberships.data.size).to eq(1)
959+
expect(organization_memberships.data[0].user_id).to eq('user_01HXYSZBKQE2N3NHBKZHDP1X5X')
960+
end
961+
end
962+
end
936963
end
937964

938965
describe '.create_organization_membership' do
@@ -988,6 +1015,56 @@
9881015
end
9891016
end
9901017

1018+
describe '.deactivate_organization_membership' do
1019+
context 'with a valid id' do
1020+
it 'returns a organization membership' do
1021+
VCR.use_cassette 'user_management/deactivate_organization_membership' do
1022+
organization_membership = described_class.deactivate_organization_membership(
1023+
id: 'om_01HXYT0G3H5QG9YTSHSHFZQE6D',
1024+
)
1025+
1026+
expect(organization_membership.id.instance_of?(String))
1027+
expect(organization_membership.instance_of?(WorkOS::OrganizationMembership))
1028+
end
1029+
end
1030+
end
1031+
1032+
context 'with an invalid id' do
1033+
it 'returns an error' do
1034+
expect do
1035+
described_class.deactivate_organization_membership(
1036+
id: 'invalid_organization_membership_id',
1037+
).to raise_error(WorkOS::APIError)
1038+
end
1039+
end
1040+
end
1041+
end
1042+
1043+
describe '.reactivate_organization_membership' do
1044+
context 'with a valid id' do
1045+
it 'returns a organization membership' do
1046+
VCR.use_cassette 'user_management/reactivate_organization_membership' do
1047+
organization_membership = described_class.reactivate_organization_membership(
1048+
id: 'om_01HXYT0G3H5QG9YTSHSHFZQE6D',
1049+
)
1050+
1051+
expect(organization_membership.id.instance_of?(String))
1052+
expect(organization_membership.instance_of?(WorkOS::OrganizationMembership))
1053+
end
1054+
end
1055+
end
1056+
1057+
context 'with an invalid id' do
1058+
it 'returns an error' do
1059+
expect do
1060+
described_class.reactivate_organization_membership(
1061+
id: 'invalid_organization_membership_id',
1062+
).to raise_error(WorkOS::APIError)
1063+
end
1064+
end
1065+
end
1066+
end
1067+
9911068
describe '.get_invitation' do
9921069
context 'with a valid id' do
9931070
it 'returns an invitation' do

spec/support/fixtures/vcr_cassettes/user_management/deactivate_organization_membership.yml

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/support/fixtures/vcr_cassettes/user_management/list_organization_memberships/with_statuses_option.yml

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/support/fixtures/vcr_cassettes/user_management/reactivate_organization_membership.yml

Lines changed: 64 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)