decidim-proposals 0.15.2 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -0
  3. data/app/assets/config/decidim_proposals_manifest.js +1 -0
  4. data/app/assets/javascripts/decidim/proposals/add_proposal.js.es6 +1 -1
  5. data/app/assets/javascripts/decidim/proposals/admin/proposals_form.js.es6 +23 -0
  6. data/app/cells/decidim/proposals/collaborative_draft_cell.rb +0 -2
  7. data/app/cells/decidim/proposals/collaborative_draft_m_cell.rb +5 -1
  8. data/app/cells/decidim/proposals/highlighted_proposals/show.erb +3 -0
  9. data/app/cells/decidim/proposals/highlighted_proposals_cell.rb +25 -0
  10. data/app/cells/decidim/proposals/highlighted_proposals_for_component/show.erb +19 -0
  11. data/app/cells/decidim/proposals/highlighted_proposals_for_component_cell.rb +34 -0
  12. data/app/cells/decidim/proposals/participatory_text_proposal/buttons.erb +33 -0
  13. data/app/cells/decidim/proposals/participatory_text_proposal/show.erb +9 -0
  14. data/app/cells/decidim/proposals/participatory_text_proposal_cell.rb +77 -0
  15. data/app/cells/decidim/proposals/proposal_cell.rb +0 -2
  16. data/app/cells/decidim/proposals/proposal_m/footer.erb +1 -1
  17. data/app/cells/decidim/proposals/proposal_m_cell.rb +6 -1
  18. data/app/commands/decidim/proposals/accept_access_to_collaborative_draft.rb +3 -3
  19. data/app/commands/decidim/proposals/admin/answer_proposal.rb +2 -1
  20. data/app/commands/decidim/proposals/admin/create_proposal.rb +7 -7
  21. data/app/commands/decidim/proposals/admin/import_participatory_text.rb +8 -8
  22. data/app/commands/decidim/proposals/admin/update_proposal.rb +13 -6
  23. data/app/commands/decidim/proposals/admin/update_proposal_category.rb +1 -1
  24. data/app/commands/decidim/proposals/create_collaborative_draft.rb +6 -3
  25. data/app/commands/decidim/proposals/create_proposal.rb +25 -11
  26. data/app/commands/decidim/proposals/endorse_proposal.rb +1 -2
  27. data/app/commands/decidim/proposals/hashtags_methods.rb +36 -0
  28. data/app/commands/decidim/proposals/publish_collaborative_draft.rb +39 -34
  29. data/app/commands/decidim/proposals/publish_proposal.rb +13 -17
  30. data/app/commands/decidim/proposals/reject_access_to_collaborative_draft.rb +2 -3
  31. data/app/commands/decidim/proposals/request_access_to_collaborative_draft.rb +1 -2
  32. data/app/commands/decidim/proposals/update_collaborative_draft.rb +11 -8
  33. data/app/commands/decidim/proposals/update_proposal.rb +37 -13
  34. data/app/commands/decidim/proposals/withdraw_collaborative_draft.rb +3 -3
  35. data/app/commands/decidim/proposals/withdraw_proposal.rb +14 -1
  36. data/app/controllers/decidim/proposals/admin/participatory_texts_controller.rb +2 -1
  37. data/app/controllers/decidim/proposals/admin/proposals_controller.rb +9 -1
  38. data/app/controllers/decidim/proposals/collaborative_drafts_controller.rb +8 -0
  39. data/app/controllers/decidim/proposals/proposals_controller.rb +64 -27
  40. data/app/controllers/decidim/proposals/versions_controller.rb +5 -1
  41. data/app/events/decidim/proposals/accepted_proposal_event.rb +8 -0
  42. data/app/events/decidim/proposals/evaluating_proposal_event.rb +3 -0
  43. data/app/events/decidim/proposals/proposal_endorsed_event.rb +4 -0
  44. data/app/events/decidim/proposals/publish_proposal_event.rb +4 -0
  45. data/app/events/decidim/proposals/rejected_proposal_event.rb +8 -0
  46. data/app/forms/decidim/proposals/admin/import_participatory_text_form.rb +4 -0
  47. data/app/forms/decidim/proposals/admin/proposal_form.rb +49 -0
  48. data/app/forms/decidim/proposals/collaborative_draft_form.rb +2 -0
  49. data/app/forms/decidim/proposals/proposal_form.rb +32 -0
  50. data/app/helpers/decidim/proposals/admin/proposals_helper.rb +19 -0
  51. data/app/helpers/decidim/proposals/application_helper.rb +48 -12
  52. data/app/helpers/decidim/proposals/control_version_helper.rb +61 -0
  53. data/app/helpers/decidim/proposals/participatory_texts_helper.rb +8 -0
  54. data/app/helpers/decidim/proposals/proposal_cells_helper.rb +7 -1
  55. data/app/helpers/decidim/proposals/proposal_endorsements_helper.rb +8 -6
  56. data/app/jobs/decidim/proposals/notify_proposals_mentioned_job.rb +2 -2
  57. data/app/jobs/decidim/proposals/settings_change_job.rb +8 -6
  58. data/app/models/decidim/proposals/collaborative_draft.rb +3 -0
  59. data/app/models/decidim/proposals/proposal.rb +20 -8
  60. data/app/permissions/decidim/proposals/admin/permissions.rb +1 -1
  61. data/app/presenters/decidim/proposals/admin_log/value_types/proposal_title_body_presenter.rb +2 -1
  62. data/app/presenters/decidim/proposals/collaborative_draft_presenter.rb +15 -2
  63. data/app/presenters/decidim/proposals/official_author_presenter.rb +4 -0
  64. data/app/presenters/decidim/proposals/proposal_presenter.rb +10 -14
  65. data/app/queries/decidim/proposals/metrics/endorsements_metric_manage.rb +54 -0
  66. data/app/queries/decidim/proposals/metrics/proposal_followers_metric_measure.rb +56 -0
  67. data/app/queries/decidim/proposals/metrics/proposal_participants_metric_measure.rb +64 -0
  68. data/app/services/decidim/proposals/proposal_search.rb +46 -5
  69. data/app/views/decidim/participatory_processes/participatory_process_groups/_highlighted_proposals.html.erb +1 -1
  70. data/app/views/decidim/proposals/admin/proposals/_form.html.erb +43 -2
  71. data/app/views/decidim/proposals/admin/proposals/_proposal-tr.html.erb +6 -2
  72. data/app/views/decidim/proposals/admin/proposals/edit.html.erb +1 -1
  73. data/app/views/decidim/proposals/admin/proposals/new.html.erb +1 -1
  74. data/app/views/decidim/proposals/collaborative_drafts/_edit_form_fields.html.erb +81 -0
  75. data/app/views/decidim/proposals/collaborative_drafts/complete.html.erb +1 -49
  76. data/app/views/decidim/proposals/collaborative_drafts/edit.html.erb +1 -29
  77. data/app/views/decidim/proposals/collaborative_drafts/show.html.erb +5 -5
  78. data/app/views/decidim/proposals/proposals/_edit_form_fields.html.erb +27 -3
  79. data/app/views/decidim/proposals/proposals/_filters.html.erb +5 -2
  80. data/app/views/decidim/proposals/proposals/_proposal.html.erb +5 -1
  81. data/app/views/decidim/proposals/proposals/_proposal_similar.html.erb +2 -2
  82. data/app/views/decidim/proposals/proposals/_vote_button.html.erb +39 -35
  83. data/app/views/decidim/proposals/proposals/_votes_count.html.erb +16 -12
  84. data/app/views/decidim/proposals/proposals/new.html.erb +1 -1
  85. data/app/views/decidim/proposals/proposals/participatory_texts/_index.html.erb +19 -0
  86. data/app/views/decidim/proposals/proposals/participatory_texts/_proposal_vote_button.html.erb +46 -0
  87. data/app/views/decidim/proposals/proposals/participatory_texts/_proposal_votes_count.html.erb +41 -0
  88. data/app/views/decidim/proposals/proposals/participatory_texts/_view_index.html.erb +10 -0
  89. data/app/views/decidim/proposals/proposals/participatory_texts/participatory_text.html.erb +15 -0
  90. data/app/views/decidim/proposals/proposals/show.html.erb +45 -4
  91. data/app/views/decidim/proposals/versions/_version.html.erb +2 -2
  92. data/app/views/decidim/proposals/versions/index.html.erb +1 -1
  93. data/app/views/decidim/proposals/versions/show.html.erb +2 -2
  94. data/config/locales/ca.yml +87 -33
  95. data/config/locales/de.yml +87 -36
  96. data/config/locales/en.yml +87 -33
  97. data/config/locales/es-PY.yml +87 -33
  98. data/config/locales/es.yml +88 -34
  99. data/config/locales/eu.yml +87 -33
  100. data/config/locales/fi-pl.yml +87 -33
  101. data/config/locales/fi.yml +87 -33
  102. data/config/locales/fr.yml +87 -33
  103. data/config/locales/gl.yml +87 -33
  104. data/config/locales/hu.yml +87 -33
  105. data/config/locales/id-ID.yml +84 -30
  106. data/config/locales/it.yml +87 -33
  107. data/config/locales/nl.yml +87 -33
  108. data/config/locales/pl.yml +87 -33
  109. data/config/locales/pt-BR.yml +87 -33
  110. data/config/locales/pt.yml +87 -33
  111. data/config/locales/ru.yml +21 -38
  112. data/config/locales/sv.yml +87 -33
  113. data/config/locales/tr-TR.yml +86 -32
  114. data/config/locales/uk.yml +21 -38
  115. data/db/migrate/20181026073215_add_created_in_meeting.rb +7 -0
  116. data/lib/decidim/proposals.rb +2 -0
  117. data/lib/decidim/proposals/component.rb +74 -0
  118. data/lib/decidim/proposals/doc_to_markdown.rb +40 -0
  119. data/lib/decidim/proposals/engine.rb +52 -35
  120. data/lib/decidim/proposals/odt_to_markdown.rb +46 -0
  121. data/lib/decidim/proposals/proposal_serializer.rb +29 -13
  122. data/lib/decidim/proposals/test/factories.rb +76 -0
  123. data/lib/decidim/proposals/version.rb +1 -1
  124. metadata +56 -20
  125. data/app/views/decidim/participatory_spaces/_highlighted_proposals.html.erb +0 -15
