Commit be95958a authored by Beat Seeliger's avatar Beat Seeliger

Merge branch 'Features/quittieren-spv' into 'develop'

Features/quittieren-spv

See merge request !854
parents 83bed1c8 82799372
Pipeline #31561 passed with stage
in 37 minutes and 35 seconds
class SemesterProcessVolunteersController < ApplicationController
before_action :prepare_review, :initialize_nested_objects, only: [:review_semester, :submit_review]
before_action :set_semester_process_volunteer, only: [:show, :edit, :update, :take_responsibility]
before_action :set_semester_process_volunteer, only: [:show, :edit, :update, :take_responsibility, :mark_as_done]
before_action :set_semester, only: [:index]
include SemesterProcessVolunteerHelper
def review_semester
end
def review_semester; end
def submit_review
# you shall not pass
......@@ -44,6 +43,7 @@ class SemesterProcessVolunteersController < ApplicationController
@q.sorts = ['volunteer_contact_last_name asc'] if @q.sorts.empty?
@spvs = @q.result.paginate(page: params[:page])
set_responsibles
set_reviewers
end
def show; end
......@@ -61,13 +61,28 @@ class SemesterProcessVolunteersController < ApplicationController
def take_responsibility
respond_to do |format|
if @spv.update(responsible: current_user)
format.html { redirect_to(@redirect_back_path, notice: 'Halbjahres-Rapport übernommen.') }
format.html { redirect_to semester_process_volunteers_path, notice: 'Semester Prozess übernommen.' }
format.json do
render json: { link: url_for(@spv.responsible), at: I18n.l(@spv.responsibility_taken_at.to_date),
email: @spv.responsible.email }, status: :ok
end
else
format.html { redirect_to(@redirect_back_path, notice: 'Fehler: Übernehmen fehlgeschlagen.') }
format.html { redirect_to semester_process_volunteers_path, notice: 'Fehler: Übernehmen fehlgeschlagen.' }
format.json { render json: { errors: @spv.errors.messages }, status: :unprocessable_entity }
end
end
end
def mark_as_done
respond_to do |format|
if @spv.update(reviewed_by: current_user, reviewed_at: Time.zone.now)
format.html { redirect_to semester_process_volunteers_path, notice: 'Semester Prozess quittiert.' }
format.json do
render json: { link: url_for(@spv.reviewed_by), at: I18n.l(@spv.reviewed_at.to_date),
email: @spv.reviewed_by.email }, status: :ok
end
else
format.html { redirect_to semester_process_volunteers_path, notice: 'Fehler: Quittieren fehlgeschlagen.' }
format.json { render json: { errors: @spv.errors.messages }, status: :unprocessable_entity }
end
end
......@@ -84,10 +99,10 @@ class SemesterProcessVolunteersController < ApplicationController
def review_params
params.require(:semester_process_volunteer).permit(
volunteer_attributes: [:id ,:waive, :iban, :bank],
volunteer_attributes: [:id, :waive, :iban, :bank],
semester_feedbacks_attributes: [[semester_feedback: [:mission, :goals, :achievements, :future, :comments, :conversation, :spv_mission_id]],
[hour: [:hours, :spv_mission_id ]]])
[hour: [:hours, :spv_mission_id]]]
)
end
def set_semester_process_volunteer
......@@ -120,6 +135,19 @@ class SemesterProcessVolunteersController < ApplicationController
end
end
def set_reviewers
@reviewers = SemesterProcessVolunteer.joins(reviewed_by: [profile: [:contact]])
.distinct
.select('users.id, contacts.full_name')
.map do |reviewed_by|
{
q: :reviewed_by_id_eq,
text: "Quittiert von #{reviewed_by.full_name}",
value: reviewed_by.id
}
end
end
def semester_process_volunteer_params
params.require(:semester_process_volunteer).permit(:semester)
end
......
......@@ -17,4 +17,5 @@ class SemesterProcessVolunteerPolicy < ApplicationPolicy
alias_method :update?, :superadmin?
alias_method :destroy?, :superadmin?
alias_method :take_responsibility?, :superadmin?
alias_method :mark_as_done?, :superadmin?
end
......@@ -11,4 +11,8 @@ nav.navbar.section-navigation
{ q: :responsible_id_null, text: 'Offen', value: 'true' },
{ q: :responsible_id_not_null, text: 'Übernommen', value: 'true' },
*@responsibles)
= custom_filter_dropdown('Quittiert',
{ q: :reviewed_by_id_null, text: 'Unquittiert', value: 'true' },
{ q: :reviewed_by_id_not_null, text: 'Quittiert', value: 'true' },
*@reviewers)
hr
......@@ -20,6 +20,7 @@ h1= t_title(:index)
th= t_attr(:commited_by)
th Letzte Bestätigung
th= sort_link @q, :responsible_profile_contact_full_name, 'Übernommen'
th= sort_link @q, :reviewed_by_profile_full_name, 'Quittiert'
tbody
- @spvs.each do |spv|
......@@ -53,6 +54,15 @@ h1= t_title(:index)
= api_button('Übernehmen', subject: [spv],
action: :take_responsibility, extra_class: 'm-t-10',
template: 'Übernommen durch <a href="<%= data.link %>"><%= data.email %></a> am <%= data.at %>')
td.index-action-cell.hidden-print
- if spv.reviewed_by.present?
= 'Quittiert von '
= link_to spv.reviewed_by.email, spv.reviewed_by
= " am #{l(spv.reviewed_at.to_date)}"
- else
= api_button('Quittieren', subject: [spv],
action: :mark_as_done, extra_class: 'm-t-10',
template: 'Quittiert von <a href="<%= data.link %>"><%= data.email %></a> am <%= data.at %>')
= bootstrap_paginate(@spvs)
......
......@@ -96,11 +96,11 @@ Rails.application.routes.draw do
get :send_half_year, on: :member
end
resources :semester_process_volunteers do
get :review_semester, on: :member
patch :submit_review, on: :member
put :take_responsibility, on: :member
put :mark_as_done, on: :member
end
resources :semester_processes, except: [:destroy]
......
......@@ -13,42 +13,54 @@ class SemesterProcessVolunteerActionsTest < ApplicationSystemTestCase
semester_process: @semester_process)
login_as @superadmin
visit semester_process_volunteers_path
end
test 'take responsibility for semester process volunteer works' do
visit semester_process_volunteers_path
def action_on_semester_process_volunteer_index(path, text)
within 'tbody' do
page.find("[data-url$=\"#{take_responsibility_semester_process_volunteer_path(@spv1)}\"]").click
page.find("[data-url$=\"#{path}\"]").click
end
wait_for_ajax
@spv1.reload
assert page.has_text? "Übernommen durch #{@superadmin.email}"\
" am #{I18n.l(@spv1.responsibility_taken_at.to_date)}"
assert page.has_text? "#{text} #{@superadmin.email}"
end
test 'take responsibility for semester process volunteer filter works' do
login_as @superadmin
visit semester_process_volunteers_path
def filters_setup
## SETUP ##
# Offen/open -> @spv1
# Übernommen/responsibility taken over from superadmin1
# Übernommen/Quittiert from superadmin2
@volunteer2 = create :volunteer_with_user
@volunteer2.contact.update(first_name: 'volunteer2', last_name: 'volunteer2')
@spv2 = create(:semester_process_volunteer, :with_mission, volunteer: @volunteer2,
semester_process: @semester_process)
@superadmin2 = create :user
@spv2.update(responsible: @superadmin2)
@spv2.update(responsible: @superadmin2, reviewed_by: @superadmin2, reviewed_at: Time.zone.now)
# Übernommen/responsibility taken over from superadmin2
# Übernommen/Quittiert from superadmin3
@volunteer3 = create :volunteer_with_user
@volunteer3.contact.update(first_name: 'volunteer3', last_name: 'volunteer3')
@spv3 = create(:semester_process_volunteer, :with_mission, volunteer: @volunteer3,
semester_process: @semester_process)
@superadmin3 = create :user
@spv3.update(responsible: @superadmin3)
@spv3.update(responsible: @superadmin3, reviewed_by: @superadmin3, reviewed_at: Time.zone.now)
## SETUP END ##
end
test 'take responsibility for semester process volunteer works' do
path = take_responsibility_semester_process_volunteer_path(@spv1)
text = 'Übernommen durch'
action_on_semester_process_volunteer_index(path, text)
end
test 'quittieren for semester process volunteer works' do
path = mark_as_done_semester_process_volunteer_path(@spv1)
text = 'Quittiert von'
action_on_semester_process_volunteer_index(path, text)
end
test 'take responsibility for semester process volunteer filter works' do
filters_setup
# filter for Alle/all
within page.find_all('nav.section-navigation').last do
click_link 'Übernommen'
......@@ -72,9 +84,9 @@ class SemesterProcessVolunteerActionsTest < ApplicationSystemTestCase
within 'tbody' do
assert page.find("[data-url$=\"#{take_responsibility_semester_process_volunteer_path(@spv1)}\"]")
end
refute page.has_text? "Übernommen durch #{@superadmin2.email}"\
assert_not page.has_text? "Übernommen durch #{@superadmin2.email}"\
" am #{I18n.l(@spv2.responsibility_taken_at.to_date)}"
refute page.has_text? "Übernommen durch #{@superadmin3.email}"\
assert_not page.has_text? "Übernommen durch #{@superadmin3.email}"\
" am #{I18n.l(@spv3.responsibility_taken_at.to_date)}"
# filter for Übernommen/responsibility taken over in general
......@@ -83,7 +95,7 @@ class SemesterProcessVolunteerActionsTest < ApplicationSystemTestCase
click_link 'Übernommen'
end
visit current_url
refute page.has_link? 'Übernehmen', href: take_responsibility_semester_process_volunteer_path(@spv1)
assert_not page.has_link? 'Übernehmen', href: take_responsibility_semester_process_volunteer_path(@spv1)
assert page.has_text? "Übernommen durch #{@superadmin2.email}"\
" am #{I18n.l(@spv2.responsibility_taken_at.to_date)}"
assert page.has_text? "Übernommen durch #{@superadmin3.email}"\
......@@ -97,10 +109,67 @@ class SemesterProcessVolunteerActionsTest < ApplicationSystemTestCase
click_link "Übernommen von #{@superadmin2.profile.contact.full_name}"
end
visit current_url
refute page.has_link? 'Übernehmen', href: take_responsibility_semester_process_volunteer_path(@spv1)
assert_not page.has_link? 'Übernehmen', href: take_responsibility_semester_process_volunteer_path(@spv1)
assert page.has_text? "Übernommen durch #{@superadmin2.email}"\
" am #{I18n.l(@spv2.responsibility_taken_at.to_date)}"
refute page.has_text? "Übernommen durch #{@superadmin3.email}"\
assert_not page.has_text? "Übernommen durch #{@superadmin3.email}"\
" am #{I18n.l(@spv3.responsibility_taken_at.to_date)}"
end
test 'quittieren for semester process volunteer filter works' do
filters_setup
# filter for Alle/all (Quittieren)
within page.find_all('nav.section-navigation').last do
click_link 'Quittiert'
click_link 'Alle'
end
visit current_url
within 'tbody' do
assert page.find("[data-url$=\"#{mark_as_done_semester_process_volunteer_path(@spv1)}\"]")
end
assert page.has_text? "Quittiert von #{@superadmin2.email}"\
" am #{I18n.l(@spv2.reviewed_at.to_date)}"
assert page.has_text? "Quittiert von #{@superadmin3.email}"\
" am #{I18n.l(@spv3.reviewed_at.to_date)}"
# filter for Unquittiert
within page.find_all('nav.section-navigation').last do
click_link 'Quittiert'
click_link 'Unquittiert'
end
visit current_url
within 'tbody' do
assert page.find("[data-url$=\"#{mark_as_done_semester_process_volunteer_path(@spv1)}\"]")
end
assert_not page.has_text? "Quittiert von #{@superadmin2.email}"\
" am #{I18n.l(@spv2.reviewed_at.to_date)}"
assert_not page.has_text? "Quittiert von #{@superadmin3.email}"\
" am #{I18n.l(@spv3.reviewed_at.to_date)}"
# filter for Quittiert/mark_as_done in general
click_link 'Quittiert: Unquittiert', match: :first
within 'li.dropdown.open' do
click_link 'Quittiert'
end
visit current_url
assert_not page.has_link? 'Quittieren', href: mark_as_done_semester_process_volunteer_path(@spv1)
assert page.has_text? "Quittiert von #{@superadmin2.email}"\
" am #{I18n.l(@spv2.reviewed_at.to_date)}"
assert page.has_text? "Quittiert von #{@superadmin3.email}"\
" am #{I18n.l(@spv3.reviewed_at.to_date)}"
# filter for quittiert/mark_as_done by superadmin1
click_link 'Quittiert: Quittiert', match: :first
within 'li.dropdown.open' do
assert page.has_link? "Quittiert von #{@superadmin2.profile.contact.full_name}"
assert page.has_link? "Quittiert von #{@superadmin3.profile.contact.full_name}"
click_link "Quittiert von #{@superadmin2.profile.contact.full_name}"
end
visit current_url
assert_not page.has_link? 'Quittieren', href: mark_as_done_semester_process_volunteer_path(@spv1)
assert page.has_text? "Quittiert von #{@superadmin2.email}"\
" am #{I18n.l(@spv2.reviewed_at.to_date)}"
assert_not page.has_text? "Quittiert von #{@superadmin3.email}"\
" am #{I18n.l(@spv3.reviewed_at.to_date)}"
end
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