decidim-core 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 (238) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/decidim/notifications.js.es6 +8 -6
  3. data/app/assets/javascripts/decidim/user_registrations.js.es6 +25 -1
  4. data/app/assets/stylesheets/decidim/application.scss.erb +4 -0
  5. data/app/assets/stylesheets/decidim/layouts/_home.scss +79 -0
  6. data/app/assets/stylesheets/decidim/modules/_author-avatar.scss +2 -1
  7. data/app/assets/stylesheets/decidim/modules/_cards.scss +82 -38
  8. data/app/assets/stylesheets/decidim/modules/_collapsible-list.scss +16 -0
  9. data/app/assets/stylesheets/decidim/modules/_definition-data.scss +27 -0
  10. data/app/assets/stylesheets/decidim/modules/_fingerprint.scss +8 -0
  11. data/app/assets/stylesheets/decidim/modules/_horizontal-tabs.scss +51 -0
  12. data/app/assets/stylesheets/decidim/modules/_inline-filters.scss +5 -3
  13. data/app/assets/stylesheets/decidim/modules/_margins.scss +6 -4
  14. data/app/assets/stylesheets/decidim/modules/_modules.scss +3 -0
  15. data/app/assets/stylesheets/decidim/modules/_navbar.scss +113 -7
  16. data/app/assets/stylesheets/decidim/modules/_signup.scss +22 -5
  17. data/app/assets/stylesheets/decidim/modules/_toggle.scss +9 -0
  18. data/app/assets/stylesheets/decidim/modules/_typography.scss +5 -1
  19. data/app/assets/stylesheets/decidim/utils/_helpers.scss +42 -0
  20. data/app/assets/stylesheets/decidim/utils/_mixins.scss +6 -0
  21. data/app/assets/stylesheets/decidim/utils/_settings.scss +3 -2
  22. data/app/cells/decidim/announcement/show.erb +11 -0
  23. data/app/cells/decidim/announcement_cell.rb +32 -0
  24. data/app/cells/decidim/author/comments.erb +6 -0
  25. data/app/cells/decidim/author/contact.erb +3 -0
  26. data/app/cells/decidim/author/date.erb +5 -0
  27. data/app/cells/decidim/author/flag.erb +5 -0
  28. data/app/cells/decidim/author/profile.erb +9 -0
  29. data/app/cells/decidim/{profile → author}/profile_inline.erb +1 -1
  30. data/app/cells/decidim/author/show.erb +18 -0
  31. data/app/cells/decidim/author/withdraw.erb +6 -0
  32. data/app/cells/decidim/author_cell.rb +109 -0
  33. data/app/cells/decidim/card/show.erb +18 -16
  34. data/app/cells/decidim/card_cell.rb +17 -4
  35. data/app/cells/decidim/card_m/author.erb +3 -0
  36. data/app/cells/decidim/card_m/badge.erb +1 -0
  37. data/app/cells/decidim/card_m/comments_counter.erb +3 -0
  38. data/app/cells/decidim/card_m/data.erb +0 -0
  39. data/app/cells/decidim/card_m/footer.erb +0 -0
  40. data/app/cells/decidim/card_m/header.erb +17 -0
  41. data/app/cells/decidim/card_m/image.erb +5 -0
  42. data/app/cells/decidim/card_m/label.erb +3 -0
  43. data/app/cells/decidim/card_m/show.erb +24 -0
  44. data/app/cells/decidim/card_m/status.erb +9 -0
  45. data/app/cells/decidim/card_m/tags.erb +0 -0
  46. data/app/cells/decidim/card_m_cell.rb +136 -0
  47. data/app/cells/decidim/collapsible_list/show.erb +20 -0
  48. data/app/cells/decidim/collapsible_list_cell.rb +66 -0
  49. data/app/cells/decidim/fingerprint/show.erb +22 -0
  50. data/app/cells/decidim/fingerprint_cell.rb +17 -0
  51. data/app/cells/decidim/follow_button/show.erb +34 -0
  52. data/app/cells/decidim/follow_button_cell.rb +40 -0
  53. data/app/cells/decidim/followers/show.erb +9 -0
  54. data/app/cells/decidim/followers_cell.rb +18 -0
  55. data/app/cells/decidim/following/show.erb +9 -0
  56. data/app/cells/decidim/following_cell.rb +24 -0
  57. data/app/cells/decidim/notifications/show.erb +48 -0
  58. data/app/cells/decidim/notifications_cell.rb +21 -0
  59. data/app/cells/decidim/progress_bar/show.erb +17 -0
  60. data/app/cells/decidim/progress_bar_cell.rb +68 -0
  61. data/app/cells/decidim/tags/category.erb +1 -0
  62. data/app/cells/decidim/tags/scope.erb +1 -0
  63. data/app/cells/decidim/tags/show.erb +5 -0
  64. data/app/cells/decidim/tags_cell.rb +62 -0
  65. data/app/cells/decidim/tos_page/announcement.erb +2 -0
  66. data/app/cells/decidim/tos_page/refuse_btn_modal.erb +23 -0
  67. data/app/cells/decidim/tos_page/sticky_form.erb +29 -0
  68. data/app/cells/decidim/tos_page_cell.rb +39 -0
  69. data/app/cells/decidim/user_profile/footer.erb +5 -0
  70. data/app/cells/decidim/user_profile/header.erb +20 -0
  71. data/app/cells/decidim/user_profile_cell.rb +26 -0
  72. data/app/commands/decidim/create_omniauth_registration.rb +1 -1
  73. data/app/commands/decidim/create_registration.rb +2 -1
  74. data/app/commands/decidim/search.rb +45 -0
  75. data/app/controllers/concerns/decidim/devise_controllers.rb +15 -12
  76. data/app/controllers/concerns/decidim/http_caching_disabler.rb +21 -0
  77. data/app/controllers/concerns/decidim/impersonate_users.rb +1 -6
  78. data/app/controllers/concerns/decidim/locale_switcher.rb +1 -1
  79. data/app/controllers/concerns/decidim/needs_permission.rb +70 -0
  80. data/app/controllers/concerns/decidim/needs_tos_accepted.rb +42 -0
  81. data/app/controllers/concerns/decidim/participatory_space_context.rb +1 -7
  82. data/app/controllers/concerns/decidim/user_profile.rb +3 -1
  83. data/app/controllers/decidim/account_controller.rb +4 -4
  84. data/app/controllers/decidim/application_controller.rb +17 -8
  85. data/app/controllers/decidim/components/base_controller.rb +14 -9
  86. data/app/controllers/decidim/cookie_policy_controller.rb +0 -2
  87. data/app/controllers/decidim/devise/confirmations_controller.rb +13 -0
  88. data/app/controllers/decidim/devise/invitations_controller.rb +3 -1
  89. data/app/controllers/decidim/devise/omniauth_registrations_controller.rb +9 -3
  90. data/app/controllers/decidim/devise/passwords_controller.rb +1 -1
  91. data/app/controllers/decidim/devise/registrations_controller.rb +1 -7
  92. data/app/controllers/decidim/doorkeeper/authorizations_controller.rb +0 -2
  93. data/app/controllers/decidim/doorkeeper/credentials_controller.rb +0 -1
  94. data/app/controllers/decidim/errors_controller.rb +0 -2
  95. data/app/controllers/decidim/follows_controller.rb +4 -2
  96. data/app/controllers/decidim/locales_controller.rb +1 -1
  97. data/app/controllers/decidim/messaging/conversations_controller.rb +5 -5
  98. data/app/controllers/decidim/newsletters_controller.rb +0 -2
  99. data/app/controllers/decidim/notifications_controller.rb +3 -19
  100. data/app/controllers/decidim/notifications_settings_controller.rb +2 -2
  101. data/app/controllers/decidim/pages_controller.rb +12 -10
  102. data/app/controllers/decidim/profiles_controller.rb +10 -4
  103. data/app/controllers/decidim/reports_controller.rb +14 -1
  104. data/app/controllers/decidim/scopes_controller.rb +3 -3
  105. data/app/controllers/decidim/searches_controller.rb +39 -0
  106. data/app/controllers/decidim/static_map_controller.rb +0 -2
  107. data/app/controllers/decidim/tos_controller.rb +20 -0
  108. data/app/controllers/decidim/widgets_controller.rb +0 -1
  109. data/app/forms/decidim/follow_form.rb +1 -0
  110. data/app/forms/decidim/registration_form.rb +2 -1
  111. data/app/helpers/decidim/card_helper.rb +2 -0
  112. data/app/helpers/decidim/cells_paginate_helper.rb +16 -0
  113. data/app/helpers/decidim/cta_button_helper.rb +1 -1
  114. data/app/helpers/decidim/decidim_form_helper.rb +4 -0
  115. data/app/helpers/decidim/icon_helper.rb +2 -0
  116. data/app/helpers/decidim/resource_helper.rb +1 -2
  117. data/app/helpers/decidim/scopes_helper.rb +17 -10
  118. data/app/helpers/decidim/searches_helper.rb +16 -0
  119. data/app/helpers/decidim/tooltip_helper.rb +12 -0
  120. data/app/models/decidim/organization.rb +10 -0
  121. data/app/models/decidim/permission_action.rb +40 -0
  122. data/app/models/decidim/searchable_resource.rb +37 -0
  123. data/app/models/decidim/static_page.rb +4 -0
  124. data/app/models/decidim/user.rb +39 -3
  125. data/app/permissions/decidim/default_permissions.rb +61 -0
  126. data/app/permissions/decidim/permissions.rb +106 -0
  127. data/app/permissions/decidim/user_manager_permissions.rb +24 -0
  128. data/app/presenters/decidim/admin_log/organization_presenter.rb +2 -1
  129. data/app/presenters/decidim/home_stats_presenter.rb +2 -8
  130. data/app/presenters/decidim/user_presenter.rb +8 -0
  131. data/app/services/decidim/traceability.rb +6 -9
  132. data/app/types/decidim/core/user_type.rb +1 -1
  133. data/app/views/decidim/devise/invitations/edit.html.erb +56 -10
  134. data/app/views/decidim/devise/registrations/new.html.erb +36 -14
  135. data/app/views/decidim/devise/shared/_newsletter_modal.html.erb +25 -0
  136. data/app/views/decidim/follows/update_button.js.erb +2 -2
  137. data/app/views/decidim/messaging/conversations/_message.html.erb +1 -1
  138. data/app/views/{pages → decidim/pages}/decidim_page.html.erb +5 -0
  139. data/app/views/decidim/pages/home.html.erb +17 -0
  140. data/app/views/{pages → decidim/pages}/home/_extended.html.erb +0 -0
  141. data/app/views/{pages → decidim/pages}/home/_footer_sub_hero.html.erb +0 -0
  142. data/app/views/{pages → decidim/pages}/home/_hero.html.erb +0 -0
  143. data/app/views/{pages → decidim/pages}/home/_highlighted_content_banner.html.erb +0 -0
  144. data/app/views/{pages → decidim/pages}/home/_highlighted_processes.html.erb +0 -0
  145. data/app/views/{pages → decidim/pages}/home/_statistics.html.erb +0 -0
  146. data/app/views/{pages → decidim/pages}/home/_sub_hero.html.erb +0 -0
  147. data/app/views/decidim/profiles/_followers.html.erb +5 -0
  148. data/app/views/decidim/profiles/_following.html.erb +5 -0
  149. data/app/views/decidim/profiles/_notifications.html.erb +0 -0
  150. data/app/views/decidim/profiles/_user.html.erb +59 -0
  151. data/app/views/decidim/profiles/_user_follow.erb +32 -0
  152. data/app/views/decidim/profiles/show.html.erb +32 -59
  153. data/app/views/decidim/searches/_count.html.erb +1 -0
  154. data/app/views/decidim/searches/_filters.html.erb +20 -0
  155. data/app/views/decidim/searches/_filters_small_view.html.erb +18 -0
  156. data/app/views/decidim/searches/_results.html.erb +5 -0
  157. data/app/views/decidim/searches/index.html.erb +20 -0
  158. data/app/views/decidim/searches/index.js.erb +5 -0
  159. data/app/views/decidim/shared/_address_details.html.erb +7 -9
  160. data/app/views/decidim/shared/_announcement.html.erb +1 -6
  161. data/app/views/decidim/shared/_author_reference.html.erb +1 -1
  162. data/app/views/decidim/shared/_follow_button.html.erb +1 -34
  163. data/app/views/decidim/shared/_static_map.html.erb +3 -1
  164. data/app/views/decidim/shared/_tags.html.erb +1 -11
  165. data/app/views/kaminari/decidim/_paginator.html.erb +16 -15
  166. data/app/views/layouts/decidim/_head.html.erb +1 -0
  167. data/app/views/layouts/decidim/_topbar_search.html.erb +8 -0
  168. data/app/views/layouts/decidim/_user_menu.html.erb +2 -2
  169. data/app/views/layouts/decidim/_wrapper.html.erb +3 -2
  170. data/config/initializers/devise.rb +1 -1
  171. data/config/initializers/rack_attack.rb +28 -0
  172. data/config/locales/ca.yml +136 -55
  173. data/config/locales/en.yml +135 -54
  174. data/config/locales/es.yml +136 -55
  175. data/config/locales/eu.yml +136 -54
  176. data/config/locales/fi.yml +135 -54
  177. data/config/locales/fr.yml +136 -54
  178. data/config/locales/gl.yml +136 -54
  179. data/config/locales/it.yml +136 -54
  180. data/config/locales/nl.yml +136 -54
  181. data/config/locales/pl.yml +144 -54
  182. data/config/locales/pt-BR.yml +136 -54
  183. data/config/locales/pt.yml +136 -54
  184. data/config/locales/ru.yml +150 -60
  185. data/config/locales/sv.yml +136 -54
  186. data/config/locales/uk.yml +146 -57
  187. data/config/routes.rb +11 -1
  188. data/db/migrate/20180209122819_create_decidim_searchable_resource.rb +21 -0
  189. data/db/migrate/20180508111640_add_tos_version_to_organization.rb +19 -0
  190. data/db/migrate/20180508111710_add_accepted_tos_version_field_to_users.rb +25 -0
  191. data/db/seeds.rb +33 -26
  192. data/lib/decidim/component_manifest.rb +35 -27
  193. data/lib/decidim/content_processor.rb +21 -3
  194. data/lib/decidim/core.rb +27 -16
  195. data/lib/decidim/core/engine.rb +8 -19
  196. data/lib/decidim/core/test.rb +2 -0
  197. data/lib/decidim/core/test/factories.rb +34 -4
  198. data/lib/decidim/core/test/shared_examples/fingerprint_examples.rb +15 -0
  199. data/lib/decidim/core/test/shared_examples/searchable_results_examples.rb +27 -0
  200. data/lib/decidim/core/version.rb +1 -1
  201. data/lib/decidim/events/base_event.rb +5 -1
  202. data/lib/decidim/fingerprint_calculator.rb +42 -0
  203. data/lib/decidim/fingerprintable.rb +63 -0
  204. data/lib/decidim/form_builder.rb +1 -0
  205. data/lib/decidim/manifest_registry.rb +4 -10
  206. data/lib/decidim/participable.rb +4 -0
  207. data/lib/decidim/participatory_space_manifest.rb +36 -0
  208. data/lib/decidim/participatory_space_resourceable.rb +11 -0
  209. data/lib/decidim/resource_manifest.rb +10 -11
  210. data/lib/decidim/resourceable.rb +3 -2
  211. data/lib/decidim/search_resource_fields_mapper.rb +93 -0
  212. data/lib/decidim/searchable.rb +85 -0
  213. data/lib/decidim/settings_manifest.rb +3 -2
  214. data/lib/decidim/traceable.rb +2 -0
  215. data/lib/decidim/view_model.rb +9 -0
  216. data/lib/tasks/decidim_tasks.rake +79 -1
  217. metadata +149 -76
  218. data/app/assets/stylesheets/decidim/extras/_register_form.scss +0 -9
  219. data/app/cells/decidim/author_box/show.erb +0 -10
  220. data/app/cells/decidim/author_box_cell.rb +0 -21
  221. data/app/cells/decidim/profile/show.erb +0 -13
  222. data/app/cells/decidim/profile_cell.rb +0 -17
  223. data/app/controllers/concerns/decidim/needs_authorization.rb +0 -46
  224. data/app/models/decidim/abilities/admin_ability.rb +0 -29
  225. data/app/models/decidim/abilities/base_ability.rb +0 -56
  226. data/app/models/decidim/abilities/everyone_ability.rb +0 -25
  227. data/app/models/decidim/abilities/participatory_process_admin_ability.rb +0 -28
  228. data/app/models/decidim/abilities/participatory_process_collaborator_ability.rb +0 -28
  229. data/app/models/decidim/abilities/participatory_process_moderator_ability.rb +0 -15
  230. data/app/models/decidim/abilities/user_manager_ability.rb +0 -35
  231. data/app/views/decidim/notifications/_notification.html.erb +0 -20
  232. data/app/views/decidim/notifications/index.html.erb +0 -36
  233. data/app/views/decidim/shared/_author.html.erb +0 -21
  234. data/app/views/pages/home.html.erb +0 -17
  235. data/db/migrate/20180613080638_rename_missing_features_to_components.rb +0 -15
  236. data/lib/decidim/abilities.rb +0 -7
  237. data/lib/decidim/abilities/participatory_process_role_ability.rb +0 -60
  238. data/lib/decidim/page_finder.rb +0 -49
