Commit 54dbea9d authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

add button to reactivate resigned volunteers

parent e4ce5595
Pipeline #38172 failed with stage
in 37 minutes and 40 seconds
class VolunteersController < ApplicationController
before_action :set_volunteer, only: [:show, :edit, :update, :terminate, :account, :update_bank_details]
before_action :set_volunteer, only: [:show, :edit, :update, :terminate, :account, :update_bank_details, :reactivate]
def index
authorize Volunteer
......@@ -119,6 +118,11 @@ class VolunteersController < ApplicationController
end
end
def reactivate
state = @volunteer.reactivate! ? 'success' : 'failure'
redirect_to edit_volunteer_path(@volunteer), notice: t("volunteers.notices.reactivation.#{state}")
end
private
def not_resigned
......
......@@ -526,6 +526,18 @@ class Volunteer < ApplicationRecord
end
end
def reactivate!
update!(acceptance: 'accepted')
return true if external?
if user.present? && (user.sign_in_count.zero? || !user.invitation_accepted?)
user.invite!
else
self.user = User.invite!(email: contact.primary_email, role: 'volunteer')
end
save
end
private
def kinds_done_ids
......
......@@ -35,18 +35,23 @@ class VolunteerPolicy < ApplicationPolicy
user_owns_record?
end
def reactivate?
record.resigned? && superadmin_or_departments_record_or_assignable_to_department?
end
# controller action policies
alias_method :index?, :superadmin_or_department_manager?
alias_method :search?, :superadmin_or_department_manager?
alias_method :new?, :superadmin_or_department_manager?
alias_method :create?, :superadmin_or_department_manager?
alias_method :seeking_clients?, :superadmin_or_department_manager?
alias_method :terminate?, :superadmin_or_departments_record?
alias_method :show?, :volunteer_managing_or_volunteers_profile?
alias_method :edit?, :volunteer_managing_or_volunteers_profile?
alias_method :update?, :volunteer_managing_or_volunteers_profile?
alias_method :index?, :superadmin_or_department_manager?
alias_method :search?, :superadmin_or_department_manager?
alias_method :new?, :superadmin_or_department_manager?
alias_method :create?, :superadmin_or_department_manager?
alias_method :seeking_clients?, :superadmin_or_department_manager?
alias_method :terminate?, :superadmin_or_departments_record?
alias_method :show?, :volunteer_managing_or_volunteers_profile?
alias_method :edit?, :volunteer_managing_or_volunteers_profile?
alias_method :update?, :volunteer_managing_or_volunteers_profile?
alias_method :update_bank_details?, :volunteer_managing_or_volunteers_profile?
alias_method :account?, :superadmin?
alias_method :account?, :superadmin?
alias_method :reactivate?, :reactivate?
# supplementary policies
alias_method :superadmin_privileges?, :superadmin?
......
= simple_error_notice f
- if policy(volunteer).reactivate?
h3.m-t-30= t('.reactivate.title')
p== t('.reactivate.hint')
= link_to t('.reactivate.button'), reactivate_volunteer_path(volunteer), class: 'btn btn-default m-t-10',
data: { confirm: t('.reactivate.confirm') }
hr.m-y-30
- if current_user && policy(volunteer).update_acceptance?
.row
.col-xs-12.col-md-4
......
......@@ -239,6 +239,11 @@ de:
undecided: Angemeldet
undecided_at: Angemeldet am
havent_logged_in: Nie eingeloggt
reactivate:
title: Beendete/n Freiwillige/n wider Akzeptiert setzen
button: Freiwillige/n wieder aktivieren
hint: Freiwillige/r kann wider Einsätze machen, wie wenn sie/er neu akzeptiert worden wäre.<br>Hatte die/der Freiwillige vor der Beendigung ein Login auf dieser Platform, so wird dieses wider aktiviert.<br>Es kann das selbe Login/Passwort wie vorher verwendet werden.
confirm: Soll die/der Freiwillige wirklich reaktiviert werden?
create: &id-volunteers-create
<<: *id-availability
acceptance: *id-volunteer-acceptance
......@@ -271,6 +276,10 @@ de:
<<: *id-volunteers-index
acceptance: *id-volunteer-acceptance
state: *id-volunteer-active-states
notices:
reactivation:
success: Freiwillige/r erfolgreich reaktiviert
failure: Freiwillige/r reaktivieren schlug fehl
volunteers: *id-volunteers-by-actions
accompaniment_info: Bei der AOZ gibt es mehrere Möglichkeiten, sich freiwillig zu engagieren. Erfahren Sie mehr über die verschiedenen Einsatzbereiche für Freiwillige hier.
already_computed: Dieser Freiwillige hat keine verrechenbaren Stunden, darum kann keine neue Spesenabrechnung erzeugt werden.
......
......@@ -117,6 +117,7 @@ Rails.application.routes.draw do
get :find_client, on: :member, to: 'assignments#find_client'
get :seeking_clients, on: :collection
patch :update_bank_details, on: :member
get :reactivate, on: :member
resources :assignments, except: [:destroy], concerns: [:assignment_feedbacks, :hours_resources]
resources :billing_expenses, only: [:index]
......
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