Class: Decidim::Meetings::Seeds
- Inherits:
-
Seeds
- Object
- Seeds
- Decidim::Meetings::Seeds
- Defined in:
- lib/decidim/meetings/seeds.rb
Instance Attribute Summary collapse
-
#participatory_space ⇒ Object
readonly
Returns the value of attribute participatory_space.
Instance Method Summary collapse
- #call ⇒ Object
- #create_component! ⇒ Object
-
#create_meeting!(component:, type: :in_person, author_type: :official) ⇒ Decidim::Meeting
Create a meeting.
- #create_meeting_registration!(meeting:) ⇒ Object
- #create_questionnaire_for!(meeting:) ⇒ Object
- #create_service!(meeting:) ⇒ Object
-
#initialize(participatory_space:) ⇒ Seeds
constructor
A new instance of Seeds.
- #meeting_params(component:, type:, author_type:) ⇒ Object
Constructor Details
#initialize(participatory_space:) ⇒ Seeds
Returns a new instance of Seeds.
11 12 13 |
# File 'lib/decidim/meetings/seeds.rb', line 11 def initialize(participatory_space:) @participatory_space = participatory_space end |
Instance Attribute Details
#participatory_space ⇒ Object (readonly)
Returns the value of attribute participatory_space.
9 10 11 |
# File 'lib/decidim/meetings/seeds.rb', line 9 def participatory_space @participatory_space end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/decidim/meetings/seeds.rb', line 15 def call component = create_component! number_of_records.times do create_meeting!(component:, type: :online) create_meeting!(component:, type: :online_live_event) create_meeting!(component:, type: :hybrid) meeting = create_meeting!(component:, type: :in_person) number_of_records.times do create_service!(meeting:) end create_questionnaire_for!(meeting:) number_of_records.times do |_n| create_meeting_registration!(meeting:) end (attached_to: meeting) end create_meeting!(component:, type: [:in_person, :online, :hybrid].sample, author_type: :user) end |
#create_component! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/decidim/meetings/seeds.rb', line 40 def create_component! params = { name: Decidim::Components::Namer.new(participatory_space.organization.available_locales, :meetings).i18n_name, published_at: Time.current, manifest_name: :meetings, participatory_space: } Decidim.traceability.perform_action!( "publish", Decidim::Component, admin_user, visibility: "all" ) do Decidim::Component.create!(params) end end |
#create_meeting!(component:, type: :in_person, author_type: :official) ⇒ Decidim::Meeting
Create a meeting
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/decidim/meetings/seeds.rb', line 147 def create_meeting!(component:, type: :in_person, author_type: :official) params = meeting_params(component:, type:, author_type:) resource = Decidim.traceability.create!( Decidim::Meetings::Meeting, admin_user, params, visibility: "all" ) Decidim::EventsManager.publish( event: "decidim.events.meetings.meeting_created", event_class: Decidim::Meetings::CreateMeetingEvent, resource:, followers: resource.participatory_space.followers ) Decidim.traceability.perform_action!(:publish, resource, admin_user, visibility: "all") do resource.publish! end Decidim::Comments::Seed.comments_for(resource) resource end |
#create_meeting_registration!(meeting:) ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/decidim/meetings/seeds.rb', line 194 def create_meeting_registration!(meeting:) r = SecureRandom.hex(4) email = "meeting-registered-user-#{meeting.id}-#{r}@example.org" user = find_or_initialize_user_by(email:) Decidim::Meetings::Registration.create!( meeting:, user: ) end |
#create_questionnaire_for!(meeting:) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/decidim/meetings/seeds.rb', line 181 def create_questionnaire_for!(meeting:) Decidim::Forms::Questionnaire.create!( title: Decidim::Faker::Localized.paragraph, description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 3) end, tos: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 2) end, questionnaire_for: meeting ) end |
#create_service!(meeting:) ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/decidim/meetings/seeds.rb', line 173 def create_service!(meeting:) Decidim::Meetings::Service.create!( meeting:, title: Decidim::Faker::Localized.sentence(word_count: 2), description: Decidim::Faker::Localized.sentence(word_count: 5) ) end |
#meeting_params(component:, type:, author_type:) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/decidim/meetings/seeds.rb', line 58 def meeting_params(component:, type:, author_type:) start_time = ::Faker::Date.between(from: 20.weeks.ago, to: 20.weeks.from_now) end_time = start_time + [rand(1..4).hours, rand(1..20).days].sample registration_type = Decidim::Meetings::Meeting::REGISTRATION_TYPES.keys.sample params = { component:, title: Decidim::Faker::Localized.sentence(word_count: 2), description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 3) end, location: Decidim::Faker::Localized.sentence(word_count: rand(2..20)), location_hints: Decidim::Faker::Localized.sentence(word_count: rand(2..20)), start_time:, end_time:, address: "#{::Faker::Address.street_address} #{::Faker::Address.zip} #{::Faker::Address.city}", latitude: ::Faker::Address.latitude, longitude: ::Faker::Address.longitude, registrations_enabled: [true, false].sample, available_slots: (10..50).step(10).to_a.sample, author: participatory_space.organization, registration_type:, registration_terms: Decidim::Faker::Localized.wrapped("<p>", "</p>") do Decidim::Faker::Localized.paragraph(sentence_count: 3) end, send_reminders_before_hours: 48, published_at: ::Faker::Boolean.boolean(true_ratio: 0.8) ? Time.current : nil } params = case type when :hybrid params.merge( type_of_meeting: :hybrid, online_meeting_url: "https://www.youtube.com/watch?v=f6JMgJAQ2tc", iframe_access_level: :all, iframe_embed_type: [:embed_in_meeting_page, :open_in_live_event_page, :open_in_new_tab].sample ) when :online params.merge( location: nil, location_hints: nil, latitude: nil, longitude: nil, type_of_meeting: :online, online_meeting_url: "https://www.youtube.com/watch?v=f6JMgJAQ2tc", iframe_access_level: :all, iframe_embed_type: [:embed_in_meeting_page, :open_in_live_event_page, :open_in_new_tab].sample ) when :online_live_event params.merge( location: nil, location_hints: nil, latitude: nil, longitude: nil, type_of_meeting: :online, online_meeting_url: "https://www.youtube.com/watch?v=f6JMgJAQ2tc", iframe_access_level: :all, iframe_embed_type: :open_in_live_event_page ) else params # :in_person end params = case registration_type when :on_different_platform params.merge(registration_url: Faker::Internet.url) when :on_this_platform params.merge(registrations_enabled: true) else params # registration_disabled end case when :user params.merge( author: Decidim::User.where(decidim_organization_id: participatory_space.decidim_organization_id).all.sample ) else params # official end end |