Commit 31068893 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou
Browse files

volunteers seeking clients, restrict new assignment on volunteer show

parent f61d2454
......@@ -54,7 +54,7 @@ class AssignmentsController < ApplicationController
@assignment.destroy
client.state = Client::REGISTERED
client.save
if Volunteer.without_clients.include?(volunteer)
if Volunteer.seeking_clients.include?(volunteer)
volunteer.state = Volunteer::ACCEPTED
volunteer.save
end
......@@ -63,8 +63,8 @@ class AssignmentsController < ApplicationController
def find_volunteer
@client = Client.find(params[:id])
@q = Volunteer.without_clients.ransack(params[:q])
@without_clients = @q.result
@q = Volunteer.seeking_clients.ransack(params[:q])
@seeking_clients = @q.result
authorize Assignment
end
......
......@@ -47,9 +47,9 @@ class VolunteersController < ApplicationController
redirect_to volunteers_url, notice: t('volunteer_destroyed')
end
def without_clients
@q = Volunteer.without_clients.ransack(params[:q])
@without_clients = @q.result
def seeking_clients
@q = Volunteer.seeking_clients.ransack(params[:q])
@seeking_clients = @q.result
end
private
......
......@@ -97,8 +97,8 @@ class Volunteer < ApplicationRecord
"#{contact.first_name} #{contact.last_name}"
end
def self.without_clients
Volunteer.includes(:assignments).where(assignments: { volunteer_id: nil })
def self.seeking_clients
Volunteer.where(state: [Volunteer::ACCEPTED, Volunteer::ACTIVE_FURTHER, Volunteer::INACTIVE])
end
private
......
......@@ -42,7 +42,7 @@ class VolunteerPolicy < ApplicationPolicy
user.superadmin?
end
def without_clients?
def seeking_clients?
user.superadmin?
end
......
......@@ -54,5 +54,5 @@
th
tbody
- @without_clients.each do |volunteer|
- @seeking_clients.each do |volunteer|
= render partial: 'without_client', object: volunteer, locals: {client: @client.id}
= render 'volunteer', volunteer: seeking_client
= render 'volunteer', volunteer: without_client
......@@ -12,4 +12,4 @@
= form_navigation_btn :new, with_row: false, with_col: true, cols: 4
- if policy(Volunteer).destroy?
.col-xs-4
= button_link t('without_clients'), without_clients_volunteers_url
= button_link t('seeking_clients'), seeking_clients_volunteers_url
.row
.col-xs-12
h1= t('seeking_clients')
= render 'columns', volunteers: @seeking_clients
......@@ -2,9 +2,10 @@
.col-xs-12
h1= @volunteer.contact.full_name
.row
.col-xs-12
= button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
- if Volunteer.seeking_clients.include?(@volunteer)
.row
.col-xs-12
= button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
- if policy(Volunteer).supervisor?
= render 'journals/journal_block', journaled_for: @volunteer
......
.row
.col-xs-12
h1= t('without_clients')
= render 'columns', volunteers: @without_clients
......@@ -555,7 +555,7 @@ de:
tuesday: Dienstag
wednesday: Mittwoch
when: Zeit
without_clients: Ohne Klienten
seeking_clients: Klienten suchen
working_days: Arbeitstage
your_region: In welcher Region können Sie sich Ihren Einsatz vorstellen?
add_journal_entry: Journal Eintrag verfassen
......
......@@ -392,7 +392,7 @@ en:
tuesday: Tuesday
wednesday: Wednesday
when: Time
without_clients: Without clients
seeking_clients: Looking for clients
working_days: Working days
your_expectations: What do you expect from a person who would accompany you / your volunteer work?
your_region: In which region can you imagine your employment?
......
......@@ -16,7 +16,7 @@ Rails.application.routes.draw do
end
resources :departments
resources :volunteers do
get :without_clients, on: :collection
get :seeking_clients, on: :collection
get :find_client, on: :member, to: 'assignments#find_client'
resources :journals
end
......
......@@ -2,7 +2,7 @@ require 'test_helper'
class VolunteerTest < ActiveSupport::TestCase
def setup
@volunteer = create :volunteer, :with_language_skills
@volunteer = create :volunteer, :with_language_skills, state: Volunteer::ACCEPTED
end
test 'valid factory' do
......@@ -19,16 +19,18 @@ class VolunteerTest < ActiveSupport::TestCase
assert new_volunteer.contact.present?
end
test 'volunteers without clients' do
result = Volunteer.without_clients
test 'volunteers seeking_clients' do
result = Volunteer.seeking_clients
assert_equal [@volunteer], result.to_a
end
test 'a volunteer with an assignment should not show up in without assignment' do
@client = create :client
@user = create :user
@volunteer.assignments.create!(client: @client, creator: @user)
result = Volunteer.without_clients
@volunteer.assignments.create(client: @client, creator: @user)
@volunteer.state = Volunteer::ACTIVE
@volunteer.save
result = Volunteer.seeking_clients
assert_equal [], result.to_a
end
end
......@@ -31,15 +31,15 @@ class VolunteerPolicyTest < PolicyAssertions::Test
refute_permit @social_worker, Volunteer, 'index?'
end
test 'Without clients: superadmin can see volunteers without clients' do
assert_permit @superadmin, Volunteer, 'without_clients?'
test 'Seeking clients: superadmin can see volunteers seeking clients' do
assert_permit @superadmin, Volunteer, 'seeking_clients?'
end
test 'Without clients: social worker cannot see volunteers without clients' do
refute_permit @social_worker, Volunteer, 'without_clients?'
test 'Seeking clients: social worker cannot see volunteers seeking clients' do
refute_permit @social_worker, Volunteer, 'seeking_clients?'
end
test 'Without clients: department manager cannot see volunteers without clients' do
refute_permit @department_manager, Volunteer, 'without_clients?'
test 'Seeking clients: department manager cannot see volunteers seeking clients' do
refute_permit @department_manager, Volunteer, 'seeking_clients?'
end
end
......@@ -5,7 +5,7 @@ class AssignmentsTest < ApplicationSystemTestCase
@user = create :user, email: 'superadmin@example.com'
login_as @user
@client = create :client
@volunteer = create :volunteer
@volunteer = create :volunteer, state: Volunteer::ACTIVE_FURTHER
end
test 'new assignment form with preselected fields' do
......@@ -41,10 +41,10 @@ class AssignmentsTest < ApplicationSystemTestCase
test 'assign unassigned client (volunteer side)' do
# FIXME: If we follow the same logic with the previous test
# visit volunteers_path
# click_link 'Without clients'
# click_link 'Looking for clients'
# the test fails to find the 'Find client' link
# as it doesn't actually click the 'Without clients link'
visit without_clients_volunteers_path
# as it doesn't actually click the 'Looking for clients link'
visit seeking_clients_volunteers_path
click_link 'Find client'
click_link 'Reserve'
click_button 'Create Assignment'
......
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