Commit 8f99d575 authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

client can be reactivated

parent 37db6546
......@@ -4,7 +4,7 @@ class ClientsController < ApplicationController
include ContactAttributes
rescue_from Client::NotDestroyableError, with: :user_not_authorized
before_action :set_client, only: [:show, :edit, :update, :destroy, :set_terminated]
before_action :set_client, only: [:show, :edit, :update, :destroy, :set_terminated, :reactivate]
before_action :set_social_worker_collection, only: [:new, :create, :edit, :update]
before_action :set_assignments, only: [:show, :edit]
......@@ -79,6 +79,11 @@ class ClientsController < ApplicationController
end
end
def reactivate
state = @client.reactivate!(current_user) ? 'success' : 'failure'
redirect_to edit_client_path(@client), notice: t("clients.notices.reactivation.#{state}")
end
private
def create_success_notice
......
......@@ -7,9 +7,9 @@ class Assignment < ApplicationRecord
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
has_many :hours, as: :hourable
has_many :feedbacks, as: :feedbackable
has_many :trial_feedbacks, as: :trial_feedbackable
# Semester process relations
#
......
......@@ -21,9 +21,9 @@ class GroupOffer < ApplicationRecord
has_many :group_assignment_logs
has_many :hours, as: :hourable, dependent: :destroy, inverse_of: :hourable
has_many :trial_feedbacks, as: :trial_feedbackable, inverse_of: :trial_feedbackable,
dependent: :destroy
has_many :hours, as: :hourable, dependent: :destroy
has_many :feedbacks, as: :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
......
......@@ -16,15 +16,20 @@ class ClientPolicy < ApplicationPolicy
social_worker? && (user_owns_record? || user_involved_authority?)
end
def reactivate?
record.class.name == 'Client' && record.resigned? &&
superadmin_or_client_responsible?
end
# controller action policies
alias_method :index?, :superadmin_or_department_manager_or_social_worker?
alias_method :search?, :superadmin_or_department_manager_or_social_worker?
alias_method :new?, :superadmin_or_department_manager_or_social_worker?
alias_method :create?, :superadmin_or_department_manager_or_social_worker?
alias_method :show?, :superadmin_or_department_manager_or_social_worker?
alias_method :destroy?, :superadmin_or_client_responsible?
alias_method :edit?, :superadmin_or_client_responsible?
alias_method :update?, :superadmin_or_client_responsible?
alias_method :index?, :superadmin_or_department_manager_or_social_worker?
alias_method :search?, :superadmin_or_department_manager_or_social_worker?
alias_method :new?, :superadmin_or_department_manager_or_social_worker?
alias_method :create?, :superadmin_or_department_manager_or_social_worker?
alias_method :show?, :superadmin_or_department_manager_or_social_worker?
alias_method :destroy?, :superadmin_or_client_responsible?
alias_method :edit?, :superadmin_or_client_responsible?
alias_method :update?, :superadmin_or_client_responsible?
alias_method :set_terminated?, :superadmin_or_department_managers_record?
# suplementary policies
......
= simple_error_notice f
- if policy(f.object).reactivate?
h3.m-t-30= t('.reactivate.title')
p== t('.reactivate.hint')
= link_to t('.reactivate.button'), reactivate_client_path(f.object), class: 'btn btn-default m-t-10',
data: { confirm: t('.reactivate.confirm') }
hr.m-y-30
.row
.col-xs-12.col-md-6
fieldset
......
......@@ -700,12 +700,22 @@ de:
slim: *id-certificates-show
update: *id-certificates-form
clients:
form:
reactivate:
title: Klient/in wieder Aktivieren
hint: Klient/in wird wieder aktiviert.
button: Klient/in wieder aktivieren
confirm: Soll der/die Klient/in wirklich wieder auf aktiv gesetzt werden?
client:
acceptance: *id-client-acceptance
show:
acceptance: *id-client-acceptance
show_navigation:
acceptance: *id-client-acceptance
notices:
reactivation:
success: Klient/in erfolgreich reaktiviert
failure: Klient/in reaktivieren schlug fehl
contacts:
fields:
<<: *id-generic_keys
......
......@@ -62,7 +62,7 @@ Rails.application.routes.draw do
end
resources :client_notifications, :departments, :performance_reports, :email_templates, :users
resources :clients, concerns: :search do
resources :clients, concerns: [:search, :reactivate] do
resources :journals, except: [:show]
patch :set_terminated, on: :member
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