@@ -6,12 +6,12 @@ module Decidim
6
6
  include Decidim::UserProfile
7
7
 
8
8
  def show
9
- authorize! :show, current_user
9
+ enforce_permission_to :read, :user, current_user: current_user
10
10
  @notifications_settings = form(NotificationsSettingsForm).from_model(current_user)
11
11
  end
12
12
 
13
13
  def update
14
- authorize! :update, current_user
14
+ enforce_permission_to :update, :user, current_user: current_user
15
15
  @notifications_settings = form(NotificationsSettingsForm).from_params(params)
16
16
 
17
17
  UpdateNotificationsSettings.call(current_user, @notifications_settings) do
@@ -1,29 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency "decidim/page_finder"
4
-
5
3
  module Decidim
6
4
  # This controller serves static pages using HighVoltage.
7
5
  class PagesController < Decidim::ApplicationController
8
- include HighVoltage::StaticPage
9
-
10
6
  layout "layouts/decidim/application"
11
7
 
12
- authorize_resource :public_pages, class: false
13
- delegate :page, to: :page_finder
14
8
  helper_method :page, :stats
15
9
  helper CtaButtonHelper
16
10
  helper Decidim::SanitizeHelper
17
11
  skip_before_action :store_current_location
18
12
 
19
13
  def index