@@ -6,6 +6,7 @@ module Decidim
6
6
  # A command with all the business logic when a user updates a proposal.
7
7
  class UpdateProposal < Rectify::Command
8
8
  include AttachmentMethods
9
+ include HashtagsMethods
9
10
 
10
11
  # Public: Initializes the command.
11
12
  #
@@ -35,6 +36,7 @@ module Decidim
35
36
 
36
37
  transaction do
37
38
  update_proposal
39
+ update_proposal_author
38
40
  create_attachment if process_attachments?
39
41
  end
40
42
 
@@ -46,21 +48,26 @@ module Decidim
46
48
  attr_reader :form, :proposal, :attachment
47
49
 
48
50
  def update_proposal
49
- parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
50
- parsed_body = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.body, current_organization: form.current_organization).rewrite
51
-
52
51
  Decidim.traceability.update!(
53
52
  proposal,
54
53
  form.current_user,
55
- title: parsed_title,
56
- body: parsed_body,
54
+ title: title_with_hashtags,
55
+ body: body_with_hashtags,
57
56
  category: form.category,
58
57
  scope: form.scope,
59
58
  address: form.address,
60
59
  latitude: form.latitude,
61
- longitude: form.longitude
60
+ longitude: form.longitude,
61
+ created_in_meeting: form.created_in_meeting
62
62
  )
