Skip to content

Commit

Permalink
feat(users): include account enabled field
Browse files Browse the repository at this point in the history
and mail nickname
  • Loading branch information
stakach committed May 27, 2024
1 parent 119f8d0 commit 40cf22b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: office365
version: 1.24.0
version: 1.25.0

crystal: ">= 0.36.1"

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module SpecHelper
end

def mock_list_users
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users?$filter=accountEnabled eq true")
WebMock.stub(:get, "https://graph.microsoft.com/v1.0/users?$select=id,userPrincipalName,surname,preferredLanguage,officeLocation,mobilePhone,mail,jobTitle,givenName,displayName,businessPhones,accountEnabled,mailNickname&$filter=accountEnabled eq true")
.to_return(mock_user_query.to_json)
end

Expand Down
3 changes: 3 additions & 0 deletions src/models/user.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module Office365
@[JSON::Field(key: "userPrincipalName")]
property user_principal_name : String

@[JSON::Field(key: "accountEnabled")]
property account_enabled : Bool?

# Additional Properties (get through $select query parameter)
property contacts : Array(Contact)?

Expand Down
10 changes: 9 additions & 1 deletion src/users.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ module Office365::Users
get_user response
end

def list_users_request(q : String? = nil, limit : Int32? = nil, filter : String? = nil)
SELECT_FIELDS = %w(id userPrincipalName surname preferredLanguage officeLocation mobilePhone mail jobTitle givenName displayName businessPhones accountEnabled mailNickname)

def list_users_request(q : String? = nil, limit : Int32? = nil, filter : String? = nil, additional_fields : Array(String)? = nil)
if q
queries = q.split(" ")
filter_params = [] of String
Expand All @@ -61,7 +63,13 @@ module Office365::Users

limit = limit.to_s if limit

fields = SELECT_FIELDS
if additional_fields
fields += additional_fields
end

query_params = URI::Params.new({
"$select" => fields.join(","),
"$filter" => filter_param,
"$top" => limit,
}.compact.transform_values { |val| [val] })
Expand Down

0 comments on commit 40cf22b

Please sign in to comment.