Implement index action. Repair destroy
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
class UserExerciseFeedbacksController < ApplicationController
|
||||
include CommonBehavior
|
||||
|
||||
before_action :set_user_exercise_feedback, only: [:edit, :update]
|
||||
before_action :set_user_exercise_feedback, only: [:show, :edit, :update]
|
||||
before_action :set_user_exercise_feedback_by_id, only: [:destroy]
|
||||
|
||||
def comment_presets
|
||||
[[0,t('user_exercise_feedback.difficulty_easy')],
|
||||
@ -19,10 +20,14 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
[4,t('user_exercise_feedback.estimated_time_more_30')]]
|
||||
end
|
||||
|
||||
def authorize!
|
||||
authorize(@uef)
|
||||
def index
|
||||
@uefs = UserExerciseFeedback.order(:id).paginate(page: params[:page])
|
||||
authorize!
|
||||
end
|
||||
|
||||
def show
|
||||
authorize!
|
||||
end
|
||||
private :authorize!
|
||||
|
||||
def create
|
||||
@exercise = Exercise.find(uef_params[:exercise_id])
|
||||
@ -49,7 +54,8 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
end
|
||||
|
||||
def destroy
|
||||
destroy_and_respond(object: @tag)
|
||||
authorize!
|
||||
destroy_and_respond(object: @uef)
|
||||
end
|
||||
|
||||
def edit
|
||||
@ -58,11 +64,6 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
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
|
||||
@ -89,6 +90,12 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def authorize!
|
||||
authorize(@uef || @uefs)
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
@ -98,6 +105,14 @@ class UserExerciseFeedbacksController < ApplicationController
|
||||
@uef = UserExerciseFeedback.find_by(exercise_id: params[:user_exercise_feedback][:exercise_id], user: current_user)
|
||||
end
|
||||
|
||||
def set_user_exercise_feedback_by_id
|
||||
@uef = UserExerciseFeedback.find(params[:id])
|
||||
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
|
||||
|
||||
def validate_inputs(uef_params)
|
||||
begin
|
||||
if uef_params[:difficulty].to_i < 0 || uef_params[:difficulty].to_i >= comment_presets.size
|
||||
|
@ -1,8 +1,4 @@
|
||||
class UserExerciseFeedbackPolicy < ApplicationPolicy
|
||||
def author?
|
||||
@user == @record.author
|
||||
end
|
||||
private :author?
|
||||
class UserExerciseFeedbackPolicy < AdminOrAuthorPolicy
|
||||
|
||||
def create?
|
||||
everyone
|
||||
@ -12,8 +8,4 @@ class UserExerciseFeedbackPolicy < ApplicationPolicy
|
||||
everyone
|
||||
end
|
||||
|
||||
[:show? ,:destroy?, :edit?, :update?].each do |action|
|
||||
define_method(action) { admin? || author?}
|
||||
end
|
||||
|
||||
end
|
||||
|
19
app/views/user_exercise_feedbacks/index.html.slim
Normal file
19
app/views/user_exercise_feedbacks/index.html.slim
Normal file
@ -0,0 +1,19 @@
|
||||
h1 = UserExerciseFeedback.model_name.human(count: 2)
|
||||
|
||||
.table-responsive
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
th colspan=2 = t('activerecord.attributes.user_exercise_feedback.user')
|
||||
th = t('activerecord.attributes.user_exercise_feedback.exercise')
|
||||
th colspan=2 = t('shared.actions')
|
||||
tbody
|
||||
- @uefs.each do |uef|
|
||||
tr
|
||||
td = uef.user.id
|
||||
td = uef.user.name
|
||||
td = link_to(uef.exercise.title, uef.exercise)
|
||||
td = link_to(t('shared.show'), uef)
|
||||
td = link_to(t('shared.destroy'), uef, data: {confirm: t('shared.confirm_destroy')}, method: :delete)
|
||||
|
||||
= render('shared/pagination', collection: @uefs)
|
@ -116,6 +116,9 @@ de:
|
||||
name: "Name"
|
||||
updated_at: "Letzte Änderung"
|
||||
exercises: "Aufgaben"
|
||||
user_exercise_feedback:
|
||||
user: "Autor"
|
||||
exercise: "Aufgabe"
|
||||
models:
|
||||
code_harbor_link:
|
||||
one: CodeHarbor-Link
|
||||
|
@ -116,6 +116,9 @@ en:
|
||||
name: "Name"
|
||||
updated_at: "Last Update"
|
||||
exercises: "Exercises"
|
||||
user_exercise_feedback:
|
||||
user: "Author"
|
||||
exercise: "Exercise"
|
||||
models:
|
||||
code_harbor_link:
|
||||
one: CodeHarbor Link
|
||||
|
Reference in New Issue
Block a user