decidim-sortitions 0.11.2 → 0.12.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/sortitions/sortition_cell.rb +21 -0
  3. data/app/cells/decidim/sortitions/sortition_m/data.erb +15 -0
  4. data/app/cells/decidim/sortitions/sortition_m/footer.erb +13 -0
  5. data/app/cells/decidim/sortitions/sortition_m_cell.rb +53 -0
  6. data/app/controllers/decidim/sortitions/admin/sortitions_controller.rb +13 -11
  7. data/app/models/decidim/sortitions/sortition.rb +1 -1
  8. data/app/permissions/decidim/sortitions/admin/permissions.rb +34 -0
  9. data/app/permissions/decidim/sortitions/permissions.rb +15 -0
  10. data/app/views/decidim/sortitions/admin/sortitions/index.html.erb +4 -4
  11. data/app/views/decidim/sortitions/sortitions/_linked_sortitions.html.erb +0 -1
  12. data/app/views/decidim/sortitions/sortitions/_proposal.html.erb +1 -24
  13. data/app/views/decidim/sortitions/sortitions/_sortition.html.erb +1 -25
  14. data/app/views/decidim/sortitions/sortitions/show.html.erb +1 -1
  15. data/config/locales/ca.yml +15 -9
  16. data/config/locales/en.yml +17 -11
  17. data/config/locales/es.yml +16 -10
  18. data/config/locales/eu.yml +16 -10
  19. data/config/locales/fi.yml +16 -10
  20. data/config/locales/fr.yml +16 -10
  21. data/config/locales/gl.yml +15 -9
  22. data/config/locales/it.yml +16 -10
  23. data/config/locales/nl.yml +15 -9
  24. data/config/locales/pl.yml +19 -11
  25. data/config/locales/pt-BR.yml +16 -10
  26. data/config/locales/pt.yml +16 -10
  27. data/config/locales/ru.yml +53 -0
  28. data/config/locales/sv.yml +16 -10
  29. data/config/locales/uk.yml +24 -17
  30. data/lib/decidim/sortitions/admin_engine.rb +0 -9
  31. data/lib/decidim/sortitions/component.rb +3 -1
  32. data/lib/decidim/sortitions/engine.rb +5 -0
  33. data/lib/decidim/sortitions/version.rb +1 -1
  34. metadata +20 -16
  35. data/app/models/decidim/sortitions/abilities/admin/admin_ability.rb +0 -23
  36. data/app/models/decidim/sortitions/abilities/admin/process_admin_ability.rb +0 -46
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1ef23ed70e331643ec97f813391b6741104b87fc343866b8398e036a9e82c96
4
- data.tar.gz: 57dbadaf6345196c746ca77af4427128af3bdb807a6f08caa403b9e1093cbd7e
3
+ metadata.gz: 2072e34e4976e77facfc3467d970c431218b6b6f7cc61d0cbdabc63b6a1bc0d2
4
+ data.tar.gz: 3a18c0e5d4ee513109409fc85f4cd38092f81e1ef73f1f6d056034b202ed0f07
5
5
  SHA512:
6
- metadata.gz: 9dac3b56666a789eb8ab8f5e8e1d6e048b8bb0f5263568a10b6a0a627b62fc31b1800e9b1d431bfaf619180f497c2d4d11648e8628d604cceefd62389348c237
7
- data.tar.gz: '07609b63ea5d7bf93a134855dd61abb3a000e3cdd653c7fee4c8355a73de8f3eebced35059f0af2c08fd635949e3bc42e4f8f5e2cde4c14b5dd41beee4d75664'
6
+ metadata.gz: 217933b8292b8ea8be3b600ee059dbbab9a11e05cce58377ae0fd5135097fe900aee6b1c3f7a97cff7c18b4eede4852053feb22aaaeadb1a60f7b14c9a238d02
7
+ data.tar.gz: cc3eb7c079941f66df0e3ef077a59678120bbb44280236bd78a2108cd2daf11675b6a0b910fa36b552d6173f4dbbbf0edf9e63452f510dbcc2ce1f6fccc35b74
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cell/partial"
4
+
5
+ module Decidim
6
+ module Sortitions
7
+ # This cell renders the card for an instance of a Sortition
8
+ # the default size is the Medium Card (:m)
9
+ class SortitionCell < Decidim::ViewModel
10
+ def show
11
+ cell card_size, model, @options
12
+ end
13
+
14
+ private
15
+
16
+ def card_size
17
+ "decidim/sortitions/sortition_m"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ <div class="card__icondata">
2
+ <ul class="card-data">
3
+ <li class="card-data__item">
4
+ <%= icon "random-seed", class: "icon--big" %>
5
+ </li>
6
+ <li class="card-data__item">
7
+ <div class="text-left text-uppercase">
8
+ <strong class="heading4">
9
+ <%= model.seed %>
10
+ </strong>
11
+ &nbsp;<small><%= t("decidim.sortitions.sortitions.sortition.random_seed") %></small>
12
+ </div>
13
+ </li>
14
+ </ul>
15
+ </div>
@@ -0,0 +1,13 @@
1
+ <div class="card__footer">
2
+ <div class="card__support">
3
+ <div class="text-uppercase">
4
+ <strong class="text-large">
5
+ <%= proposals_count %>
6
+ </strong>
7
+ <small class="text-medium">
8
+ <%= t("decidim.sortitions.sortitions.sortition.selected_proposals", count: proposals_count) %>
9
+ </small>
10
+ </div>
11
+ <%= link_to t("decidim.sortitions.sortitions.sortition.view"), resource_path, class: "card__button button--sc button small secondary light" %>
12
+ </div>
13
+ </div>
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cell/partial"
4
+
5
+ module Decidim
6
+ module Sortitions
7
+ # This cell renders a sortition with its M-size card.
8
+ class SortitionMCell < Decidim::CardMCell
9
+ include Decidim::Sortitions::Engine.routes.url_helpers
10
+
11
+ private
12
+
13
+ def has_author?
14
+ false
15
+ end
16
+
17
+ def has_state?
18
+ true
19
+ end
20
+
21
+ # Even though we need to render the badge, we can't do it in the normal
22
+ # way, because the paragraph comes from a user input and contains HTML.
23
+ # This causes the badge and the paragraph to appear in different lines.
24
+ # In order to fix it, check the `description` method.
25
+ def has_badge?
26
+ false
27
+ end
28
+
29
+ def badge_name
30
+ return t("filters.cancelled", scope: "decidim.sortitions.sortitions") if model.cancelled?
31
+ t("filters.active", scope: "decidim.sortitions.sortitions")
32
+ end
33
+
34
+ def state_classes
35
+ return ["muted"] if model.cancelled?
36
+ ["success"]
37
+ end
38
+
39
+ def proposals_count
40
+ @proposals_count = model.proposals.count
41
+ end
42
+
43
+ # In order to render the badge inline with the paragraph text we need to
44
+ # find the opening `<p>` tag and include the badge right after it. This
45
+ # makes the layout look good.
46
+ def description
47
+ text = decidim_sanitize(translated_attribute(model.additional_info))
48
+ text.gsub!(/^<p>/, "<p>#{render :badge}")
49
+ html_truncate(text, length: 100)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -11,16 +11,18 @@ module Decidim
11
11
  def index; end
12
12
 
13
13
  def show
14
- authorize! :show, sortition
14
+ enforce_permission_to :read, :sortition, sortition: sortition
15
15
  end
16
16
 
17
17
  def edit
18
- authorize! :update, sortition
18
+ enforce_permission_to :update, :sortition, sortition: sortition
19
+
19
20
  @form = edit_sortition_form.from_model(sortition, current_participatory_space: current_participatory_space)
20
21
  end
21
22
 
22
23
  def update
23
- authorize! :update, sortition
24
+ enforce_permission_to :update, :sortition, sortition: sortition
25
+
24
26
  @form = edit_sortition_form.from_params(params, current_participatory_space: current_participatory_space)
25
27
  UpdateSortition.call(@form) do
26
28
  on(:ok) do |_sortition|
@@ -36,12 +38,14 @@ module Decidim
36
38
  end
37
39
 
38
40
  def new
39
- authorize! :create, Sortition
41
+ enforce_permission_to :create, :sortition
42
+
40
43
  @form = sortition_form.instance(current_participatory_space: current_participatory_space)
41
44
  end
42
45
 
43
46
  def create
44
- authorize! :create, Sortition
47
+ enforce_permission_to :create, :sortition
48
+
45
49
  @form = sortition_form.from_params(params, current_participatory_space: current_participatory_space)
46
50
  CreateSortition.call(@form) do
47
51
  on(:ok) do |sortition|
@@ -57,12 +61,14 @@ module Decidim
57
61
  end
58
62
 
59
63
  def confirm_destroy
