Skip to content

Commit

Permalink
Add organization_id to Directory User and Directory Group (#165)
Browse files Browse the repository at this point in the history
* Additionally add directory_id to Directory User
  • Loading branch information
willmanduffy authored Jul 14, 2022
1 parent 8976ac0 commit 9d14cb3
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 46 deletions.
6 changes: 5 additions & 1 deletion lib/workos/directory_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DirectoryGroup < DeprecatedHashWrapper
include HashProvider
extend T::Sig

attr_accessor :id, :directory_id, :idp_id, :name, :created_at, :updated_at, :raw_attributes
attr_accessor :id, :directory_id, :idp_id, :name, :created_at, :updated_at,
:raw_attributes, :organization_id

# rubocop:disable Metrics/AbcSize
sig { params(json: String).void }
Expand All @@ -18,6 +19,7 @@ def initialize(json)

@id = T.let(raw.id, String)
@directory_id = T.let(raw.directory_id, String)
@organization_id = raw.organization_id
@idp_id = T.let(raw.idp_id, String)
@name = T.let(raw.name, String)
@created_at = T.let(raw.created_at, String)
Expand All @@ -32,6 +34,7 @@ def to_json(*)
{
id: id,
directory_id: directory_id,
organization_id: organization_id,
idp_id: idp_id,
name: name,
created_at: created_at,
Expand All @@ -53,6 +56,7 @@ def parse_json(json_string)
WorkOS::Types::DirectoryGroupStruct.new(
id: hash[:id],
directory_id: hash[:directory_id],
organization_id: hash[:organization_id],
idp_id: hash[:idp_id],
name: hash[:name],
created_at: hash[:created_at],
Expand Down
8 changes: 7 additions & 1 deletion lib/workos/directory_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ class DirectoryUser < DeprecatedHashWrapper
extend T::Sig

attr_accessor :id, :idp_id, :emails, :first_name, :last_name, :username, :state,
:groups, :custom_attributes, :raw_attributes
:groups, :custom_attributes, :raw_attributes, :directory_id, :organization_id

# rubocop:disable Metrics/AbcSize
sig { params(json: String).void }
def initialize(json)
raw = parse_json(json)

@id = T.let(raw.id, String)
@directory_id = T.let(raw.directory_id, String)
@organization_id = raw.organization_id
@idp_id = T.let(raw.idp_id, String)
@emails = T.let(raw.emails, Array)
@first_name = raw.first_name
Expand All @@ -35,6 +37,8 @@ def initialize(json)
def to_json(*)
{
id: id,
directory_id: directory_id,
organization_id: organization_id,
idp_id: idp_id,
emails: emails,
first_name: first_name,
Expand Down Expand Up @@ -64,6 +68,8 @@ def parse_json(json_string)

WorkOS::Types::DirectoryUserStruct.new(
id: hash[:id],
directory_id: hash[:directory_id],
organization_id: hash[:organization_id],
idp_id: hash[:idp_id],
emails: hash[:emails],
first_name: hash[:first_name],
Expand Down
1 change: 1 addition & 0 deletions lib/workos/types/directory_group_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Types
class DirectoryGroupStruct < T::Struct
const :id, String
const :directory_id, String
const :organization_id, T.nilable(String)
const :idp_id, String
const :name, String
const :created_at, String
Expand Down
2 changes: 2 additions & 0 deletions lib/workos/types/directory_user_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Types
# for the DirectoryUser class
class DirectoryUserStruct < T::Struct
const :id, String
const :directory_id, String
const :organization_id, T.nilable(String)
const :idp_id, String
const :emails, T::Array[T.untyped]
const :first_name, T.nilable(String)
Expand Down
5 changes: 4 additions & 1 deletion spec/lib/workos/directory_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,12 @@
)

expect(group['directory_id']).to eq('directory_01G2Z8ADK5NPMVTWF48MVVE4HT')
expect(group['organization_id']).to eq('org_01EGS4P7QR31EZ4YWD1Z1XA176')
expect(group['idp_id']).to eq('01jlao4614two3d')
expect(group['name']).to eq('Sales')
expect(group.name).to eq('Sales')
expect(group['created_at']).to eq('2022-05-13T17:45:31.732Z')
expect(group['updated_at']).to eq('2022-06-07T17:45:35.739Z')
expect(group['updated_at']).to eq('2022-07-13T17:45:42.618Z')
end
end
end
Expand All @@ -471,6 +472,8 @@
)

expect(user['first_name']).to eq('Logan')
expect(user.directory_id).to eq('directory_01FAZYMST676QMTFN1DDJZZX87')
expect(user.organization_id).to eq('org_01FAZWCWR03DVWA83NCJYKKD54')
expect(user.first_name).to eq('Logan')
end
end
Expand Down
22 changes: 10 additions & 12 deletions spec/support/fixtures/vcr_cassettes/directory_sync/get_group.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 28 additions & 31 deletions spec/support/fixtures/vcr_cassettes/directory_sync/get_user.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d14cb3

Please sign in to comment.