Class: Decidim::ParticipatoryProcesses::Seeds

Inherits:
Seeds
  • Object
show all
Defined in:
lib/decidim/participatory_processes/seeds.rb

Instance Method Summary collapse

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/decidim/participatory_processes/seeds.rb', line 9

def call
  create_content_block!

  process_groups = []
  2.times do
    process_groups << create_process_group!
  end

  process_groups.each do |process_group|
    Decidim::ContentBlocksCreator.new(process_group).create_default!
  end

  process_types = []
  2.times do
    process_types << create_process_type!
  end

  2.times do |_n|
    process = create_process!(process_group: process_groups.sample, process_type: process_types.sample)

    create_follow!(Decidim::User.where(organization:, admin: true).first, process)
    create_follow!(Decidim::User.where(organization:, admin: false).first, process)

    create_process_step!(process:)

    create_process_user_roles!(process:)

    Decidim::ContentBlocksCreator.new(process).create_default!

    create_attachments!(attached_to: process)

    2.times do
      create_category!(participatory_space: process)
    end

    seed_components_manifests!(participatory_space: process)
  end
end

#create_content_block!Object



48
49
50
51
52
53
54
55
56
# File 'lib/decidim/participatory_processes/seeds.rb', line 48

def create_content_block!
  Decidim::ContentBlock.create(
    organization:,
    weight: 31,
    scope_name: :homepage,
    manifest_name: :highlighted_processes,
    published_at: Time.current
  )
end

#create_process!(process_group: nil, process_type: nil) ⇒ Object



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
# File 'lib/decidim/participatory_processes/seeds.rb', line 84

def create_process!(process_group: nil, process_type: nil)
  n = rand(2)
  params = {
    title: Decidim::Faker::Localized.sentence(word_count: 5),
    slug: Decidim::Faker::Internet.unique.slug(words: nil, glue: "-"),
    subtitle: Decidim::Faker::Localized.sentence(word_count: 2),
    hashtag: "##{::Faker::Lorem.word}",
    short_description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.sentence(word_count: 3)
    end,
    description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    organization:,
    hero_image: ::Faker::Boolean.boolean(true_ratio: 0.5) ? hero_image : nil, # Keep after organization
    promoted: true,
    published_at: 2.weeks.ago,
    meta_scope: Decidim::Faker::Localized.word,
    developer_group: Decidim::Faker::Localized.sentence(word_count: 1),
    local_area: Decidim::Faker::Localized.sentence(word_count: 2),
    target: Decidim::Faker::Localized.sentence(word_count: 3),
    participatory_scope: Decidim::Faker::Localized.sentence(word_count: 1),
    participatory_structure: Decidim::Faker::Localized.sentence(word_count: 2),
    start_date: Date.current,
    end_date: 2.months.from_now,
    participatory_process_group: process_group,
    participatory_process_type: process_type,
    scope: n.positive? ? nil : Decidim::Scope.all.sample
  }

  process = Decidim.traceability.perform_action!(
    "publish",
    Decidim::ParticipatoryProcess,
    organization.users.first,
    visibility: "all"
  ) do
    Decidim::ParticipatoryProcess.create!(params)
  end
  process.add_to_index_as_search_resource

  process
end

#create_process_group!Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/decidim/participatory_processes/seeds.rb', line 58

def create_process_group!
  Decidim::ParticipatoryProcessGroup.create!(
    title: Decidim::Faker::Localized.sentence(word_count: 3),
    description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    hashtag: ::Faker::Internet.slug,
    group_url: ::Faker::Internet.url,
    organization:,
    hero_image: ::Faker::Boolean.boolean(true_ratio: 0.5) ? hero_image : nil, # Keep after organization
    developer_group: Decidim::Faker::Localized.sentence(word_count: 1),
    local_area: Decidim::Faker::Localized.sentence(word_count: 2),
    meta_scope: Decidim::Faker::Localized.word,
    target: Decidim::Faker::Localized.sentence(word_count: 3),
    participatory_scope: Decidim::Faker::Localized.sentence(word_count: 1),
    participatory_structure: Decidim::Faker::Localized.sentence(word_count: 2)
  )
end

#create_process_step!(process:) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/decidim/participatory_processes/seeds.rb', line 127

def create_process_step!(process:)
  Decidim::ParticipatoryProcessStep.find_or_initialize_by(
    participatory_process: process,
    active: true
  ).update!(
    title: Decidim::Faker::Localized.sentence(word_count: 1, supplemental: false, random_words_to_add: 2),
    description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
      Decidim::Faker::Localized.paragraph(sentence_count: 3)
    end,
    start_date: 1.month.ago,
    end_date: 2.months.from_now
  )
end

#create_process_type!Object



77
78
79
80
81
82
# File 'lib/decidim/participatory_processes/seeds.rb', line 77

def create_process_type!
  Decidim::ParticipatoryProcessType.create!(
    title: Decidim::Faker::Localized.word,
    organization:
  )
end

#create_process_user_roles!(process:) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/decidim/participatory_processes/seeds.rb', line 141

def create_process_user_roles!(process:)
  # Create users with specific roles
  Decidim::ParticipatoryProcessUserRole::ROLES.each do |role|
    email = "participatory_process_#{process.id}_#{role}@example.org"
    user = find_or_initialize_user_by(email:)

    Decidim::ParticipatoryProcessUserRole.find_or_create_by!(
      user:,
      participatory_process: process,
      role:
    )
  end
end