fixed response in order to redirect correctly on ajax requests. Fixed policy
This commit is contained in:
@ -411,17 +411,22 @@ class ExercisesController < ApplicationController
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
# redirect to feedback page if score is less than 100 percent
|
# redirect to feedback page if score is less than 100 percent
|
||||||
redirect_to_user_feedback
|
redirect_to_user_feedback
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
redirect_to_lti_return_path
|
redirect_to_lti_return_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_to_user_feedback
|
def redirect_to_user_feedback
|
||||||
if UserExerciseFeedback.find_by(exercise: @exercise, user: current_user)
|
url = if UserExerciseFeedback.find_by(exercise: @exercise, user: current_user)
|
||||||
redirect_to(edit_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id}))
|
edit_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id})
|
||||||
else
|
else
|
||||||
redirect_to(new_user_exercise_feedback_path(user_exercise_feedback: {exercise_id: @exercise.id}))
|
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
|
end
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
class UserExerciseFeedback < ActiveRecord::Base
|
class UserExerciseFeedback < ActiveRecord::Base
|
||||||
|
include Creation
|
||||||
|
|
||||||
belongs_to :user, polymorphic: true
|
|
||||||
belongs_to :exercise
|
belongs_to :exercise
|
||||||
|
|
||||||
validates :user_id, uniqueness: { scope: [:exercise_id, :user_type] }
|
validates :user_id, uniqueness: { scope: [:exercise_id, :user_type] }
|
||||||
|
@ -1,38 +1,19 @@
|
|||||||
class UserExerciseFeedbackPolicy < AdminOrAuthorPolicy
|
class UserExerciseFeedbackPolicy < ApplicationPolicy
|
||||||
def author?
|
def author?
|
||||||
@user == @record.author
|
@user == @record.author
|
||||||
end
|
end
|
||||||
private :author?
|
private :author?
|
||||||
|
|
||||||
def batch_update?
|
|
||||||
admin?
|
|
||||||
end
|
|
||||||
|
|
||||||
def create?
|
def create?
|
||||||
everyone
|
everyone
|
||||||
end
|
end
|
||||||
|
|
||||||
def show?
|
def new?
|
||||||
@user.internal_user?
|
everyone
|
||||||
end
|
end
|
||||||
|
|
||||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
[:show? ,:destroy?, :edit?, :update?].each do |action|
|
||||||
define_method(action) { admin? || author?}
|
define_method(action) { admin? || author?}
|
||||||
end
|
end
|
||||||
|
|
||||||
[:reload?].each do |action|
|
|
||||||
define_method(action) { everyone }
|
|
||||||
end
|
|
||||||
|
|
||||||
class Scope < Scope
|
|
||||||
def resolve
|
|
||||||
if @user.admin?
|
|
||||||
@scope.all
|
|
||||||
elsif @user.internal_user?
|
|
||||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
|
||||||
else
|
|
||||||
@scope.none
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user