60
- authorize! :destroy, sortition
64
+ enforce_permission_to :destroy, :sortition, sortition: sortition
65
+
61
66
  @form = destroy_sortition_form.from_model(sortition, current_participatory_space: current_participatory_space)
62
67
  end
63
68
 
64
69
  def destroy
65
- authorize! :destroy, sortition
70
+ enforce_permission_to :destroy, :sortition, sortition: sortition
71
+
66
72
  @form = destroy_sortition_form.from_params(params, current_participatory_space: current_participatory_space)
67
73
  DestroySortition.call(@form) do
68
74
  on(:ok) do |_sortition|
@@ -94,10 +100,6 @@ module Decidim
94
100
  def proposal_components
95
101
  ParticipatorySpaceProposalComponents.for(current_participatory_space)
96
102
  end
97
-
98
- def ability_context
99
- super.merge(current_participatory_space: current_participatory_space)
100
- end
101
103
  end
102
104
  end
103
105
  end
@@ -79,7 +79,7 @@ module Decidim
79
79
  def self.order_randomly(seed)
80
80
  transaction do
81
81
  connection.execute("SELECT setseed(#{connection.quote(seed)})")
82
- order("RANDOM()").load
82
+ order(Arel.sql("RANDOM()")).load
83
83
  end
84
84
  end
85
85
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Sortitions
5
+ module Admin
6
+ class Permissions < Decidim::DefaultPermissions
7
+ def permissions
8
+ return permission_action unless user
9
+
10
+ return permission_action if permission_action.scope != :admin
11
+
12
+ return permission_action if permission_action.subject != :sortition
13
+
14
+ case permission_action.action
15
+ when :destroy
16
+ permission_action.allow! if sortition.present? && !sortition.cancelled?
17
+ when :update
18
+ permission_action.allow! if sortition.present?
19
+ when :create, :read
20
+ permission_action.allow!
21
+ end
22
+
23
+ permission_action
24
+ end
25
+
26
+ private
27
+
28
+ def sortition
29
+ @sortition ||= context.fetch(:sortition, nil)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Sortitions
5
+ class Permissions < Decidim::DefaultPermissions
6
+ def permissions
7
+ return permission_action unless user
8
+
9
+ return Decidim::Sortitions::Admin::Permissions.new(user, permission_action, context).permissions if permission_action.scope == :admin
10
+
11
+ permission_action
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,8 +3,8 @@
3
3
  <h2 class="card-title">
4
4
  <%= t(".title") %>
5
5
  <div class="button--title">
6
- <% if can? :create, Decidim::Sortitions::Sortition %>
7
- <%= link_to t("actions.new", scope: "decidim.sortitions.admin", name: t("models.sortition.name", scope: "decidim.sortitions.admin")), new_sortition_path, class: "button tiny button--simple" if can? :manage, current_component %>
6
+ <% if allowed_to? :create, :sortition %>
7
+ <%= link_to t("actions.new", scope: "decidim.sortitions.admin", name: t("models.sortition.name", scope: "decidim.sortitions.admin")), new_sortition_path, class: "button tiny button--simple" %>
8
8
  <% end %>
9
9
  </div>
10
10
  </h2>
@@ -33,14 +33,14 @@
33
33
  t("actions.show", scope: "decidim.sortitions.admin"),
34
34
  class: "action-icon--preview" %>
35
35
 
36
- <% if can? :destroy, sortition %>
36
+ <% if allowed_to? :update, :sortition, sortition: sortition %>
37
37
  <%= icon_link_to "pencil",
38
38
  edit_sortition_path(sortition),
39
39
  t("actions.edit", scope: "decidim.sortitions.admin"),
40
40
  class: "action-icon--edit" %>
41
41
  <% end %>
42
42
 
43
- <% if can? :destroy, sortition %>
43
+ <% if allowed_to? :destroy, :sortition, sortition: sortition %>
44
44
  <%= icon_link_to "circle-x",
45
45
  confirm_destroy_sortition_path(sortition),
46
46
  t("actions.destroy", scope: "decidim.sortitions.admin"),
@@ -1,6 +1,5 @@
1
1
  <div class="card card--action card--list">
2
2
  <% resources.each do |sortition| %>
3
- <% next unless sortition.component.published? %>
4
3
  <div class="card--list__item">
5
4
  <div class="card--list__text">
6
5
  <%= link_to resource_locator(sortition).path do %>