20
- @pages = current_organization.static_pages.all.to_a.sort do |a, b|
21
- a.title[I18n.locale.to_s] <=> b.title[I18n.locale.to_s]
14
+ enforce_permission_to :read, :public_page
15
+ @pages = current_organization.static_pages.sorted_by_i18n_title
16
+ end
17
+
18
+ def show
19
+ enforce_permission_to :read, :public_page, page: page
20
+ if params[:id] == "home"
21
+ render :home
22
+ else
23
+ render :decidim_page
22
24
  end
23
25
  end
24
26
 
25
- def page_finder
26
- @page_finder ||= Decidim::PageFinder.new(params[:id], current_organization)
27
+ def page
28
+ @page ||= current_organization.static_pages.find_by(slug: params[:id])
27
29
  end
28
30
 
29
31
  private
@@ -3,13 +3,14 @@
3
3
  module Decidim
4
4
  # The controller to handle the user's public profile page.
5
5
  class ProfilesController < Decidim::ApplicationController
6
- skip_authorization_check
7
-
8
6
  helper Decidim::Messaging::ConversationHelper
9
7
 
10
- helper_method :user
8
+ helper_method :user, :active_content
11
9
 
12
- def show; end
10
+ def show
11
+ return redirect_to profile_notifications_path(nickname: params[:nickname]) if current_user == user && params[:active].blank?
12
+ return redirect_to profile_path(nickname: params[:nickname]) if current_user != user && params[:active] == "notifications"
13
+ end
13
14
 
