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
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Shared behaviour for signed_in users that require the latest TOS accepted
5
+ module NeedsTosAccepted
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_action :tos_accepted_by_user
10
+ helper_method :terms_and_conditions_page
11
+ end
12
+
13
+ private
14
+
15
+ def tos_accepted_by_user
16
+ return true unless current_user
17
+ return if current_user.tos_accepted?
18
+ return if permitted_paths?
19
+
20
+ redirect_to_tos
21
+ end
22
+
23
+ def terms_and_conditions_page
24
+ @terms_and_conditions_page ||= Decidim::StaticPage.find_by(slug: "terms-and-conditions", organization: current_organization)
25
+ end
26
+
27
+ def permitted_paths?
28
+ permitted_paths = [tos_path, decidim.delete_account_path, decidim.accept_tos_path]
29
+ permitted_paths.include?(request.path)
30
+ end
31
+
32
+ def tos_path
33
+ decidim.page_path terms_and_conditions_page
34
+ end
35
+
36
+ def redirect_to_tos
37
+ flash[:notice] = flash[:notice] if flash[:notice]
38
+ flash[:secondary] = t("required_review.alert", scope: "decidim.pages.terms_and_conditions")
39
+ redirect_to tos_path
40
+ end
41
+ end
42
+ end
@@ -44,13 +44,7 @@ module Decidim
44
44
  end
45
45
 
46
46
  def authorize_participatory_space
47
- authorize! :read, current_participatory_space
48
- end
49
-
50
- def ability_context
51
- super.merge(
52
- current_participatory_space: current_participatory_space
53
- )
47
+ enforce_permission_to :read, :participatory_space, current_participatory_space: current_participatory_space
54
48
  end
55
49
 
56
50
  def layout
@@ -21,7 +21,9 @@ module Decidim
21
21
  :user_groups
22
22
 
23
23
  before_action :current_user
24
- authorize_resource :current_user
24
+ before_action do
25
+ enforce_permission_to :update_profile, :user, current_user: current_user
26
+ end
25
27
  end
26
28
 
27
29
  # Public: Available authorization handlers in order to conditionally
@@ -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 :show, :user, current_user: current_user
10
10
  @account = form(AccountForm).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
  @account = form(AccountForm).from_params(account_params)
16
16
 
17
17
  UpdateAccount.call(current_user, @account) do
@@ -34,12 +34,12 @@ module Decidim
34
34
  end
35
35
 
36
36
  def delete
37
- authorize! :delete, current_user
37
+ enforce_permission_to :delete, :user, current_user: current_user
38
38
  @form = form(DeleteAccountForm).from_model(current_user)
39
39
  end
40
40
 
41
41
  def destroy
42
- authorize! :delete, current_user
42
+ enforce_permission_to :delete, :user, current_user: current_user
43
43
  @form = form(DeleteAccountForm).from_params(params)
44
44
 
45
45
  DestroyAccount.call(current_user, @form) do
@@ -5,9 +5,11 @@ module Decidim
5
5
  class ApplicationController < ::DecidimController
6
6
  include NeedsOrganization
7
7
  include LocaleSwitcher
8
- include NeedsAuthorization
8
+ include NeedsPermission
9
9
  include PayloadInfo
10
10
  include ImpersonateUsers
11
+ include NeedsTosAccepted
12
+ include HttpCachingDisabler
11
13
 
12
14
  helper Decidim::MetaTagsHelper
13
15
  helper Decidim::DecidimFormHelper
@@ -30,6 +32,8 @@ module Decidim
30
32
 
31
33
  layout "layouts/decidim/application"
32
34
 
35
+ skip_before_action :disable_http_caching, unless: :user_signed_in?
36
+
33
37
  private
34
38
 
35
39
  # Stores the url where the user will be redirected after login.
@@ -44,21 +48,26 @@ module Decidim
44
48
  store_location_for(:user, value)
45
49
  end
46
50
 
47
- def user_not_authorized_path
51
+ def user_has_no_permission_path
48
52
  decidim.root_path
49
53
  end
50
54
 