63
63
  end
64
+
65
+ def update_proposal_author
66
+ proposal.coauthorships.clear
67
+ proposal.add_coauthor(form.author)
68
+ proposal.save!
69
+ proposal
70
+ end
64
71
  end
65
72
  end
66
73
  end
@@ -59,7 +59,7 @@ module Decidim
59
59
  event: "decidim.events.proposals.proposal_update_category",
60
60
  event_class: Decidim::Proposals::Admin::UpdateProposalCategoryEvent,
61
61
  resource: proposal,
62
- recipient_ids: proposal.coauthorships.pluck(:decidim_author_id)
62
+ affected_users: proposal.notifiable_identities
63
63
  )
64
64
  end
65
65
  end
@@ -5,6 +5,8 @@ module Decidim
5
5
  # A command with all the business logic when a user creates a new collaborative draft.
6
6
  class CreateCollaborativeDraft < Rectify::Command
7
7
  include AttachmentMethods
8
+ include HashtagsMethods
9
+
8
10
  # Public: Initializes the command.
9
11
  #
10
12
  # form - A form object with the params.
@@ -45,11 +47,12 @@ module Decidim
45
47
  @collaborative_draft = Decidim.traceability.perform_action!(
46
48
  :create,
47
49
  CollaborativeDraft,
48
- @form.current_user
50
+ @form.current_user,
51
+ visibility: "public-only"
49
52
  ) do
