Verified Commit 31526cbd authored by Kaspar Vollenweider's avatar Kaspar Vollenweider
Browse files

remove TrialFeedback and trial period reminder mailer

parent 6488d4c6
class ListResponsesController < ApplicationController
before_action { set_default_filter(author_volunteer: 'true', reviewer_id_null: 'true') }
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
end
......@@ -63,7 +63,7 @@ class PerformanceReportsController < ApplicationController
:active_assignment, :active_group_assignment, :only_assignment_active, :only_group_active, :active_both, [:active_total, :active],
:assignment_hour_records, :assignment_hours, :group_offer_hour_records, :group_offer_hours, [:total_hours, :active],
:assignment_feedbacks, :group_offer_feedbacks, [:total_feedbacks, :active],
:assignment_trial_feedbacks, :group_offer_trial_feedbacks, [:total_trial_feedbacks, :active]
# :assignment_trial_feedbacks, :group_offer_trial_feedbacks, [:total_trial_feedbacks, :active]
] + Event.kinds.keys.map(&:to_sym) + [[:total_events, :active]],
clients: [:created, :inactive, :resigned, :active_assignment, [:total, :active]],
assignments: [:created, :started, :active, :ended, :first_instruction_lessons, [:all, :active]],
......
class ReminderMailingsController < ApplicationController
before_action :set_reminder_mailing, only: [:show, :edit, :update, :destroy, :send_trial_period, :send_termination]
before_action :set_reminder_mailing, only: [:show, :edit, :update, :destroy, :send_termination]
def index
authorize ReminderMailing
......@@ -12,20 +12,6 @@ class ReminderMailingsController < ApplicationController
def show; end
def new_trial_period
@assignments = Assignment.need_trial_period_reminder_mailing.distinct
@group_assignments = GroupAssignment.need_trial_period_reminder_mailing.distinct
@reminder_mailing = ReminderMailing.new(kind: 'trial_period', creator: current_user,
reminder_mailing_volunteers: @assignments + @group_assignments)
if EmailTemplate.trial.active.any?
@reminder_mailing.assign_attributes(EmailTemplate.trial.active.first.slice(:subject, :body))
else
redirect_to new_email_template_path, notice: 'Sie müssen eine aktive E-Mailvorlage haben,'\
"\r\nbevor Sie eine Probezeit Erinnerung erstellen können."
end
authorize @reminder_mailing
end
def new_termination
@reminder_mailing = ReminderMailing.new(kind: 'termination',
reminder_mailing_volunteers: [find_termination_mailable])
......@@ -58,18 +44,6 @@ class ReminderMailingsController < ApplicationController
' Erinnerungs-Mailing bereits versendet wurde, kann es nicht mehr geändert werden.')
end
def send_trial_period
if @reminder_mailing.sending_triggered?
return redirect_to reminder_mailings_path, notice: 'Dieses Erinnerungs-Mailing wurde bereits'\
' versandt.'
end
@reminder_mailing.reminder_mailing_volunteers.picked.each do |mailing_volunteer|
VolunteerMailer.public_send(@reminder_mailing.kind, mailing_volunteer).deliver_later
end
@reminder_mailing.update(sending_triggered: true)
redirect_to reminder_mailings_path, notice: 'Probezeit Erinnerungs-Emails werden versendet.'
end
def send_termination
if @reminder_mailing.sending_triggered?
return redirect_to reminder_mailings_path, notice: 'Dieses Beendigungs-Mailing wurde bereits'\
......
class TrialFeedbacksController < ApplicationController
before_action :set_trial_feedback, only: [:show, :edit, :update, :destroy, :mark_as_done]
before_action :set_volunteer
before_action :set_trial_feedbackable
def index
authorize TrialFeedback
@trial_feedbacks = policy_scope(TrialFeedback).where(trial_feedbackable: @trial_feedbackable)
end
def show; end
def new
set_volunteer
@trial_feedback = TrialFeedback.new(trial_feedbackable: @trial_feedbackable,
volunteer: @volunteer, author: current_user)
authorize @trial_feedback
return if params[:rmv_id].blank?
rmv = ReminderMailingVolunteer.find(params[:rmv_id].to_i)
return if rmv.reminder_mailable != @trial_feedbackable || rmv.volunteer.user != current_user
rmv.update(link_visits: rmv.link_visits + 1)
end
def edit; end
def create
@trial_feedback = TrialFeedback.new(trial_feedback_params.merge(author_id: current_user.id,
volunteer_id: @volunteer.id, reviewer_id: current_user.superadmin? ? current_user.id : nil))
@trial_feedback.trial_feedbackable = @trial_feedbackable
authorize @trial_feedback
if @trial_feedback.save
redirect_to @trial_feedback.volunteer, make_notice
else
render :new
end
end
def update
if @trial_feedback.update(trial_feedback_params
.merge(reviewer_id: current_user.superadmin? ? current_user.id : nil))
update_redirect
else
render :edit
end
end
def destroy
@trial_feedback.destroy
redirect_back(fallback_location: url_for(@trial_feedbackable))
end
def mark_as_done
redirect_path = list_responses_trial_feedbacks_path(params.to_unsafe_hash.slice(:q))
if @trial_feedback.update(reviewer: current_user)
redirect_to(redirect_path, notice: 'Probezeit Feedback als angeschaut markiert.')
else
redirect_to(redirect_path, notice: 'Fehler: Angeschaut markieren fehlgeschlagen.')
end
end
private
def set_volunteer
@volunteer ||= Volunteer.find_by(id: params[:volunteer_id])
end
def set_trial_feedbackable
return @trial_feedbackable = Assignment.find(params[:assignment_id]) if params[:assignment_id]
@trial_feedbackable = GroupOffer.find(params[:group_offer_id]) if params[:group_offer_id]
end
def set_trial_feedback
@trial_feedback = TrialFeedback.find(params[:id])
@trial_feedbackable = @trial_feedback.trial_feedbackable
@volunteer = @trial_feedback.volunteer
authorize @trial_feedback
end
def update_notice
if current_user.superadmin?
'Probezeit Feedback quittiert.'
else
'Probezeit Feedback wurde erfolgreich geändert.'
end
end
def update_redirect
if request.referer.include?('need_review')
redirect_to need_review_volunteers_path, notice: 'Probezeit Feedback quittiert.'
else
redirect_to @trial_feedback.volunteer, notice: update_notice
end
end
def trial_feedback_params
params.require(:trial_feedback).permit(:body, :volunteer_id, :group_offer_id, :assignment_id,
:trial_feedbackable_id)
end
end
......@@ -24,13 +24,6 @@ class VolunteerMailer < ApplicationMailer
mail(to: @volunteer.contact.primary_email, subject: @subject)
end
def trial_period(reminder_mailing_volunteer)
@volunteer = reminder_mailing_volunteer.volunteer
@subject, @body = reminder_mailing_volunteer.process_template.values_at(:subject, :body)
reminder_mailing_volunteer.update(email_sent: true)
mail(to: @volunteer.contact.primary_email, subject: @subject)
end
def half_year_process_email(semester_process_mail)
@volunteer = semester_process_mail.volunteer
@subject, @body = semester_process_mail.process_template.values_at(:subject, :body)
......
......@@ -9,7 +9,6 @@ class Assignment < ApplicationRecord
has_many :hours, as: :hourable
has_many :feedbacks, as: :feedbackable
has_many :trial_feedbacks, as: :trial_feedbackable
# Semester process relations
#
......
......@@ -5,7 +5,6 @@ class AssignmentLog < ApplicationRecord
has_many :hours, as: :hourable, dependent: :destroy
has_many :feedbacks, as: :feedbackables, dependent: :destroy
has_many :trial_feedbacks, as: :trial_feedbackable, dependent: :destroy
def restore_assignment
assignment.restore && delete
......
module FeedbackTrialFeedbackCommon
extend ActiveSupport::Concern
included do
include ReviewsCommon
scope :author_volunteer, lambda { |toggle|
return all unless toggle
if toggle[:author_volunteer] == 'true'
author_is_volunteer
elsif toggle[:author_volunteer] == 'false'
author_isnt_volunteer
else
all
end
}
scope :submitted_before, lambda { |submitted_at|
created_after(submitted_at)
}
scope :author_isnt_volunteer, lambda {
joins(:volunteer).where("#{model_name.plural}.author_id != volunteers.user_id")
}
scope :author_is_volunteer, lambda {
joins(:volunteer).where("#{model_name.plural}.author_id = volunteers.user_id")
}
scope :since_last_submitted, lambda { |submitted_at|
submitted_before(submitted_at) if submitted_at
}
end
end
......@@ -45,18 +45,10 @@ module GroupAssignmentAndAssignmentCommon
)
}
scope :need_trial_period_reminder_mailing, lambda {
active.start_before(5.weeks.ago).no_reminder_mailing
}
scope :with_reminder_mailing_kind, lambda { |kind_number|
loj_mailings.where('reminder_mailings.kind = ?', kind_number)
}
scope :with_trial_period_reminder_mailing, lambda {
with_reminder_mailing_kind(1)
}
scope :submitted_since, lambda { |date|
started.where("#{model_name.plural}.submitted_at < ?", date)
.or(
......
class EmailTemplate < ApplicationRecord
before_save :ensure_exactly_one_active_per_kind
enum kind: { signup: 0, trial: 1, termination: 2, half_year_process_email: 4, half_year_process_overdue: 5 }
enum kind: {
signup: 0,
# trial: 1, # comment out to document that this number should not be used for new kind
termination: 2,
half_year_process_email: 4,
half_year_process_overdue: 5
}
validates :kind, presence: true
scope :order_by_active, -> { order(active: :desc) }
......@@ -31,7 +37,6 @@ class EmailTemplate < ApplicationRecord
{
signup: [],
assignment: [:Anrede, :Name, :EinsatzTitel, :FeedbackLink],
trial: ReminderMailing.template_varnames(:trial_period).values,
termination: ReminderMailing.template_varnames(:termination).values,
half_year_process_email: ReminderMailing.template_varnames(:half_year_process_email).values,
half_year_process_overdue: ReminderMailing.template_varnames(:half_year_process_overdue).values
......@@ -40,6 +45,7 @@ class EmailTemplate < ApplicationRecord
def ensure_exactly_one_active_per_kind
return unless active && changed.include?('active')
EmailTemplate.where(kind: kind).update(active: false)
end
end
......@@ -22,9 +22,10 @@ class GroupOffer < ApplicationRecord
has_many :group_assignment_logs
has_many :hours, as: :hourable, dependent: :destroy
# TODO: Verify if both obsolete and then remove accordingly
# obsolete?
# has_many :feedbacks, as: :feedbackable, dependent: :destroy
has_many :trial_feedbacks, as: :trial_feedbackable, dependent: :destroy
# has_many :trial_feedbacks, as: :trial_feedbackable, dependent: :destroy
has_many :volunteers, through: :group_assignments
has_many :volunteer_contacts, through: :volunteers, source: :contact
......
......@@ -42,7 +42,6 @@ class PerformanceReport < ApplicationRecord
active_total = assignment_active + group_active
hours = Hour.date_between(:meeting_date, *periods).where(volunteer_id: volunteers.ids)
feedbacks = SemesterFeedback.created_between(*periods).joins(:semester_process_volunteer, :volunteer).where(volunteers: {id: volunteers.ids})
trial_feedbacks = TrialFeedback.created_between(*periods).where(volunteer_id: volunteers.ids)
event_volunteers = EventVolunteer
.where(volunteer_id: volunteers.ids)
......@@ -68,9 +67,6 @@ class PerformanceReport < ApplicationRecord
total_feedbacks: feedbacks.count,
assignment_feedbacks: feedbacks.where(group_assignment: nil).count,
group_offer_feedbacks: feedbacks.where(assignment: nil).count,
assignment_trial_feedbacks: trial_feedbacks.assignment.count,
group_offer_trial_feedbacks: trial_feedbacks.group_offer.count,
total_trial_feedbacks: trial_feedbacks.count,
total_events: event_volunteers.count,
}
......
......@@ -10,10 +10,6 @@ class ReminderMailing < ApplicationRecord
# method var_name pairs per reminder_mailing kind
TEMPLATE_VARNAMES = {
trial_period: {
einsatz_start: :EinsatzStart,
feedback_link_trial: :FeedbackLink
}.merge(TEMPLATE_VARNAMES_GENERAL),
termination: {
einsatz_start: :EinsatzStart,
feedback_link_termination: :FeedbackLink
......@@ -41,7 +37,12 @@ class ReminderMailing < ApplicationRecord
source_type: 'GroupAssignment'
has_many :process_submitters, through: :reminder_mailing_volunteers, source: :process_submitted_by
enum kind: { trial_period: 1, termination: 2, half_year_process_email: 3, half_year_process_overdue: 4 }
enum kind: {
# trial_period: 1, # disabled kind. Left to document so 1 is not used for another kind
termination: 2,
half_year_process_email: 3,
half_year_process_overdue: 4
}
ransacker :kind, formatter: ->(value) { kinds[value] }
......
......@@ -12,7 +12,6 @@ class ReminderMailingVolunteer < ApplicationRecord
scope :picked, (-> { where(picked: true) })
scope :kind, ->(kind) { joins(:reminder_mailing).where('reminder_mailings.kind = ?', kind) }
scope :trial_period, (-> { kind(ReminderMailing.kinds[:trial_period]) })
scope :termination, (-> { kind(ReminderMailing.kinds[:termination]) })
scope :termination_for, ->(mailable) { termination.where(reminder_mailable: mailable) }
......@@ -49,10 +48,7 @@ class ReminderMailingVolunteer < ApplicationRecord
end
def feedback_url(options = {})
if reminder_mailing.trial_period?
path = [volunteer, reminder_mailable.polymorph_url_object, TrialFeedback]
action = :new
elsif reminder_mailing.termination?
if reminder_mailing.termination?
path = reminder_mailable
action = :terminate
else
......@@ -114,10 +110,6 @@ class ReminderMailingVolunteer < ApplicationRecord
"#{reminder_mailing.creator.email})"
end
def feedback_link_trial
"[Probezeit-Feedback erstellen](#{feedback_url})"
end
def feedback_link_termination
"[Abschlussevaluations-Feedback erstellen](#{feedback_url})"
end
......
class TrialFeedback < ApplicationRecord
include FeedbackTrialFeedbackCommon
belongs_to :volunteer
belongs_to :author, class_name: 'User', inverse_of: 'trial_feedbacks',
foreign_key: 'author_id'
belongs_to :reviewer, class_name: 'User', foreign_key: 'reviewer_id',
inverse_of: 'reviewed_trial_feedbacks', optional: true
belongs_to :trial_feedbackable, polymorphic: true, optional: true
validates :body, presence: true
scope :assignment, (-> { where(trial_feedbackable_type: 'Assignment') })
scope :group_offer, (-> { where(trial_feedbackable_type: 'GroupOffer') })
scope :from_assignments, lambda { |assignment_ids|
assignment.where(trial_feedbackable_id: assignment_ids)
}
scope :from_group_offers, lambda { |group_offer_ids|
group_offer.where(trial_feedbackable_id: group_offer_ids)
}
def assignment?
trial_feedbackable_type == 'Assignment'
end
def group_offer?
trial_feedbackable_type == 'GroupOffer'
end
def trial_feedbackable_id_and_type=(id_and_type)
self.trial_feedbackable_id, self.trial_feedbackable_type = id_and_type.split(',', 2)
end
def trial_feedbackable_id_and_type
"#{trial_feedbackable_id},#{trial_feedbackable_type}"
end
end
......@@ -13,7 +13,6 @@ class TrialPeriod < ApplicationRecord
scope :verified, -> { where.not(verified_at: nil) }
scope :trial_period_running, lambda {
not_verified.where('end_date >= ?', Date.current)
}
......@@ -42,11 +41,11 @@ class TrialPeriod < ApplicationRecord
body: "Einsatz: #{mission.to_label}")
journal.assignment = mission if mission.class.name == 'Assignment'
journal.save!
update_attributes!(verified_at: Time.zone.now, verified_by: user)
update!(verified_at: Time.zone.now, verified_by: user)
end
# allow ransack to use defined scopes
def self.ransackable_scopes(auth_object = nil)
def self.ransackable_scopes(_auth_object = nil)
['not_verified', 'verified', 'trial_period_running', 'trial_period_overdue']
end
end
......@@ -26,7 +26,6 @@ class User < ApplicationRecord
has_many :assignment_volunteers, through: :assignments, source: :volunteer
has_many :feedbacks, inverse_of: 'author', foreign_key: 'author_id'
has_many :trial_feedbacks, inverse_of: 'author', foreign_key: 'author_id'
has_many :billing_expenses
has_many :group_offers, inverse_of: 'creator', foreign_key: 'creator_id'
......@@ -41,8 +40,6 @@ class User < ApplicationRecord
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'
# trial period relations
......
......@@ -188,10 +188,6 @@ class ApplicationPolicy
superadmin? || (volunteer? && in_feedbackable?)
end
def superadmin_or_volunteers_trial_feedback?
superadmin? || volunteer? && of_and_from_volunteer? && in_trial_feedbackable?
end
def of_and_from_volunteer?
user.volunteer.id == record.volunteer.id && user.id == record.author.id
end
......@@ -204,14 +200,6 @@ class ApplicationPolicy
end
end
def in_trial_feedbackable?
if record.trial_feedbackable.class == Assignment
record.trial_feedbackable.volunteer.id == user.volunteer.id
else
record.trial_feedbackable.volunteers.ids.include? user.volunteer.id
end
end
alias_method :index?, :deny_all!
alias_method :new?, :deny_all!
alias_method :create?, :deny_all!
......
class ListResponsePolicy < ApplicationPolicy
alias_method :trial_feedbacks?, :superadmin?
end
class ReminderMailingPolicy < ApplicationPolicy
alias_method :index?, :superadmin?
alias_method :new_trial_period?, :superadmin?
alias_method :new_termination?, :superadmin?
alias_method :show?, :superadmin?
alias_method :send_trial_period?, :superadmin?
alias_method :send_termination?, :superadmin?
alias_method :create?, :superadmin?
alias_method :edit?, :superadmin?
......
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