Commit 37db6546 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

assignment and group_assignment reactivatable? checks for client or...

assignment and group_assignment reactivatable? checks for client or group_offer not terminated or resigned
parent e1203948
...@@ -74,7 +74,7 @@ module GroupAssignmentAndAssignmentCommon ...@@ -74,7 +74,7 @@ module GroupAssignmentAndAssignmentCommon
end end
def reactivatable? def reactivatable?
terminated? && volunteer.accepted? terminated? && dependency_allows_reactivation? && volunteer.accepted?
end end
def reactivate!(user) def reactivate!(user)
...@@ -89,6 +89,14 @@ module GroupAssignmentAndAssignmentCommon ...@@ -89,6 +89,14 @@ module GroupAssignmentAndAssignmentCommon
private private
def dependency_allows_reactivation?
if assignment?
client.accepted?
else
!group_offer.terminated?
end
end
def add_remaining_hours def add_remaining_hours
return unless remaining_hours? return unless remaining_hours?
......
...@@ -529,8 +529,7 @@ class Volunteer < ApplicationRecord ...@@ -529,8 +529,7 @@ class Volunteer < ApplicationRecord
end end
def reactivate!(user) def reactivate!(user)
update!(acceptance: 'accepted', reactivated_by: user, reactivated_at: Time.zone.now, resigned_at: nil, update!(acceptance: 'accepted', reactivated_by: user, reactivated_at: Time.zone.now, resigned_at: nil)
resigned_by_id: nil)
return true if external? return true if external?
if user.present? && (user.sign_in_count.zero? || !user.invitation_accepted?) if user.present? && (user.sign_in_count.zero? || !user.invitation_accepted?)
......
class AddReactivatedByFields < ActiveRecord::Migration[5.1] class AddReactivatedByFields < ActiveRecord::Migration[5.1]
def change def change
change_table :clients do |t| change_table :clients do |t|
t.references :ractivated_by, references: :users, index: true t.references :reactivated_by, references: :users, index: true
t.datetime :reactivated_at t.datetime :reactivated_at
end end
change_table :volunteers do |t| change_table :volunteers do |t|
t.references :ractivated_by, references: :users, index: true t.references :reactivated_by, references: :users, index: true
t.datetime :reactivated_at t.datetime :reactivated_at
end end
change_table :assignments do |t| change_table :assignments do |t|
t.references :ractivated_by, references: :users, index: true t.references :reactivated_by, references: :users, index: true
t.datetime :reactivated_at
end
change_table :assignment_logs do |t|
t.references :reactivated_by, references: :users, index: true
t.datetime :reactivated_at t.datetime :reactivated_at
end end
change_table :group_assignments do |t| change_table :group_assignments do |t|
t.references :ractivated_by, references: :users, index: true t.references :reactivated_by, references: :users, index: true
t.datetime :reactivated_at
end
change_table :group_assignment_logs do |t|
t.references :reactivated_by, references: :users, index: true
t.datetime :reactivated_at t.datetime :reactivated_at
end end
end end
......
...@@ -55,6 +55,8 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -55,6 +55,8 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.string "special_agreement" t.string "special_agreement"
t.text "agreement_text" t.text "agreement_text"
t.bigint "submitted_by_id" t.bigint "submitted_by_id"
t.bigint "reactivated_by_id"
t.datetime "reactivated_at"
t.index ["assignment_id"], name: "index_assignment_logs_on_assignment_id" t.index ["assignment_id"], name: "index_assignment_logs_on_assignment_id"
t.index ["client_id"], name: "index_assignment_logs_on_client_id" t.index ["client_id"], name: "index_assignment_logs_on_client_id"
t.index ["creator_id"], name: "index_assignment_logs_on_creator_id" t.index ["creator_id"], name: "index_assignment_logs_on_creator_id"
...@@ -62,6 +64,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -62,6 +64,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.index ["period_end"], name: "index_assignment_logs_on_period_end" t.index ["period_end"], name: "index_assignment_logs_on_period_end"
t.index ["period_end_set_by_id"], name: "index_assignment_logs_on_period_end_set_by_id" t.index ["period_end_set_by_id"], name: "index_assignment_logs_on_period_end_set_by_id"
t.index ["period_start"], name: "index_assignment_logs_on_period_start" t.index ["period_start"], name: "index_assignment_logs_on_period_start"
t.index ["reactivated_by_id"], name: "index_assignment_logs_on_reactivated_by_id"
t.index ["submitted_at"], name: "index_assignment_logs_on_submitted_at" t.index ["submitted_at"], name: "index_assignment_logs_on_submitted_at"
t.index ["submitted_by_id"], name: "index_assignment_logs_on_submitted_by_id" t.index ["submitted_by_id"], name: "index_assignment_logs_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_assignment_logs_on_termination_submitted_at" t.index ["termination_submitted_at"], name: "index_assignment_logs_on_termination_submitted_at"
...@@ -114,14 +117,14 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -114,14 +117,14 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.integer "pdf_file_size" t.integer "pdf_file_size"
t.datetime "pdf_updated_at" t.datetime "pdf_updated_at"
t.bigint "submitted_by_id" t.bigint "submitted_by_id"
t.bigint "ractivated_by_id" t.bigint "reactivated_by_id"
t.datetime "reactivated_at" t.datetime "reactivated_at"
t.index ["client_id"], name: "index_assignments_on_client_id" t.index ["client_id"], name: "index_assignments_on_client_id"
t.index ["creator_id"], name: "index_assignments_on_creator_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"], 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_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 ["period_start"], name: "index_assignments_on_period_start"
t.index ["ractivated_by_id"], name: "index_assignments_on_ractivated_by_id" t.index ["reactivated_by_id"], name: "index_assignments_on_reactivated_by_id"
t.index ["submitted_at"], name: "index_assignments_on_submitted_at" t.index ["submitted_at"], name: "index_assignments_on_submitted_at"
t.index ["submitted_by_id"], name: "index_assignments_on_submitted_by_id" t.index ["submitted_by_id"], name: "index_assignments_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_assignments_on_termination_submitted_at" t.index ["termination_submitted_at"], name: "index_assignments_on_termination_submitted_at"
...@@ -212,7 +215,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -212,7 +215,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.datetime "accepted_at" t.datetime "accepted_at"
t.datetime "rejected_at" t.datetime "rejected_at"
t.text "additional_comments" t.text "additional_comments"
t.bigint "ractivated_by_id" t.bigint "reactivated_by_id"
t.datetime "reactivated_at" t.datetime "reactivated_at"
t.index ["acceptance"], name: "index_clients_on_acceptance" t.index ["acceptance"], name: "index_clients_on_acceptance"
t.index ["accepted_at"], name: "index_clients_on_accepted_at" t.index ["accepted_at"], name: "index_clients_on_accepted_at"
...@@ -220,7 +223,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -220,7 +223,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.index ["deleted_at"], name: "index_clients_on_deleted_at" t.index ["deleted_at"], name: "index_clients_on_deleted_at"
t.index ["involved_authority_id"], name: "index_clients_on_involved_authority_id" t.index ["involved_authority_id"], name: "index_clients_on_involved_authority_id"
t.index ["nationality"], name: "index_clients_on_nationality" t.index ["nationality"], name: "index_clients_on_nationality"
t.index ["ractivated_by_id"], name: "index_clients_on_ractivated_by_id" t.index ["reactivated_by_id"], name: "index_clients_on_reactivated_by_id"
t.index ["rejected_at"], name: "index_clients_on_rejected_at" t.index ["rejected_at"], name: "index_clients_on_rejected_at"
t.index ["resigned_at"], name: "index_clients_on_resigned_at" t.index ["resigned_at"], name: "index_clients_on_resigned_at"
t.index ["resigned_by_id"], name: "index_clients_on_resigned_by_id" t.index ["resigned_by_id"], name: "index_clients_on_resigned_by_id"
...@@ -337,10 +340,13 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -337,10 +340,13 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.string "trial_period_end" t.string "trial_period_end"
t.text "agreement_text" t.text "agreement_text"
t.bigint "submitted_by_id" t.bigint "submitted_by_id"
t.bigint "reactivated_by_id"
t.datetime "reactivated_at"
t.index ["deleted_at"], name: "index_group_assignment_logs_on_deleted_at" t.index ["deleted_at"], name: "index_group_assignment_logs_on_deleted_at"
t.index ["group_assignment_id"], name: "index_group_assignment_logs_on_group_assignment_id" t.index ["group_assignment_id"], name: "index_group_assignment_logs_on_group_assignment_id"
t.index ["group_offer_id"], name: "index_group_assignment_logs_on_group_offer_id" t.index ["group_offer_id"], name: "index_group_assignment_logs_on_group_offer_id"
t.index ["period_end_set_by_id"], name: "index_group_assignment_logs_on_period_end_set_by_id" t.index ["period_end_set_by_id"], name: "index_group_assignment_logs_on_period_end_set_by_id"
t.index ["reactivated_by_id"], name: "index_group_assignment_logs_on_reactivated_by_id"
t.index ["submitted_by_id"], name: "index_group_assignment_logs_on_submitted_by_id" t.index ["submitted_by_id"], name: "index_group_assignment_logs_on_submitted_by_id"
t.index ["termination_submitted_by_id"], name: "index_group_assignment_logs_on_termination_submitted_by_id" t.index ["termination_submitted_by_id"], name: "index_group_assignment_logs_on_termination_submitted_by_id"
t.index ["termination_verified_by_id"], name: "index_group_assignment_logs_on_termination_verified_by_id" t.index ["termination_verified_by_id"], name: "index_group_assignment_logs_on_termination_verified_by_id"
...@@ -380,14 +386,14 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -380,14 +386,14 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.integer "pdf_file_size" t.integer "pdf_file_size"
t.datetime "pdf_updated_at" t.datetime "pdf_updated_at"
t.bigint "submitted_by_id" t.bigint "submitted_by_id"
t.bigint "ractivated_by_id" t.bigint "reactivated_by_id"
t.datetime "reactivated_at" t.datetime "reactivated_at"
t.index ["deleted_at"], name: "index_group_assignments_on_deleted_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 ["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"], 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_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 ["period_start"], name: "index_group_assignments_on_period_start"
t.index ["ractivated_by_id"], name: "index_group_assignments_on_ractivated_by_id" t.index ["reactivated_by_id"], name: "index_group_assignments_on_reactivated_by_id"
t.index ["submitted_at"], name: "index_group_assignments_on_submitted_at" 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 ["submitted_by_id"], name: "index_group_assignments_on_submitted_by_id"
t.index ["termination_submitted_at"], name: "index_group_assignments_on_termination_submitted_at" t.index ["termination_submitted_at"], name: "index_group_assignments_on_termination_submitted_at"
...@@ -806,7 +812,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -806,7 +812,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.boolean "teenager" t.boolean "teenager"
t.bigint "department_id" t.bigint "department_id"
t.datetime "last_billing_expense_on" t.datetime "last_billing_expense_on"
t.bigint "ractivated_by_id" t.bigint "reactivated_by_id"
t.datetime "reactivated_at" t.datetime "reactivated_at"
t.index ["acceptance"], name: "index_volunteers_on_acceptance" t.index ["acceptance"], name: "index_volunteers_on_acceptance"
t.index ["accepted_at"], name: "index_volunteers_on_accepted_at" t.index ["accepted_at"], name: "index_volunteers_on_accepted_at"
...@@ -818,7 +824,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do ...@@ -818,7 +824,7 @@ ActiveRecord::Schema.define(version: 20190314100216) do
t.index ["external"], name: "index_volunteers_on_external" t.index ["external"], name: "index_volunteers_on_external"
t.index ["invited_at"], name: "index_volunteers_on_invited_at" t.index ["invited_at"], name: "index_volunteers_on_invited_at"
t.index ["nationality"], name: "index_volunteers_on_nationality" t.index ["nationality"], name: "index_volunteers_on_nationality"
t.index ["ractivated_by_id"], name: "index_volunteers_on_ractivated_by_id" 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_at"], name: "index_volunteers_on_rejected_at"
t.index ["resigned_at"], name: "index_volunteers_on_resigned_at" t.index ["resigned_at"], name: "index_volunteers_on_resigned_at"
t.index ["salutation"], name: "index_volunteers_on_salutation" 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