50
53
  draft = CollaborativeDraft.new(
51
- title: form.title,
52
- body: form.body,
54
+ title: title_with_hashtags,
55
+ body: body_with_hashtags,
53
56
  category: form.category,
54
57
  scope: form.scope,
55
58
  component: form.component,
@@ -5,6 +5,8 @@ module Decidim
5
5
  # A command with all the business logic when a user creates a new proposal.
6
6
  class CreateProposal < Rectify::Command
7
7
  include AttachmentMethods
8
+ include HashtagsMethods
9
+
8
10
  # Public: Initializes the command.
9
11
  #
10
12
  # form - A form object with the params.
@@ -41,18 +43,30 @@ module Decidim
41
43
 
42
44
  attr_reader :form, :proposal, :attachment
43
45
 
46
+ def proposal_attributes
47
+ fields = {}
48
+
49
+ fields[:title] = title_with_hashtags
50
+ fields[:body] = body_with_hashtags
51
+ fields[:component] = form.component
52
+
53
+ fields
54
+ end
55
+
56
+ # This will be the PaperTrail version that is
57
+ # shown in the version control feature (1 of 1)
44
58
  def create_proposal
45
- parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
46
- parsed_body = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.body, current_organization: form.current_organization).rewrite
47
-
48
- @proposal = Proposal.new(
49
- title: parsed_title,
50
- body: parsed_body,
51
- component: form.component
52
- )
53
- @proposal.add_coauthor(@current_user, user_group: user_group)
54
- @proposal.save!
55
- @proposal
59
+ @proposal = Decidim.traceability.perform_action!(
60
+ :create,
61
+ Decidim::Proposals::Proposal,
62
+ @current_user,
63
+ visibility: "public-only"
64
+ ) do
65
+ proposal = Proposal.new(proposal_attributes)
66
+ proposal.add_coauthor(@current_user, user_group: user_group)
67
+ proposal.save!
68
+ proposal
69
+ end
56
70
  end
57
71
 
58
72
  def proposal_limit_reached?
@@ -44,12 +44,11 @@ module Decidim
44
44
  end
45
45
 
46
46
  def notify_endorser_followers
47
- recipient_ids = @current_user.followers.pluck(:id)
48
47
  Decidim::EventsManager.publish(
49
48
  event: "decidim.events.proposals.proposal_endorsed",
50
49
  event_class: Decidim::Proposals::ProposalEndorsedEvent,
51
50
  resource: @proposal,
52
- recipient_ids: recipient_ids.uniq,
51
+ followers: @current_user.followers,
53
52
  extra: {
54
53
  endorser_id: @current_user.id
55
54
  }
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Proposals
5
+ # A module with all the hash tags common methods for proposals
6
+ # and collaborative draft commands.
7
+ module HashtagsMethods
8
+ private
9
+
10
+ def title_with_hashtags
11
+ @title_with_hashtags ||= Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
12
+ end
13
+
14
+ def body_with_hashtags
15
+ @body_with_hashtags ||= begin
16
+ ret = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.body, current_organization: form.current_organization).rewrite.strip
17
+ ret += "\n" + body_extra_hashtags.strip unless body_extra_hashtags.empty?
18
+ ret
19
+ end
20
+ end
21
+
22
+ def body_extra_hashtags
23
+ @body_extra_hashtags ||= if form.respond_to?(:extra_hashtags)
24
+ Decidim::ContentProcessor.parse_with_processor(
25
+ :hashtag,
26
+ form.extra_hashtags.map { |hashtag| "##{hashtag}" }.join(" "),
27
+ current_organization: form.current_organization,
28
+ extra_hashtags: true
29
+ ).rewrite
30
+ else
31
+ ""
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -25,12 +25,10 @@ module Decidim
25
25
  return broadcast(:invalid) unless @collaborative_draft.authored_by? @current_user
