Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions decidim-core/app/cells/decidim/address/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<%= start_and_end_time %>
</div>
</div>
</div>
</li>
<% end %>
</ul>
12 changes: 11 additions & 1 deletion decidim-core/app/cells/decidim/address_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def location_hints
end

def location
return pending_address_text if pending_address?

decidim_sanitize_translated(model.location)
end

def address
decidim_sanitize_translated(model.address)
decidim_sanitize_translated(model.address) if model.respond_to?(:address) && model.address.present?
end

def display_start_and_end_time?
Expand Down Expand Up @@ -63,5 +65,13 @@ def start_time
def end_time
l model.end_time, format: "%H:%M %p %Z"
end

def pending_address?
address.blank? && model.location.is_a?(Hash) ? model.location.values.none?(&:present?) : model.location.blank?
end

def pending_address_text
t("show.pending_address", scope: "decidim.meetings.meetings")
end
end
end
13 changes: 13 additions & 0 deletions decidim-core/spec/cells/decidim/address_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
end
end

context "when address is pending" do
let(:location) { {} }
let(:address) { "" }

before do
allow(model).to receive(:location).and_return(location)
end

it "renders pending address text" do
expect(subject.find(".address__location")).to have_content(I18n.t("show.pending_address", scope: "decidim.meetings.meetings"))
end
end

