diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 7a26627a..4f5e5b81 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -7,6 +7,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, :reload] + before_action :set_external_user, only: [:statistics] before_action :set_file_types, only: [:create, :edit, :new, :update] before_action :set_teams, only: [:create, :edit, :new, :update] @@ -125,6 +126,14 @@ class ExercisesController < ApplicationController end private :set_exercise + def set_external_user + if params[:external_user_id] + @external_user = ExternalUser.find(params[:external_user_id]) + authorize! + end + end + private :set_exercise + def set_file_types @file_types = FileType.all.order(:name) end @@ -143,6 +152,11 @@ class ExercisesController < ApplicationController end def statistics + if(@external_user) + render 'exercises/external_users/statistics' + else + render 'exercises/statistics' + end end def submit diff --git a/app/controllers/external_users_controller.rb b/app/controllers/external_users_controller.rb index 1d22dc58..26af4fbf 100644 --- a/app/controllers/external_users_controller.rb +++ b/app/controllers/external_users_controller.rb @@ -13,4 +13,10 @@ class ExternalUsersController < ApplicationController @user = ExternalUser.find(params[:id]) authorize! end + + def statistics + @user = ExternalUser.find(params[:id]) + authorize! + end + end diff --git a/app/policies/external_user_policy.rb b/app/policies/external_user_policy.rb index 6f638a8e..2e11060b 100644 --- a/app/policies/external_user_policy.rb +++ b/app/policies/external_user_policy.rb @@ -1,2 +1,5 @@ class ExternalUserPolicy < AdminOnlyPolicy + def statistics? + admin? + end end diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim new file mode 100644 index 00000000..489a7e21 --- /dev/null +++ b/app/views/exercises/external_users/statistics.html.slim @@ -0,0 +1 @@ +h1 = "#{@exercise} for external user #{@external_user}" \ No newline at end of file diff --git a/app/views/external_users/statistics.html.slim b/app/views/external_users/statistics.html.slim new file mode 100644 index 00000000..6c49b967 --- /dev/null +++ b/app/views/external_users/statistics.html.slim @@ -0,0 +1,2 @@ +h1 = @user +H2 = 'Hallo' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7bb17297..24f6a0d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,13 @@ Rails.application.routes.draw do get '/help', to: 'application#help' + concern :statistics do + member do + get :statistics + end + end + + resources :consumers resources :execution_environments do @@ -47,7 +54,9 @@ Rails.application.routes.draw do end end - resources :external_users, only: [:index, :show] + resources :external_users, only: [:index, :show], concerns: :statistics do + resources :exercises, concerns: :statistics + end namespace :code_ocean do resources :files, only: [:create, :destroy]