@@ -1,24 +1 @@
1
- <div class="column">
2
- <article class="card card--proposal">
3
- <div class="card__content">
4
- <div class="card__header">
5
- <%= link_to proposal_path(proposal) do %>
6
- <h5 class="card__title"><%= proposal.title %></h5>
7
- <% end %>
8
- <div class="card__author author-data author-data--small">
9
- <%= render partial: "decidim/shared/author_reference", locals: { author: present(proposal).author } %>
10
- </div>
11
- <%= resource_reference(proposal, class: "reference--text-left") %>
12
- </div>
13
- <%= render partial: "proposal_badge", locals: { proposal: proposal } %>
14
- <p><%= truncate(proposal.body, length: 100) %></p>
15
- <%= render partial: "decidim/shared/tags", locals: { resource: proposal, tags_class_extra: "tags--proposal" } %>
16
- </div>
17
- <div class="card__footer">
18
- <div class="card__support">
19
- <div class="card__support__data"></div>
20
- <%= link_to t(".view_proposal"), proposal_path(proposal), class: "card__button button small secondary" %>
21
- </div>
22
- </div>
23
- </article>
24
- </div>
1
+ <%= card_for proposal %>
@@ -1,25 +1 @@
1
- <div class="column">
2
- <article class="card card--sortition">
3
- <div class="card__content">
4
- <div class="card__header">
5
- <%= link_to sortition do %>
6
- <h5 class="card__title"><%= translated_attribute sortition.title %></h5>
7
- <% end %>
8
- <div class="card__author author-data author-data--small">
9
- <%= render partial: "sortition_author", locals: { sortition: sortition } %>
10
- </div>
11
- <%= resource_reference(sortition, class: "reference--text-left") %>
12
- </div>
13
- <p class="card__desc">
14
- <%= decidim_sanitize html_truncate(translated_attribute(sortition.additional_info), length: 100, separator: "...") %>
15
- </p>
16
- <%= render partial: "tags", locals: { sortition: sortition } %>
17
- </div>
18
- <div class="card__footer">
19
- <div class="card__support">
20
- <div class="card__support__data"><%= t ".selected_proposals", count: sortition.selected_proposals.count %></div>
21
- <%= link_to t(".view_sortition"), sortition, class: "card__button button small secondary" %>
22
- </div>
23
- </div>
24
- </article>
25
- </div>
1
+ <%= card_for sortition %>
@@ -70,7 +70,7 @@
70
70
  </div>
71
71
  <div class="row">
72
72
  <div id="proposals" class="columns mediumlarge-12 large-12">
73
- <div class="row small-up-1 medium-up-2 card-grid">
73
+ <div class="row small-up-1 medium-up-2 large-up-3 card-grid">
74
74
  <%= render partial: "proposal", collection: sortition.proposals %>
75
75
  </div>
76
76
  </div>
@@ -5,10 +5,17 @@ ca:
5
5
  additional_info: Informació sobre el sorteig
6
6
  decidim_category_id: Categories del conjunt de propostes en què voleu aplicar el sorteig
7
7
  decidim_proposals_component_id: Propostes establertes
8
- dice: Resultat de la tirada de daus (tira un dau de sis cares o busca alguna altra manera de generar un número de 1 a 6) i introdueix-lo aquí, a diferència de ser testimoni del resultat. Això contribueix en la qualitat de l'aleatorietat
8
+ dice: Resultat de la tirada de daus. Tira un dau de sis cares o busca alguna altra manera de generar un número de 1 a 6 i introdueix-lo aquí, a diferència de ser testimoni del resultat. Això contribueix en la qualitat de l'aleatorietat
9
9
  target_items: Nombre de propostes a seleccionar (indica el nombre de propostes que voleu seleccionar mitjançant el sorteig del grup de propostes que hàgiu triat prèviament)
10
10
  title: Títol
11
11
  witnesses: Testimonis
12
+ models:
13
+ decidim/sortitions/create_sortition_event: Sorteig
14
+ activerecord:
15
+ models:
16
+ decidim/sortitions/sortition:
17
+ one: Sorteig
18
+ other: Sortejos
12
19
  decidim:
13
20
  components:
14
21
  sortitions:
@@ -23,6 +30,10 @@ ca:
23
30
  email_outro: Has rebut aquesta notificació perquè estàs seguint "%{participatory_space_title}". Pots deixar de seguir-lo des de l'enllaç anterior.
24
31
  email_subject: S'ha afegit un nou sorteig a %{participatory_space_title}
25
32
  notification_title: El sorteig <a href="%{resource_path}">%{resource_title}</a> s'ha afegit a %{participatory_space_title}
