From 9c8d0b01eb478cc365fc60a44e0324c752a56325 Mon Sep 17 00:00:00 2001 From: Jan Renz Date: Mon, 20 Apr 2015 22:30:31 +0200 Subject: [PATCH] Fix reset of tasks --- app/controllers/exercises_controller.rb | 6 +++++- app/policies/exercise_policy.rb | 4 ++-- app/views/exercises/_editor.html.slim | 2 +- ...how.json.jbuilder => reload.json.jbuilder} | 0 config/application.rb | 7 +++++++ config/routes.rb | 1 + spec/controllers/exercises_controller_spec.rb | 19 ++++++++----------- 7 files changed, 24 insertions(+), 15 deletions(-) rename app/views/exercises/{show.json.jbuilder => reload.json.jbuilder} (100%) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 00941719..cff4a870 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -6,7 +6,7 @@ class ExercisesController < ApplicationController before_action :handle_file_uploads, only: [:create, :update] before_action :set_execution_environments, only: [:create, :edit, :new, :update] - before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :run, :statistics, :submit] + before_action :set_exercise, only: MEMBER_ACTIONS + [:clone, :implement, :run, :statistics, :submit, :reload] before_action :set_file_types, only: [:create, :edit, :new, :update] before_action :set_teams, only: [:create, :edit, :new, :update] @@ -138,6 +138,10 @@ class ExercisesController < ApplicationController def show end + #we might want to think about auth here + def reload + end + def statistics end diff --git a/app/policies/exercise_policy.rb b/app/policies/exercise_policy.rb index b5aff89b..1e4cf150 100644 --- a/app/policies/exercise_policy.rb +++ b/app/policies/exercise_policy.rb @@ -12,12 +12,12 @@ class ExercisePolicy < AdminOrAuthorPolicy define_method(action) { admin? || author? || team_member? } end - [:implement?, :submit?].each do |action| + [:implement?, :submit?, :reload?].each do |action| define_method(action) { everyone } end def team_member? - @record.team.try(:members, []).include?(@user) + @record.team.try(:members, []).include?(@user) if @record.team end private :team_member? diff --git a/app/views/exercises/_editor.html.slim b/app/views/exercises/_editor.html.slim index 09d07190..0794cb41 100644 --- a/app/views/exercises/_editor.html.slim +++ b/app/views/exercises/_editor.html.slim @@ -4,7 +4,7 @@ - @files.each do |file| = render('editor_frame', exercise: exercise, file: file) #editor-buttons.btn-group - = render('editor_button', data: {:'data-message-confirm' => t('exercises.editor.confirm_start_over'), :'data-url' => exercise_path(exercise)}, icon: 'fa fa-history', id: 'start-over', label: t('exercises.editor.start_over')) + = render('editor_button', data: {:'data-message-confirm' => t('exercises.editor.confirm_start_over'), :'data-url' => reload_exercise_path(exercise)}, icon: 'fa fa-history', id: 'start-over', label: t('exercises.editor.start_over')) = render('editor_button', data: {:'data-message-success' => t('submissions.create.success'), :'data-placement' => 'top', :'data-tooltip' => true}, icon: 'fa fa-save', id: 'save', label: t('exercises.editor.save'), title: t('.tooltips.save')) .btn-group = render('editor_button', disabled: true, icon: 'fa fa-ban', id: 'dummy', label: t('exercises.editor.dummy')) diff --git a/app/views/exercises/show.json.jbuilder b/app/views/exercises/reload.json.jbuilder similarity index 100% rename from app/views/exercises/show.json.jbuilder rename to app/views/exercises/reload.json.jbuilder diff --git a/config/application.rb b/config/application.rb index 91dec8cf..744438a9 100644 --- a/config/application.rb +++ b/config/application.rb @@ -30,5 +30,12 @@ module CodeOcean config.autoload_paths << Rails.root.join('lib') config.eager_load_paths << Rails.root.join('lib') + case (RUBY_ENGINE) + when 'ruby' + # ... + when 'jruby' + # plattform specific + java.lang.Class.for_name('javax.crypto.JceSecurity').get_declared_field('isRestricted').tap{|f| f.accessible = true; f.set nil, false} + end end end diff --git a/config/routes.rb b/config/routes.rb index a20b8fef..7e0b4c33 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -40,6 +40,7 @@ Rails.application.routes.draw do post :clone get :implement get :statistics + get :reload post :submit end end diff --git a/spec/controllers/exercises_controller_spec.rb b/spec/controllers/exercises_controller_spec.rb index f9fcf621..5323096d 100644 --- a/spec/controllers/exercises_controller_spec.rb +++ b/spec/controllers/exercises_controller_spec.rb @@ -202,23 +202,20 @@ describe ExercisesController do describe 'GET #show' do context 'as admin' do before(:each) { get :show, id: exercise.id } + expect_assigns(exercise: :exercise) expect_status(200) expect_template(:show) end - context 'as internal user' do - let(:user) { FactoryGirl.create(:internal_user) } - before(:each) { get :show, id: exercise.id } + end + + describe 'GET #reload' do + context 'as anyone' do + before(:each) { get :reload, format: :json, id: exercise.id } + expect_assigns(exercise: :exercise) expect_status(200) - expect_template(:show) - end - context 'as external user' do - let(:user) { FactoryGirl.create(:external_user) } - before(:each) { get :show, id: exercise.id } - expect_assigns(exercise: :exercise) - expect_status(200) - expect_template(:show) + expect_template(:reload) end end