26
26
 
27
27
  transaction do
28
- @collaborative_draft.requesters.each do |requester_user|
29
- RejectAccessToCollaborativeDraft.call(@collaborative_draft, current_user, requester_user)
30
- end
31
-
32
- @new_proposal = publish_collaborative_draft
33
- broadcast(:invalid) unless @new_proposal
28
+ reject_access_to_collaborative_draft
29
+ publish_collaborative_draft
30
+ create_proposal!
31
+ link_collaborative_draft_and_proposal
34
32
  end
35
33
 
36
34
  broadcast(:ok, @new_proposal)
@@ -40,47 +38,54 @@ module Decidim
40
38
 
41
39
  private
42
40
 
41
+ def reject_access_to_collaborative_draft
42
+ @collaborative_draft.requesters.each do |requester_user|
43
+ RejectAccessToCollaborativeDraft.call(@collaborative_draft, current_user, requester_user)
44
+ end
45
+ end
46
+
43
47
  def publish_collaborative_draft
44
48
  Decidim.traceability.update!(
45
49
  @collaborative_draft,
46
50
  @current_user,
47
- state: "published",
48
- published_at: Time.current
51
+ { state: "published", published_at: Time.current },
52
+ visibility: "public-only"
49
53
  )
50
- create_proposal
51
54
  end
52
55
 
53
- def create_proposal
54
- proposal_form_params = ActionController::Parameters.new(
55
- proposal: @collaborative_draft.as_json
56
- )
57
- proposal_form_params[:proposal][:category_id] = @collaborative_draft.category.id if @collaborative_draft.category
58
- proposal_form_params[:proposal][:scope_id] = @collaborative_draft.scope.id if @collaborative_draft.scope
59
- proposal_form = Decidim::Proposals::ProposalForm.from_params(
60
- proposal_form_params
61
- ).with_context(
62
- current_user: @current_user,
63
- current_organization: @current_user.organization,
64
- current_component: @collaborative_draft.component,
65
- current_participatory_space: @collaborative_draft.participatory_space
66
- )
56
+ def proposal_attributes
57
+ fields = {}
67
58
 
68
- result = CreateProposal.call(proposal_form, @current_user, @collaborative_draft.coauthorships)
69
- return publish_proposal(result[:ok]) if result[:ok]
59
+ parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, @collaborative_draft.title, current_organization: @collaborative_draft.organization).rewrite
60
+ parsed_body = Decidim::ContentProcessor.parse_with_processor(:hashtag, @collaborative_draft.body, current_organization: @collaborative_draft.organization).rewrite
70
61
 
71
- false
72
- end
62
+ fields[:title] = parsed_title
63
+ fields[:body] = parsed_body
64
+ fields[:component] = @collaborative_draft.component
65
+ fields[:scope] = @collaborative_draft.scope
66
+ fields[:address] = @collaborative_draft.address
67
+ fields[:published_at] = Time.current
73
68
 
74
- def publish_proposal(new_proposal)
75
- result = PublishProposal.call(new_proposal, @current_user)
76
- return link_collaborative_draft_and_proposal(result[:ok]) if result[:ok]
69
+ fields
70
+ end
77
71
 
78
- false
72
+ def create_proposal!
73
+ @new_proposal = Decidim.traceability.perform_action!(
74
+ :create,
75
+ Decidim::Proposals::Proposal,
76
+ @current_user,
77
+ visibility: "public-only"
78
+ ) do
79
+ new_proposal = Proposal.new(proposal_attributes)
80
+ new_proposal.coauthorships = @collaborative_draft.coauthorships
81
+ new_proposal.category = @collaborative_draft.category
82
+ new_proposal.save!
83
+ new_proposal
84
+ end
79
85
  end
80
86
 
