Skip to content

Commit 4fb8959

Browse files
antopalidialecslupu
authored andcommitted
Allow meeting addresses to be unset/TBD (decidim#14389)
* update validations, add pending_location_text * add tests * update notifications * add tests * refactor: move pending_location? logic to model * Apply suggestions from code review Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro> * fix test * fix validations * change validations * fix validations * change tests --------- Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
1 parent b2876ec commit 4fb8959

16 files changed

Lines changed: 198 additions & 22 deletions

File tree

decidim-core/app/cells/decidim/address/show.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<%= start_and_end_time %>
2525
</div>
2626
</div>
27+
</div>
2728
</li>
2829
<% end %>
2930
</ul>

decidim-core/app/cells/decidim/address_cell.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ def location_hints
2424
end
2525

2626
def location
27+
return pending_location_text if model.respond_to?(:pending_location?) && model.pending_location?
28+
2729
decidim_sanitize_translated(model.location)
2830
end
2931

3032
def address
31-
decidim_sanitize_translated(model.address)
33+
decidim_sanitize_translated(model.address) if model.respond_to?(:address) && model.address.present?
34+
end
35+
36+
def pending_location_text
37+
t("show.pending_address", scope: "decidim.meetings.meetings")
3238
end
3339

3440
def display_start_and_end_time?

decidim-core/spec/cells/decidim/address_cell_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@
3737
end
3838
end
3939

40+
context "when address is pending" do
41+
let(:location) { { "ca" => "", "en" => "", "es" => "", "machine_translations" => { "es" => "Location" } } }
42+
43+
before do
44+
allow(model).to receive(:location).and_return location
45+
allow(model).to receive(:pending_location?).and_return(true)
46+
end
47+
48+
it "renders pending address text" do
49+
expect(subject.find(".address__location")).to have_content(I18n.t("show.pending_address", scope: "decidim.meetings.meetings"))
50+
end
51+
end
52+
4053
context "with an online meeting url" do
4154
let(:my_cell) { cell("decidim/address", model, online: true) }
4255
let(:model) { create(:dummy_resource) }

decidim-meetings/app/cells/decidim/meetings/dates_and_map_cell.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def same_day?
3232
end
3333

3434
def display_map?
35-
maps_enabled? && !online?
35+
maps_enabled? && !online? && model.address.present?
3636
end
3737
end
3838
end

decidim-meetings/app/commands/decidim/meetings/admin/update_meeting.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def send_notification
4545
event: "decidim.events.meetings.meeting_updated",
4646
event_class: Decidim::Meetings::UpdateMeetingEvent,
4747
resource:,
48-
followers: resource.followers
48+
followers: resource.followers,
49+
extra: { changed_fields: resource.previous_changes.keys & important_attributes }
4950
)
5051
end
5152

@@ -54,13 +55,17 @@ def should_notify_followers?
5455
end
5556

5657
def important_attributes
57-
%w(start_time end_time address)
58+
%w(start_time end_time address location)
5859
end
5960

6061
def start_time_changed?
6162
resource.previous_changes["start_time"].present?
6263
end
6364

65+
def address_changed?
66+
resource.previous_changes["address"].present? || resource.previous_changes["location"].present?
67+
end
68+
6469
def schedule_upcoming_meeting_notification
6570
return if resource.start_time < Time.zone.now
6671
return unless resource.reminder_enabled

decidim-meetings/app/events/decidim/meetings/update_meeting_event.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,31 @@ module Decidim
44
module Meetings
55
class UpdateMeetingEvent < Decidim::Events::SimpleEvent
66
include Decidim::Meetings::MeetingEvent
7+
8+
i18n_attributes :changed_fields
9+
10+
def notification_title
11+
I18n.t(
12+
"notification_title",
13+
scope: i18n_scope,
14+
changed_fields: changed_fields,
15+
resource_title: translated_attribute(resource.title),
16+
resource_path: resource_path
17+
).html_safe
18+
end
19+
20+
private
21+
22+
def changed_field_keys
23+
extra[:changed_fields] || []
24+
end
25+
26+
def changed_fields
27+
keys = changed_field_keys
28+
return "" if keys.empty?
29+
30+
keys.map { |key| I18n.t("field_names.#{key}", scope: i18n_scope) }.to_sentence
31+
end
732
end
833
end
934
end

decidim-meetings/app/forms/decidim/meetings/admin/meeting_form.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class MeetingForm < ::Decidim::Meetings::BaseMeetingForm
3636
validates :registration_type, presence: true
3737
validates :registration_url, presence: true, url: true, if: ->(form) { form.on_different_platform? }
3838
validates :type_of_meeting, presence: true
39-
validates :location, translatable_presence: true, if: ->(form) { form.in_person_meeting? || form.hybrid_meeting? }
39+
validates :address, presence: true, if: ->(form) { form.needs_address? && form.location.values.any?(&:present?) && form.address.blank? }
40+
validates :location, translatable_presence: true, if: ->(form) { form.needs_address? && form.address.present? }
41+
validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? && form.needs_address? }
4042
validates :online_meeting_url, url: true, if: ->(form) { form.online_meeting? || form.hybrid_meeting? }
4143
validates :comments_start_time, date: { before: :comments_end_time, allow_blank: true, if: proc { |obj| obj.comments_end_time.present? } }
4244
validates :comments_end_time, date: { after: :comments_start_time, allow_blank: true, if: proc { |obj| obj.comments_start_time.present? } }

decidim-meetings/app/forms/decidim/meetings/base_meeting_form.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class BaseMeetingForm < Decidim::Form
1313

1414
validates :current_component, presence: true
1515

16-
validates :address, presence: true, if: ->(form) { form.needs_address? }
17-
validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? && form.needs_address? }
1816
validates :start_time, presence: true, date: { before: :end_time }
1917
validates :end_time, presence: true, date: { after: :start_time }
2018

decidim-meetings/app/forms/decidim/meetings/meeting_form.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class MeetingForm < ::Decidim::Meetings::BaseMeetingForm
2020
attribute :iframe_embed_type, String, default: "none"
2121
attribute :iframe_access_level, String
2222

23+
validates :address, presence: true, if: ->(form) { form.needs_address? }
24+
validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? && form.needs_address? }
2325
validates :iframe_embed_type, inclusion: { in: Decidim::Meetings::Meeting.participants_iframe_embed_types }
2426
validates :title, presence: true
2527
validates :description, presence: true

decidim-meetings/app/models/decidim/meetings/meeting.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ def has_registration_for?(user)
213213
registrations.where(user:).any?
214214
end
215215

216+
def pending_location?
217+
!online? && location.except("machine_translations").values.all?(&:blank?)
218+
end
219+
216220
def maps_enabled?
217221
component.settings.maps_enabled?
218222
end

0 commit comments

Comments
 (0)