Commit f0ea0ae6 authored by Zsolt Benke's avatar Zsolt Benke
Browse files

Changed filter for pending invitations

parent a35a0042
......@@ -95,6 +95,9 @@ class User < ApplicationRecord
scope :social_workers, (-> { where(role: SOCIAL_WORKER) })
scope :signed_in_at_least_once, (-> { where.not(last_sign_in_at: nil) })
scope :with_pending_invitation, lambda {
where(invitation_accepted_at: nil).where.not(invitation_sent_at: nil)
}
def superadmin?
role == SUPERADMIN
......
......@@ -84,8 +84,8 @@ class Volunteer < ApplicationRecord
unless: :user_deleted?
scope :process_eq, lambda { |process|
return unless process.present?
return where(external: false, user: nil) if process == 'not_logged_in'
return unless process.present?
return joins(:user).merge(User.with_pending_invitation) if process == 'havent_logged_in'
where(acceptance: process)
}
scope :with_hours, (-> { joins(:hours) })
......@@ -321,8 +321,8 @@ class Volunteer < ApplicationRecord
acceptance_filters.append(
{
q: :acceptance_eq,
value: 'not_logged_in',
text: human_attribute_name(:not_logged_in)
value: 'havent_logged_in',
text: human_attribute_name(:havent_logged_in)
}
).map do |filter|
filter[:q] = :process_eq
......
......@@ -24,6 +24,9 @@ tr id=(dom_id(volunteer))
td.button-acceptance.index-action-cell
= link_to t(".acceptance.#{volunteer.acceptance}"), '#',
class: "btn btn-xs btn-acceptance-#{volunteer.acceptance}"
- if volunteer.pending_invitation?
br
'Nie eingeloggt
- if !volunteer.external && !volunteer.user
br
'Kein Login
......
......@@ -227,7 +227,7 @@ de:
resigned_at: Beendet am
undecided: Angemeldet
undecided_at: Angemeldet am
not_logged_in: Kein Login
havent_logged_in: Nie eingeloggt
create: &id-volunteers-create
<<: *id-availability
acceptance: *id-volunteer-acceptance
......
......@@ -136,4 +136,21 @@ class UserTest < ActiveSupport::TestCase
assert superadmin.missing_profile?
refute volunteer.missing_profile?
end
test 'with_pending_invitation' do
user = User.create(email: 'user@example.com', role: :volunteer)
assert_nil user.invitation_sent_at
assert_nil user.invitation_accepted_at
user.invite!
refute_nil user.reload.invitation_sent_at
assert_nil user.invitation_accepted_at
users = User.with_pending_invitation
assert_includes users, user
[@user, @superadmin, @social_worker, @department_manager].each do |user|
assert_not_includes users, user
end
end
end
......@@ -400,7 +400,7 @@ class VolunteerScopesTest < ActiveSupport::TestCase
Volunteer.destroy_all
# load test data
@volunteer_imported = create :volunteer, :imported
@volunteer_not_logged_in = Volunteer.create!(contact: create(:contact), acceptance: :accepted, salutation: :mrs)
Volunteer.acceptance_collection.each do |acceptance|
volunteer = create :volunteer, acceptance: acceptance
instance_variable_set("@volunteer_#{acceptance}", volunteer)
......@@ -421,7 +421,8 @@ class VolunteerScopesTest < ActiveSupport::TestCase
end
# special case for volunteers whose haven't logged in
volunteers = Volunteer.process_eq('not_logged_in')
assert_includes volunteers, @volunteer_imported
@volunteer_not_logged_in.invite_user
volunteers = Volunteer.process_eq('havent_logged_in')
assert_includes volunteers, @volunteer_not_logged_in
end
end
......@@ -190,7 +190,7 @@ class VolunteersFilterDropdownsTest < ApplicationSystemTestCase
Volunteer.destroy_all
# load test data
@volunteer_imported = create :volunteer, :imported
@volunteer_not_logged_in = Volunteer.create!(contact: create(:contact), acceptance: :accepted, salutation: :mrs)
Volunteer.acceptance_collection.each do |acceptance|
volunteer = create :volunteer, acceptance: acceptance, salutation: 'mrs'
instance_variable_set("@volunteer_#{acceptance}", volunteer)
......@@ -200,12 +200,12 @@ class VolunteersFilterDropdownsTest < ApplicationSystemTestCase
visit volunteers_path
click_link 'Prozess'
click_link 'Kein Login', match: :first
assert page.has_text? @volunteer_imported
click_link 'Nie eingeloggt', match: :first
assert page.has_text? @volunteer_not_logged_in
Volunteer.process_eq('not_logged_in').each do |volunteer|
Volunteer.process_eq('havent_logged_in').each do |volunteer|
within "tr##{dom_id volunteer}" do
assert page.has_text? 'Kein Login'
assert page.has_text? 'Nie eingeloggt'
end
end
......
Supports Markdown
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