Commit d63c1b86 authored by Jiri Strojil's avatar Jiri Strojil

Initial cleanup

parent a19b58ff
Pipeline #33443 failed with stage
in 34 minutes and 48 seconds
......@@ -11,7 +11,6 @@ class JournalsController < ApplicationController
def new
@journal = @journaled.journals.new
handle_feedback_quote
handle_semester_feedback_quote
authorize @journal
end
......@@ -58,17 +57,6 @@ class JournalsController < ApplicationController
@journaled = Volunteer.find(params[:volunteer_id])
end
def handle_feedback_quote
return unless params[:feedback_id]
@feedback = Feedback.find_by(id: params[:feedback_id])
return unless @feedback
@journal.category = :feedback
@journal.title = "Feedback vom #{I18n.l(@feedback.created_at.to_date)}: "
@journal.body = @feedback.slice(:goals, :achievements, :future, :comments).map do |key, fb_quote|
"#{I18n.t("activerecord.attributes.feedback.#{key}")}:\n«#{fb_quote}»" if fb_quote.present?
end.compact.join("\n\n")
end
def handle_semester_feedback_quote
return unless params[:semester_feedback_id]
@semester_feedback = SemesterFeedback.find_by(id: params[:semester_feedback_id])
......
class ListResponsesController < ApplicationController
before_action { set_default_filter(author_volunteer: 'true', reviewer_id_null: 'true') }
def feedbacks
authorize :list_response
@q = Feedback.created_asc.author_volunteer(params[:q]).ransack(params[:q])
@q.sorts = ['updated_at asc'] if @q.sorts.empty?
@feedbacks = @q.result.paginate(page: params[:page])
set_responsibles
end
def trial_feedbacks
authorize :list_response
@q = TrialFeedback.created_asc.author_volunteer(params[:q]).ransack(params[:q])
@q.sorts = ['updated_at asc'] if @q.sorts.empty?
@trial_feedbacks = @q.result.paginate(page: params[:page])
end
private
def set_responsibles
@responsibles = Feedback.joins(responsible: [profile: [:contact]])
.distinct
.select('users.id, contacts.full_name')
.map do |responsible|
{
q: :responsible_id_eq,
text: "Übernommen von #{responsible.full_name}",
value: responsible.id
}
end
end
end
class Feedback < ApplicationRecord
include FeedbackTrialFeedbackCommon
attr_reader :feedbackable_id_and_type
belongs_to :volunteer
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') })
scope :group_offer, (-> { where(feedbackable_type: 'GroupOffer') })
scope :from_assignments, lambda { |assignment_ids|
assignment.where(feedbackable_id: assignment_ids)
}
scope :from_group_offers, lambda { |group_offer_ids|
group_offer.where(feedbackable_id: group_offer_ids)
}
# READ ONLY MODEL
before_save { false }
def responsible=(responsible_user)
self.responsible_at = Time.zone.now
super(responsible_user)
end
def assignment?
feedbackable_type == 'Assignment'
end
def group_offer?
feedbackable_type == 'GroupOffer'
end
def feedbackable_id_and_type=(id_and_type)
self.feedbackable_id, self.feedbackable_type = id_and_type.split(',', 2)
end
def feedbackable_id_and_type
"#{feedbackable_id},#{feedbackable_type}"
end
end
......@@ -7,7 +7,6 @@ class GroupAssignment < ApplicationRecord
has_many :group_assignment_logs
has_many :hours, ->(object) { where(volunteer: object.volunteer) }, through: :group_offer
has_many :feedbacks, ->(object) { where(volunteer: object.volunteer) }, through: :group_offer
delegate :title, to: :group_offer
......@@ -45,10 +44,6 @@ class GroupAssignment < ApplicationRecord
hours.since_last_submitted(submitted_at)
end
def feedbacks_since_last_submitted
feedbacks.since_last_submitted(submitted_at)
end
def polymorph_url_object
group_offer
end
......
......@@ -22,7 +22,6 @@ class GroupOffer < ApplicationRecord
has_many :group_assignment_logs
has_many :hours, as: :hourable, dependent: :destroy, inverse_of: :hourable
has_many :feedbacks, as: :feedbackable, dependent: :destroy, inverse_of: :feedbackable
has_many :trial_feedbacks, as: :trial_feedbackable, inverse_of: :trial_feedbackable,
dependent: :destroy
......
......@@ -41,7 +41,7 @@ class PerformanceReport < ApplicationRecord
only_assignment_active = assignment_active - active_both
active_total = assignment_active + group_active
hours = Hour.date_between(:meeting_date, *periods).where(volunteer_id: volunteers.ids)
feedbacks = Feedback.created_between(*periods).where(volunteer_id: volunteers.ids)
feedbacks = SemesterFeedback.created_between(*periods).where(volunteer_id: volunteers.ids)
trial_feedbacks = TrialFeedback.created_between(*periods).where(volunteer_id: volunteers.ids)
event_volunteers = EventVolunteer
......@@ -65,8 +65,6 @@ class PerformanceReport < ApplicationRecord
group_offer_hour_records: hours.group_offer.count,
group_offer_hours: hours.group_offer.total_hours,
total_hours: hours.total_hours,
assignment_feedbacks: feedbacks.assignment.count,
group_offer_feedbacks: feedbacks.group_offer.count,
total_feedbacks: feedbacks.count,
assignment_trial_feedbacks: trial_feedbacks.assignment.count,
group_offer_trial_feedbacks: trial_feedbacks.group_offer.count,
......@@ -136,7 +134,7 @@ class PerformanceReport < ApplicationRecord
started_ga = group_assignments.start_within(*periods)
ended_ga = group_assignments.end_within(*periods)
created_ga = group_assignments.created_between(*periods)
feedbacks = Feedback.created_between(*periods).from_group_offers(group_offers.ids)
feedbacks = SemesterFeedback.created_between(*periods).from_group_offers(group_offers.ids)
{
all: group_offers.count,
created: group_offers.created_after(periods.first).count,
......
......@@ -35,7 +35,6 @@ class Volunteer < ApplicationRecord
has_many :departments, through: :group_offers
has_many :hours, dependent: :destroy
has_many :feedbacks, dependent: :destroy
has_many :certificates
......
......@@ -8,11 +8,4 @@ class FeedbackPolicy < ApplicationPolicy
alias_method :index?, :superadmin_or_volunteer?
alias_method :show?, :superadmin_or_feedback_about_volunteer?
alias_method :edit?, :superadmin_or_feedback_about_volunteer?
alias_method :update?, :superadmin_or_feedback_about_volunteer?
alias_method :new?, :superadmin_or_volunteers_feedback?
alias_method :create?, :superadmin_or_volunteers_feedback?
alias_method :destroy?, :superadmin_or_volunteers_feedback?
alias_method :mark_as_done?, :superadmin?
alias_method :take_responsibility?, :superadmin?
end
class ListResponsePolicy < ApplicationPolicy
alias_method :feedbacks?, :superadmin?
alias_method :trial_feedbacks?, :superadmin?
end
h1= t_title(:edit)
= render 'form'
= bootstrap_row_col { button_link icon_span(:back), @volunteer }
h1= t_title(:new)
= render 'form'
= bootstrap_row_col { button_link icon_span(:back), default_redirect || @volunteer || :back }
= render 'reminder_mailings/section_navigation'
h1 Eingereichte Halbjahres-Rapporte
nav.navbar.section-navigation.hidden-print
ul.list-inline
li= clear_filter_button
= custom_filter_dropdown('Geprüft',
{ q: :reviewer_id_not_null, text: 'Quittiert', value: 'true' },
{ q: :reviewer_id_null, text: 'Unquittiert', value: 'true' })
= custom_filter_dropdown('Übernommen',
{ q: :responsible_id_null, text: 'Offen', value: 'true' },
{ q: :responsible_id_not_null, text: 'Übernommen', value: 'true' },
*@responsibles)
= custom_filter_dropdown('Autor',
{ q: :author_volunteer, text: 'Freiwillige/r', value: 'true' },
{ q: :author_volunteer, text: 'AOZ', value: 'false' })
= bootstrap_paginate(@feedbacks)
table.table.table-striped.list-responses-table
thead
tr
th.limit-width Journal / Stunden
th.limit-width= sort_link @q, :volunteer_contact_full_name, 'Freiwillige/r'
th.limit-width Einsatz
th= sort_link @q, :author_profile_contact_full_name, 'Autor/in'
th Ziele
th Erfolge
th Zukunft
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
- @feedbacks.each do |record|
tr*{ data: { feedback_id: record.id } }
td.index-action-cell
= button_link icon_span(:journal), volunteer_journals_path(record.volunteer), title: 'Journal'
= button_link icon_span(:journal_new), new_volunteer_journal_path(record.volunteer, feedback_id: record.id),
title: 'Neuen Journal eintrag mit Zitat erstellen'
= button_link icon_span(:hours), volunteer_hours_path(record.volunteer), title: 'Stunden'
td.index-action-cell
a href="#{url_for(record.feedbackable)}" title="#{record.feedbackable.to_label}"
- record.feedbackable.label_parts.reject(&:blank?).each do |label_part|
span= label_part.truncate(30)
td
- if record.author.volunteer?
= link_to record.volunteer.contact.full_name, record.volunteer
- else
= link_to record.author.profile.contact.natural_name, record.author.profile
td= record.goals
= td_truncate_content_modal(record.achievements, 'Erfolge', shorten_size: 300)
= td_truncate_content_modal(record.future, 'Zukunft', shorten_size: 300)
= td_truncate_content_modal(record.comments, t_attr(:comments, Feedback), shorten_size: 300)
td= t(record.conversation)
td.index-action-cell
span= I18n.l record.created_at.to_date
- if record.reviewer.present?
span Quittiert 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
= api_button('Übernehmen', subject: [record.volunteer, record.feedbackable, record],
action: :take_responsibility, extra_class: 'm-t-10',
template: 'Übernommen durch <a href="<%= data.link %>"><%= data.email %></a> am <%= data.at %>')
td.index-action-cell.hidden-print
- if record.reviewer.present?
= link_to 'Anzeigen', polymorphic_path([record.volunteer, record.feedbackable, record])
- else
= api_button 'Quittieren', subject: [record.volunteer, record.feedbackable, record],
action: :mark_as_done, extra_class: 'm-t-10',
template: '<a href="<%= data.link %>">Anzeigen</a>'
= bootstrap_paginate(@feedbacks)
nav.navbar.section-navigation.hidden-print
ul.section-nav-ul.list-unstyled
li= section_nav_button 'Probezeit Feedback Eingang', list_responses_trial_feedbacks_path
li= section_nav_button 'Halbjahres-Rapport Eingang', list_responses_feedbacks_path
li= section_nav_button 'Halbjahres-Rapport Eingang', semester_process_volunteers_path
li= section_nav_button 'Probezeit Erinnerung erstellen', new_trial_period_reminder_mailings_path
li= section_nav_button 'Halbjahres Erinnerung erstellen', new_half_year_reminder_mailings_path
li= section_nav_button 'Versandte Erinnerungen', reminder_mailings_path
......
......@@ -67,8 +67,6 @@ Rails.application.routes.draw do
resources :event_volunteers, only: [:create, :destroy]
end
resources :feedbacks, only: [:new, :create]
resources :group_assignments, only: [:show, :create, :edit, :update],
concerns: [:submit_feedback, :termination_actions] do
put :set_end_today, on: :member
......@@ -84,7 +82,6 @@ Rails.application.routes.draw do
get :search_volunteer, on: :member
end
get 'list_responses/feedbacks', to: 'list_responses#feedbacks'
get 'list_responses/trial_feedbacks', to: 'list_responses#trial_feedbacks'
resources :profiles, except: [:destroy, :index]
......
FactoryBot.define do
factory :feedback do
association :feedbackable, factory: :assignment
volunteer
association :author, factory: :user
goals { FFaker::Lorem.words(4).join(', ') }
achievements { FFaker::Lorem.sentence }
future { FFaker::Lorem.sentence }
comments { FFaker::Lorem.paragraph }
conversation false
after(:build) do |feedback|
if feedback.volunteer.present? && feedback.feedbackable.blank?
feedback.volunteer.user = create(:user_volunteer) if feedback.volunteer.user.blank?
feedback.feedbackable = create(:assignment, volunteer: feedback.volunteer)
elsif feedback.volunteer.blank? && feedback.feedbackable.present?
feedback.volunteer = feedback.feedbackable.volunteer
elsif feedback.volunteer.blank? && feedback.feedbackable.blank?
feedback.volunteer = create(:volunteer)
feedback.feedbackable = create(:assignment, volunteer: feedback.volunteer)
end
feedback.author ||= feedback.volunteer&.user || create(:user)
end
end
end
require 'test_helper'
class FeedbackTest < ActiveSupport::TestCase
test 'since_last_submitted_scope' do
volunteer = create :volunteer
assignment = create :assignment, volunteer: volunteer
feedback = create :feedback, feedbackable: assignment, volunteer: volunteer,
author: volunteer.user
feedback_by_superadmin = create :feedback, feedbackable: assignment, volunteer: volunteer,
author: create(:user)
assignment_last_submitted = create :assignment, volunteer: volunteer,
submitted_at: 6.months.ago
before_last_submitted_feedback = create :feedback, volunteer: volunteer, author: volunteer.user,
feedbackable: assignment_last_submitted
before_last_submitted_feedback.update(created_at: 8.months.ago, updated_at: 8.months.ago)
after_last_submitted_feedback = create :feedback, volunteer: volunteer, author: volunteer.user,
feedbackable: assignment_last_submitted
after_last_submitted_feedback.update(created_at: 2.months.ago, updated_at: 2.months.ago)
before_last_submitted_feedback_superadmin = create :feedback, volunteer: volunteer,
author: create(:user), feedbackable: assignment_last_submitted
before_last_submitted_feedback_superadmin.update(created_at: 8.months.ago,
updated_at: 8.months.ago)
after_last_submitted_feedback_superadmin = create :feedback, volunteer: volunteer,
author: create(:user), feedbackable: assignment_last_submitted
after_last_submitted_feedback_superadmin.update(created_at: 2.months.ago,
updated_at: 2.months.ago)
assignment.reload
assignment_last_submitted.reload
query_via_assignment = assignment.feedbacks_since_last_submitted
query_via_feedback = Feedback.where(feedbackable: assignment).since_last_submitted(nil)
assert query_via_assignment.include? feedback
assert query_via_assignment.include? feedback_by_superadmin
assert query_via_feedback.include? feedback
assert query_via_feedback.include? feedback_by_superadmin
query_via_assignment = assignment_last_submitted.feedbacks_since_last_submitted
query_via_feedback = Feedback.where(feedbackable: assignment_last_submitted)
.since_last_submitted(assignment_last_submitted.submitted_at)
assert query_via_feedback.include? after_last_submitted_feedback
assert query_via_assignment.include? after_last_submitted_feedback
refute query_via_assignment.include? before_last_submitted_feedback
refute query_via_assignment.include? before_last_submitted_feedback_superadmin
assert query_via_assignment.include? after_last_submitted_feedback_superadmin
refute query_via_feedback.include? before_last_submitted_feedback
refute query_via_feedback.include? before_last_submitted_feedback_superadmin
assert query_via_feedback.include? after_last_submitted_feedback_superadmin
end
test 'set_responsible_also_sets_responsible_at' do
feedback = create :feedback
feedback.update(responsible: create(:user))
assert feedback.responsible_at.present?
end
end
......@@ -74,19 +74,4 @@ class GroupAssignmentTerminatesTest < ApplicationSystemTestCase
mail = ActionMailer::Base.deliveries.last
assert_equal @superadmin.email, mail['to'].to_s
end
test 'terminate group assignment without feedback or hours' do
Hour.destroy_all
Feedback.destroy_all
login_as @superadmin
visit terminate_group_assignment_path(@group_assignment)
page.accept_confirm do
click_on 'Einsatz wird hiermit abgeschlossen'
end
visit terminate_group_assignment_path(@group_assignment)
assert_text "Beendigungs Feedback vom #{I18n.l Time.zone.today}"
end
end
......@@ -43,87 +43,7 @@ class ListResponseFeedbacksTest < ApplicationSystemTestCase
visit reminder_mailings_path
end
test 'feedbacks_list_contains_only_relevant_records' do
click_link exact_text: 'Halbjahres-Rapport Eingang'
assert page.has_link? 'Journal', href: volunteer_journals_path(@assignment_pendent.volunteer)
assert page.has_link? @assignment_pendent.volunteer.contact.last_name
assert page.has_link? @assignment_fb_pendent.feedbackable.to_label
assert page.has_link? @group_assignment_pendent.volunteer.contact.last_name
# marked done shoudn't be displayed
refute page.has_link? @assignment_done.volunteer.contact.last_name
refute page.has_link? @assignment_fb_done.feedbackable.to_label
refute page.has_link? @group_assignment_done.volunteer.contact.last_name
# feedback not by volunteer shouldn't be displayed
refute page.has_link? @assignment_superadmin.volunteer.contact.last_name
refute page.has_link? @assignment_fb_superadmin.feedbackable.to_label
refute page.has_link? @group_assignment_superadmin.volunteer.contact.last_name
end
test 'feedbacks list without filter shows marked done feedback' do
click_link exact_text: 'Halbjahres-Rapport Eingang'
click_link 'Filter aufheben'
visit current_url
# marked done shoud now be displayed
assert page.has_link? 'Journal', href: volunteer_journals_path(@assignment_done.volunteer)
assert page.has_link? @assignment_done.volunteer.contact.last_name
assert page.has_link? @assignment_fb_done.feedbackable.to_label
assert page.has_link? @group_assignment_done.volunteer.contact.last_name
assert page.has_link? @group_assignment_fb_done.feedbackable.to_label
end
test 'feedbacks_list_with_filter_erledigt_shows_only_marked_done' do
click_link exact_text: 'Halbjahres-Rapport Eingang'
click_link 'Geprüft: Unquittiert'
within 'li.dropdown.open' do
click_link 'Quittiert'
end
visit current_url
# not marked done should now be filtered
refute page.has_link? @assignment_pendent.volunteer.contact.last_name
refute page.has_link? @assignment_fb_pendent.feedbackable.to_label
refute page.has_link? @group_assignment_pendent.volunteer.contact.last_name
# marked done shoud be displayed
assert page.has_link? 'Journal', href: volunteer_journals_path(@assignment_done.volunteer)
assert page.has_link? @assignment_done.volunteer.contact.last_name
assert page.has_link? @assignment_fb_done.feedbackable.to_label
assert page.has_link? @group_assignment_done.volunteer.contact.last_name
end
test 'marking_feedback_done_works' do
click_link exact_text: 'Halbjahres-Rapport Eingang'
within 'tbody' do
page.find("[data-url$=\"#{polymorphic_path([
@assignment_pendent.volunteer,
@assignment_pendent,
@assignment_fb_pendent
], action: :mark_as_done)}\"]").click
end
wait_for_ajax
assert page.has_link? 'Anzeigen', href: polymorphic_path([
@assignment_pendent.volunteer,
@assignment_pendent,
@assignment_fb_pendent
])
assert_equal @superadmin, @assignment_fb_pendent.reload.reviewer
within 'tbody' do
page.find("[data-url$=\"#{polymorphic_path([
@group_assignment_fb_pendent.volunteer,
@group_assignment_fb_pendent.feedbackable,
@group_assignment_fb_pendent
], action: :mark_as_done)}\"]").click
end
wait_for_ajax
assert page.has_link? 'Anzeigen', href: polymorphic_path([
@group_assignment_fb_pendent.volunteer,
@group_assignment_fb_pendent.feedbackable,
@group_assignment_fb_pendent
])
assert_equal @superadmin, @group_assignment_fb_pendent.reload.reviewer
end
test 'new_feedback_journal_entry_button_has_feedback_prefilled' do
visit list_responses_feedbacks_path
......@@ -230,28 +150,6 @@ class ListResponseFeedbacksTest < ApplicationSystemTestCase
])
end
test 'truncate_modal_shows_all_text' do
comments = FFaker::Lorem.paragraph(20)
achievements = FFaker::Lorem.paragraph(20)
future = FFaker::Lorem.paragraph(20)
@assignment_fb_pendent.update(comments: comments, achievements: achievements, future: future)
@group_assignment_fb_pendent.update(reviewer: @superadmin)
click_link 'Halbjahres-Rapport Eingang'
page.find('td', text: comments.truncate(300)).click
assert page.has_text? comments
click_button 'Schliessen'
page.find('td', text: future.truncate(300)).click
assert page.has_text? future
click_button 'Schliessen'
page.find('td', text: achievements.truncate(300)).click
assert page.has_text? achievements
end
test 'Creating new trial feedback reminder if no active mail template redirect to creating one' do
ClientNotification.destroy_all
click_link 'Halbjahres Erinnerung erstellen'
......
......@@ -91,19 +91,4 @@ class TerminateAssignmentsTest < ApplicationSystemTestCase
@volunteer.reload
assert @volunteer.waive
end
test 'terminate_assignment_without_feedback_or_hours' do
Hour.destroy_all
Feedback.destroy_all
login_as @superadmin
visit terminate_assignment_path(@assignment)
page.accept_confirm do
click_on 'Einsatz wird hiermit abgeschlossen'
end
visit terminate_assignment_path(@assignment)
assert_text "Beendigungs Feedback vom #{I18n.l Time.zone.today}"
end
end
......@@ -22,7 +22,7 @@ class ActiveSupport::TestCase
# FIXME: make sure all users are deleted, sometimes records stick around
# when tests are aborted
really_destroy_with_deleted(
Feedback, TrialFeedback, Hour, Journal, BillingExpense, Certificate, Import,
TrialFeedback, Hour, Journal, BillingExpense, Certificate, Import,
AssignmentLog, Assignment, GroupAssignmentLog, GroupAssignment, GroupOffer,
ClientNotification, LanguageSkill, Relative, Event, EventVolunteer,
Volunteer, Client, User, Contact, Department, SemesterProcess, SemesterFeedback,
......
Markdown is supported
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