Commit 057de166 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

Merge branch 'fix_again/semester_review_bugs' into 'develop'

Fix wrong journal association and semester feedback form invalid bugs

See merge request !933
parents 0865a285 635884c2
Pipeline #39393 passed with stage
in 37 minutes and 6 seconds
class ReviewSemestersController < ApplicationController
before_action :prepare_review, :initialize_nested_objects, only: [:review_semester, :submit_review]
include ReviewSemesterHelper, SemesterProcessVolunteerHelper
def review_semester; end
def submit_review
......@@ -23,6 +21,96 @@ class ReviewSemestersController < ApplicationController
private
def save_feedback_data!
@semester_process_volunteer.volunteer.validate_waive_and_bank = true
ActiveRecord::Base.transaction do
@semester_process_volunteer.save!
@volunteer.save!
@nested_objects.each do |_key, hash|
hash.each { |_id, obj| obj.save! }
end
end
# reload the variable
@semester_process_volunteer.reload
true
rescue ActiveRecord::RecordInvalid => exception
null_reviewed
flash[:alert] = exception.message
false
end
def create_journals
spv = @semester_process_volunteer
return unless spv.commited_at?
volunteer = spv.volunteer
semester_feedbacks = spv.semester_feedbacks
Journal.create(user: current_user, journalable: volunteer,
category: :feedback, title: "Semester Prozess Feedback vom #{I18n.l(Time.zone.today)}: ",
body: render_semester_feedbacks(semester_feedbacks))
end
def null_reviewed
@semester_process_volunteer.commited_by = nil
@semester_process_volunteer.commited_at = nil
end
def assign_volunteer_attributes
@volunteer.assign_attributes(review_params[:volunteer_attributes]
.slice(:waive, :bank, :iban))
end
def set_reviewed
@semester_process_volunteer.commited_by = current_user
@semester_process_volunteer.commited_at = Time.zone.now
end
def build_nested_objects
review_params[:semester_feedbacks_attributes].each do |_key, hash|
spv_mission = SemesterProcessVolunteerMission.find(hash[:semester_feedback][:spv_mission_id])
@nested_objects[spv_mission.id.to_s][:feedback] = SemesterFeedback.new(hash[:semester_feedback].merge({
author: current_user, semester_process_volunteer: @semester_process_volunteer
}))
if hash[:hour][:hours].to_i.positive?
@nested_objects[spv_mission.id.to_s][:hours] = Hour.new(hash[:hour].merge({
volunteer: spv_mission.volunteer,
meeting_date: spv_mission.semester_process_volunteer.semester.last.to_date,
hourable: spv_mission.mission.group_assignment? ? spv_mission.mission.group_offer : spv_mission.mission
}))
end
end
end
def prepare_review
@semester_process_volunteer = SemesterProcessVolunteer.find(params[:id])
authorize @semester_process_volunteer
@volunteer = @semester_process_volunteer.volunteer
@missions = @semester_process_volunteer.missions
end
def initialize_nested_objects
@nested_objects = {}
@semester_process_volunteer.semester_process_volunteer_missions.need_feedback.each do |spvm|
@nested_objects[spvm.id.to_s] = { feedback: @semester_process_volunteer.semester_feedback_with_mission(spvm.mission) || SemesterFeedback.new }
end
@nested_objects
end
def render_semester_feedbacks(semester_feedbacks)
text = ''
semester_feedbacks.each do |semester_feedback|
text += semester_feedback.mission.to_label
text += "\n\n"
text += semester_feedback.slice(:goals, :achievements, :future, :comments).map do |key, sfb_quote|
"#{I18n.t("activerecord.attributes.feedback.#{key}")}:\n«#{sfb_quote}»" if sfb_quote.present?
end.compact.join("\n\n")
text += "\n\n"
end
text
end
def review_params
params.require(:semester_process_volunteer).permit(
volunteer_attributes: [:id, :waive, :iban, :bank],
......@@ -30,4 +118,4 @@ class ReviewSemestersController < ApplicationController
[hour: [:hours, :spv_mission_id, :activity]]]
)
end
end
\ No newline at end of file
end
......@@ -2,8 +2,6 @@ class SemesterProcessVolunteersController < ApplicationController
before_action :set_semester_process_volunteer, only: [:show, :edit, :update, :take_responsibility, :mark_as_done, :update_notes]
before_action :set_semester, only: [:index]
include SemesterProcessVolunteerHelper
def review_semester
authorize SemesterProcessVolunteer.find(params[:id])
redirect_to review_semester_review_semester_url params[:id]
......@@ -70,6 +68,19 @@ class SemesterProcessVolunteersController < ApplicationController
private
def set_responsibles
@responsibles = SemesterProcessVolunteer.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
def set_semester
@semester = Semester.new
if params[:semester]
......@@ -80,6 +91,26 @@ class SemesterProcessVolunteersController < ApplicationController
end
end
def set_reviewers
@reviewers = SemesterProcessVolunteer.joins(reviewed_by: [profile: [:contact]])
.distinct
.select('users.id, contacts.full_name')
.map do |reviewed_by|
{
q: :reviewed_by_id_eq,
text: "Quittiert von #{reviewed_by.full_name}",
value: reviewed_by.id
}
end
end
def set_semester_process_volunteer
@spv = SemesterProcessVolunteer.find(params[:id])
authorize @spv
@semester_process = @spv.semester_process
@volunteer = @spv.volunteer
end
def semester_process_volunteer_params
params.require(:semester_process_volunteer).permit(:semester, :notes)
end
......
......@@ -2,8 +2,6 @@ class SemesterProcessesController < ApplicationController
before_action :set_semester_process, only: [:edit, :update, :overdue]
before_action :set_semester, only: [:new, :create]
include SemesterProcessHelper
def new
@semester_process = SemesterProcess.new(semester: @selected_semester, kind: :mail )
new_or_edit
......@@ -63,6 +61,12 @@ class SemesterProcessesController < ApplicationController
end
end
def sort_volunteers
@semester_process.new_semester_process_volunteers.sort do |spv1, spv2|
spv1.volunteer.contact.full_name <=> spv2.volunteer.contact.full_name
end
end
def update_or_create
authorize @semester_process
......
module ReviewSemesterHelper
def initialize_nested_objects
@nested_objects = {}
@semester_process_volunteer.semester_process_volunteer_missions.each do |spvm|
@nested_objects[spvm.id.to_s] = { feedback: @semester_process_volunteer.semester_feedback_with_mission(spvm.mission) || SemesterFeedback.new }
end
@nested_objects
end
def set_reviewed
@semester_process_volunteer.commited_by = current_user
@semester_process_volunteer.commited_at = Time.zone.now
end
def assign_volunteer_attributes
@volunteer.assign_attributes(review_params[:volunteer_attributes]
.slice(:waive, :bank, :iban))
end
def build_nested_objects
review_params[:semester_feedbacks_attributes].each do |_key, hash|
spv_mission = SemesterProcessVolunteerMission.find(hash[:semester_feedback][:spv_mission_id])
@nested_objects[spv_mission.id.to_s][:feedback] = SemesterFeedback.new(hash[:semester_feedback].merge({
author: current_user, semester_process_volunteer: @semester_process_volunteer
}))
if hash[:hour][:hours].to_i.positive?
@nested_objects[spv_mission.id.to_s][:hours] = Hour.new(hash[:hour].merge({
volunteer: spv_mission.volunteer,
meeting_date: spv_mission.semester_process_volunteer.semester.last.to_date,
hourable: spv_mission.mission.group_assignment? ? spv_mission.mission.group_offer : spv_mission.mission
}))
end
end
end
def null_reviewed
@semester_process_volunteer.commited_by = nil
@semester_process_volunteer.commited_at = nil
end
def save_feedback_data!
@semester_process_volunteer.volunteer.validate_waive_and_bank = true
ActiveRecord::Base.transaction do
@semester_process_volunteer.save!
@volunteer.save!
@nested_objects.each do |_key, hash|
hash.each { |_id, obj| obj.save! }
end
end
# reload the variable
@semester_process_volunteer.reload
true
rescue ActiveRecord::RecordInvalid => exception
null_reviewed
flash[:alert] = exception.message
false
end
def create_journals
spv = @semester_process_volunteer
return unless spv.commited_at?
volunteer = spv.volunteer
semester_feedbacks = spv.semester_feedbacks
Journal.create(user: volunteer.user, journalable: volunteer,
category: :feedback, title: "Semester Prozess Feedback vom #{I18n.l(Time.zone.today)}: ",
body: render_semester_feedbacks(semester_feedbacks))
end
def prepare_review
@semester_process_volunteer = SemesterProcessVolunteer.find(params[:id])
authorize @semester_process_volunteer
@volunteer = @semester_process_volunteer.volunteer
@missions = @semester_process_volunteer.missions
end
end
\ No newline at end of file
module SemesterProcessHelper
def sort_volunteers
@semester_process.new_semester_process_volunteers.sort do |spv1, spv2|
spv1.volunteer.contact.full_name <=> spv2.volunteer.contact.full_name
end
end
end
module SemesterProcessVolunteerHelper
def render_semester_feedbacks(semester_feedbacks)
text = ''
semester_feedbacks.each do |semester_feedback|
text += semester_feedback.mission.to_label
text += "\n\n"
text += semester_feedback.slice(:goals, :achievements, :future, :comments).map do |key, sfb_quote|
"#{I18n.t("activerecord.attributes.feedback.#{key}")}:\n«#{sfb_quote}»" if sfb_quote.present?
end.compact.join("\n\n")
text += "\n\n"
end
text
end
def assign_volunteer_attributes
@volunteer.assign_attributes(review_params[:volunteer_attributes]
.slice(:waive, :bank, :iban))
end
def render_missions(spv)
html = ""
spv.missions.each do |m|
html += link_to m.to_label, "/#{m.class.name.underscore.pluralize}/#{m.id}/edit", target: '_blank'
html += "<br>"
end
html.html_safe
end
def set_responsibles
@responsibles = SemesterProcessVolunteer.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
def set_reviewers
@reviewers = SemesterProcessVolunteer.joins(reviewed_by: [profile: [:contact]])
.distinct
.select('users.id, contacts.full_name')
.map do |reviewed_by|
{
q: :reviewed_by_id_eq,
text: "Quittiert von #{reviewed_by.full_name}",
value: reviewed_by.id
}
end
end
def set_semester_process_volunteer
@spv = SemesterProcessVolunteer.find(params[:id])
authorize @spv
@semester_process = @spv.semester_process
@volunteer = @spv.volunteer
end
end
class Journal < ApplicationRecord
include ImportRelation
belongs_to :user, -> { with_deleted }, inverse_of: 'journals'
belongs_to :assignment, optional: true
belongs_to :journalable, polymorphic: true, required: false
CATEGORIES = [
:telephone,
:conversation,
......@@ -15,6 +10,12 @@ class Journal < ApplicationRecord
:group_offer
].freeze
belongs_to :user, -> { with_deleted }, inverse_of: 'journals'
belongs_to :assignment, optional: true
belongs_to :journalable, polymorphic: true, required: false
validates :category, presence: true
def self.categories_filters
CATEGORIES.map do |category|
{
......@@ -24,6 +25,4 @@ class Journal < ApplicationRecord
}
end
end
validates :category, presence: true
end
......@@ -36,7 +36,10 @@ h1 Semester Prozess
- else
.label.label-warning Unbestätigt
td= link_to_if policy(Volunteer).edit?, spv.volunteer.contact.full_name, edit_volunteer_path(spv.volunteer)
td= render_missions(spv)
td.index-action-cell.hidden-print
- spv.missions.each do |mission|
= link_to mission.to_label, edit_polymorphic_path([mission]), target: '_blank'
br
= td_truncate_content_modal(spv.render_feedback(:goals), 'Ziele', shorten_size: 300)
= td_truncate_content_modal(spv.render_feedback(:achievements), 'Erfolge', shorten_size: 300)
= td_truncate_content_modal(spv.render_feedback(:future), 'Zukunft', shorten_size: 300)
......
......@@ -71,7 +71,8 @@ FactoryBot.define do
if ev.add_hours
spv.semester_process_volunteer_missions.map do |sem_proc_mission|
create(:hour, hourable: sem_proc_mission.mission)
hourable = sem_proc_mission.mission.assignment? ? sem_proc_mission.mission : sem_proc_mission.mission.group_offer
create(:hour, hourable: hourable, volunteer: spv.volunteer)
end
end
end
......
......@@ -57,21 +57,21 @@ FactoryBot.define do
end
trait :fake_single_assignments do
man { [true, false].sample }
woman { [true, false].sample }
family { [true, false].sample }
kid { [true, false].sample }
teenager { [true, false].sample }
unaccompanied { [true, false].sample }
man { FFaker::Boolean.maybe }
woman { FFaker::Boolean.maybe }
family { FFaker::Boolean.maybe }
kid { FFaker::Boolean.maybe }
teenager { FFaker::Boolean.maybe }
unaccompanied { FFaker::Boolean.maybe }
end
trait :fake_availability do
flexible { [true, false].sample }
morning { [true, false].sample }
afternoon { [true, false].sample }
evening { [true, false].sample }
workday { [true, false].sample }
weekend { [true, false].sample }
flexible { FFaker::Boolean.maybe }
morning { FFaker::Boolean.maybe }
afternoon { FFaker::Boolean.maybe }
evening { FFaker::Boolean.maybe }
workday { FFaker::Boolean.maybe }
weekend { FFaker::Boolean.maybe }
end
trait :imported do
......
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