Commit e1203948 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

add reactivated_by and reactivated_at and client reactivation

parent 5e0cd5b5
Pipeline #39840 failed with stage
in 13 minutes and 53 seconds
......@@ -144,7 +144,7 @@ class AssignmentsController < ApplicationController
end
def reactivate
state = @assignment.reactivate! ? 'success' : 'failure'
state = @assignment.reactivate!(current_user) ? 'success' : 'failure'
redirect_back fallback_location: edit_assignment_path(@assignment),
notice: t("assignments.notices.reactivation.#{state}")
end
......
......@@ -103,7 +103,7 @@ class GroupAssignmentsController < ApplicationController
end
def reactivate
state = @group_assignment.reactivate! ? 'success' : 'failure'
state = @group_assignment.reactivate!(current_user) ? 'success' : 'failure'
redirect_back fallback_location: edit_group_assignment_path(@group_assignment),
notice: t("group_assignments.notices.reactivation.#{state}")
end
......
......@@ -119,7 +119,7 @@ class VolunteersController < ApplicationController
end
def reactivate
state = @volunteer.reactivate! ? 'success' : 'failure'
state = @volunteer.reactivate!(current_user) ? 'success' : 'failure'
redirect_to edit_volunteer_path(@volunteer), notice: t("volunteers.notices.reactivation.#{state}")
end
......
......@@ -2,11 +2,14 @@ class Assignment < ApplicationRecord
include AssignmentCommon
include VolunteersGroupAndTandemStateUpdate
has_one :assignment_log
belongs_to :reactivated_by, class_name: 'User', inverse_of: 'reactivated_assignments',
optional: true
has_many :hours, as: :hourable
has_many :feedbacks, as: :feedbackable
has_many :trial_feedbacks, as: :trial_feedbackable
has_one :assignment_log, dependent: :nullify
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, dependent: :destroy, inverse_of: :trial_feedbackable
# Semester process relations
#
......
......@@ -18,6 +18,8 @@ class Client < ApplicationRecord
belongs_to :user, -> { with_deleted }, inverse_of: 'clients'
belongs_to :resigned_by, class_name: 'User', inverse_of: 'resigned_clients',
optional: true
belongs_to :reactivated_by, class_name: 'User', inverse_of: 'reactivated_clients',
optional: true
belongs_to :involved_authority, -> { with_deleted }, class_name: 'User',
inverse_of: 'involved_authorities', optional: true
has_many :manager_departments, through: :user, source: :departments
......@@ -125,6 +127,10 @@ class Client < ApplicationRecord
assignments.with_deleted.blank?
end
def reactivate!(user)
update!(acceptance: 'accepted', resigned_at: nil, reactivated_by: user, reactivated_at: Time.zone.now)
end
private
def check_if_destroyable!
......
......@@ -77,9 +77,9 @@ module GroupAssignmentAndAssignmentCommon
terminated? && volunteer.accepted?
end
def reactivate!
def reactivate!(user)
update!(period_end: nil, termination_verified_at: nil, termination_submitted_at: nil, termination_verified_by: nil,
termination_submitted_by: nil, period_end_set_by: nil)
termination_submitted_by: nil, period_end_set_by: nil, reactivated_by: user, reactivated_at: Time.zone.now)
if assignment?
assignment_log.delete
elsif group_assignment?
......
......@@ -2,10 +2,10 @@ class GroupAssignment < ApplicationRecord
include VolunteersGroupAndTandemStateUpdate
include GroupAssignmentCommon
after_save :update_group_offer_search_field
has_many :group_assignment_logs
belongs_to :reactivated_by, class_name: 'User', inverse_of: 'reactivated_group_assignments',
optional: true
has_many :group_assignment_logs, dependent: :nullify
has_many :hours, ->(object) { where(volunteer: object.volunteer) }, through: :group_offer
delegate :title, to: :group_offer
......@@ -15,6 +15,8 @@ class GroupAssignment < ApplicationRecord
message: 'Diese/r Freiwillige ist schon im Gruppenangebot'
}
after_save :update_group_offer_search_field
scope :running, (-> { no_end.have_start })
def termination_verifiable?
......
......@@ -72,6 +72,16 @@ class User < ApplicationRecord
has_many :resigned_clients, class_name: 'Client', foreign_key: 'resigned_by_id',
inverse_of: 'resigned_by'
# reactivated relations
has_many :reactivated_clients, class_name: 'Client', foreign_key: 'reactivated_by_id',
inverse_of: 'reactivated_by'
has_many :reactivated_volunteers, class_name: 'Volunteer', foreign_key: 'reactivated_by_id',
inverse_of: 'reactivated_by'
has_many :reactivated_assignments, class_name: 'Assignment', foreign_key: 'reactivated_by_id',
inverse_of: 'reactivated_by'
has_many :reactivated_group_assignments, class_name: 'GroupAssignment', foreign_key: 'reactivated_by_id',
inverse_of: 'reactivated_by'
# Mailing process done relation
has_many :mailing_volunteer_processes_submitted, class_name: 'ReminderMailingVolunteer',
inverse_of: 'process_submitted_by', foreign_key: 'process_submitted_by_id'
......
......@@ -28,6 +28,8 @@ 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',
optional: true
belongs_to :department, optional: true
has_one :registrar_department, through: :registrar
......@@ -508,7 +510,7 @@ class Volunteer < ApplicationRecord
end
def user_needed_for_invitation?
!user.present? && accepted?
user.blank? && accepted?
end
def invite_email_valid?
......@@ -526,8 +528,9 @@ class Volunteer < ApplicationRecord
end
end
def reactivate!
update!(acceptance: 'accepted')
def reactivate!(user)
update!(acceptance: 'accepted', reactivated_by: user, reactivated_at: Time.zone.now, resigned_at: nil,
resigned_by_id: nil)
return true if external?
if user.present? && (user.sign_in_count.zero? || !user.invitation_accepted?)
......
......@@ -52,7 +52,6 @@ class VolunteerPolicy < ApplicationPolicy
alias_method :update?, :volunteer_managing_or_volunteers_profile?
alias_method :update_bank_details?, :volunteer_managing_or_volunteers_profile?
alias_method :account?, :superadmin?
alias_method :reactivate?, :reactivate?
# supplementary policies
alias_method :superadmin_privileges?, :superadmin?
......
class AddReactivatedByFields < ActiveRecord::Migration[5.1]
def change
change_table :clients do |t|
t.references :ractivated_by, references: :users, index: true
t.datetime :reactivated_at
end
change_table :volunteers do |t|
t.references :ractivated_by, references: :users, index: true
t.datetime :reactivated_at
end
change_table :assignments do |t|
t.references :ractivated_by, references: :users, index: true
t.datetime :reactivated_at
end
change_table :group_assignments do |t|
t.references :ractivated_by, references: :users, index: true
t.datetime :reactivated_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: 20181218094649) do
ActiveRecord::Schema.define(version: 20190314100216) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -114,11 +114,14 @@ ActiveRecord::Schema.define(version: 20181218094649) do
t.integer "pdf_file_size"
t.datetime "pdf_updated_at"
t.bigint "submitted_by_id"
t.bigint "ractivated_by_id"
t.datetime "reactivated_at"
t.index ["client_id"], name: "index_assignments_on_client_id"
t.index ["creator_id"], name: "index_assignments_on_creator_id"
t.index ["period_end"], name: "index_assignments_on_period_end"
t.index ["period_end_set_by_id"], name: "index_assignments_on_period_end_set_by_id"
t.index ["period_start"], name: "index_assignments_on_period_start"
t.index ["ractivated_by_id"], name: "index_assignments_on_ractivated_by_id"
t.index ["submitted_at"], name: "index_assignments_on_submitted_at"
t.index ["submitted_by_id"], name: "index_assignments_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_assignments_on_termination_submitted_at"
......@@ -209,12 +212,15 @@ ActiveRecord::Schema.define(version: 20181218094649) do
t.datetime "accepted_at"
t.datetime "rejected_at"
t.text "additional_comments"
t.bigint "ractivated_by_id"
t.datetime "reactivated_at"
t.index ["acceptance"], name: "index_clients_on_acceptance"
t.index ["accepted_at"], name: "index_clients_on_accepted_at"
t.index ["birth_year"], name: "index_clients_on_birth_year"
t.index ["deleted_at"], name: "index_clients_on_deleted_at"
t.index ["involved_authority_id"], name: "index_clients_on_involved_authority_id"
t.index ["nationality"], name: "index_clients_on_nationality"
t.index ["ractivated_by_id"], name: "index_clients_on_ractivated_by_id"
t.index ["rejected_at"], name: "index_clients_on_rejected_at"
t.index ["resigned_at"], name: "index_clients_on_resigned_at"
t.index ["resigned_by_id"], name: "index_clients_on_resigned_by_id"
......@@ -374,11 +380,14 @@ ActiveRecord::Schema.define(version: 20181218094649) do
t.integer "pdf_file_size"
t.datetime "pdf_updated_at"
t.bigint "submitted_by_id"
t.bigint "ractivated_by_id"
t.datetime "reactivated_at"
t.index ["deleted_at"], name: "index_group_assignments_on_deleted_at"
t.index ["group_offer_id"], name: "index_group_assignments_on_group_offer_id"
t.index ["period_end"], name: "index_group_assignments_on_period_end"
t.index ["period_end_set_by_id"], name: "index_group_assignments_on_period_end_set_by_id"
t.index ["period_start"], name: "index_group_assignments_on_period_start"
t.index ["ractivated_by_id"], name: "index_group_assignments_on_ractivated_by_id"
t.index ["submitted_at"], name: "index_group_assignments_on_submitted_at"
t.index ["submitted_by_id"], name: "index_group_assignments_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_group_assignments_on_termination_submitted_at"
......@@ -797,6 +806,8 @@ ActiveRecord::Schema.define(version: 20181218094649) do
t.boolean "teenager"
t.bigint "department_id"
t.datetime "last_billing_expense_on"
t.bigint "ractivated_by_id"
t.datetime "reactivated_at"
t.index ["acceptance"], name: "index_volunteers_on_acceptance"
t.index ["accepted_at"], name: "index_volunteers_on_accepted_at"
t.index ["active"], name: "index_volunteers_on_active"
......@@ -807,6 +818,7 @@ ActiveRecord::Schema.define(version: 20181218094649) do
t.index ["external"], name: "index_volunteers_on_external"
t.index ["invited_at"], name: "index_volunteers_on_invited_at"
t.index ["nationality"], name: "index_volunteers_on_nationality"
t.index ["ractivated_by_id"], name: "index_volunteers_on_ractivated_by_id"
t.index ["rejected_at"], name: "index_volunteers_on_rejected_at"
t.index ["resigned_at"], name: "index_volunteers_on_resigned_at"
t.index ["salutation"], name: "index_volunteers_on_salutation"
......
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