14
15
  private
15
16
 
@@ -19,5 +20,10 @@ module Decidim
19
20
  organization: current_organization
20
21
  )
21
22
  end
23
+
24
+ def active_content
25
+ return "following" if current_user != user && params[:active].blank?
26
+ params[:active].presence
27
+ end
22
28
  end
23
29
  end
@@ -4,10 +4,12 @@ module Decidim
4
4
  # Exposes the report resource so users can report a reportable.
5
5
  class ReportsController < Decidim::ApplicationController
6
6
  include FormFactory
7
+ include NeedsPermission
8
+
7
9
  before_action :authenticate_user!
8
10
 
9
11
  def create
10
- authorize! :report, reportable
12
+ enforce_permission_to :create, :moderation
11
13
 
12
14
  @form = form(Decidim::ReportForm).from_params(params)
13
15
 
@@ -29,5 +31,16 @@ module Decidim
29
31
  def reportable
30
32
  @reportable ||= GlobalID::Locator.locate_signed params[:sgid]
31
33
  end
34
+
35
+ def permission_class_chain
36
+ [
37
+ reportable.participatory_space.manifest.permissions_class,
38
+ Decidim::Permissions
39
+ ]
40
+ end
41
+
42
+ def permission_scope
43
+ :public
44
+ end
32
45
  end
