redirect from ember quiz stats when no permission
also better organize testing of permission redirection into a module closes CNVS-12829 test plan: - enable fabulous quizzes - as an instructor - visit a quiz show page - verify that user can navigate through Overview, Moderate, Statistics tabs - as a student - visist a quiz show page - verify that users gets redirected to the Overview when navigating to Moderate or Statistics Tab - verify that redirect happens if user enters the correct url for moderate or statistics as well. Change-Id: Ib87c42c53d9e53f224914cdab34d1781592a8512 Reviewed-on: https://gerrit.instructure.com/34256 Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Reviewed-by: Derek DeVries <ddevries@instructure.com> Reviewed-by: Josh Simpson <jsimpson@instructure.com> Product-Review: Jason Madsen <jmadsen@instructure.com>
This commit is contained in:
parent
9be9ca6c7f
commit
584c76285c
|
@ -1,7 +1,16 @@
|
||||||
define [ 'ember', 'underscore' ], (Ember, _) ->
|
define [
|
||||||
|
'ember'
|
||||||
|
'underscore'
|
||||||
|
'../mixins/redirect'
|
||||||
|
], (Ember, _, Redirect) ->
|
||||||
|
|
||||||
{RSVP} = Ember
|
{RSVP} = Ember
|
||||||
|
|
||||||
Ember.Route.extend
|
Ember.Route.extend Redirect,
|
||||||
|
|
||||||
|
beforeModel: (transition) ->
|
||||||
|
@validateRoute('canManage', 'quiz.show')
|
||||||
|
|
||||||
model: (transition, options) ->
|
model: (transition, options) ->
|
||||||
quiz = @modelFor('quiz')
|
quiz = @modelFor('quiz')
|
||||||
quiz.get('quizStatistics').then((items)->
|
quiz.get('quizStatistics').then((items)->
|
||||||
|
@ -18,4 +27,4 @@ define [ 'ember', 'underscore' ], (Ember, _) ->
|
||||||
# anyway, do it manually:
|
# anyway, do it manually:
|
||||||
set = @modelFor('quizStatistics').get('questionStatistics')
|
set = @modelFor('quizStatistics').get('questionStatistics')
|
||||||
set.clear()
|
set.clear()
|
||||||
set.pushObjects(@store.all('questionStatistics'))
|
set.pushObjects(@store.all('questionStatistics'))
|
||||||
|
|
|
@ -13,6 +13,9 @@ define [
|
||||||
App = startApp()
|
App = startApp()
|
||||||
fixtures.create()
|
fixtures.create()
|
||||||
subject = App.__container__.lookup('adapter:quizReport')
|
subject = App.__container__.lookup('adapter:quizReport')
|
||||||
|
|
||||||
|
#tmp workaround. these tests shouldn't need to visit the route
|
||||||
|
env.setUserPermissions(true, true)
|
||||||
visit('/1/statistics')
|
visit('/1/statistics')
|
||||||
|
|
||||||
teardown: ->
|
teardown: ->
|
||||||
|
@ -20,4 +23,4 @@ define [
|
||||||
|
|
||||||
test 'it uses the report URL', ->
|
test 'it uses the report URL', ->
|
||||||
url = subject.buildURL 'quizReport', 14
|
url = subject.buildURL 'quizReport', 14
|
||||||
ok url.match('/api/v1/courses/1/quizzes/1/reports/14')
|
ok url.match('/api/v1/courses/1/quizzes/1/reports/14')
|
||||||
|
|
|
@ -7,3 +7,14 @@ define ['../shared/environment'], (env) ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
env.setEnv ENV
|
env.setEnv ENV
|
||||||
|
|
||||||
|
{
|
||||||
|
setUserPermissions: (canManage, canUpdate) ->
|
||||||
|
prevContextAsset = env.get('env').context_asset_string
|
||||||
|
env.setEnv
|
||||||
|
context_asset_string: prevContextAsset
|
||||||
|
PERMISSIONS:
|
||||||
|
manage: canManage
|
||||||
|
update: canUpdate
|
||||||
|
env
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ define [
|
||||||
'../start_app'
|
'../start_app'
|
||||||
'../shared_ajax_fixtures'
|
'../shared_ajax_fixtures'
|
||||||
'../environment_setup'
|
'../environment_setup'
|
||||||
'../../shared/environment'
|
'../test_redirection'
|
||||||
], (Ember, startApp, fixtures, env) ->
|
]
|
||||||
|
, (Ember, startApp, fixtures, env, testRedirection) ->
|
||||||
|
|
||||||
module "Quiz Moderate: Integration",
|
module "Quiz Moderate: Integration",
|
||||||
|
|
||||||
|
@ -15,28 +16,7 @@ define [
|
||||||
teardown: ->
|
teardown: ->
|
||||||
Ember.run App, 'destroy'
|
Ember.run App, 'destroy'
|
||||||
|
|
||||||
test 'redirect non-permissioned users to quiz.show', ->
|
testRedirection
|
||||||
env.setEnv
|
path: '/1/moderate'
|
||||||
PERMISSIONS:
|
defaultRoute: 'quiz.moderate'
|
||||||
manage: false
|
redirectRoute: 'quiz.show'
|
||||||
update: false
|
|
||||||
|
|
||||||
visit('/1/moderate')
|
|
||||||
andThen ->
|
|
||||||
wait().then ->
|
|
||||||
# this can change to currentRoute() once we update ember >= 1.5.0
|
|
||||||
currentRoute = App.__container__.lookup('controller:application').get('currentRouteName')
|
|
||||||
equal currentRoute, 'quiz.show'
|
|
||||||
|
|
||||||
test 'permissioned users should see moderate page', ->
|
|
||||||
env.setEnv
|
|
||||||
PERMISSIONS:
|
|
||||||
manage: true
|
|
||||||
update: true
|
|
||||||
|
|
||||||
visit('/1/moderate')
|
|
||||||
andThen ->
|
|
||||||
wait().then ->
|
|
||||||
# this can change to currentRoute() once we update ember >= 1.5.0
|
|
||||||
currentRoute = App.__container__.lookup('controller:application').get('currentRouteName')
|
|
||||||
equal currentRoute, 'quiz.moderate'
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ define [
|
||||||
'../start_app'
|
'../start_app'
|
||||||
'../environment_setup'
|
'../environment_setup'
|
||||||
'../shared_ajax_fixtures'
|
'../shared_ajax_fixtures'
|
||||||
], (Ember, startApp, env, fixtures) ->
|
'../test_redirection'
|
||||||
|
], (Ember, startApp, env, fixtures, testRedirection) ->
|
||||||
App = null
|
App = null
|
||||||
|
|
||||||
{$} = Ember
|
{$} = Ember
|
||||||
|
@ -18,6 +19,7 @@ define [
|
||||||
|
|
||||||
testPage = (desc, callback) ->
|
testPage = (desc, callback) ->
|
||||||
test desc, ->
|
test desc, ->
|
||||||
|
env.setUserPermissions(true, true)
|
||||||
visit('/1/statistics').then callback
|
visit('/1/statistics').then callback
|
||||||
|
|
||||||
testPage 'it renders', ->
|
testPage 'it renders', ->
|
||||||
|
@ -29,3 +31,8 @@ define [
|
||||||
equal q.get('quizReports.length'), 2, 'loads quiz reports'
|
equal q.get('quizReports.length'), 2, 'loads quiz reports'
|
||||||
ok qs = route.modelFor('quizStatistics'), 'loads quiz statistics'
|
ok qs = route.modelFor('quizStatistics'), 'loads quiz statistics'
|
||||||
equal qs.get('questionStatistics.length'), 11, 'loads question statistics'
|
equal qs.get('questionStatistics.length'), 11, 'loads question statistics'
|
||||||
|
|
||||||
|
testRedirection
|
||||||
|
path: '/1/statistics'
|
||||||
|
defaultRoute: 'quiz.statistics'
|
||||||
|
redirectRoute: 'quiz.show'
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
define [
|
||||||
|
'./environment_setup'
|
||||||
|
], (env) ->
|
||||||
|
verifyRoute = (path, expected) ->
|
||||||
|
visit(path)
|
||||||
|
andThen ->
|
||||||
|
wait().then ->
|
||||||
|
# this can change to currentRoute() once we update ember >= 1.5.0
|
||||||
|
currentRoute = App.__container__.lookup('controller:application').get('currentRouteName')
|
||||||
|
equal currentRoute, expected
|
||||||
|
|
||||||
|
testRedirection = (options) ->
|
||||||
|
{path, defaultRoute, redirectRoute} = options
|
||||||
|
test "permissioned users should see #{defaultRoute}", ->
|
||||||
|
env.setUserPermissions(true, true)
|
||||||
|
verifyRoute(path, defaultRoute)
|
||||||
|
|
||||||
|
test 'redirect non-permissioned users to #{redirectRoute}', ->
|
||||||
|
env.setUserPermissions(false, false)
|
||||||
|
verifyRoute(path, redirectRoute)
|
||||||
|
|
||||||
|
testRedirection
|
Loading…
Reference in New Issue