add index to sis imports api

closes CNVS-9946
closes CNVS-10008
refs CNVS-3680

test plan
 - get https://<canvas>/api/v1/accounts/<account_id>/sis_imports
 - should show a paginated list of past imports for the account
 - run rake doc:api
 - https://<canvas>/doc/api/sis_imports.html should render 
 - it should have the SIS import object

Change-Id: I5d81e0049a2a16455e9acbea5be2effc2c2dd633
Reviewed-on: https://gerrit.instructure.com/27539
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Jeremy Putnam <jeremyp@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2013-12-15 04:23:20 -07:00
parent be7b91c911
commit e8ed4b6531
3 changed files with 121 additions and 3 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2011 Instructure, Inc.
# Copyright (C) 2011 - 2013 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -19,6 +19,59 @@
# @API SIS Imports
#
# API for importing data from Student Information Systems
#
# @object SisImport
# {
# // The unique identifier for the SIS import.
# "id": 1,
#
# // The date the SIS import was created.
# "created_at": "2013-12-01T23:59:00-06:00",
#
# // The date the SIS import finished.
# // Returns null if not finished.
# "ended_at": "2013-12-02T00:03:21-06:00",
#
# // The date the SIS import was last updated.
# "updated_at": "2013-12-02T00:03:21-06:00",
#
# // The current state of the SIS import.
# // - 'created': The SIS import has been created.
# // - 'imported': The SIS import is currently processing.
# // - 'imported': The SIS import has completed successfully.
# // - 'imported_with_messages': The SIS import completed with errors or warnings.
# // - 'failed_with_messages': The SIS import failed with errors.
# // - 'failed': The SIS import failed.
# "workflow_state": "imported",
#
# // data
# "data": {
# // The type of SIS import
# "import_type": "instructure_csv",
#
# // Which file were included in the SIS import
# "supplied_batches": ["term", "course", "section", "user", "enrollment"],
#
# // The number of rows processed for each type of import
# "counts": {
# "accounts": 0,
# "terms": 3,
# "abstract_courses": 0,
# "courses": 121,
# "sections": 278,
# "xlists": 0,
# "users": 346,
# "enrollments": 1542,
# "groups": 0,
# "group_memberships": 0,
# "grade_publishing_results": 0
# }
# },
#
# // The progress of the SIS import.
# "progress": "100"
# }
#
class SisImportsApiController < ApplicationController
before_filter :get_context
before_filter :check_account
@ -28,6 +81,22 @@ class SisImportsApiController < ApplicationController
raise "SIS imports can only be executed on enabled accounts" unless @account.allow_sis_import
end
# @API Get SIS import list
#
# Returns the list of SIS imports for an account
#
# Examples:
# curl 'https://<canvas>/api/v1/accounts/<account_id>/sis_imports' \
# -H "Authorization: Bearer <token>"
#
# @returns [SisImport]
def index
if authorized_action(@account, @current_user, :manage_sis)
@batches = Api.paginate(@account.sis_batches.order('created_at DESC'), self, url_for({action: :index, controller: :sis_imports_api}))
render :json => ({ sis_imports: @batches})
end
end
# @API Import SIS data
#
# Import SIS data into Canvas. Must be on a root account with SIS imports
@ -106,6 +175,8 @@ class SisImportsApiController < ApplicationController
# by this import. Requires that 'override_sis_stickiness' is also provided.
# If 'add_sis_stickiness' is also provided, 'clear_sis_stickiness' will
# overrule the behavior of 'add_sis_stickiness'
#
# @returns SisImport
def create
if authorized_action(@account, @current_user, :manage_sis)
params[:import_type] ||= 'instructure_csv'
@ -190,6 +261,12 @@ class SisImportsApiController < ApplicationController
# @API Get SIS import status
#
# Get the status of an already created SIS import.
#
# Examples:
# curl 'https://<canvas>/api/v1/accounts/<account_id>/sis_imports/<sis_import_id>' \
# -H "Authorization: Bearer <token>"
#
# @returns SisImport
def show
if authorized_action(@account, @current_user, :manage_sis)
@batch = SisBatch.find(params[:id])

View File

@ -547,7 +547,7 @@ routes.draw do
match 'avatars' => 'accounts#avatars', :as => :avatars
match 'sis_import' => 'accounts#sis_import', :as => :sis_import, :via => :get
resources :sis_imports, :only => [:create, :show], :controller => :sis_imports_api
resources :sis_imports, :only => [:create, :show, :index], :controller => :sis_imports_api
match 'users' => 'users#create', :as => :add_user, :via => :post
match 'users/:user_id/delete' => 'accounts#confirm_delete_user', :as => :confirm_delete_user
match 'users/:user_id' => 'accounts#remove_user', :as => :delete_user, :via => :delete
@ -1028,6 +1028,7 @@ routes.draw do
scope(:controller => :sis_imports_api) do
post 'accounts/:account_id/sis_imports', :action => :create
get 'accounts/:account_id/sis_imports/:id', :action => :show
get 'accounts/:account_id/sis_imports', :action => :index
end
scope(:controller => :users) do

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2011 Instructure, Inc.
# Copyright (C) 2011 - 2013 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -438,4 +438,44 @@ describe SisImportsApiController, :type => :integration do
SisBatch.count.should == 0
end
it "should list sis imports for an account" do
@user = user_with_pseudonym :active_all => true
user_session @user
@account = Account.create(name: 'sis account')
@account.allow_sis_import = true
@account.save!
@account.add_user(@user, 'AccountAdmin')
batch = post_csv(
"account_id,parent_account_id,name,status",
"A001,,TestAccount,active"
)
run_jobs
json = api_call(:get, "/api/v1/accounts/#{@account.id}/sis_imports.json",
{ :controller => 'sis_imports_api', :action => 'index',
:format => 'json', :account_id => @account.id.to_s })
json["sis_imports"].first.delete("created_at")
json["sis_imports"].first.delete("updated_at")
json["sis_imports"].first.delete("ended_at")
json.should == {"sis_imports"=>[{
"data" => { "import_type" => "instructure_csv",
"supplied_batches" => ["account"],
"counts" => { "abstract_courses" => 0,
"courses" => 0,
"sections" => 0,
"accounts" => 1,
"enrollments" => 0,
"grade_publishing_results" => 0,
"users" => 0,
"xlists" => 0,
"groups" => 0,
"group_memberships" => 0,
"terms" => 0, }},
"progress" => 100,
"id" => batch.id,
"workflow_state"=>"imported" }]
}
end
end