diff --git a/app/controllers/user_exercise_feedbacks_controller.rb b/app/controllers/user_exercise_feedbacks_controller.rb new file mode 100644 index 00000000..445b1a83 --- /dev/null +++ b/app/controllers/user_exercise_feedbacks_controller.rb @@ -0,0 +1,42 @@ +class UserExerciseFeedbackController < ApplicationController + include CommonBehavior + + def authorize! + authorize(@uef) + end + private :authorize! + + def create + @tag = Tag.new(tag_params) + authorize! + create_and_respond(object: @tag) + end + + def destroy + destroy_and_respond(object: @tag) + end + + def edit + end + + def uef_params + params[:tag].permit(:feedback_text, :difficulty) + end + private :uef_params + + def new + @uef = UserExerciseFeedback.new + authorize! + end + + def show + end + + def update + update_and_respond(object: @UserExerciseFeedback, params: uef_params) + end + + def to_s + name + 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..8325b9fa --- /dev/null +++ b/app/policies/user_exercise_feedback_policy.rb @@ -0,0 +1,34 @@ +class TagPolicy < AdminOrAuthorPolicy + def author? + @user == @record.author + end + private :author? + + def batch_update? + admin? + end + + def show? + @user.internal_user? + end + + [:clone?, :destroy?, :edit?, :update?].each do |action| + define_method(action) { admin? || author?} + 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 diff --git a/app/views/user_exercise_feedbacks/_form.html.slim b/app/views/user_exercise_feedbacks/_form.html.slim new file mode 100644 index 00000000..60bde323 --- /dev/null +++ b/app/views/user_exercise_feedbacks/_form.html.slim @@ -0,0 +1,8 @@ += form_for(@uef) do |f| + = render('shared/form_errors', object: @uef) + .form-group + = f.label(:feedback_text) + = f.text_field(:feedback_text, class: 'form-control', required: true) + = f.label(:difficulty) + = f.text_field(:difficulty, class: 'form-control', required: true) + .actions = render('shared/submit_button', f: f, object: @uef) diff --git a/app/views/user_exercise_feedbacks/new.html.slim b/app/views/user_exercise_feedbacks/new.html.slim new file mode 100644 index 00000000..7abfbd34 --- /dev/null +++ b/app/views/user_exercise_feedbacks/new.html.slim @@ -0,0 +1,3 @@ +h1 = t('shared.new_model', model: UserExerciseFeedback.model_name.human) + += render('form') diff --git a/config/locales/en.yml b/config/locales/en.yml index 853c703f..eeadb83a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -546,4 +546,9 @@ en: previous_label: '← Previous Page' file_template: no_template_label: "Empty File" + user_exercise_feedback: + easy: "it was easy" + some_what_easy: "it was somewhat easy" + some_what_difficult: "it was somewhat difficult" + difficult: "difficult" diff --git a/config/routes.rb b/config/routes.rb index a88a4c3d..281af37c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,6 +86,13 @@ Rails.application.routes.draw do end end + resources :user_exercise_feedbacks do + member do + get :reload + post :submit + end + end + resources :interventions do member do post :clone diff --git a/db/migrate/20170411090543_improve_user_feedback.rb b/db/migrate/20170411090543_improve_user_feedback.rb new file mode 100644 index 00000000..4050ee3a --- /dev/null +++ b/db/migrate/20170411090543_improve_user_feedback.rb @@ -0,0 +1,6 @@ +class ImproveUserFeedback < ActiveRecord::Migration + def change + remove_column :user_exercise_feedbacks, :difficulty + add_column :user_exercise_feedbacks, :difficulty, :string + end +end