33
+ pages:
34
+ home:
35
+ statistics:
36
+ sortitions_count: Sortejos
26
37
  participatory_processes:
27
38
  statistics:
28
39
  sortitions_count: Sortejos
@@ -106,8 +117,6 @@ ca:
106
117
  label: 'Ordeneu els sortejos per:'
107
118
  random: Aleatori
108
119
  recent: Recent
109
- proposal:
110
- view_proposal: Veure proposta
111
120
  results_count:
112
121
  count:
113
122
  one: proposta seleccionada
@@ -127,10 +136,11 @@ ca:
127
136
  time_seed: "(2) Llavor de temps"
128
137
  witnesses: Testimonis
129
138
  sortition:
139
+ random_seed: Llavor aleatòria
130
140
  selected_proposals:
131
141
  one: 1 proposta seleccionada
132
- other: "%{count} propostes seleccionades"
133
- view_sortition: Mostra el sorteig
142
+ other: '%{count} propostes seleccionades'
143
+ view: Veure
134
144
  sortition_author:
135
145
  deleted: Usuari eliminat
136
146
  sortition_cancel_author:
@@ -139,7 +149,3 @@ ca:
139
149
  count:
140
150
  one: 1 sorteig
141
151
  other: "%{count} classificacions"
142
- pages:
143
- home:
144
- statistics:
145
- sortitions_count: Sortejos
@@ -6,10 +6,17 @@ en:
6
6
  additional_info: Sortition information
7
7
  decidim_category_id: Categories of the set of proposals in which you want to apply the draw
8
8
  decidim_proposals_component_id: Proposals set
9
- dice: Result of die roll (roll a 6-sided die (or look for another random way to generate a number from 1 to 6) and enter here, as opposed to witness the resulting number, this contributes to the quality and guarantees of the randomness of the result
9
+ dice: Result of die roll. Roll a 6-sided die, or look for another random way to generate a number from 1 to 6, and enter here the resulting number in front of some witnesses. This contributes to the quality and guarantees of the randomness of the result
10
10
  target_items: Number of proposals to be selected (indicates the number of proposals you want to be selected by drawing lots of the group of proposals you have previously chosen)
11
11
  title: Title
12
12
  witnesses: Witnesses
13
+ models:
14
+ decidim/sortitions/create_sortition_event: Sortition
15
+ activerecord:
16
+ models:
17
+ decidim/sortitions/sortition:
18
+ one: Sortition
19
+ other: Sortitions
13
20
  decidim:
14
21
  components:
15
22
  sortitions:
@@ -24,6 +31,10 @@ en:
24
31
  email_outro: You have received this notification because you are following "%{participatory_space_title}". You can unfollow it from the previous link.
25
32
  email_subject: New sortition added to %{participatory_space_title}
26
33
  notification_title: The sortition <a href="%{resource_path}">%{resource_title}</a> has been added to %{participatory_space_title}
34
+ pages:
35
+ home:
36
+ statistics:
37
+ sortitions_count: Sortitions
27
38
  participatory_processes:
28
39
  statistics:
29
40
  sortitions_count: Sortitions
@@ -77,7 +88,7 @@ en:
77
88
  selected_proposals: Proposals selected for draw
78
89
  update:
79
90
  error: There was an error updating the sortition.
80
- success: Sortition successfully update
91
+ success: Sortition successfully updated
81
92
  admin_log:
82
93
  sortition:
83
94
  create: "%{user_name} created the %{resource_name} sortition in %{space_name}"
@@ -107,8 +118,6 @@ en:
107
118
  label: 'Order sortitions by:'
108
119
  random: Random
109
120
  recent: Recent
110
- proposal:
111
- view_proposal: View proposal
112
121
  results_count:
113
122
  count:
114
123
  one: selected proposal
@@ -132,10 +141,11 @@ en:
132
141
  time_seed: "(2) Time seed"
133
142
  witnesses: Witnesses
134
143
  sortition:
144
+ random_seed: Random seed
135
145
  selected_proposals:
136
- one: 1 proposal selected
137
- other: "%{count} proposals selected"
138
- view_sortition: View sortition
146
+ one: proposal selected
147
+ other: proposals selected
148
+ view: View
139
149
  sortition_author:
140
150
  deleted: Deleted user
141
151
  sortition_cancel_author:
@@ -144,7 +154,3 @@ en:
144
154
  count:
145
155
  one: 1 sortition
146
156
  other: "%{count} sortitions"
147
- pages:
148
- home:
149
- statistics:
150
- sortitions_count: Sortitions