support ?user_id in list admins endpoint
fixes CAT-225 test plan: * GET /api/v1/accounts/:account_id/admins?user_id[]=123 * hit the above endpoint for an account with admins. change the 123 user_id to the id of a user with admin rights. * verify that the result is just the admin user for that user * hit the same endpoint with some nonadmin user * verify that the result is [] * verify that if you send in multiple user_ids, you receive admins for all those user_ids example: GET /api/v1/accounts/:account_id/admins?user_id[]=1&user_id[]=2 should return admins for that account_id with user_id's 1 or 2 Change-Id: I533135d80dfbe359d96f750e71a59fe714a67e98 Reviewed-on: https://gerrit.instructure.com/35888 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Dave Donahue <ddonahue@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com>
This commit is contained in:
parent
dfba8c41fd
commit
81963deff9
|
@ -54,7 +54,7 @@ class AdminsController < ApplicationController
|
|||
#
|
||||
# Flag an existing user as an admin within the account.
|
||||
#
|
||||
# @argument user_id [String]
|
||||
# @argument user_id [Integer]
|
||||
# The id of the user to promote.
|
||||
#
|
||||
# @argument role [Optional, String]
|
||||
|
@ -92,15 +92,19 @@ class AdminsController < ApplicationController
|
|||
render :json => admin_json(admin, @current_user, session)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# @API List account admins
|
||||
#
|
||||
# List the admins in the account
|
||||
#
|
||||
#
|
||||
# @argument user_id[] [Optional, [Integer]]
|
||||
# Scope the results to those with user IDs equal to any of the IDs specified here.
|
||||
#
|
||||
# @returns [Admin]
|
||||
def index
|
||||
if authorized_action(@context, @current_user, :manage_account_memberships)
|
||||
scope = @context.account_users
|
||||
scope = scope.where(user_id: params[:user_id]) if params[:user_id]
|
||||
route = polymorphic_url([:api_v1, @context, :admins])
|
||||
admins = Api.paginate(scope.order(:id), self, route)
|
||||
render :json => admins.collect{ |admin| admin_json(admin, @current_user, session) }
|
||||
|
|
|
@ -240,6 +240,48 @@ describe "Admins API", type: :request do
|
|||
"login_id"=>@admin.pseudonym.unique_id}}]
|
||||
end
|
||||
|
||||
it "should scope the results to the user_id if given" do
|
||||
2.times do |x|
|
||||
u = user(:name => "User #{x}", :account => @account)
|
||||
@account.account_users.create!(:user => u, :membership_type => "MT #{x}")
|
||||
end
|
||||
@user = @admin
|
||||
json = api_call(:get, @path, @path_opts.merge(user_id: @admin.id))
|
||||
json.should ==[{"id"=>@admin.account_users.first.id,
|
||||
"role"=>"AccountAdmin",
|
||||
"user"=>
|
||||
{"id"=>@admin.id,
|
||||
"name"=>@admin.name,
|
||||
"sortable_name"=>@admin.sortable_name,
|
||||
"short_name"=>@admin.short_name,
|
||||
"login_id"=>@admin.pseudonym.unique_id}}]
|
||||
end
|
||||
|
||||
it "should scope the results to the array of user_ids if given" do
|
||||
2.times do |x|
|
||||
u = user(:name => "User #{x}", :account => @account)
|
||||
@account.account_users.create!(:user => u, :membership_type => "MT #{x}")
|
||||
end
|
||||
another_admin = @user
|
||||
@user = @admin
|
||||
json = api_call(:get, @path, @path_opts.merge(user_id: [@admin.id, another_admin.id]))
|
||||
json.should ==[{"id"=>@admin.account_users.first.id,
|
||||
"role"=>"AccountAdmin",
|
||||
"user"=>
|
||||
{"id"=>@admin.id,
|
||||
"name"=>@admin.name,
|
||||
"sortable_name"=>@admin.sortable_name,
|
||||
"short_name"=>@admin.short_name,
|
||||
"login_id"=>@admin.pseudonym.unique_id}},
|
||||
{"id"=>another_admin.account_users.first.id,
|
||||
"role"=>"MT 1",
|
||||
"user"=>
|
||||
{"id"=>another_admin.id,
|
||||
"name"=>another_admin.name,
|
||||
"sortable_name"=>another_admin.sortable_name,
|
||||
"short_name"=>another_admin.short_name}}]
|
||||
end
|
||||
|
||||
it "should paginate" do
|
||||
4.times do |x|
|
||||
u = user(:name => "User #{x}", :account => @account)
|
||||
|
|
Loading…
Reference in New Issue