-
Notifications
You must be signed in to change notification settings - Fork 76
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
Basic Groups support #48
Changes from 12 commits
50a4c5b
6c49351
dc237ed
8b56c30
96a7e44
0a9ad75
47cce8f
6496503
fa1578e
dabd49c
a42c69d
e0f1fa6
8d65ade
f3425e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
inherit_from: | ||
- https://raw.githubusercontent.com/lessonly/rubocop-default-configuration/master/.rubocop.yml | ||
|
||
Metrics/BlockLength: | ||
# don't warn about block length in block-centered DSLs | ||
Exclude: | ||
- 'config/routes.rb' | ||
- 'spec/**/*.rb' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,37 @@ def authenticate_with_oauth_bearer | |
|
||
yield searchable_attribute, authentication_attribute | ||
end | ||
|
||
def find_value_for(attribute) | ||
params.dig(*path_for(attribute)) | ||
end | ||
|
||
# `path_for` is a recursive method used to find the "path" for | ||
# `.dig` to take when looking for a given attribute in the | ||
# params. | ||
# | ||
# Example: `path_for(:name)` should return an array that looks | ||
# like [:names, 0, :givenName]. `.dig` can then use that path | ||
# against the params to translate the :name attribute to "John". | ||
|
||
def path_for(attribute, object = controller_schema, path = []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/CyclomaticComplexity: Cyclomatic complexity for path_for is too high. [7/6] |
||
at_path = path.empty? ? object : object.dig(*path) | ||
return path if at_path == attribute | ||
|
||
case at_path | ||
when Hash | ||
at_path.each do |key, _value| | ||
found_path = path_for(attribute, object, [*path, key]) | ||
return found_path if found_path | ||
end | ||
nil | ||
when Array | ||
at_path.each_with_index do |_value, index| | ||
found_path = path_for(attribute, object, [*path, index]) | ||
return found_path if found_path | ||
end | ||
nil | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
module ScimRails | ||
class ScimGroupsController < ScimRails::ApplicationController | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Style/Documentation: Missing top-level class documentation comment. |
||
def index | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/AbcSize: Assignment Branch Condition size for index is too high. [36.24/15] |
||
if params[:filter].present? | ||
query = ScimRails::ScimQueryParser.new( | ||
params[:filter], ScimRails.config.queryable_group_attributes | ||
) | ||
|
||
groups = @company | ||
.public_send(ScimRails.config.scim_groups_scope) | ||
.where( | ||
"#{ScimRails.config.scim_groups_model.connection.quote_column_name(query.attribute)} #{query.operator} ?", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [118/80] |
||
query.parameter | ||
) | ||
.order(ScimRails.config.scim_groups_list_order) | ||
else | ||
groups = @company | ||
.public_send(ScimRails.config.scim_groups_scope) | ||
.preload(:users) | ||
.order(ScimRails.config.scim_groups_list_order) | ||
end | ||
|
||
counts = ScimCount.new( | ||
start_index: params[:startIndex], | ||
limit: params[:count], | ||
total: groups.count | ||
) | ||
|
||
json_scim_response(object: groups, counts: counts) | ||
end | ||
|
||
def show | ||
group = @company | ||
.public_send(ScimRails.config.scim_groups_scope) | ||
.find(params[:id]) | ||
json_scim_response(object: group) | ||
end | ||
|
||
def create | ||
group = @company | ||
.public_send(ScimRails.config.scim_groups_scope) | ||
.create!(permitted_group_params) | ||
|
||
json_scim_response(object: group, status: :created) | ||
end | ||
|
||
def put_update | ||
group = @company | ||
.public_send(ScimRails.config.scim_groups_scope) | ||
.find(params[:id]) | ||
group.update!(permitted_group_params) | ||
json_scim_response(object: group) | ||
end | ||
|
||
def destroy | ||
unless ScimRails.config.group_destroy_method | ||
raise ScimRails::ExceptionHandler::UnsupportedDeleteRequest | ||
end | ||
group = @company | ||
.public_send(ScimRails.config.scim_groups_scope) | ||
.find(params[:id]) | ||
group.public_send(ScimRails.config.group_destroy_method) | ||
head :no_content | ||
end | ||
|
||
private | ||
|
||
def permitted_group_params | ||
converted = mutable_attributes.each.with_object({}) do |attribute, hash| | ||
hash[attribute] = find_value_for(attribute) | ||
end | ||
return converted unless params[:members] | ||
converted.merge(member_params) | ||
end | ||
|
||
def member_params | ||
{ | ||
ScimRails.config.group_member_relation_attribute => | ||
params[:members].map do |member| | ||
member[ScimRails.config.group_member_relation_schema.keys.first] | ||
end | ||
} | ||
end | ||
|
||
def mutable_attributes | ||
ScimRails.config.mutable_group_attributes | ||
end | ||
|
||
def controller_schema | ||
ScimRails.config.mutable_group_attributes_schema | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/AbcSize: Assignment Branch Condition size for find_value is too high. [17.75/15]
Metrics/MethodLength: Method has too many lines. [18/10]