-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for include parameter on listing and showing roles
* GET /v3/roles?include=user & GET /v3/roles/:guid?include=user endpoints * Moved a controller function that makes the call to UAA to get usernames and origins into the user model so it could be shared by the decorators * Updated docs [#164176870] Co-authored-by: Merric de Launey <[email protected]> Co-authored-by: Mona Mohebbi <[email protected]>
- Loading branch information
1 parent
8cb7300
commit a61176a
Showing
13 changed files
with
291 additions
and
25 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
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,21 @@ | ||
# require 'models/runtime/user' | ||
|
||
module VCAP::CloudController | ||
class IncludeRoleUserDecorator | ||
class << self | ||
def match?(include_params) | ||
include_params&.include?('user') | ||
end | ||
|
||
def decorate(hash, roles) | ||
hash[:included] ||= {} | ||
user_guids = roles.map(&:user_guid).uniq | ||
users = User.where(guid: user_guids).order(:created_at) | ||
uaa_users = User.uaa_users_info(user_guids) | ||
|
||
hash[:included][:users] = users.map { |user| Presenters::V3::UserPresenter.new(user, uaa_users: uaa_users).to_hash } | ||
hash | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'messages/base_message' | ||
|
||
module VCAP::CloudController | ||
class RoleShowMessage < BaseMessage | ||
register_allowed_keys [:include] | ||
|
||
validates_with NoAdditionalParamsValidator | ||
validates_with IncludeParamValidator, valid_values: ['user'] | ||
|
||
def self.from_params(params) | ||
super(params, %w(include)) | ||
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
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
Oops, something went wrong.