add option to filter sis imports api index by date

test plan:
* should be able to supply a "created_since" argument
 for the SIS Imports API index (see the documentation)
 and only retrieve imports created past a certain date

closes #CNVS-17669

Change-Id: I31bb5a8cff9f1dff983f0f7ad9efdda7cec00bd8
Reviewed-on: https://gerrit.instructure.com/46310
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Tyler Pickett <tpickett+gerrit@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Tyler Pickett <tpickett+gerrit@instructure.com>
QA-Review: Clare Strong <clare@instructure.com>
This commit is contained in:
James Williams 2014-12-26 10:20:12 -07:00
parent 8ab9af5900
commit 73420c8fa6
2 changed files with 26 additions and 4 deletions

View File

@ -200,14 +200,21 @@ class SisImportsApiController < ApplicationController
#
# Returns the list of SIS imports for an account
#
# Examples:
# curl 'https://<canvas>/api/v1/accounts/<account_id>/sis_imports' \
# -H "Authorization: Bearer <token>"
# @argument created_since [Optional, DateTime]
# If set, only shows imports created after the specified date (use ISO8601 format)
#
# Example:
# 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}))
scope = @account.sis_batches.order('created_at DESC')
if created_since = CanvasTime.try_parse(params[:created_since])
scope = scope.where("created_at > ?", created_since)
end
@batches = Api.paginate(scope, self, url_for({action: :index, controller: :sis_imports_api}))
render :json => ({ sis_imports: @batches})
end
end

View File

@ -525,6 +525,21 @@ describe SisImportsApiController, type: :request do
})
end
it "should filter sis imports by date if requested" do
batch = @account.sis_batches.create
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, :created_since => 1.day.from_now.iso8601 })
expect(json["sis_imports"].count).to eq 0
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, :created_since => 1.day.ago.iso8601 })
expect(json["sis_imports"].count).to eq 1
end
it "should not fail when options are nil" do
batch = @account.sis_batches.create
expect(batch.options).to be_nil