Verified Commit a35a2aa7 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻
Browse files

add take responsibility action to feedback and list_response_feedback

parent 0b62a3ed
class FeedbacksController < ApplicationController
before_action :set_feedback, only: [:show, :edit, :update, :destroy, :mark_as_done]
before_action :set_feedback,
only: [:show, :edit, :update, :destroy, :mark_as_done, :take_responsibility]
before_action :set_feedbackable
before_action :set_volunteer
......@@ -53,6 +54,13 @@ class FeedbacksController < ApplicationController
redirect_to(redirect_path, notice: 'Halbjahres-Rapport quittiert.')
else
redirect_to(redirect_path, notice: 'Fehler: Quittieren fehlgeschlagen.')
end
def take_responsibility
if @feedback.update(responsible: current_user)
redirect_to(@redirect_back_path, notice: 'Halbjahres-Rapport übernommen.')
else
redirect_to(@redirect_back_path, notice: 'Fehler: Übernehmen fehlgeschlagen.')
end
end
......
......@@ -7,6 +7,8 @@ class Feedback < ApplicationRecord
belongs_to :author, class_name: 'User', inverse_of: 'feedbacks'
belongs_to :reviewer, class_name: 'User', foreign_key: 'reviewer_id',
inverse_of: 'reviewed_feedbacks', optional: true
belongs_to :responsible, class_name: 'User', foreign_key: 'responsible_id',
inverse_of: 'responsible_feedbacks', optional: true
belongs_to :feedbackable, polymorphic: true, optional: true
scope :assignment, (-> { where(feedbackable_type: 'Assignment') })
......@@ -18,6 +20,11 @@ class Feedback < ApplicationRecord
group_offer.where(feedbackable_id: group_offer_ids)
}
def responsible=(responsible_user)
self.responsible_at = Time.zone.now
super(responsible_user)
end
def assignment?
feedbackable_type == 'Assignment'
end
......
......@@ -38,6 +38,8 @@ class User < ApplicationRecord
has_many :reminder_mailings, inverse_of: 'creator', foreign_key: 'creator_id'
has_many :reviewed_feedbacks, class_name: 'Feedback', foreign_key: 'reviewer_id',
inverse_of: 'reviewer'
has_many :responsible_feedbacks, inverse_of: 'responsible', foreign_key: 'responsible_id',
class_name: 'Feedback'
has_many :reviewed_trial_feedbacks, class_name: 'TrialFeedback', foreign_key: 'reviewer_id',
inverse_of: 'reviewer'
has_many :reviewed_hours, class_name: 'Hour', foreign_key: 'reviewer_id', inverse_of: 'reviewer'
......
......@@ -6,12 +6,13 @@ class FeedbackPolicy < ApplicationPolicy
end
end
alias_method :index?, :superadmin_or_volunteer?
alias_method :new?, :superadmin_or_volunteers_feedback?
alias_method :show?, :superadmin_or_volunteers_feedback?
alias_method :edit?, :superadmin_or_volunteers_feedback?
alias_method :create?, :superadmin_or_volunteers_feedback?
alias_method :update?, :superadmin_or_volunteers_feedback?
alias_method :destroy?, :superadmin_or_volunteers_feedback?
alias_method :mark_as_done?, :superadmin?
alias_method :index?, :superadmin_or_volunteer?
alias_method :new?, :superadmin_or_volunteers_feedback?
alias_method :show?, :superadmin_or_volunteers_feedback?
alias_method :edit?, :superadmin_or_volunteers_feedback?
alias_method :create?, :superadmin_or_volunteers_feedback?
alias_method :update?, :superadmin_or_volunteers_feedback?
alias_method :destroy?, :superadmin_or_volunteers_feedback?
alias_method :mark_as_done?, :superadmin?
alias_method :take_responsibility?, :superadmin?
end
......@@ -27,6 +27,7 @@ table.table.table-striped.list-responses-table
th= t_attr(:comments, Feedback)
th.limit-width= sort_link @q, :conversation, 'Gespräch'
th= sort_link @q, :created_at, 'Datum'
th= sort_link @q, :responsible, 'Übernommen'
th.limit-width
tbody
......@@ -58,6 +59,15 @@ table.table.table-striped.list-responses-table
span
= "Angeschaut von: "
= link_to record.reviewer.email, record.reviewer
td.index-action-cell.hidden-print
- if record.responsible.present?
= 'Übernommen durch '
= link_to record.responsible.email, record.responsible
= " am #{l(record.responsible_at.to_date)}"
- else
= link_to 'Übernehmen', polymorphic_path([record.volunteer, record.feedbackable, record],
action: :take_responsibility, q: search_parameters, page: params[:page]),
{ method: :put, class: 'btn btn-default btn-xs m-t-10' }
td.index-action-cell.hidden-print
- if record.reviewer.present?
= link_to 'Anzeigen', polymorphic_path([record.volunteer, record.feedbackable, record])
......
......@@ -8,8 +8,9 @@ Rails.application.routes.draw do
get :hours_and_feedbacks_submitted, on: :collection
end
concern :mark_submitted_at do
concern :feedback_submit_and_responsibility do
put :mark_as_done, on: :member
put :take_responsibility, on: :member
end
concern :hours_resources do
......@@ -22,8 +23,8 @@ Rails.application.routes.draw do
concern :assignment_feedbacks do
resources :hours
resources :feedbacks, concerns: :mark_submitted_at
resources :trial_feedbacks, concerns: :mark_submitted_at
resources :feedbacks, concerns: :feedback_submit_and_responsibility
resources :trial_feedbacks, concerns: :feedback_submit_and_responsibility
end
concern :termination_actions do
......
class AddResponsibleToFeedbak < ActiveRecord::Migration[5.1]
def change
change_table :feedbacks do |t|
t.references :responsible, references: :users
t.datetime :responsible_at
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180607142252) do
ActiveRecord::Schema.define(version: 20180704073944) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -311,9 +311,12 @@ ActiveRecord::Schema.define(version: 20180607142252) do
t.string "feedbackable_type"
t.bigint "feedbackable_id"
t.bigint "reviewer_id"
t.bigint "responsible_id"
t.datetime "responsible_at"
t.index ["author_id"], name: "index_feedbacks_on_author_id"
t.index ["deleted_at"], name: "index_feedbacks_on_deleted_at"
t.index ["feedbackable_type", "feedbackable_id"], name: "index_feedbacks_on_feedbackable_type_and_feedbackable_id"
t.index ["responsible_id"], name: "index_feedbacks_on_responsible_id"
t.index ["reviewer_id"], name: "index_feedbacks_on_reviewer_id"
t.index ["volunteer_id"], name: "index_feedbacks_on_volunteer_id"
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment