From 352d1322577df34879ea4e0c7865fc9815b90e1e Mon Sep 17 00:00:00 2001 From: Xander Moffatt Date: Thu, 22 Aug 2019 17:44:31 -0600 Subject: [PATCH] add data services index action closes PLAT-4744 Test Plan: - see that the index action returns a list Change-Id: I92cc07c5476c7dd48202f38b62e09df6aa591b62 Reviewed-on: https://gerrit.instructure.com/206435 Reviewed-by: Weston Dransfield Tested-by: Jenkins QA-Review: Marc Phillips Product-Review: Marc Phillips --- .../lti/data_services_controller.rb | 18 +++++++++++++++++- config/routes.rb | 1 + lib/schemas/lti/tool_configuration.rb | 3 ++- .../live_events_subscription_service.rb | 2 +- lib/token_scopes.rb | 4 +++- .../lti/data_services_controller_spec.rb | 13 ++++++++++++- .../advantage_services_shared_context.rb | 1 + 7 files changed, 37 insertions(+), 5 deletions(-) diff --git a/app/controllers/lti/data_services_controller.rb b/app/controllers/lti/data_services_controller.rb index 303509315bc..1e97a98e3a4 100644 --- a/app/controllers/lti/data_services_controller.rb +++ b/app/controllers/lti/data_services_controller.rb @@ -66,7 +66,8 @@ module Lti ACTION_SCOPE_MATCHERS = { create: all_of(TokenScopes::LTI_CREATE_DATA_SERVICE_SUBSCRIPTION_SCOPE), show: all_of(TokenScopes::LTI_SHOW_DATA_SERVICE_SUBSCRIPTION_SCOPE), - update: all_of(TokenScopes::LTI_UPDATE_DATA_SERVICE_SUBSCRIPTION_SCOPE) + update: all_of(TokenScopes::LTI_UPDATE_DATA_SERVICE_SUBSCRIPTION_SCOPE), + index: all_of(TokenScopes::LTI_LIST_DATA_SERVICE_SUBSCRIPTION_SCOPE) }.freeze.with_indifferent_access rescue_from Lti::SubscriptionsValidator::InvalidContextType do @@ -153,6 +154,21 @@ module Lti forward_service_response(response) end + # @API List all Data Services Event Subscriptions + # + # This endpoint returns a paginated list with a default limit of 100 items per result set. + # You can retrieve the next result set by setting a 'StartKey' header in your next request + # with the value of the 'EndKey' header in the response. + # + # Example use of a 'StartKey' header object: + # { "Id":"71d6dfba-0547-477d-b41d-db8cb528c6d1","OwnerId":"domain.instructure.com" } + # + # @returns DataServiceSubscription + def index + response = Services::LiveEventsSubscriptionService.index(jwt_body) + forward_service_response(response) + end + private def scopes_matcher diff --git a/config/routes.rb b/config/routes.rb index f8068afa164..0dc007b25df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2349,6 +2349,7 @@ CanvasRails::Application.routes.draw do post "/accounts/:account_id/data_services", action: :create, as: :data_services_create get "/accounts/:account_id/data_services/:id", action: :show, as: :data_services_show put "/accounts/:account_id/data_services/:id", action: :update, as: :data_services_update + get "/accounts/:account_id/data_services", action: :index, as: :data_services_index end # Names and Roles Provisioning (NRPS) v2 Service diff --git a/lib/schemas/lti/tool_configuration.rb b/lib/schemas/lti/tool_configuration.rb index 90ea8bf81bd..b261e3b440c 100644 --- a/lib/schemas/lti/tool_configuration.rb +++ b/lib/schemas/lti/tool_configuration.rb @@ -57,7 +57,8 @@ module Schemas::Lti "https://canvas.instructure.com/lti/public_jwk/scope/update", "https://canvas.instructure.com/lti/data_services/scope/create", "https://canvas.instructure.com/lti/data_services/scope/show", - "https://canvas.instructure.com/lti/data_services/scope/update" + "https://canvas.instructure.com/lti/data_services/scope/update", + "https://canvas.instructure.com/lti/data_services/scope/list" ].freeze } }.freeze, diff --git a/lib/services/live_events_subscription_service.rb b/lib/services/live_events_subscription_service.rb index 8e354fa815d..e5c807b7d66 100644 --- a/lib/services/live_events_subscription_service.rb +++ b/lib/services/live_events_subscription_service.rb @@ -81,7 +81,7 @@ module Services request(:delete, "/api/subscriptions/#{subscription_id}", options) end - def index(jwt_body, opts) + def index(jwt_body, opts = {}) options = { headers: headers(jwt_body, opts) } request(:get, '/api/subscriptions', options) end diff --git a/lib/token_scopes.rb b/lib/token_scopes.rb index 20ed5ccd94c..c67c45eaa02 100644 --- a/lib/token_scopes.rb +++ b/lib/token_scopes.rb @@ -31,6 +31,7 @@ class TokenScopes LTI_CREATE_DATA_SERVICE_SUBSCRIPTION_SCOPE = "https://canvas.instructure.com/lti/data_services/scope/create".freeze LTI_SHOW_DATA_SERVICE_SUBSCRIPTION_SCOPE = "https://canvas.instructure.com/lti/data_services/scope/show".freeze LTI_UPDATE_DATA_SERVICE_SUBSCRIPTION_SCOPE = "https://canvas.instructure.com/lti/data_services/scope/update".freeze + LTI_LIST_DATA_SERVICE_SUBSCRIPTION_SCOPE = "https://canvas.instructure.com/lti/data_services/scope/list".freeze LTI_SCOPES = { LTI_AGS_LINE_ITEM_SCOPE => I18n.t("Can create and view assignment data in the gradebook associated with the tool."), LTI_AGS_LINE_ITEM_READ_ONLY_SCOPE => I18n.t("Can view assignment data in the gradebook associated with the tool."), @@ -40,7 +41,8 @@ class TokenScopes LTI_UPDATE_PUBLIC_JWK_SCOPE => I18n.t("Can update public jwk for LTI services."), LTI_CREATE_DATA_SERVICE_SUBSCRIPTION_SCOPE => I18n.t("Can create subscription to data service data."), LTI_SHOW_DATA_SERVICE_SUBSCRIPTION_SCOPE => I18n.t("Can show subscription to data service data."), - LTI_UPDATE_DATA_SERVICE_SUBSCRIPTION_SCOPE => I18n.t("Can update subscription to data service data.") + LTI_UPDATE_DATA_SERVICE_SUBSCRIPTION_SCOPE => I18n.t("Can update subscription to data service data."), + LTI_LIST_DATA_SERVICE_SUBSCRIPTION_SCOPE => I18n.t("Can list subscriptions to data service data.") }.freeze LTI_AGS_SCOPES = [ LTI_AGS_LINE_ITEM_SCOPE, LTI_AGS_LINE_ITEM_READ_ONLY_SCOPE, LTI_AGS_RESULT_READ_ONLY_SCOPE, LTI_AGS_SCORE_SCOPE ].freeze diff --git a/spec/controllers/lti/data_services_controller_spec.rb b/spec/controllers/lti/data_services_controller_spec.rb index ce673520931..3c6dbd3067b 100644 --- a/spec/controllers/lti/data_services_controller_spec.rb +++ b/spec/controllers/lti/data_services_controller_spec.rb @@ -60,7 +60,7 @@ describe Lti::DataServicesController do let(:expected_mime_type) { described_class::MIME_TYPE } let(:scope_to_remove) { "https://canvas.instructure.com/lti/data_services/scope/show"} let(:params_overrides) do - { subscription: subscription, account_id: root_account.id, id: 'testid' } + { account_id: root_account.id, id: 'testid' } end end end @@ -75,4 +75,15 @@ describe Lti::DataServicesController do end end end + + describe '#index' do + it_behaves_like 'lti services' do + let(:action) { :index } + let(:expected_mime_type) { described_class::MIME_TYPE } + let(:scope_to_remove) { "https://canvas.instructure.com/lti/data_services/scope/list"} + let(:params_overrides) do + { account_id: root_account.id } + end + end + end end diff --git a/spec/controllers/lti/ims/concerns/advantage_services_shared_context.rb b/spec/controllers/lti/ims/concerns/advantage_services_shared_context.rb index 103cc2c519e..c0ad533f1b0 100644 --- a/spec/controllers/lti/ims/concerns/advantage_services_shared_context.rb +++ b/spec/controllers/lti/ims/concerns/advantage_services_shared_context.rb @@ -36,6 +36,7 @@ shared_context 'advantage services context' do https://canvas.instructure.com/lti/data_services/scope/create https://canvas.instructure.com/lti/data_services/scope/show https://canvas.instructure.com/lti/data_services/scope/update + https://canvas.instructure.com/lti/data_services/scope/list ).join(' ') end let(:access_token_signing_key) { Canvas::Security.encryption_key }