context "with an online meeting url" do
let(:my_cell) { cell("decidim/address", model, online: true) }
let(:model) { create(:dummy_resource) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def same_day?
end

def display_map?
maps_enabled? && !online?
maps_enabled? && !online? && model.address.present?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ def copy_meeting!
description: parsed_description,
end_time: form.end_time,
start_time: form.start_time,
address: form.address,
address: form.location_pending ? "" : form.address,
latitude: form.latitude,
longitude: form.longitude,
location: form.location,
location: form.location_pending ? {} : form.location,
location_hints: form.location_hints,
component: meeting.component,
private_meeting: form.private_meeting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def attributes
title: parsed_title,
description: parsed_description,
type_of_meeting: form.clean_type_of_meeting,
address: form.location_pending ? "" : form.address,
location: form.location_pending ? {} : form.location,
author: form.current_organization,
registration_terms: form.current_component.settings.default_registration_terms,
questionnaire: Decidim::Forms::Questionnaire.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def attributes
super.merge({
title: parsed_title,
description: parsed_description,
type_of_meeting: form.clean_type_of_meeting
type_of_meeting: form.clean_type_of_meeting,
address: form.location_pending ? "" : form.address,
location: form.location_pending ? nil : form.location
})
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Admin
class MeetingForm < ::Decidim::Meetings::BaseMeetingForm
include TranslatableAttributes

attribute :location_pending, Boolean, default: false
attribute :services, Array[MeetingServiceForm]
attribute :component_ids, Array[Integer]
attribute :private_meeting, Boolean
Expand All @@ -32,7 +33,9 @@ class MeetingForm < ::Decidim::Meetings::BaseMeetingForm
validates :registration_type, presence: true
validates :registration_url, presence: true, url: true, if: ->(form) { form.on_different_platform? }
validates :type_of_meeting, presence: true
validates :location, translatable_presence: true, if: ->(form) { form.in_person_meeting? || form.hybrid_meeting? }
validates :location, translatable_presence: true, if: ->(form) { !form.location_pending && (form.in_person_meeting? || form.hybrid_meeting?) }
validates :address, presence: true, if: ->(form) { !form.location_pending && (form.in_person_meeting? || form.hybrid_meeting?) }
validates :address, geocoding: true, if: ->(form) { !form.location_pending && form.has_address? && !form.geocoded? }
validates :online_meeting_url, url: true, if: ->(form) { form.online_meeting? || form.hybrid_meeting? }
validates :comments_start_time, date: { before: :comments_end_time, allow_blank: true, if: proc { |obj| obj.comments_end_time.present? } }
validates :comments_end_time, date: { after: :comments_start_time, allow_blank: true, if: proc { |obj| obj.comments_start_time.present? } }
Expand All @@ -54,6 +57,7 @@ def map_model(model)
presenter = MeetingEditionPresenter.new(model)
self.title = presenter.title(all_locales: true)
self.description = presenter.editor_description(all_locales: true)
self.location_pending = model.address.blank? && model.location.to_h.values.none?(&:present?)
end

def services_to_persist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class BaseMeetingForm < Decidim::Form
attribute :end_time, Decidim::Attributes::TimeWithZone

validates :current_component, presence: true

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

Expand Down
2 changes: 2 additions & 0 deletions decidim-meetings/app/forms/decidim/meetings/meeting_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class MeetingForm < ::Decidim::Meetings::BaseMeetingForm
validates :title, presence: true, etiquette: true
validates :description, presence: true, etiquette: true
validates :type_of_meeting, presence: true
validates :address, presence: true, if: ->(form) { form.needs_address? }
validates :address, geocoding: true, if: ->(form) { form.has_address? && !form.geocoded? && form.needs_address? }
validates :location, presence: true, if: ->(form) { form.in_person_meeting? || form.hybrid_meeting? }
validates :online_meeting_url, presence: true, url: true, if: ->(form) { form.online_meeting? || form.hybrid_meeting? }
validates :registration_type, presence: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@
</div>

<div class="row column" data-meeting-type="in_person">
<%= form.geocoding_field :address, help_text: t(".address_help") %>
<%= form.check_box :location_pending, label: t("location_pending", scope: "decidim.meetings.admin.meetings.form"), "data-toggle": "location_fields-div" %>
<p class="help-text"><%= t(".location_pending_help") %></p>
</div>

<div class="row column" data-meeting-type="in_person">
<%= form.translated :text_area, :location, help_text: t(".location_help") %>
<div id="location_fields-div" data-toggler=".hide" class="<%= @form.location_pending ? "hide" : nil %>">
<div class="row column" data-meeting-type="in_person">
<%= form.geocoding_field :address %>
<p class="help-text"><%= t(".address_help") %></p>
</div>

<div class="row column" data-meeting-type="in_person">
<%= form.translated :text_area, :location %>
<p class="help-text"><%= t(".location_help") %></p>
</div>
</div>

<div class="row column">
Expand Down
3 changes: 3 additions & 0 deletions decidim-meetings/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ en:
iframe_embed_type_html: 'Only a few services allow embedding in meeting or live event from the following domains: %{domains}'
location_help: 'Location: message directed to the users implying the spot to meet at'
location_hints_help: 'Location hints: additional info. Example: the floor of the building if it is an in-person meeting, or the meeting password if it is an online meeting with restricted access.'
location_pending: In-person/Hybrid, venue to be decided
location_pending_help: Select this option if the venue has not been decided yet. The message 'Place will be communicated soon' will be shown on the public page.
online_meeting_url_help: 'Link: allow participants to connect directly to your meeting'
registration_url_help: 'Link: allow participants to go on the external service you are using for registrations'
select_a_meeting_type: Please select a meeting type
Expand Down Expand Up @@ -604,6 +606,7 @@ en:
micro_camera_permissions_warning: When you click on the button below, you will be asked for microphone and/or camera permissions, and you will join the videoconference
no_slots_available: No slots available
organizations: Attending organizations
pending_address: Place will be communicated soon.
redirect_notice: This meeting is part of another space, so you have been moved to %{current_space_name}. <br>If you prefer, you can go back to <a href="%{previous_space_url}">%{previous_space_name}</a>.
registration_code_help_text: Your registration code
registration_state:
Expand Down
13 changes: 13 additions & 0 deletions decidim-meetings/spec/commands/admin/copy_meeting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Decidim::Meetings
let!(:meeting) { create(:meeting, component:, taxonomies: [taxonomy]) }

let(:current_user) { create(:user, :admin, :confirmed, organization:) }
let(:location_pending) { false }
let(:address) { "address" }
let(:invalid) { false }
let(:latitude) { 40.1234 }
Expand All @@ -32,6 +33,7 @@ module Decidim::Meetings
invalid?: invalid,
title: { en: "title" },
description: { en: "description" },
location_pending:,
location: { en: "location" },
location_hints: { en: "location hints" },
start_time:,
Expand Down Expand Up @@ -90,6 +92,17 @@ module Decidim::Meetings
expect { subject.call }.to broadcast(:ok)
end

context "and location_pending is true" do
let(:location_pending) { true }

it "sets location to nil" do
expect { subject.call }.to change(Meeting, :count).by(1)
new_meeting = Meeting.last
expect(new_meeting.location).to be_empty
expect(new_meeting.address).to be_empty
end
end

context "and saves the correct meeting type" do
context "with in_person meeting type" do
let!(:meeting) { create(:meeting, :in_person, component:) }
Expand Down
13 changes: 13 additions & 0 deletions decidim-meetings/spec/commands/admin/create_meeting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Decidim::Meetings
let(:current_user) { create(:user, :admin, :confirmed, organization:) }
let(:participatory_process) { create(:participatory_process, organization:) }
let(:current_component) { create(:component, participatory_space: participatory_process, manifest_name: "meetings") }
let(:location_pending) { false }
let(:address) { "address" }
let(:invalid) { false }
let(:latitude) { 40.1234 }
Expand Down Expand Up @@ -54,6 +55,7 @@ module Decidim::Meetings
location_hints: { en: "location_hints" },
start_time:,
end_time: 1.day.from_now + 1.hour,
location_pending:,
address:,
latitude:,
longitude:,
Expand Down Expand Up @@ -94,6 +96,17 @@ module Decidim::Meetings
expect { subject.call }.to change(Meeting, :count).by(1)
end

context "and location_pending is true" do
let(:location_pending) { true }

it "sets location to nil" do
expect { subject.call }.to change(Meeting, :count).by(1)
new_meeting = Meeting.last
expect(new_meeting.location).to be_empty
expect(new_meeting.address).to be_empty
end
end

it "sets the taxonomies" do
subject.call
expect(meeting.taxonomizations).to match_array(taxonomizations)
Expand Down
13 changes: 13 additions & 0 deletions decidim-meetings/spec/commands/admin/update_meeting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Decidim::Meetings

let(:meeting) { create(:meeting, :published) }
let(:organization) { meeting.component.organization }
let(:location_pending) { false }
let(:address) { meeting.address }
let(:invalid) { false }
let(:latitude) { 40.1234 }
Expand Down Expand Up @@ -39,6 +40,7 @@ module Decidim::Meetings
invalid?: invalid,
title: { en: "title" },
description: { en: "description" },
location_pending:,
location: { en: "location" },
location_hints: { en: "location_hints" },
start_time: 1.day.from_now,
Expand Down Expand Up @@ -80,6 +82,16 @@ module Decidim::Meetings
expect(translated(meeting.title)).to eq "title"
end

context "and location_pending is true" do
let(:location_pending) { true }

it "sets location to nil" do
subject.call
expect(translated(meeting.location)).to be_nil
expect(meeting.address).to be_empty
end
end

it "sets the taxonomies" do
subject.call
expect(meeting.reload.taxonomies).to eq(taxonomizations.map(&:taxonomy))
Expand Down Expand Up @@ -137,6 +149,7 @@ module Decidim::Meetings
invalid?: false,
title:,
description: meeting.description,
location_pending:,
location: meeting.location,
location_hints: meeting.location_hints,
start_time:,
Expand Down
32 changes: 32 additions & 0 deletions decidim-meetings/spec/forms/admin/meeting_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Decidim::Meetings
let(:services_attributes) do
services.map(&:attributes)
end
let(:location_pending) { false }
let(:address) { "Somewhere over the rainbow" }
let(:latitude) { 40.1234 }
let(:longitude) { 2.1234 }
Expand All @@ -59,6 +60,7 @@ module Decidim::Meetings
title_en: title[:en],
description_en: description[:en],
short_description_en: short_description[:en],
location_pending:,
location_en: location[:en],
location_hints_en: location_hints[:en],
address:,
Expand Down Expand Up @@ -93,6 +95,36 @@ module Decidim::Meetings

it { is_expected.to be_valid }

describe "when location_pending enabled" do
let(:location_pending) { true }

it { is_expected.to be_valid }

context "and location is missing" do
let(:location) { { en: nil } }

it { is_expected.to be_valid }
end

context "and address is missing" do
let(:address) { nil }

it { is_expected.to be_valid }
end

context "and location is present" do
let(:location) { { en: "location" } }

it { is_expected.to be_valid }
end

context "and address is present" do
let(:address) { "Somewhere over the rainbow" }

it { is_expected.to be_valid }
end
end

describe "when title is missing" do
let(:title) { { en: nil } }

Expand Down
37 changes: 37 additions & 0 deletions decidim-meetings/spec/system/admin/admin_manages_meetings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,43 @@
expect(page).to have_content("created the #{translated(attributes[:title])} meeting on the")
end

context "when the venue has not been decided yet" do
it "creates a new meeting without a location" do
click_on "New meeting"

fill_in_i18n(:meeting_title, "#meeting-title-tabs", **attributes[:title].except("machine_translations"))

expect(page).to have_no_field("In-person/Hybrid, venue to be decided")

select "In person", from: :meeting_type_of_meeting

expect(page).to have_field("In-person/Hybrid, venue to be decided")

check "In-person/Hybrid, venue to be decided"

expect(page).to have_no_field(:meeting_location_en)
expect(page).to have_no_field(:meeting_address)

fill_in_i18n_editor(:meeting_description, "#meeting-description-tabs", **attributes[:description].except("machine_translations"))
select "Registration disabled", from: :meeting_registration_type
fill_in_datepicker :meeting_start_time_date, with: meeting_start_date
fill_in_timepicker :meeting_start_time_time, with: meeting_start_time
fill_in_datepicker :meeting_end_time_date, with: meeting_end_date
fill_in_timepicker :meeting_end_time_time, with: meeting_end_time

within ".new_meeting" do
find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

new_meeting = Decidim::Meetings::Meeting.last
puts "Meeting location: #{new_meeting.location}"
expect(new_meeting.location).to be_empty
expect(new_meeting.address).to be_empty
end
end

context "when no taxonomy filter is selected" do
let(:taxonomy_filter_ids) { [] }

Expand Down
Loading
Loading