diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb
index 8af8bb8e..337cb9d4 100644
--- a/app/controllers/exercises_controller.rb
+++ b/app/controllers/exercises_controller.rb
@@ -380,8 +380,12 @@ class ExercisesController < ApplicationController
if @submission.normalized_score == 1.0
# if user is external and has an own rfc, redirect to it and message him to clean up and accept the answer. (we need to check that the user is external,
# otherwise an internal user could be shown a false rfc here, since current_user.id is polymorphic, but only makes sense for external users when used with rfcs.)
+ # redirect 10 percent pseudorandomly to the feedback page
if current_user.respond_to? :external_id
- if rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise, user_id: current_user.id).first
+ if ((current_user.id + @submission.exercise.created_at.to_i) % 10 == 1)
+ redirect_to_user_feedback
+ return
+ elsif rfc = RequestForComment.unsolved.where(exercise_id: @submission.exercise, user_id: current_user.id).first
# set a message that informs the user that his own RFC should be closed.
flash[:notice] = I18n.t('exercises.submit.full_score_redirect_to_own_rfc')
flash.keep(:notice)
@@ -405,8 +409,25 @@ class ExercisesController < ApplicationController
return
end
end
+ else
+ # redirect to feedback page if score is less than 100 percent
+ redirect_to_user_feedback
+ return
end
redirect_to_lti_return_path
end
+ def redirect_to_user_feedback
+ url = if UserExerciseFeedback.find_by(exercise: @exercise, user: current_user)
+ edit_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id})
+ else
+ new_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id})
+ end
+
+ respond_to do |format|
+ format.html { redirect_to(url) }
+ format.json { render(json: {redirect: url}) }
+ end
+ end
+
end
diff --git a/app/controllers/user_exercise_feedbacks_controller.rb b/app/controllers/user_exercise_feedbacks_controller.rb
new file mode 100644
index 00000000..0d1e1925
--- /dev/null
+++ b/app/controllers/user_exercise_feedbacks_controller.rb
@@ -0,0 +1,115 @@
+class UserExerciseFeedbacksController < ApplicationController
+ include CommonBehavior
+
+ before_action :set_user_exercise_feedback, only: [:edit, :update]
+
+ def comment_presets
+ [[0,t('user_exercise_feedback.difficulty_easy')],
+ [1,t('user_exercise_feedback.difficulty_some_what_easy')],
+ [2,t('user_exercise_feedback.difficulty_ok')],
+ [3,t('user_exercise_feedback.difficulty_some_what_difficult')],
+ [4,t('user_exercise_feedback.difficult_too_difficult')]]
+ end
+
+ def time_presets
+ [[0,t('user_exercise_feedback.estimated_time_less_5')],
+ [1,t('user_exercise_feedback.estimated_time_5_to_10')],
+ [2,t('user_exercise_feedback.estimated_time_10_to_20')],
+ [3,t('user_exercise_feedback.estimated_time_20_to_30')],
+ [4,t('user_exercise_feedback.estimated_time_more_30')]]
+ end
+
+ def authorize!
+ authorize(@uef)
+ end
+ private :authorize!
+
+ def create
+ @exercise = Exercise.find(uef_params[:exercise_id])
+ rfc = RequestForComment.unsolved.where(exercise_id: @exercise.id, user_id: current_user.id).first
+ submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first rescue nil
+
+ if @exercise
+ @uef = UserExerciseFeedback.new(uef_params)
+ if validate_inputs(uef_params)
+ authorize!
+ path =
+ if rfc && submission && submission.normalized_score == 1.0
+ request_for_comment_path(rfc)
+ else
+ implement_exercise_path(@exercise)
+ end
+ create_and_respond(object: @uef, path: proc{path})
+ else
+ flash[:danger] = t('shared.message_failure')
+ redirect_to(:back, id: uef_params[:exercise_id])
+ end
+ end
+
+ end
+
+ def destroy
+ destroy_and_respond(object: @tag)
+ end
+
+ def edit
+ @texts = comment_presets.to_a
+ @times = time_presets.to_a
+ authorize!
+ end
+
+ def uef_params
+ params[:user_exercise_feedback].permit(:feedback_text, :difficulty, :exercise_id, :user_estimated_worktime).merge(user_id: current_user.id, user_type: current_user.class.name)
+ end
+ private :uef_params
+
+ def new
+ @texts = comment_presets.to_a
+ @times = time_presets.to_a
+ @uef = UserExerciseFeedback.new
+ @exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
+ authorize!
+ end
+
+ def update
+ submission = current_user.submissions.where(exercise_id: @exercise.id).order('created_at DESC').first rescue nil
+ rfc = RequestForComment.unsolved.where(exercise_id: @exercise.id, user_id: current_user.id).first
+ authorize!
+ if @exercise && validate_inputs(uef_params)
+ path =
+ if rfc && submission && submission.normalized_score == 1.0
+ request_for_comment_path(rfc)
+ else
+ implement_exercise_path(@exercise)
+ end
+ update_and_respond(object: @uef, params: uef_params, path: path)
+ else
+ flash[:danger] = t('shared.message_failure')
+ redirect_to(:back, id: uef_params[:exercise_id])
+ end
+ end
+
+ def to_s
+ name
+ end
+
+ def set_user_exercise_feedback
+ @exercise = Exercise.find(params[:user_exercise_feedback][:exercise_id])
+ @uef = UserExerciseFeedback.find_by(exercise_id: params[:user_exercise_feedback][:exercise_id], user: current_user)
+ end
+
+ def validate_inputs(uef_params)
+ begin
+ if uef_params[:difficulty].to_i < 0 || uef_params[:difficulty].to_i >= comment_presets.size
+ return false
+ elsif uef_params[:user_estimated_worktime].to_i < 0 || uef_params[:user_estimated_worktime].to_i >= time_presets.size
+ return false
+ else
+ return true
+ end
+ rescue
+ return false
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/user_exercise_feedback.rb b/app/models/user_exercise_feedback.rb
index d3ec09d5..78d84972 100644
--- a/app/models/user_exercise_feedback.rb
+++ b/app/models/user_exercise_feedback.rb
@@ -1,8 +1,11 @@
class UserExerciseFeedback < ActiveRecord::Base
+ include Creation
- belongs_to :user, polymorphic: true
belongs_to :exercise
validates :user_id, uniqueness: { scope: [:exercise_id, :user_type] }
+ def to_s
+ "User Exercise Feedback"
+ end
end
\ No newline at end of file
diff --git a/app/policies/user_exercise_feedback_policy.rb b/app/policies/user_exercise_feedback_policy.rb
new file mode 100644
index 00000000..20a89a6e
--- /dev/null
+++ b/app/policies/user_exercise_feedback_policy.rb
@@ -0,0 +1,19 @@
+class UserExerciseFeedbackPolicy < ApplicationPolicy
+ def author?
+ @user == @record.author
+ end
+ private :author?
+
+ def create?
+ everyone
+ end
+
+ def new?
+ everyone
+ end
+
+ [:show? ,:destroy?, :edit?, :update?].each do |action|
+ define_method(action) { admin? || author?}
+ end
+
+end
diff --git a/app/views/exercises/_comment_exercise_dialogcontent.html.slim b/app/views/exercises/_comment_exercise_dialogcontent.html.slim
deleted file mode 100644
index 89d1fd41..00000000
--- a/app/views/exercises/_comment_exercise_dialogcontent.html.slim
+++ /dev/null
@@ -1,5 +0,0 @@
-h5 =t('exercises.implement.comment.addComment')
-textarea#commentOnExercise.form-control(style='resize:none;')
-
-p=''
-button#addCommentExerciseButton.btn.btn-block.btn-primary(type='button') =t('exercises.implement.comment.addCommentButton')
diff --git a/app/views/request_for_comments/show.html.erb b/app/views/request_for_comments/show.html.erb
index 57c48828..ffc7f661 100644
--- a/app/views/request_for_comments/show.html.erb
+++ b/app/views/request_for_comments/show.html.erb
@@ -20,7 +20,6 @@
<%= t('activerecord.attributes.request_for_comments.question')%>: <%= t('request_for_comments.no_question') %>
<% end %>
-
<% if (policy(@request_for_comment).mark_as_solved? and not @request_for_comment.solved?) %>
@@ -62,7 +61,6 @@ also, all settings from the rails model needed for the editor configuration in t
<% end %>
<%= render('shared/modal', id: 'comment-modal', title: t('exercises.implement.comment.dialogtitle'), template: 'exercises/_comment_dialogcontent') %>
-<%= render('shared/modal', id: 'comment-exercise-modal', title: t('exercises.implement.comment.addCommentExercise'), template: 'exercises/_comment_exercise_dialogcontent') %>