81
- def link_collaborative_draft_and_proposal(new_proposal)
82
- @collaborative_draft.link_resources(new_proposal, "created_from_collaborative_draft")
83
- new_proposal
87
+ def link_collaborative_draft_and_proposal
88
+ @collaborative_draft.link_resources(@new_proposal, "created_from_collaborative_draft")
84
89
  end
85
90
  end
86
91
  end
@@ -23,15 +23,7 @@ module Decidim
23
23
  return broadcast(:invalid) unless @proposal.authored_by?(@current_user)
24
24
 
25
25
  transaction do
26
- Decidim.traceability.perform_action!(
27
- "publish",
28
- @proposal,
29
- @current_user,
30
- visibility: "public-only"
31
- ) do
32
- @proposal.update published_at: Time.current
33
- end
34
-
26
+ publish_proposal
35
27
  increment_scores
36
28
  send_notification
37
29
  send_notification_to_participatory_space
@@ -42,6 +34,14 @@ module Decidim
42
34
 
43
35
  private
44
36
 
37
+ # Prevent PaperTrail from creating an additional version
38
+ # in the proposal multi-step creation process (step 4: publish)
39
+ def publish_proposal
40
+ PaperTrail.request(enabled: false) do
41
+ @proposal.update published_at: Time.current
42
+ end
43
+ end
44
+
45
45
  def send_notification
46
46
  return if @proposal.coauthorships.empty?
47
47
 
@@ -49,7 +49,7 @@ module Decidim
49
49
  event: "decidim.events.proposals.proposal_published",
50
50
  event_class: Decidim::Proposals::PublishProposalEvent,
51
51
  resource: @proposal,
52
- recipient_ids: coauthors_followers(@proposal)
52
+ followers: coauthors_followers
53
53
  )
54
54
  end
55
55
 
@@ -58,19 +58,15 @@ module Decidim
58
58
  event: "decidim.events.proposals.proposal_published",
59
59
  event_class: Decidim::Proposals::PublishProposalEvent,
60
60
  resource: @proposal,
61
- recipient_ids: @proposal.participatory_space.followers.pluck(:id) - coauthors_followers(@proposal),
61
+ followers: @proposal.participatory_space.followers - coauthors_followers,
62
62
  extra: {
63
63
  participatory_space: true
64
64
  }
65
65
  )
66
66
  end
67
67
 
68
- def coauthors_followers(_proposal)
69
- followers_ids = []
70
- @proposal.authors.each do |author|
71
- followers_ids += author.followers.pluck(:id)
72
- end
73
- followers_ids
68
+ def coauthors_followers
69
+ @coauthors_followers ||= @proposal.authors.flat_map(&:followers)
74
70
  end
75
71
 
76
72
  def increment_scores
@@ -38,12 +38,11 @@ module Decidim
38
38
  private
39
39
 
40
40
  def notify_collaborative_draft_authors
41
- recipient_ids = @collaborative_draft.authors.pluck(:id)
42
41
  Decidim::EventsManager.publish(
43
42
  event: "decidim.events.proposals.collaborative_draft_access_rejected",
44
43
  event_class: Decidim::Proposals::CollaborativeDraftAccessRejectedEvent,
45
44
  resource: @collaborative_draft,
46
- recipient_ids: recipient_ids.uniq,
45
+ affected_users: @collaborative_draft.authors,
47
46
  extra: {
48
47
  requester_id: @requester_user.id
49
48
  }
@@ -55,7 +54,7 @@ module Decidim
55
54
  event: "decidim.events.proposals.collaborative_draft_access_requester_rejected",
56
55
  event_class: Decidim::Proposals::CollaborativeDraftAccessRequesterRejectedEvent,
57
56
  resource: @collaborative_draft,
58
- recipient_ids: [@requester_user.id]
57
+ affected_users: [@requester_user]
59
58
  )
60
59
  end
61
60
  end
@@ -34,12 +34,11 @@ module Decidim
34
34
  private
35
35
 
36
36
  def notify_collaborative_draft_authors
