Merge pull request #242 from openHPI/fix_proxy_exercise
Add user (ID and type) to proxy exercise
This commit is contained in:
@ -9,7 +9,7 @@ class ProxyExercisesController < ApplicationController
|
|||||||
private :authorize!
|
private :authorize!
|
||||||
|
|
||||||
def clone
|
def clone
|
||||||
proxy_exercise = @proxy_exercise.duplicate(token: nil, exercises: @proxy_exercise.exercises)
|
proxy_exercise = @proxy_exercise.duplicate(public: false, token: nil, exercises: @proxy_exercise.exercises, user: current_user)
|
||||||
proxy_exercise.send(:generate_token)
|
proxy_exercise.send(:generate_token)
|
||||||
if proxy_exercise.save
|
if proxy_exercise.save
|
||||||
redirect_to(proxy_exercise, notice: t('shared.object_cloned', model: ProxyExercise.model_name.human))
|
redirect_to(proxy_exercise, notice: t('shared.object_cloned', model: ProxyExercise.model_name.human))
|
||||||
@ -39,7 +39,7 @@ class ProxyExercisesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def proxy_exercise_params
|
def proxy_exercise_params
|
||||||
params[:proxy_exercise].permit(:description, :title, :exercise_ids => []) if params[:proxy_exercise].present?
|
params[:proxy_exercise].permit(:description, :title, :public, :exercise_ids => []).merge(user_id: current_user.id, user_type: current_user.class.name) if params[:proxy_exercise].present?
|
||||||
end
|
end
|
||||||
private :proxy_exercise_params
|
private :proxy_exercise_params
|
||||||
|
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
class ProxyExercise < ApplicationRecord
|
class ProxyExercise < ApplicationRecord
|
||||||
|
include Creation
|
||||||
|
include DefaultValues
|
||||||
|
|
||||||
after_initialize :generate_token
|
after_initialize :generate_token
|
||||||
after_initialize :set_reason
|
after_initialize :set_reason
|
||||||
|
after_initialize :set_default_values
|
||||||
|
|
||||||
has_and_belongs_to_many :exercises
|
has_and_belongs_to_many :exercises
|
||||||
has_many :user_proxy_exercise_exercises
|
has_many :user_proxy_exercise_exercises
|
||||||
|
|
||||||
|
validates :public, boolean_presence: true
|
||||||
|
|
||||||
def count_files
|
def count_files
|
||||||
exercises.count
|
exercises.count
|
||||||
end
|
end
|
||||||
@ -19,6 +24,11 @@ class ProxyExercise < ApplicationRecord
|
|||||||
end
|
end
|
||||||
private :generate_token
|
private :generate_token
|
||||||
|
|
||||||
|
def set_default_values
|
||||||
|
set_default_values_if_present(public: false)
|
||||||
|
end
|
||||||
|
private :set_default_values
|
||||||
|
|
||||||
def duplicate(attributes = {})
|
def duplicate(attributes = {})
|
||||||
proxy_exercise = dup
|
proxy_exercise = dup
|
||||||
proxy_exercise.attributes = attributes
|
proxy_exercise.attributes = attributes
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
.form-group
|
.form-group
|
||||||
= f.label(:description)
|
= f.label(:description)
|
||||||
= f.pagedown :description, input_html: { preview: true, rows: 10 }
|
= f.pagedown :description, input_html: { preview: true, rows: 10 }
|
||||||
|
.form-check.mb-3
|
||||||
|
label.form-check-label
|
||||||
|
= f.check_box(:public, class: 'form-check-input')
|
||||||
|
= t('activerecord.attributes.exercise.public')
|
||||||
|
|
||||||
h3 Exercises
|
h3 Exercises
|
||||||
.table-responsive
|
.table-responsive
|
||||||
|
@ -11,13 +11,17 @@ h1 = ProxyExercise.model_name.human(count: 2)
|
|||||||
tr
|
tr
|
||||||
th.p-1 = sort_link(@search, :title, t('activerecord.attributes.proxy_exercise.title'))
|
th.p-1 = sort_link(@search, :title, t('activerecord.attributes.proxy_exercise.title'))
|
||||||
th.p-1 = t('activerecord.attributes.exercise.token')
|
th.p-1 = t('activerecord.attributes.exercise.token')
|
||||||
|
th.p-1 = t('activerecord.attributes.exercise.public')
|
||||||
th.p-1 = t('activerecord.attributes.proxy_exercise.files_count')
|
th.p-1 = t('activerecord.attributes.proxy_exercise.files_count')
|
||||||
th.p-1 colspan=6 = t('shared.actions')
|
th.p-1 colspan=6 = t('shared.actions')
|
||||||
tbody
|
tbody
|
||||||
- @proxy_exercises.each do |proxy_exercise|
|
- @proxy_exercises.each do |proxy_exercise|
|
||||||
tr data-id=proxy_exercise.id
|
tr data-id=proxy_exercise.id
|
||||||
td.p-1.pt-2 = link_to(proxy_exercise.title,proxy_exercise)
|
td.p-1.pt-2 = link_to(proxy_exercise.title,proxy_exercise)
|
||||||
td.p-1.pt-2 = proxy_exercise.token
|
td.p-1.pt-2
|
||||||
|
code
|
||||||
|
= proxy_exercise.token
|
||||||
|
td.p-1.pt-2.public data-value=proxy_exercise.public? = symbol_for(proxy_exercise.public?)
|
||||||
td.p-1.pt-2 = proxy_exercise.count_files
|
td.p-1.pt-2 = proxy_exercise.count_files
|
||||||
td.p-1.pt-2 = link_to(t('shared.edit'), edit_proxy_exercise_path(proxy_exercise)) if policy(proxy_exercise).edit?
|
td.p-1.pt-2 = link_to(t('shared.edit'), edit_proxy_exercise_path(proxy_exercise)) if policy(proxy_exercise).edit?
|
||||||
|
|
||||||
|
@ -11,9 +11,12 @@ h1
|
|||||||
= render('shared/edit_button', object: @proxy_exercise)
|
= render('shared/edit_button', object: @proxy_exercise)
|
||||||
|
|
||||||
= row(label: 'exercise.title', value: @proxy_exercise.title)
|
= row(label: 'exercise.title', value: @proxy_exercise.title)
|
||||||
|
= row(label: 'exercise.user', value: link_to_if(policy(@proxy_exercise.author).show?, @proxy_exercise.author, @proxy_exercise.author))
|
||||||
= row(label: 'proxy_exercise.files_count', value: @exercises.count)
|
= row(label: 'proxy_exercise.files_count', value: @exercises.count)
|
||||||
|
= row(label: 'exercise.public', value: @proxy_exercise.public?)
|
||||||
= row(label: 'exercise.description', value: @proxy_exercise.description)
|
= row(label: 'exercise.description', value: @proxy_exercise.description)
|
||||||
= row(label: 'exercise.token', value: @proxy_exercise.token)
|
= row(label: 'exercise.embedding_parameters', class: 'mb-4') do
|
||||||
|
= content_tag(:input, nil, class: 'form-control mb-4', readonly: true, value: embedding_parameters(@proxy_exercise))
|
||||||
|
|
||||||
h2.mt-4 Exercises
|
h2.mt-4 Exercises
|
||||||
.table-responsive
|
.table-responsive
|
||||||
|
9
db/migrate/20181119161514_add_user_to_proxy_exercise.rb
Normal file
9
db/migrate/20181119161514_add_user_to_proxy_exercise.rb
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class AddUserToProxyExercise < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_reference :proxy_exercises, :user, polymorphic: true, index: true
|
||||||
|
add_column :proxy_exercises, :public, :boolean, null: false, default: false
|
||||||
|
|
||||||
|
internal_user = InternalUser.find_by(id: 46) || InternalUser.first
|
||||||
|
ProxyExercise.update_all(user_id: internal_user.id, user_type: internal_user.class.name)
|
||||||
|
end
|
||||||
|
end
|
@ -263,6 +263,10 @@ ActiveRecord::Schema.define(version: 2018_11_29_093207) do
|
|||||||
t.string "token"
|
t.string "token"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.string "user_type"
|
||||||
|
t.bigint "user_id"
|
||||||
|
t.boolean "public"
|
||||||
|
t.index ["user_type", "user_id"], name: "index_proxy_exercises_on_user_type_and_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "remote_evaluation_mappings", force: :cascade do |t|
|
create_table "remote_evaluation_mappings", force: :cascade do |t|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :proxy_exercise, class: ProxyExercise do
|
factory :proxy_exercise, class: ProxyExercise do
|
||||||
|
created_by_teacher
|
||||||
token { 'dummytoken' }
|
token { 'dummytoken' }
|
||||||
title { 'Dummy' }
|
title { 'Dummy' }
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user