From c1cd721ae5d4bafdba473b4c8a58ddfcb21d8c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Maniaci?= Date: Wed, 27 Nov 2024 20:21:49 +0100 Subject: [PATCH] plugins: ensure the community plugin considers all missions The code used on `/annuaire` uses the Community plugin which allows querying everybody that's active, and everybody that's not (i.e: alumni). To figure out if they are alumni, it was grabbing the last mission (missions.last) and comparing the end date with today. That's fair but it turns out that our member files are, obviously, not always sorted chronologically. Some of them have an early mission (early in the array) that's still active, but with the previous logic it's only the last mission considered hence why they don't appaear in the current members tab. So instead use the glorious DSL (lib/member.rb) again to wrap the data and query for any `active_missions` which removes some duplicate logic and the display bug as well. --- _plugins/community.rb | 10 +++------- spec/plugins/community_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/_plugins/community.rb b/_plugins/community.rb index ddf9e8b2e491..243b100f6067 100644 --- a/_plugins/community.rb +++ b/_plugins/community.rb @@ -1,15 +1,11 @@ # frozen_string_literal: true +require_relative '../lib/models/member' + module Jekyll module CommunityFilter def community(people, state, sort_by = 'oldest') - now = Date.today - - past, current = people.partition do |person| - date = person.data['missions']&.last&.dig('end') - - date && date <= now - end + current, past = people.partition { |person| Beta::Member.new(person.data).active_missions.any? } result = state == 'past' ? past : current diff --git a/spec/plugins/community_spec.rb b/spec/plugins/community_spec.rb index 1d2d34c19100..a7784b3586a4 100644 --- a/spec/plugins/community_spec.rb +++ b/spec/plugins/community_spec.rb @@ -54,6 +54,26 @@ def member_with(name:, end_date: nil, start_date: nil) expect(past).to contain_exactly alum end + context 'when the member has an active mission earlier in the missions array' do + before do + active_mission = { end_date: Date.today.tomorrow } + + alum.data['missions'].prepend(active_mission) + end + + it 'counts them as active' do + current = template.community(members, 'current') + + expect(current).to include alum + end + + it 'does not count them as alumni' do + past = template.community(members, 'past') + + expect(past).to be_empty + end + end + it 'sorts them by newest mission start by default' do expect(template.community(members, 'current')).to start_with(with_end) end