55
+ def permission_class_chain
56
+ [
57
+ Decidim::Admin::Permissions,
58
+ Decidim::Permissions
59
+ ]
60
+ end
61
+
62
+ def permission_scope
63
+ :public
64
+ end
65
+
51
66
  # Make sure Chrome doesn't use the cache from a different format. This
52
67
  # prevents a bug where clicking the back button of the browser
53
68
  # displays the JS response instead of the HTML one.
54
69
  def add_vary_header
55
70
  response.headers["Vary"] = "Accept"
56
71
  end
57
-
58
- # Overwrites `cancancan`'s method to point to the correct ability class,
59
- # since the gem expects the ability class to be in the root namespace.
60
- def current_ability_klass
61
- Decidim::Abilities::BaseAbility
62
- end
63
72
  end
64
73
  end
@@ -8,6 +8,7 @@ module Decidim
8
8
  class BaseController < Decidim::ApplicationController
9
9
  include Settings
10
10
  include ActionAuthorization
11
+ include Decidim::NeedsPermission
11
12
 
12
13
  include ParticipatorySpaceContext
13
14
  participatory_space_layout
@@ -27,11 +28,10 @@ module Decidim
27
28
  :current_participatory_space,
28
29
  :current_manifest
29
30
 
30
- skip_authorize_resource
31
-
32
31
  before_action do
33
- authorize! :read, current_component
32
+ enforce_permission_to :read, :component, component: current_component
34
33
  end
34
+
35
35
  before_action :redirect_unless_feature_private
36
36
 
37
37
  def current_participatory_space
@@ -49,12 +49,17 @@ module Decidim
49
49
  @current_manifest ||= current_component.manifest
50
50
  end
51
51
 
52
- def ability_context
53
- super.merge(
54
- current_manifest: current_manifest,
55
- current_settings: current_settings,
56
- component_settings: component_settings
57
- )
52
+ def permission_scope
53
+ :public
54
+ end
55
+
56
+ def permission_class_chain
57
+ [
58
+ current_component.manifest.permissions_class,
59
+ current_participatory_space.manifest.permissions_class,
60
+ Decidim::Admin::Permissions,
61
+ Decidim::Permissions
62
+ ]
58
63
  end
59
64
 
60
65
  def redirect_unless_feature_private
@@ -3,8 +3,6 @@
3
3
  module Decidim
4
4
  # This controller allows the user to accept the cookie policy.
5
5
  class CookiePolicyController < Decidim::ApplicationController
6
- skip_authorization_check
7
-
8
6
  skip_before_action :store_current_location
9
7
 
10
8
  def accept
@@ -5,6 +5,19 @@ module Decidim
5
5
  # Custom Devise ConfirmationsController to avoid namespace problems.
6
6
  class ConfirmationsController < ::Devise::ConfirmationsController
7
7
  include Decidim::DeviseControllers
8
+
9
+ # Since we're using a single Devise installation for multiple
10
+ # organizations, and user emails can be repeated across organizations,
11
+ # we need to identify the user by both the email and the organization.
12
+ # Setting the organization ID here will be used by Devise internally to
13
+ # find the correct user.
14
+ #
15
+ # Note that in order for this to work we need to define the `confirmation_keys`
16
+ # Devise attribute in the `Decidim::User` model to include the
17
+ # `decidim_organization_id` attribute.
18
+ def resource_params
19
+ super.merge(decidim_organization_id: current_organization.id)
20
+ end
8
21
  end
9
22
  end
10
23
  end
@@ -5,6 +5,7 @@ module Decidim
5
5
  # This controller customizes the behaviour of Devise::Invitiable.
6
6
  class InvitationsController < ::Devise::InvitationsController
7
7
  include Decidim::DeviseControllers
8
+ include NeedsTosAccepted
8
9
 
9
10
  before_action :configure_permitted_parameters
10
11
 
@@ -25,13 +26,14 @@ module Decidim
25
26
  def accept_resource
26
27
  resource = resource_class.accept_invitation!(update_resource_params)
27
28
  resource.update!(managed: false) if resource.managed?
29
+ resource.update!(accepted_tos_version: resource.organization.tos_version)
28
30
  resource
29
31
  end
30
32
 
31
33
  protected
32
34
 