37
- recipient_ids = @collaborative_draft.authors.pluck(:id)
38
37
  Decidim::EventsManager.publish(
39
38
  event: "decidim.events.proposals.collaborative_draft_access_requested",
40
39
  event_class: Decidim::Proposals::CollaborativeDraftAccessRequestedEvent,
41
40
  resource: @collaborative_draft,
42
- recipient_ids: recipient_ids.uniq,
41
+ affected_users: @collaborative_draft.authors,
43
42
  extra: {
44
43
  requester_id: @current_user.id
45
44
  }
@@ -4,6 +4,8 @@ module Decidim
4
4
  module Proposals
5
5
  # A command with all the business logic when a user updates a collaborative_draft.
6
6
  class UpdateCollaborativeDraft < Rectify::Command
7
+ include HashtagsMethods
8
+
7
9
  # Public: Initializes the command.
8
10
  #
9
11
  # form - A form object with the params.
@@ -40,19 +42,20 @@ module Decidim
40
42
  Decidim.traceability.update!(
41
43
  @collaborative_draft,
42
44
  @current_user,
43
- attributes
45
+ attributes,
46
+ visibility: "public-only"
44
47
  )
45
48
  end
46
49
 
47
50
  def attributes
48
51
  {
49
- title: @form.title,
50
- body: @form.body,
51
- category: @form.category,
52
- scope: @form.scope,
53
- address: @form.address,
54
- latitude: @form.latitude,
55
- longitude: @form.longitude
52
+ title: title_with_hashtags,
53
+ body: body_with_hashtags,
54
+ category: form.category,
55
+ scope: form.scope,
56
+ address: form.address,
57
+ latitude: form.latitude,
58
+ longitude: form.longitude
56
59
  }
57
60
  end
58
61
  end
@@ -5,6 +5,8 @@ module Decidim
5
5
  # A command with all the business logic when a user updates a proposal.
6
6
  class UpdateProposal < Rectify::Command
7
7
  include AttachmentMethods
8
+ include HashtagsMethods
9
+
8
10
  # Public: Initializes the command.
9
11
  #
10
12
  # form - A form object with the params.
@@ -36,7 +38,11 @@ module Decidim
36
38
  end
37
39
 
38
40
  transaction do
39
- update_proposal
41
+ if @proposal.draft?
42
+ update_draft
43
+ else
44
+ update_proposal
45
+ end
40
46
  create_attachment if process_attachments?
41
47
  end
42
48
 
@@ -47,21 +53,39 @@ module Decidim
47
53
 
48
54
  attr_reader :form, :proposal, :current_user, :attachment
49
55
 
56
+ def proposal_attributes
57
+ fields = {}
58
+
59
+ fields[:title] = title_with_hashtags
60
+ fields[:body] = body_with_hashtags
61
+ fields[:category] = form.category
62
+ fields[:scope] = form.scope
63
+ fields[:address] = form.address
64
+ fields[:latitude] = form.latitude
65
+ fields[:longitude] = form.longitude
66
+
67
+ fields
68
+ end
69
+
70
+ # Prevent PaperTrail from creating an additional version
71
+ # in the proposal multi-step creation process (step 3: complete)
72
+ def update_draft
73
+ PaperTrail.request(enabled: false) do
74
+ @proposal.update(proposal_attributes)
75
+ @proposal.coauthorships.clear
76
+ @proposal.add_coauthor(current_user, user_group: user_group)
77
+ end
78
+ end
79
+
50
80
  def update_proposal
51
- parsed_title = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.title, current_organization: form.current_organization).rewrite
52
- parsed_body = Decidim::ContentProcessor.parse_with_processor(:hashtag, form.body, current_organization: form.current_organization).rewrite
53
-
54
- @proposal.update!(
55
- title: parsed_title,
56
- body: parsed_body,
57
- category: form.category,
58
- scope: form.scope,
59
- address: form.address,
60
- latitude: form.latitude,
61
- longitude: form.longitude
81
+ @proposal = Decidim.traceability.update!(
82
+ @proposal,
83
+ current_user,
84
+ proposal_attributes,
85
+ visibility: "public-only"
62
86
  )
63
87
  @proposal.coauthorships.clear
64
- @proposal.add_coauthor(current_user, decidim_user_group_id: user_group&.id)
88
+ @proposal.add_coauthor(current_user, user_group: user_group)
65
89
  end
66
90
 
67
91
  def proposal_limit_reached?