33
46
  end
@@ -6,10 +6,10 @@ module Decidim
6
6
  skip_before_action :store_current_location
7
7
 
8
8
  def picker
9
- authorize! :pick, Scope
9
+ enforce_permission_to :pick, :scope
10
10
 
11
11
  title = params[:title] || t("decidim.scopes.picker.title", field: params[:field]&.downcase)
12
- root = Scope.find(params[:root]) if params[:root]
12
+ root = current_organization.scopes.find(params[:root]) if params[:root]
13
13
  context = root ? { root: root.id, title: title } : { title: title }
14
14
  required = params[:required] && params[:required] != "false"
15
15
  if params[:current]
@@ -18,7 +18,7 @@ module Decidim
18
18
  parent_scopes = current.part_of_scopes(root)
19
19
  else
20
20
  current = root
21
- scopes = root&.children || Scope.top_level
21
+ scopes = root&.children || current_organization.scopes.top_level
22
22
  parent_scopes = [root].compact
23
23
  end
24
24
  render :picker, layout: nil, locals: { required: required, title: title, root: root, current: current, scopes: scopes.order(name: :asc),
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class SearchesController < Decidim::ApplicationController
5
+ include Rectify::ControllerHelpers
6
+ include FormFactory
7
+ include FilterResource
8
+ include Paginable
9
+
10
+ helper Decidim::FiltersHelper
11
+ helper_method :term
12
+
13
+ def index
14
+ Search.call(term, current_organization, filters) do
15
+ on(:ok) do |results|
16
+ expose(results: results)
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def default_filter_params
24
+ {
25
+ term: params[:term],
26
+ resource_type: nil,
27
+ decidim_scope_id: nil
28
+ }
29
+ end
30
+
31
+ def term
32
+ @term ||= filter_params[:term]
33
+ end
34
+
35
+ def filters
36
+ filter_params
37
+ end
38
+ end
39
+ end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  class StaticMapController < Decidim::ApplicationController
5
- skip_authorization_check
6
-
7
5
  def show
8
6
  send_data StaticMapGenerator.new(resource).data, type: "image/jpeg", disposition: "inline"
9
7
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # The controller to handle the current user's
5
+ # Terms and Conditions agreement.
6
+ class TosController < Decidim::ApplicationController
7
+ skip_before_action :store_current_location
8
+
9
+ def accept_tos
10
+ current_user.accepted_tos_version = Time.current
11
+ if current_user.save!
12
+ flash[:notice] = t("accept.success", scope: "decidim.pages.terms_and_conditions")
13
+ redirect_to after_sign_in_path_for current_user
14
+ else
15
+ flash[:alert] = t("accept.error", scope: "decidim.pages.terms_and_conditions")
16
+ redirect_to decidim.page_path tos_page
17
+ end
18
+ end
19
+ end
20
+ end
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  class WidgetsController < Decidim::ApplicationController
5
- skip_authorization_check only: :show
6
5
  skip_before_action :verify_authenticity_token
7
6
  after_action :allow_iframe, only: :show
8
7
  helper ResourceHelper
@@ -8,6 +8,7 @@ module Decidim
8
8
  attribute :followable_gid, String
9
9
 
10
10
  validates :followable_gid, :followable, presence: true
11
+ validates :followable, exclusion: { in: ->(form) { [form.current_user] } }
11
12
 
12
13
  def followable
13
14
  @followable ||= GlobalID::Locator.locate_signed followable_gid
@@ -20,9 +20,10 @@ module Decidim
20
20
 
21
21
  validates :sign_up_as, inclusion: { in: %w(user user_group) }
22
22
  validates :name, presence: true
23
- validates :nickname, presence: true
23
+ validates :nickname, presence: true, length: { maximum: Decidim::User.nickname_max_length }
24
24
  validates :email, presence: true, 'valid_email_2/email': { disposable: true }
25
25
  validates :password, presence: true, confirmation: true, length: { in: Decidim::User.password_length }
26
+ validates :password_confirmation, presence: true
26
27
  validates :tos_agreement, allow_nil: false, acceptance: true
27
28
 
28
29
  validates :user_group_name, presence: true, if: :user_group?
@@ -10,6 +10,8 @@ module Decidim
10
10
  #
11
11
  # Returns an HTML.
12
12
  def card_for(model, options = {})
13
+ options = { context: { current_user: current_user } }.merge(options)
14
+
13
15
  cell "decidim/card", model, options
14
16
  end
15
17
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module CellsPaginateHelper
5
+ include Kaminari::Helpers::HelperMethods
6
+ include ActionView::Helpers::OutputSafetyHelper
7
+ include ActionView::Helpers::TranslationHelper
8
+ include Cell::ViewModel::Partial
9
+ include Decidim::PaginateHelper
10
+
11
+ def paginate(scope, options = {}, &block)
12
+ options = options.reverse_merge(views_prefix: "../views/")
13
+ super
14
+ end
15
+ end
16
+ end
@@ -6,7 +6,7 @@ module Decidim
6
6
  # Renders the Call To Action button. Link and text can be configured
7
7
  # per organization.
8
8
  def cta_button
9
- button_text = translated_attribute(current_organization.cta_button_text).presence || t("pages.home.hero.participate")
9
+ button_text = translated_attribute(current_organization.cta_button_text).presence || t("decidim.pages.home.hero.participate")
10
10
 
11
11
  link_to button_text, cta_button_path, class: "hero-cta button expanded large button--sc"
12
12
  end
@@ -185,5 +185,9 @@ module Decidim
185
185
 
186
186
  alert_box(record.errors.full_messages_for(:base).join(","), "alert", false)
187
187
  end
188
+
189
+ def foundation_datepicker_locale_tag
190
+ javascript_include_tag "datepicker-locales/foundation-datepicker.#{I18n.locale}.js" if I18n.locale != :en
191
+ end
188
192
  end
189
193
  end
@@ -3,6 +3,8 @@
3
3
  module Decidim
4
4
  # Helpers related to icons
5
5
  module IconHelper
6
+ include Decidim::LayoutHelper
7
+
6
8
  # Public: Returns an icon given an instance of a Component. It defaults to
7
9
  # a question mark when no icon is found.
8
10
  #
@@ -16,9 +16,8 @@ module Decidim
16
16
  # Returns nothing.
17
17
  def linked_resources_for(resource, type, link_name)
18
18
  linked_resources = resource.linked_resources(type, link_name).group_by { |linked_resource| linked_resource.class.name }
19
- safe_join(linked_resources.map do |klass, resources|
20
- next unless resources.any? { |r| r.component.published? }
21
19
 
20
+ safe_join(linked_resources.map do |klass, resources|
22
21
  resource_manifest = klass.constantize.resource_manifest
23
22
  content_tag(:div, class: "section") do
24
23
  i18n_name = "#{resource.class.name.demodulize.underscore}_#{resource_manifest.name}"
@@ -13,7 +13,9 @@ module Decidim
13
13
  #
14
14
  # Returns boolean.
15
15
  def has_visible_scopes?(resource)
16
- resource.participatory_space.scopes_enabled? && resource.scope.present? && resource.participatory_space.scope != resource.scope
16
+ resource.participatory_space.scopes_enabled? &&
17
+ resource.scope.present? &&
18
+ resource.participatory_space.scope != resource.scope
17
19
  end
18
20
 
19
21
  # Retrieves the translated name and type for an scope.
@@ -22,13 +24,11 @@ module Decidim
22
24
  #
23
25
  # Returns a string
24
26
  def scope_name_for_picker(scope, global_name)
25
- if scope
26
- name = translated_attribute(scope.name)
27
- name << " (#{translated_attribute(scope.scope_type.name)})" if scope.scope_type
28
- name
29
- else
30
- global_name
31
- end
27
+ return global_name unless scope
28
+
29
+ name = translated_attribute(scope.name)
30
+ name << " (#{translated_attribute(scope.scope_type.name)})" if scope.scope_type
31
+ name
32
32
  end
33
33
 
34
34
  # Renders a scopes picker field in a form.
@@ -66,8 +66,15 @@ module Decidim
66
66
  # Returns nothing.
67
67
  def scopes_picker_filter(form, name)
68
68
  form.scopes_picker name, multiple: true, legend_title: I18n.t("decidim.scopes.scopes"), label: false do |scope|
69
- { url: decidim.scopes_picker_path(root: try(:current_participatory_space)&.scope, current: scope&.id, title: I18n.t("decidim.scopes.prompt"), global_value: "global"),
70
- text: scope_name_for_picker(scope, I18n.t("decidim.scopes.prompt")) }
69
+ {
70
+ url: decidim.scopes_picker_path(
71
+ root: try(:current_participatory_space)&.scope,
72
+ current: scope&.id,
73
+ title: I18n.t("decidim.scopes.prompt"),
74
+ global_value: "global"
75
+ ),
76
+ text: scope_name_for_picker(scope, I18n.t("decidim.scopes.prompt"))
77
+ }
71
78
  end
72
79
  end
73
80
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # A Helper to render and link to resources.
5
+ module SearchesHelper
6
+ def searchable_resource_human_name(resource)
7
+ resource.model_name.human.pluralize
8
+ end
9
+
10
+ def searchable_resources_as_options(all_label)
11
+ [["", all_label]] + Decidim::Searchable.searchable_resources.values.collect do |r|
12
+ [r.name, searchable_resource_human_name(r)]
13
+ end.sort
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This helper includes some methods to help with the inclusion of tooltips
5
+ # on the layout.
6
+ module TooltipHelper
7
+ def with_tooltip(title, &block)
8
+ content_tag(:span, data: { tooltip: true, disable_hover: false, click_open: false },
9
+ title: title, &block)
10
+ end
11
+ end
12
+ end
@@ -49,5 +49,15 @@ module Decidim
49
49
  def homepage_big_url
50
50
  homepage_image.big.url
51
51
  end
52
+
53
+ def public_participatory_spaces
54
+ @public_participatory_spaces ||= Decidim.participatory_space_manifests.flat_map do |manifest|
55
+ manifest.participatory_spaces.call(self).public_spaces
56
+ end
57
+ end
58
+
59
+ def published_components
60
+ @published_components ||= Component.where(participatory_space: public_participatory_spaces).published
61
+ end
52
62
  end
53
63
  end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # This class encapsulates an action, which will be used by the
5
+ # permissions system to check if the user is allowed to perform it.
6
+ #
7
+ # It consists of a `scope` (which will typically be either `:public` or
8
+ # `:admin`), the name of the `:action` that is being performed and the
9
+ # `:subject` of the action.
10
+ class PermissionAction
11
+ # action - a Symbol representing the action being performed
12
+ # scope - a Symbol representing the scope of the action
13
+ # subject - a Symbol representing the subject of the action
14
+ def initialize(action:, scope:, subject:)
15
+ @action = action
16
+ @scope = scope
17
+ @subject = subject
18
+ @state = nil
19
+ end
20
+
21
+ attr_reader :action, :scope, :subject
22
+
23
+ def allow!
24
+ raise PermissionCannotBeDisallowedError, "Allowing a previously disallowed action is not permitted: #{inspect}" if @state == :disallowed
25
+ @state = :allowed
26
+ end
27
+
28
+ def disallow!
29
+ @state = :disallowed
30
+ end
31
+
32
+ def allowed?
33
+ raise PermissionNotSetError, "Permission hasn't been allowed or disallowed yet: #{inspect}" if @state.blank?
34
+ @state == :allowed
35
+ end
36
+
37
+ class PermissionNotSetError < StandardError; end
38
+ class PermissionCannotBeDisallowedError < StandardError; end
39
+ end
40
+ end