33
35
  def configure_permitted_parameters
34
- devise_parameter_sanitizer.permit(:accept_invitation, keys: [:nickname])
36
+ devise_parameter_sanitizer.permit(:accept_invitation, keys: [:nickname, :tos_agreement, :newsletter_notifications])
35
37
  end
36
38
  end
37
39
  end
@@ -72,14 +72,13 @@ module Decidim
72
72
  private
73
73
 
74
74
  def oauth_data
75
- return {} unless request.env["omniauth.auth"]
76
- @oauth_data ||= request.env["omniauth.auth"].slice(:provider, :uid, :info)
75
+ @oauth_data ||= oauth_hash.slice(:provider, :uid, :info)
77
76
  end
78
77
 
79
78
  # Private: Create form params from omniauth hash
80
79
  # Since we are using trusted omniauth data we are generating a valid signature.
81
80
  def user_params_from_oauth_hash
82
- return nil unless request.env["omniauth.auth"]
81
+ return nil if oauth_data.empty?
83
82
  {
84
83
  provider: oauth_data[:provider],
85
84
  uid: oauth_data[:uid],
@@ -93,6 +92,13 @@ module Decidim
93
92
  def verified_email
94
93
  @verified_email ||= oauth_data.dig(:info, :email)
95
94
  end
95
+
96
+ def oauth_hash
97
+ raw_hash = request.env["omniauth.auth"]
98
+ return {} unless raw_hash
99
+
100
+ raw_hash.deep_symbolize_keys
101
+ end
96
102
  end
97
103
  end
98
104
  end
@@ -14,7 +14,7 @@ module Decidim
14
14
  # Setting the organization ID here will be used by Devise internally to
15
15
  # find the correct user.
16
16
  #
17
- # Note that in orther for this to work we need to define the `reset_password_keys`
17
+ # Note that in order for this to work we need to define the `reset_password_keys`
18
18
  # Devise attribute in the `Decidim::User` model to include the
19
19
  # `decidim_organization_id` attribute.
20
20
  def resource_params
@@ -7,9 +7,9 @@ module Decidim
7
7
  class RegistrationsController < ::Devise::RegistrationsController
8
8
  include FormFactory
9
9
  include Decidim::DeviseControllers
10
+ include NeedsTosAccepted
10
11
 
11
12
  before_action :configure_permitted_parameters
12
- helper_method :terms_and_conditions_page
13
13
 
14
14
  invisible_captcha
15
15
 
@@ -43,12 +43,6 @@ module Decidim
43
43
  end
44
44
  end
45
45
 
46
- private
47
-
48
- def terms_and_conditions_page
49
- @terms_and_conditions_page ||= Decidim::StaticPage.find_by(slug: "terms-and-conditions", organization: current_organization)
50
- end
51
-
52
46
  protected
53
47
 
54
48
  def configure_permitted_parameters
@@ -4,8 +4,6 @@ module Decidim
4
4
  module Doorkeeper
5
5
  # Custom Doorkeeper AuthorizationsController to avoid namespace problems.
6
6
  class AuthorizationsController < ::Doorkeeper::AuthorizationsController
7
- skip_authorization_check
8
-
9
7
  helper_method :oauth_application
10
8
 
11
9
  def oauth_application
@@ -4,7 +4,6 @@ module Decidim
4
4
  module Doorkeeper
5
5
  # A controller to expose a simple JSON API so OAuth clients can get the user's information.
6
6
  class CredentialsController < ApplicationController
7
- skip_authorization_check
8
7
  before_action :doorkeeper_authorize!
9
8
  respond_to :json
10
9
 
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  class ErrorsController < Decidim::ApplicationController
5
- skip_authorization_check
6
-
7
5
  def not_found
8
6
  render status: :not_found
9
7
  end
@@ -8,7 +8,8 @@ module Decidim
8
8
 
9
9
  def destroy
10
10
  @form = form(Decidim::FollowForm).from_params(params)
11
- authorize! :delete, @form.follow
11
+ @inline = params[:follow][:inline] == "true"
12
+ enforce_permission_to :delete, :follow, follow: @form.follow
12
13
 
13
14
  DeleteFollow.call(@form, current_user) do
14
15
  on(:ok) do
@@ -23,7 +24,8 @@ module Decidim
23
24
 
24
25
  def create
25
26
  @form = form(Decidim::FollowForm).from_params(params)
26
- authorize! :create, Follow
27
+ @inline = params[:follow][:inline] == "true"
28
+ enforce_permission_to :create, :follow
27
29
 
28
30
  CreateFollow.call(@form, current_user) do
29
31
  on(:ok) do
@@ -4,9 +4,9 @@ module Decidim
4
4
  # A controller to allow users switching their locale.
5
5
  class LocalesController < Decidim::ApplicationController
6
6
  skip_before_action :store_current_location
7
- authorize_resource :locales, class: false
8
7
 
9
8
  def create
9
+ enforce_permission_to :create, :locales
10
10
  current_user.update!(locale: params["locale"]) if current_user && params["locale"] && available_locales.include?(params["locale"])
11
11
 
12
12
  redirect_to referer_with_new_locale
@@ -14,7 +14,7 @@ module Decidim
14
14
  helper_method :username_list, :conversation
15
15
 
16
16
  def new
17
- authorize! :create, Conversation
17
+ enforce_permission_to :create, :conversation
18
18
  @form = form(ConversationForm).from_params(params)
19
19
 
20
20
  redirect_back(fallback_location: profile_path(current_user.nickname)) && return unless @form.recipient
@@ -24,7 +24,7 @@ module Decidim
24
24
  end
25
25
 
26
26
  def create
27
- authorize! :create, Conversation
27
+ enforce_permission_to :create, :conversation
28
28
 
29
29
  @form = form(ConversationForm).from_params(params)
30
30
 
@@ -43,13 +43,13 @@ module Decidim
43
43
  end
44
44
 
45
45
  def index
46
- authorize! :index, Conversation
46
+ enforce_permission_to :list, :conversation
47
47
 
48
48
  @conversations = UserConversations.for(current_user)
49
49
  end
50
50
 
51
51
  def show
52
- authorize! :show, conversation
52
+ enforce_permission_to :read, :conversation, conversation: conversation
53
53
 
54
54
  @conversation.mark_as_read(current_user)
55
55
 
@@ -57,7 +57,7 @@ module Decidim
57
57
  end
58
58
 
59
59
  def update
60
- authorize! :update, conversation
60
+ enforce_permission_to :update, :conversation, conversation: conversation
61
61
 
62
62
  @form = form(MessageForm).from_params(params)
63
63
 
@@ -3,8 +3,6 @@
3
3
  module Decidim
4
4
  # The controller to show the newsletter on the website.
5
5
  class NewslettersController < Decidim::ApplicationController
6
- skip_authorization_check
7
-
8
6
  layout "decidim/mailer", only: [:show]
9
7
  helper Decidim::SanitizeHelper
10
8
  include Decidim::NewslettersHelper
@@ -1,27 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Decidim
4
- # The controller to handle the user's notifications dashboard.
4
+ # The controller to handle the user's notifications deletion.
5
5
  class NotificationsController < Decidim::ApplicationController
6
- helper Decidim::IconHelper
7
- helper Decidim::PaginateHelper
8
- include Paginable
9
-
10
- helper_method :notifications
11
-
12
- def index
13
- authorize! :read, Notification
14
- @notifications = paginate(notifications)
15
- end
16
-
17
6
  def destroy
18
7
  notification = notifications.find(params[:id])
19
- authorize! :destroy, notification
8
+ enforce_permission_to :destroy, :notification, notification: notification
20
9
  notification.destroy
21
10
  end
22
11
 
23
12
  def read_all
24
- authorize! :destroy, notifications.first
13
+ enforce_permission_to :destroy, :notification, notification: notifications.first
25
14
  notifications.destroy_all
26
15
  end
27
16
 
@@ -30,10 +19,5 @@ module Decidim
30
19
  def notifications
31
20
  @notifications ||= current_user.notifications.order(created_at: :desc)
32
21
  end
33
-
34
- # Private: overwrites the amount of elements per page.
35
- def per_page
36
- 50
37
- end
38
22
  end
39
23
  end