Skip to content

Commit 81963de

Browse files
author
Landon Wilkins
committed
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>
1 parent dfba8c4 commit 81963de

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

app/controllers/admins_controller.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class AdminsController < ApplicationController
5454
#
5555
# Flag an existing user as an admin within the account.
5656
#
57-
# @argument user_id [String]
57+
# @argument user_id [Integer]
5858
# The id of the user to promote.
5959
#
6060
# @argument role [Optional, String]
@@ -92,15 +92,19 @@ def destroy
9292
render :json => admin_json(admin, @current_user, session)
9393
end
9494
end
95-
95+
9696
# @API List account admins
9797
#
9898
# List the admins in the account
99-
#
99+
#
100+
# @argument user_id[] [Optional, [Integer]]
101+
# Scope the results to those with user IDs equal to any of the IDs specified here.
102+
#
100103
# @returns [Admin]
101104
def index
102105
if authorized_action(@context, @current_user, :manage_account_memberships)
103106
scope = @context.account_users
107+
scope = scope.where(user_id: params[:user_id]) if params[:user_id]
104108
route = polymorphic_url([:api_v1, @context, :admins])
105109
admins = Api.paginate(scope.order(:id), self, route)
106110
render :json => admins.collect{ |admin| admin_json(admin, @current_user, session) }

spec/apis/v1/admins_api_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,48 @@
240240
"login_id"=>@admin.pseudonym.unique_id}}]
241241
end
242242

243+
it "should scope the results to the user_id if given" do
244+
2.times do |x|
245+
u = user(:name => "User #{x}", :account => @account)
246+
@account.account_users.create!(:user => u, :membership_type => "MT #{x}")
247+
end
248+
@user = @admin
249+
json = api_call(:get, @path, @path_opts.merge(user_id: @admin.id))
250+
json.should ==[{"id"=>@admin.account_users.first.id,
251+
"role"=>"AccountAdmin",
252+
"user"=>
253+
{"id"=>@admin.id,
254+
"name"=>@admin.name,
255+
"sortable_name"=>@admin.sortable_name,
256+
"short_name"=>@admin.short_name,
257+
"login_id"=>@admin.pseudonym.unique_id}}]
258+
end
259+
260+
it "should scope the results to the array of user_ids if given" do
261+
2.times do |x|
262+
u = user(:name => "User #{x}", :account => @account)
263+
@account.account_users.create!(:user => u, :membership_type => "MT #{x}")
264+
end
265+
another_admin = @user
266+
@user = @admin
267+
json = api_call(:get, @path, @path_opts.merge(user_id: [@admin.id, another_admin.id]))
268+
json.should ==[{"id"=>@admin.account_users.first.id,
269+
"role"=>"AccountAdmin",
270+
"user"=>
271+
{"id"=>@admin.id,
272+
"name"=>@admin.name,
273+
"sortable_name"=>@admin.sortable_name,
274+
"short_name"=>@admin.short_name,
275+
"login_id"=>@admin.pseudonym.unique_id}},
276+
{"id"=>another_admin.account_users.first.id,
277+
"role"=>"MT 1",
278+
"user"=>
279+
{"id"=>another_admin.id,
280+
"name"=>another_admin.name,
281+
"sortable_name"=>another_admin.sortable_name,
282+
"short_name"=>another_admin.short_name}}]
283+
end
284+
243285
it "should paginate" do
244286
4.times do |x|
245287
u = user(:name => "User #{x}", :account => @account)

0 commit comments

Comments
 (0)