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

return group members #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 25 additions & 10 deletions app/controllers/concerns/scimaenaga/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,31 @@ def list_objects(objects)
end

def object_response(object)
schema = case object
when Scimaenaga.config.scim_users_model
Scimaenaga.config.user_schema
when Scimaenaga.config.scim_groups_model
Scimaenaga.config.group_schema
else
raise Scimaenaga::ExceptionHandler::InvalidQuery,
"Unknown model: #{object}"
end
find_value(object, schema)
case object
when Scimaenaga.config.scim_users_model
user_object_response(object)
when Scimaenaga.config.scim_groups_model
group_object_response(object)
else
raise Scimaenaga::ExceptionHandler::InvalidQuery,
"Unknown model: #{object}"
end
end

def user_object_response(object)
find_value(object, Scimaenaga.config.user_schema)
end

def group_object_response(object)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なんでこういう実装になってるのか(なんでuserみたいにfind_valueだけじゃなくmembersを手動で作ってるのか)コメント書いた方がいいと思う

response = find_value(object, Scimaenaga.config.group_schema.except(:members))
members_attribute = Scimaenaga.config.group_schema[:members]
return response if members_attribute.nil?

members_raw = find_value(object, members_attribute)
response[:members] = members_raw.map do |member|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objectはnilありえる?

ありえるならここヌルポになる

find_value(member, Scimaenaga.config.user_abbreviated_schema)
end
response
end

# `find_value` is a recursive method that takes a "user" and a
Expand Down