diff --git a/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee b/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee index 8b4f139ce26..e71077c4c8b 100644 --- a/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee +++ b/app/coffeescripts/ember/quizzes/routes/quiz_statistics_route.coffee @@ -1,7 +1,16 @@ -define [ 'ember', 'underscore' ], (Ember, _) -> +define [ + 'ember' + 'underscore' + '../mixins/redirect' +], (Ember, _, Redirect) -> + {RSVP} = Ember - Ember.Route.extend + Ember.Route.extend Redirect, + + beforeModel: (transition) -> + @validateRoute('canManage', 'quiz.show') + model: (transition, options) -> quiz = @modelFor('quiz') quiz.get('quizStatistics').then((items)-> @@ -18,4 +27,4 @@ define [ 'ember', 'underscore' ], (Ember, _) -> # anyway, do it manually: set = @modelFor('quizStatistics').get('questionStatistics') set.clear() - set.pushObjects(@store.all('questionStatistics')) \ No newline at end of file + set.pushObjects(@store.all('questionStatistics')) diff --git a/app/coffeescripts/ember/quizzes/tests/adapters/quiz_report_adapter.spec.coffee b/app/coffeescripts/ember/quizzes/tests/adapters/quiz_report_adapter.spec.coffee index 91a98ab3c22..b2b64192675 100644 --- a/app/coffeescripts/ember/quizzes/tests/adapters/quiz_report_adapter.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/adapters/quiz_report_adapter.spec.coffee @@ -13,6 +13,9 @@ define [ App = startApp() fixtures.create() subject = App.__container__.lookup('adapter:quizReport') + + #tmp workaround. these tests shouldn't need to visit the route + env.setUserPermissions(true, true) visit('/1/statistics') teardown: -> @@ -20,4 +23,4 @@ define [ test 'it uses the report URL', -> url = subject.buildURL 'quizReport', 14 - ok url.match('/api/v1/courses/1/quizzes/1/reports/14') \ No newline at end of file + ok url.match('/api/v1/courses/1/quizzes/1/reports/14') diff --git a/app/coffeescripts/ember/quizzes/tests/environment_setup.coffee b/app/coffeescripts/ember/quizzes/tests/environment_setup.coffee index 2a61dc70e0a..a971764d3ac 100644 --- a/app/coffeescripts/ember/quizzes/tests/environment_setup.coffee +++ b/app/coffeescripts/ember/quizzes/tests/environment_setup.coffee @@ -7,3 +7,14 @@ define ['../shared/environment'], (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 + } diff --git a/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee b/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee index 62585f86497..a24ea5dbb47 100644 --- a/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/integration/quiz_moderate.spec.coffee @@ -3,8 +3,9 @@ define [ '../start_app' '../shared_ajax_fixtures' '../environment_setup' - '../../shared/environment' -], (Ember, startApp, fixtures, env) -> + '../test_redirection' +] +, (Ember, startApp, fixtures, env, testRedirection) -> module "Quiz Moderate: Integration", @@ -15,28 +16,7 @@ define [ teardown: -> Ember.run App, 'destroy' - test 'redirect non-permissioned users to quiz.show', -> - env.setEnv - PERMISSIONS: - manage: false - 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' + testRedirection + path: '/1/moderate' + defaultRoute: 'quiz.moderate' + redirectRoute: 'quiz.show' diff --git a/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee b/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee index 5ae94703f2a..15a08987b44 100644 --- a/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee +++ b/app/coffeescripts/ember/quizzes/tests/integration/quiz_statistics_integration.spec.coffee @@ -3,7 +3,8 @@ define [ '../start_app' '../environment_setup' '../shared_ajax_fixtures' -], (Ember, startApp, env, fixtures) -> + '../test_redirection' +], (Ember, startApp, env, fixtures, testRedirection) -> App = null {$} = Ember @@ -18,6 +19,7 @@ define [ testPage = (desc, callback) -> test desc, -> + env.setUserPermissions(true, true) visit('/1/statistics').then callback testPage 'it renders', -> @@ -29,3 +31,8 @@ define [ equal q.get('quizReports.length'), 2, 'loads quiz reports' ok qs = route.modelFor('quizStatistics'), 'loads quiz statistics' equal qs.get('questionStatistics.length'), 11, 'loads question statistics' + + testRedirection + path: '/1/statistics' + defaultRoute: 'quiz.statistics' + redirectRoute: 'quiz.show' diff --git a/app/coffeescripts/ember/quizzes/tests/test_redirection.coffee b/app/coffeescripts/ember/quizzes/tests/test_redirection.coffee new file mode 100644 index 00000000000..1c88f76bb07 --- /dev/null +++ b/app/coffeescripts/ember/quizzes/tests/test_redirection.coffee @@ -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