Commit 1d0b5d61 authored by Jiri Strojil's avatar Jiri Strojil

Merge branch 'fixes/other-stories' into 'develop'

on volunteer track who did the process step / wrong links in mails to admins after ending

See merge request !999
parents 17db8dc4 d118c9d6
Pipeline #63079 canceled with stage
module ProcessedByConcern
extend ActiveSupport::Concern
included do
def register_acceptance_change(resource)
return unless resource.will_save_change_to_attribute?(:acceptance)
if resource.respond_to?("#{resource.acceptance}_by_id".to_sym)
resource["#{resource.acceptance}_by_id".to_sym] = current_user.id
end
end
end
end
class VolunteersController < ApplicationController
include ProcessedByConcern
before_action :set_volunteer, only: [:show, :edit, :update, :terminate, :account, :update_bank_details, :reactivate]
before_action :set_active_and_archived_missions, only: [:show, :edit]
......@@ -62,6 +63,9 @@ class VolunteersController < ApplicationController
def update
@volunteer.attributes = volunteer_params
return render :edit unless @volunteer.valid?
register_acceptance_change(@volunteer)
if @volunteer.will_save_change_to_attribute?(:acceptance, to: 'accepted') &&
@volunteer.internal? && !@volunteer.user && @volunteer.save
redirect_to(edit_volunteer_path(@volunteer),
......@@ -81,7 +85,7 @@ class VolunteersController < ApplicationController
def terminate
if @volunteer.terminatable?
@volunteer.terminate!
@volunteer.terminate!(current_user)
redirect_back fallback_location: edit_volunteer_path(@volunteer),
notice: 'Freiwillige/r wurde erfolgreich beendet.'
else
......
......@@ -153,11 +153,18 @@ module ApplicationHelper
tag.abbr(abbr.to_s, title: full_term)
end
def show_status_date(record, *args)
tag.ul(class: "list-unstyled") do
def show_status_date(record, include_processing_person, *args)
tag.ul(class: "list-unstyled") do
record.slice(*args).compact.each do |key, value|
concat tag.li(t_attr(key) +' '+ l(value))
if include_processing_person
updated_by_attr = key.include?('_at') ? key.sub('_at', '_by') : nil
concat tag.li([
t_attr(key) +' '+ l(value), record.send(updated_by_attr).to_s
].reject(&:blank?).join(" #{I18n.t('by')} "))
else
concat tag.li(t_attr(key) +' '+ l(value))
end
end
end
end
end
end
......@@ -28,11 +28,19 @@ class Volunteer < ApplicationRecord
belongs_to :user, -> { with_deleted }, inverse_of: 'volunteer', optional: true
belongs_to :registrar, -> { with_deleted }, class_name: 'User', foreign_key: 'registrar_id', optional: true,
inverse_of: :volunteers
belongs_to :reactivated_by, class_name: 'User', inverse_of: 'reactivated_volunteers',
belongs_to :reactivated_by, -> { with_deleted }, class_name: 'User', inverse_of: 'reactivated_volunteers',
optional: true
belongs_to :department, optional: true
belongs_to :secondary_department, class_name: 'Department', optional: true
# accepance updating person
belongs_to :invited_by, -> { with_deleted }, class_name: 'User', optional: true
belongs_to :accepted_by, -> { with_deleted }, class_name: 'User', optional: true
belongs_to :resigned_by, -> { with_deleted }, class_name: 'User', optional: true
belongs_to :rejected_by, -> { with_deleted }, class_name: 'User', optional: true
belongs_to :undecided_by, -> { with_deleted }, class_name: 'User', optional: true
belongs_to :created_by, -> { with_deleted }, class_name: 'User', foreign_key: 'registrar_id', optional: true
has_one :registrar_department, through: :registrar
has_many :departments, through: :group_offers
......@@ -443,6 +451,10 @@ class Volunteer < ApplicationRecord
end
end
def undecided_by
super || registrar
end
def assignment_group_offer_collection
assignments_hour_form_collection + group_offers_form_collection
end
......@@ -491,9 +503,9 @@ class Volunteer < ApplicationRecord
['active', 'inactive', 'not_resigned', 'process_eq']
end
def terminate!
def terminate!(resigned_by)
self.class.transaction do
update(acceptance: :resigned, resigned_at: Time.zone.now)
update(acceptance: :resigned, resigned_at: Time.zone.now, resigned_by: resigned_by)
user&.destroy
end
end
......@@ -538,7 +550,7 @@ class Volunteer < ApplicationRecord
end
def reactivate!(user)
update!(acceptance: 'accepted', reactivated_by: user, reactivated_at: Time.zone.now, resigned_at: nil)
update!(acceptance: 'accepted', accepted_by: user, reactivated_by: user, reactivated_at: Time.zone.now, resigned_at: nil)
return true if external?
if user.present? && (user.sign_in_count.zero? || !user.invitation_accepted?)
......
......@@ -7,7 +7,7 @@
data: { confirm: t('.reactivate.confirm') }
hr.m-y-30
fieldset
= show_status_date(@client, :created_at)
= show_status_date(@client, false, :created_at)
.row
.col-xs-12.col-md-6
......
h1= t('.title', email: @terminated.termination_submitted_by.email)
- if @terminated.assignment?
p= link_to t('.link_text.terminated_assignment'), terminated_index_assignments_url(@link_params)
p= link_to t('.link_text.terminated_assignment'), terminated_index_assignments_url
- elsif @terminated.group_assignment?
p= link_to t('.link_text.terminated_group_assignment'), terminated_index_group_assignments_url(@link_params)
p= link_to t('.link_text.terminated_group_assignment'), terminated_index_group_assignments_url
p AOZ Fachstelle Freiwilligenarbeit
......@@ -2,10 +2,10 @@
<% if @terminated.assignment? %>
<%= t('.link_text.terminated_assignment') %>:
<%= url_for(terminated_index_assignments_url(@link_params)) %>
<%= url_for(terminated_index_assignments_url) %>
<% elsif @terminated.group_assignment? %>
<%= t('.link_text.terminated_group_assignment') %>:
<%= url_for(terminated_index_group_assignments_url(@link_params)) %>
<%= url_for(terminated_index_group_assignments_url) %>
<% end %>
AOZ Fachstelle Freiwilligenarbeit
......@@ -13,7 +13,7 @@
legend= t('.acceptance.management')
= acceptance_select(@volunteer, f)
- unless @volunteer.undecided?
= show_status_date(@volunteer, :created_at, :invited_at, :accepted_at, :undecided_at, :rejected_at, :resigned_at)
= show_status_date(@volunteer, true, :created_at, :invited_at, :accepted_at, :undecided_at, :rejected_at, :resigned_at)
= f.input :external, input_html: { data: { hide: ['bank-data', 'checklist'] }, class: 'volunteer-active-checkbox-changes' }
......
......@@ -25,7 +25,7 @@ h2.small Persönlicher Hintergrund
.row
.col-xs-12.col-md-4
fieldset
= show_status_date(@volunteer, :created_at)
= show_status_date(@volunteer, true, :created_at, :invited_at, :accepted_at, :undecided_at, :rejected_at, :resigned_at)
.table-responsive
table.table.table-no-border-top
tbody
......
......@@ -4,6 +4,7 @@ de:
actions: Aktionen
expand_all: Alle anzeigen
collapse_all: Alle einklappen
by: von
generic_keys: &id-generic_keys
salutation: Anrede
first_name: Vorname
......
class AddVolunteerProcessedBy < ActiveRecord::Migration[5.1]
def change
change_table :volunteers do |t|
t.references :invited_by
t.references :accepted_by
t.references :resigned_by
t.references :rejected_by
t.references :undecided_by
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: 20191122122407) do
ActiveRecord::Schema.define(version: 20191122135842) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -832,8 +832,14 @@ ActiveRecord::Schema.define(version: 20191122122407) do
t.bigint "reactivated_by_id"
t.datetime "reactivated_at"
t.bigint "secondary_department_id"
t.bigint "invited_by_id"
t.bigint "accepted_by_id"
t.bigint "resigned_by_id"
t.bigint "rejected_by_id"
t.bigint "undecided_by_id"
t.index ["acceptance"], name: "index_volunteers_on_acceptance"
t.index ["accepted_at"], name: "index_volunteers_on_accepted_at"
t.index ["accepted_by_id"], name: "index_volunteers_on_accepted_by_id"
t.index ["active"], name: "index_volunteers_on_active"
t.index ["activeness_might_end"], name: "index_volunteers_on_activeness_might_end"
t.index ["birth_year"], name: "index_volunteers_on_birth_year"
......@@ -841,12 +847,16 @@ ActiveRecord::Schema.define(version: 20191122122407) do
t.index ["department_id"], name: "index_volunteers_on_department_id"
t.index ["external"], name: "index_volunteers_on_external"
t.index ["invited_at"], name: "index_volunteers_on_invited_at"
t.index ["invited_by_id"], name: "index_volunteers_on_invited_by_id"
t.index ["nationality"], name: "index_volunteers_on_nationality"
t.index ["reactivated_by_id"], name: "index_volunteers_on_reactivated_by_id"
t.index ["rejected_at"], name: "index_volunteers_on_rejected_at"
t.index ["rejected_by_id"], name: "index_volunteers_on_rejected_by_id"
t.index ["resigned_at"], name: "index_volunteers_on_resigned_at"
t.index ["resigned_by_id"], name: "index_volunteers_on_resigned_by_id"
t.index ["salutation"], name: "index_volunteers_on_salutation"
t.index ["undecided_at"], name: "index_volunteers_on_undecided_at"
t.index ["undecided_by_id"], name: "index_volunteers_on_undecided_by_id"
t.index ["user_id"], name: "index_volunteers_on_user_id"
end
......
......@@ -18,8 +18,8 @@ class NotificationMailerest < ActionMailer::TestCase
assert_match @other_superadmin.email, text
assert_match @other_superadmin.email, html
assert_match '/assignments/terminated_index?q%5Btermination_verified_by_id_not_null%5D=true', text
assert_match '/assignments/terminated_index?q%5Btermination_verified_by_id_not_null%5D=true', html
assert_match '/assignments/terminated_index', text
assert_match '/assignments/terminated_index', html
end
test 'termination_submitted group_assignment' do
......@@ -34,7 +34,7 @@ class NotificationMailerest < ActionMailer::TestCase
assert_match @other_superadmin.email, text
assert_match @other_superadmin.email, html
assert_match '/group_assignments/terminated_index?q%5Btermination_verified_by_id_not_null%5D=true', text
assert_match '/group_assignments/terminated_index?q%5Btermination_verified_by_id_not_null%5D=true', html
assert_match '/group_assignments/terminated_index', text
assert_match '/group_assignments/terminated_index', html
end
end
......@@ -44,22 +44,26 @@ class VolunteerTest < ActiveSupport::TestCase
end
test 'when an internal volunteer gets terminated will be marked as resigned' do
superadmin = create :user, role: 'superadmin'
volunteer = create :volunteer, external: false
assert volunteer.valid?
volunteer.terminate!
volunteer.terminate!(superadmin)
volunteer.reload
assert volunteer.resigned?
assert_equal volunteer.resigned_by, superadmin
refute volunteer.active?
refute volunteer.user.present?
end
test 'terminate_volunteer_without_user' do
superadmin = create :user, role: 'superadmin'
volunteer = create :volunteer, external: true, acceptance: :accepted
assert_nil volunteer.user
volunteer.terminate!
volunteer.terminate!(superadmin)
assert_equal volunteer.resigned_by, superadmin
assert volunteer.resigned?
end
......
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