forked from lessonly/scim_rails
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from valerauko/groups
Why? Support for SCIM user Groups is currently missing lessonly#46 What? add options to configure how to handle Groups add API endpoints to deal with Groups
- Loading branch information
Showing
23 changed files
with
1,021 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# frozen_string_literal: true | ||
|
||
module ScimRails | ||
class ScimGroupsController < ScimRails::ApplicationController | ||
def index | ||
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} ?", | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.