Commit 00ce82ee authored by Kaspar Vollenweider's avatar Kaspar Vollenweider

assignment can be reactivated in assignment edit

parent 54dbea9d
Pipeline #38198 failed with stage
in 38 minutes and 25 seconds
......@@ -143,6 +143,12 @@ class AssignmentsController < ApplicationController
authorize :assignment, :hours_and_feedbacks_submitted?
end
def reactivate
state = @assignment.reactivate! ? 'success' : 'failure'
redirect_back fallback_location: edit_assignment_path(@assignment),
notice: t("assignments.notices.reactivation.#{state}")
end
private
def create_update_redirect
......
......@@ -70,7 +70,21 @@ module GroupAssignmentAndAssignmentCommon
end
def terminated?
termination_verifiable? && termination_verified_by.present?
ended? && termination_verified_by.present?
end
def reactivatable?
terminated? && volunteer.accepted?
end
def reactivate!
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)
if assignment?
assignment_log.delete
elsif group_assignment?
group_assignment_log.delete
end
end
private
......
......@@ -18,6 +18,10 @@ class AssignmentPolicy < ApplicationPolicy
user.involved_authorities.include?(record.client))
end
def reactivate?
record.reactivatable? && superadmin_or_department_manager_creation_or_volunteer_related?
end
# controller action policies
alias_method :index?, :superadmin_or_department_manager?
alias_method :terminated_index?, :superadmin_or_department_manager?
......
......@@ -5,6 +5,10 @@ class GroupAssignmentPolicy < ApplicationPolicy
end
end
def reactivate?
record.reactivatable? && superadmin_or_departments_offer_or_volunteer_related?
end
alias_method :show?,
:superadmin_or_department_manager_or_volunteer_related?
......
......@@ -16,6 +16,8 @@ table.table.table-striped.assignment-logs-table
- if policy(assignment.assignment).show? && assignment.assignment.pdf.exists?
= button_link icon_span(:download), assignment_path(assignment.assignment, format: :pdf),
title: 'Herunterladen'
- if policy(assignment.assignment).reactivate?
= button_link icon_span(:edit), edit_assignment_path(assignment.assignment)
td= link_to_if(policy(Client).show?, assignment.client.contact.full_name, assignment.client)
td= l(assignment.period_start) if assignment.period_start
td= l(assignment.period_end) if assignment.period_end
......
= simple_form_for(@assignment) do |f|
= simple_error_notice f
.row
.col-xs-12
= f.button :submit
- if policy(@assignment).reactivate?
h3.m-t-30= t('.reactivate.title')
p== t('.reactivate.hint')
= link_to t('.reactivate.button'), reactivate_assignment_path(@assignment), class: 'btn btn-default m-t-10',
data: { confirm: t('.reactivate.confirm') }
hr.m-y-30
.row
.col-xs-12.col-md-6
- if action_new?
......
This diff is collapsed.
......@@ -42,6 +42,10 @@ Rails.application.routes.draw do
end
end
concern :reactivate do
get :reactivate, on: :member
end
# Resource and other Routes
#
......@@ -52,7 +56,7 @@ Rails.application.routes.draw do
end
end
resources :assignments, except: [:destroy], concerns: [:submit_feedback, :termination_actions] do
resources :assignments, except: [:destroy], concerns: [:submit_feedback, :termination_actions, :reactivate] do
get :volunteer_search, on: :collection
get :client_search, on: :collection
end
......@@ -111,15 +115,14 @@ Rails.application.routes.draw do
get :thanks, on: :collection
end
resources :volunteers, except: [:destroy], concerns: :search do
resources :volunteers, except: [:destroy], concerns: [:search, :reactivate] do
put :terminate, on: :member
put :account, on: :member
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 :assignments, except: [:destroy], concerns: [:assignment_feedbacks, :hours_resources, :reactivate]
resources :billing_expenses, only: [:index]
resources :certificates
resources :group_assignments, only: [:show, :edit, :update], concerns: :hours_resources
......
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