decidim-core 0.13.1 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim-core might be problematic. Click here for more details.

Files changed (236) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/config/decidim_core_manifest.js +1 -1
  3. data/app/assets/images/decidim/gamification/badges/invitations.svg +117 -0
  4. data/app/assets/javascripts/decidim.js.es6 +4 -1
  5. data/app/assets/javascripts/decidim/ajax_modals.js.es6 +17 -0
  6. data/app/assets/javascripts/decidim/conferences.js.es6 +16 -0
  7. data/app/assets/javascripts/decidim/input_hashtags.js.es6 +115 -0
  8. data/app/assets/javascripts/decidim/input_mentions.js.es6 +2 -3
  9. data/app/assets/javascripts/decidim/vizzs/areachart.js.es6 +226 -0
  10. data/app/assets/javascripts/decidim/vizzs/metrics.js.es6 +26 -0
  11. data/app/assets/javascripts/decidim/vizzs/orgchart.js.es6 +701 -0
  12. data/app/assets/javascripts/decidim/vizzs/renders.js.es6 +11 -0
  13. data/app/assets/stylesheets/decidim/extras/_proposal_form.scss +3 -1
  14. data/app/assets/stylesheets/decidim/layouts/_home.scss +1 -1
  15. data/app/assets/stylesheets/decidim/modules/_areachart.scss +74 -0
  16. data/app/assets/stylesheets/decidim/modules/_badges.scss +116 -0
  17. data/app/assets/stylesheets/decidim/modules/_buttons.scss +5 -0
  18. data/app/assets/stylesheets/decidim/modules/_cards.scss +21 -4
  19. data/app/assets/stylesheets/decidim/modules/_chart-tooltip.scss +42 -0
  20. data/app/assets/stylesheets/decidim/modules/_collapsible-list.scss +12 -8
  21. data/app/assets/stylesheets/decidim/modules/_conference-nav.scss +31 -0
  22. data/app/assets/stylesheets/decidim/modules/_conference-programme.scss +110 -0
  23. data/app/assets/stylesheets/decidim/modules/_conference-speaker.scss +86 -0
  24. data/app/assets/stylesheets/decidim/modules/_conversation.scss +58 -0
  25. data/app/assets/stylesheets/decidim/modules/_help.scss +38 -0
  26. data/app/assets/stylesheets/decidim/modules/_hover-section.scss +29 -0
  27. data/app/assets/stylesheets/decidim/modules/_icons.scss +10 -4
  28. data/app/assets/stylesheets/decidim/modules/_input-hashtags.scss +124 -0
  29. data/app/assets/stylesheets/decidim/modules/_loading-spinner.scss +12 -0
  30. data/app/assets/stylesheets/decidim/modules/_margins.scss +2 -2
  31. data/app/assets/stylesheets/decidim/modules/_modules.scss +15 -0
  32. data/app/assets/stylesheets/decidim/modules/_navbar.scss +9 -0
  33. data/app/assets/stylesheets/decidim/modules/_orgchart.scss +62 -0
  34. data/app/assets/stylesheets/decidim/modules/_status-labels.scss +2 -1
  35. data/app/assets/stylesheets/decidim/modules/_typography.scss +9 -0
  36. data/app/assets/stylesheets/decidim/utils/_helpers.scss +28 -0
  37. data/app/assets/stylesheets/decidim/utils/_mixins.scss +63 -0
  38. data/app/cells/decidim/author/withdraw.erb +1 -1
  39. data/app/cells/decidim/author_cell.rb +1 -1
  40. data/app/cells/decidim/badge/show.erb +36 -0
  41. data/app/cells/decidim/badge_cell.rb +53 -0
  42. data/app/cells/decidim/badges/show.erb +6 -0
  43. data/app/cells/decidim/badges_cell.rb +14 -0
  44. data/app/cells/decidim/card_m/header.erb +1 -1
  45. data/app/cells/decidim/card_m/show.erb +1 -2
  46. data/app/cells/decidim/card_m/top.erb +7 -0
  47. data/app/cells/decidim/card_m_cell.rb +14 -17
  48. data/app/cells/decidim/coauthorships_cell.rb +77 -0
  49. data/app/cells/decidim/collapsible_authors/show.erb +0 -1
  50. data/app/cells/decidim/collapsible_authors_cell.rb +4 -4
  51. data/app/cells/decidim/collapsible_list/show.erb +12 -4
  52. data/app/cells/decidim/collapsible_list_cell.rb +14 -12
  53. data/app/cells/decidim/content_blocks/footer_sub_hero/show.erb +14 -0
  54. data/app/cells/decidim/content_blocks/footer_sub_hero_cell.rb +12 -0
  55. data/app/{views/decidim/pages/home/_hero.html.erb → cells/decidim/content_blocks/hero/show.erb} +4 -4
  56. data/app/cells/decidim/content_blocks/hero_cell.rb +25 -0
  57. data/app/cells/decidim/content_blocks/hero_settings_form/show.erb +7 -0
  58. data/app/cells/decidim/content_blocks/hero_settings_form_cell.rb +13 -0
  59. data/app/cells/decidim/content_blocks/highlighted_content_banner/show.erb +24 -0
  60. data/app/cells/decidim/content_blocks/highlighted_content_banner_cell.rb +16 -0
  61. data/app/{views/decidim/pages/home/_extended.html.erb → cells/decidim/content_blocks/how_to_participate/show.erb} +10 -10
  62. data/app/cells/decidim/content_blocks/how_to_participate_cell.rb +9 -0
  63. data/app/{views/decidim/pages/home/_statistics.html.erb → cells/decidim/content_blocks/stats/show.erb} +2 -2
  64. data/app/cells/decidim/content_blocks/stats_cell.rb +18 -0
  65. data/app/{views/decidim/pages/home/_sub_hero.html.erb → cells/decidim/content_blocks/sub_hero/show.erb} +2 -2
  66. data/app/cells/decidim/content_blocks/sub_hero_cell.rb +17 -0
  67. data/app/cells/decidim/conversation/show.erb +18 -0
  68. data/app/cells/decidim/conversation_cell.rb +23 -0
  69. data/app/cells/decidim/conversation_header/show.erb +17 -0
  70. data/app/cells/decidim/conversation_header_cell.rb +16 -0
  71. data/app/cells/decidim/conversations/show.erb +45 -0
  72. data/app/cells/decidim/conversations_cell.rb +24 -0
  73. data/app/cells/decidim/follow_button/show.erb +3 -3
  74. data/app/cells/decidim/follow_button_cell.rb +1 -5
  75. data/app/cells/decidim/following_cell.rb +1 -7
  76. data/app/cells/decidim/message/show.erb +15 -0
  77. data/app/cells/decidim/message_cell.rb +23 -0
  78. data/app/cells/decidim/new_conversation/show.erb +19 -0
  79. data/app/cells/decidim/new_conversation_cell.rb +19 -0
  80. data/app/cells/decidim/notifications/show.erb +1 -1
  81. data/app/cells/decidim/profile/show.erb +27 -0
  82. data/app/cells/decidim/profile_cell.rb +33 -0
  83. data/app/cells/decidim/profile_sidebar/show.erb +57 -0
  84. data/app/cells/decidim/profile_sidebar_cell.rb +31 -0
  85. data/app/cells/decidim/tos_page_cell.rb +0 -4
  86. data/app/cells/decidim/user_profile/header.erb +1 -1
  87. data/app/controllers/concerns/decidim/action_authorization.rb +13 -38
  88. data/app/controllers/concerns/decidim/needs_permission.rb +15 -6
  89. data/app/controllers/decidim/application_controller.rb +1 -0
  90. data/app/controllers/decidim/authorization_modals_controller.rb +35 -0
  91. data/app/controllers/decidim/components/base_controller.rb +0 -1
  92. data/app/controllers/decidim/devise/invitations_controller.rb +2 -1
  93. data/app/controllers/decidim/messaging/conversations_controller.rb +2 -11
  94. data/app/controllers/decidim/newsletters_controller.rb +4 -6
  95. data/app/controllers/decidim/notifications_controller.rb +4 -0
  96. data/app/controllers/decidim/pages_controller.rb +3 -7
  97. data/app/controllers/decidim/profiles_controller.rb +17 -7
  98. data/app/forms/decidim/notifications_settings_form.rb +1 -1
  99. data/app/forms/decidim/registration_form.rb +1 -1
  100. data/app/helpers/decidim/action_authorization_helper.rb +51 -46
  101. data/app/helpers/decidim/application_helper.rb +18 -0
  102. data/app/helpers/decidim/card_helper.rb +1 -1
  103. data/app/helpers/decidim/cells_helper.rb +6 -2
  104. data/app/helpers/decidim/resource_helper.rb +8 -1
  105. data/app/helpers/decidim/searches_helper.rb +5 -4
  106. data/app/helpers/decidim/traceability_helper.rb +5 -1
  107. data/app/models/decidim/authorization.rb +2 -2
  108. data/app/models/decidim/content_block.rb +144 -0
  109. data/app/models/decidim/gamification/badge_score.rb +13 -0
  110. data/app/models/decidim/messaging/message.rb +1 -1
  111. data/app/models/decidim/messaging/receipt.rb +1 -1
  112. data/app/models/decidim/organization.rb +1 -5
  113. data/app/models/decidim/resource_permission.rb +8 -0
  114. data/app/models/decidim/searchable_resource.rb +1 -1
  115. data/app/models/decidim/user.rb +17 -1
  116. data/app/permissions/decidim/default_permissions.rb +4 -3
  117. data/app/permissions/decidim/permissions.rb +33 -1
  118. data/app/presenters/decidim/hashtag_presenter.rb +32 -0
  119. data/app/presenters/decidim/resource_locator_presenter.rb +13 -0
  120. data/app/presenters/decidim/user_presenter.rb +1 -1
  121. data/app/queries/decidim/messaging/user_conversations.rb +1 -1
  122. data/app/resolvers/decidim/hashtags_resolver.rb +15 -0
  123. data/app/services/decidim/action_authorizer.rb +9 -8
  124. data/app/types/decidim/core/date_time_type.rb +1 -1
  125. data/app/types/decidim/core/hashtag_type.rb +13 -0
  126. data/app/uploaders/decidim/homepage_image_uploader.rb +1 -1
  127. data/app/uploaders/decidim/image_uploader.rb +1 -0
  128. data/app/views/decidim/authorization_modals/show.html.erb +32 -0
  129. data/app/views/decidim/messaging/conversations/create.js.erb +1 -1
  130. data/app/views/decidim/messaging/conversations/index.html.erb +1 -51
  131. data/app/views/decidim/messaging/conversations/new.html.erb +1 -5
  132. data/app/views/decidim/messaging/conversations/show.html.erb +1 -9
  133. data/app/views/decidim/messaging/conversations/update.js.erb +1 -1
  134. data/app/views/decidim/notifications/index.html.erb +1 -0
  135. data/app/views/decidim/pages/decidim_page.html.erb +9 -0
  136. data/app/views/decidim/pages/home.html.erb +12 -16
  137. data/app/views/decidim/pages/index.html.erb +8 -0
  138. data/app/views/decidim/profiles/_user_follow.erb +2 -2
  139. data/app/views/decidim/profiles/show.html.erb +1 -37
  140. data/app/views/decidim/searches/_results.html.erb +1 -1
  141. data/app/views/decidim/shared/_author_reference.html.erb +1 -1
  142. data/app/views/decidim/shared/_authorization_modal.html.erb +1 -0
  143. data/app/views/decidim/shared/_tags.html.erb +1 -1
  144. data/app/views/kaminari/decidim/_page.html.erb +1 -1
  145. data/app/views/layouts/decidim/_application.html.erb +6 -1
  146. data/app/views/layouts/decidim/_edit_link.html.erb +8 -0
  147. data/app/views/layouts/decidim/_impersonation_warning.html.erb +1 -1
  148. data/app/views/layouts/decidim/_user_menu.html.erb +2 -2
  149. data/app/views/layouts/decidim/_wrapper.html.erb +14 -1
  150. data/config/initializers/carrierwave.rb +15 -0
  151. data/config/locales/ca.yml +78 -30
  152. data/config/locales/en.yml +78 -30
  153. data/config/locales/es-PY.yml +78 -30
  154. data/config/locales/es.yml +78 -30
  155. data/config/locales/eu.yml +78 -30
  156. data/config/locales/fi.yml +262 -214
  157. data/config/locales/fr.yml +78 -30
  158. data/config/locales/gl.yml +78 -30
  159. data/config/locales/hu.yml +781 -0
  160. data/config/locales/it.yml +78 -30
  161. data/config/locales/nl.yml +78 -30
  162. data/config/locales/pl.yml +78 -30
  163. data/config/locales/pt-BR.yml +106 -58
  164. data/config/locales/pt.yml +78 -30
  165. data/config/locales/ru.yml +52 -32
  166. data/config/locales/sv.yml +183 -135
  167. data/config/locales/uk.yml +60 -40
  168. data/config/routes.rb +8 -6
  169. data/db/migrate/20180705091019_create_decidim_resource_permissions.rb +12 -0
  170. data/db/migrate/20180706104107_add_nickname_to_managed_users.rb +14 -0
  171. data/db/migrate/20180706111847_fix_result_follows.rb +9 -0
  172. data/db/migrate/20180724103814_add_content_blocks.rb +22 -0
  173. data/db/migrate/20180726112510_create_decidim_hashtags.rb +17 -0
  174. data/db/migrate/20180730071851_add_core_content_blocks.rb +28 -0
  175. data/db/migrate/20180802132147_rename_content_block_options_to_settings.rb +7 -0
  176. data/db/migrate/20180806095628_add_badge_scores.rb +11 -0
  177. data/db/migrate/20180808135006_add_images_to_content_blocks.rb +7 -0
  178. data/db/migrate/20180810092428_move_organization_fields_to_hero_content_block.rb +23 -0
  179. data/db/seeds.rb +10 -2
  180. data/lib/decidim/api/authorable_interface.rb +1 -1
  181. data/lib/decidim/coauthorable.rb +1 -0
  182. data/lib/decidim/content_block_manifest.rb +58 -0
  183. data/lib/decidim/content_block_registry.rb +87 -0
  184. data/lib/decidim/content_parsers.rb +1 -0
  185. data/lib/decidim/content_parsers/hashtag_parser.rb +36 -0
  186. data/lib/decidim/content_processor.rb +11 -0
  187. data/lib/decidim/content_renderers.rb +1 -0
  188. data/lib/decidim/content_renderers/hashtag_renderer.rb +43 -0
  189. data/lib/decidim/core.rb +28 -6
  190. data/lib/decidim/core/api.rb +1 -0
  191. data/lib/decidim/core/engine.rb +52 -1
  192. data/lib/decidim/core/test.rb +3 -0
  193. data/lib/decidim/core/test/factories.rb +32 -17
  194. data/lib/decidim/core/test/shared_examples/authorable_interface_examples.rb +10 -0
  195. data/lib/decidim/core/test/shared_examples/coauthorable.rb +3 -0
  196. data/lib/decidim/core/test/shared_examples/edit_link_shared_examples.rb +30 -0
  197. data/lib/decidim/core/test/shared_examples/has_space_in_mcell_examples.rb +15 -0
  198. data/lib/decidim/core/test/shared_examples/publicable.rb +1 -1
  199. data/lib/decidim/core/test/shared_examples/railtie_examples.rb +15 -0
  200. data/lib/decidim/core/test/shared_examples/scope_helper_examples.rb +1 -0
  201. data/lib/decidim/core/version.rb +1 -1
  202. data/lib/decidim/events/base_event.rb +2 -1
  203. data/lib/decidim/form_builder.rb +9 -3
  204. data/lib/decidim/friendly_dates.rb +1 -1
  205. data/lib/decidim/gamification.rb +109 -0
  206. data/lib/decidim/gamification/badge.rb +54 -0
  207. data/lib/decidim/gamification/badge_earned_event.rb +9 -0
  208. data/lib/decidim/gamification/badge_registry.rb +63 -0
  209. data/lib/decidim/gamification/badge_scorer.rb +118 -0
  210. data/lib/decidim/gamification/badge_status.rb +41 -0
  211. data/lib/decidim/gamification/base_event.rb +40 -0
  212. data/lib/decidim/gamification/level_up_event.rb +9 -0
  213. data/lib/decidim/hashtag.rb +15 -0
  214. data/lib/decidim/hashtaggable.rb +20 -0
  215. data/lib/decidim/query_extensions.rb +10 -0
  216. data/lib/decidim/resource_manifest.rb +10 -0
  217. data/lib/decidim/resourceable.rb +13 -0
  218. data/lib/decidim/search_resource_fields_mapper.rb +8 -3
  219. data/lib/decidim/searchable.rb +8 -0
  220. data/lib/decidim/translatable_attributes.rb +6 -18
  221. data/lib/decidim/view_model.rb +6 -0
  222. data/lib/devise/models/decidim_newsletterable.rb +1 -1
  223. data/vendor/assets/javascripts/d3.js +17813 -0
  224. metadata +125 -27
  225. data/app/cells/decidim/card_m/author.erb +0 -3
  226. data/app/cells/decidim/card_m/authors.erb +0 -9
  227. data/app/views/decidim/messaging/conversations/_message.html.erb +0 -14
  228. data/app/views/decidim/messaging/conversations/_reply.html.erb +0 -11
  229. data/app/views/decidim/messaging/conversations/_show.html.erb +0 -21
  230. data/app/views/decidim/messaging/conversations/_start.html.erb +0 -12
  231. data/app/views/decidim/pages/home/_footer_sub_hero.html.erb +0 -14
  232. data/app/views/decidim/pages/home/_highlighted_content_banner.html.erb +0 -26
  233. data/app/views/decidim/pages/home/_highlighted_processes.html.erb +0 -7
  234. data/app/views/decidim/profiles/_user.html.erb +0 -59
  235. data/app/views/decidim/shared/_action_authorization_modal.html.erb +0 -39
  236. data/app/views/layouts/decidim/_component_authorization_modals.html.erb +0 -5
@@ -8,7 +8,7 @@ module Decidim
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- helper_method :allowed_to?
11
+ helper_method :allowed_to?, :admin_allowed_to?
12
12
 
13
13
  class ::Decidim::ActionForbidden < StandardError
14
14
  end
@@ -37,15 +37,19 @@ module Decidim
37
37
  end
38
38
 
39
39
  def enforce_permission_to(action, subject, extra_context = {})
40
- Rails.logger.debug "==========="
41
- Rails.logger.debug [permission_scope, action, subject, permission_class_chain].map(&:inspect).join("\n")
42
- Rails.logger.debug "==========="
40
+ if Rails.env.development?
41
+ Rails.logger.debug "==========="
42
+ Rails.logger.debug [permission_scope, action, subject, permission_class_chain].map(&:inspect).join("\n")
43
+ Rails.logger.debug "==========="
44
+ end
43
45
 
44
46
  raise Decidim::ActionForbidden unless allowed_to?(action, subject, extra_context)
45
47
  end
46
48
 
47
- def allowed_to?(action, subject, extra_context = {}, chain = permission_class_chain, user = current_user)
48
- permission_action = Decidim::PermissionAction.new(scope: permission_scope, action: action, subject: subject)
49
+ # rubocop:disable Metrics/ParameterLists
50
+ def allowed_to?(action, subject, extra_context = {}, chain = permission_class_chain, user = current_user, scope = nil)
51
+ scope ||= permission_scope
52
+ permission_action = Decidim::PermissionAction.new(scope: scope, action: action, subject: subject)
49
53
 
50
54
  chain.inject(permission_action) do |current_permission_action, permission_class|
51
55
  permission_class.new(
@@ -57,6 +61,11 @@ module Decidim
57
61
  rescue Decidim::PermissionAction::PermissionNotSetError
58
62
  false
59
63
  end
64
+ # rubocop:enable Metrics/ParameterLists
65
+
66
+ def admin_allowed_to?(action, subject, extra_context = {}, chain = permission_class_chain, user = current_user)
67
+ allowed_to?(action, subject, extra_context, chain, user, :admin)
68
+ end
60
69
 
61
70
  def permission_class_chain
62
71
  raise "Please, make this method return an array of permission classes"
@@ -10,6 +10,7 @@ module Decidim
10
10
  include ImpersonateUsers
11
11
  include NeedsTosAccepted
12
12
  include HttpCachingDisabler
13
+ include ActionAuthorization
13
14
 
14
15
  helper Decidim::MetaTagsHelper
15
16
  helper Decidim::DecidimFormHelper
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class AuthorizationModalsController < Decidim::ApplicationController
5
+ helper_method :status, :authorize_action_path
6
+ layout false
7
+
8
+ def show; end
9
+
10
+ private
11
+
12
+ def resource
13
+ @resource ||= if params[:resource_name] && params[:resource_id]
14
+ manifest = Decidim.find_resource_manifest(params[:resource_name])
15
+ manifest&.resource_scope(current_component)&.find_by(id: params[:resource_id])
16
+ end
17
+ end
18
+
19
+ def current_component
20
+ @current_component ||= Decidim::Component.find(params[:component_id])
21
+ end
22
+
23
+ def authorization_action
24
+ @authorization_action ||= params[:authorization_action]
25
+ end
26
+
27
+ def authorize_action_path
28
+ status.current_path(redirect_url: URI(request.referer).path)
29
+ end
30
+
31
+ def status
32
+ @status ||= action_authorized_to(authorization_action, resource: resource)
33
+ end
34
+ end
35
+ end
@@ -7,7 +7,6 @@ module Decidim
7
7
  # fooling the engine into thinking it's isolated.
8
8
  class BaseController < Decidim::ApplicationController
9
9
  include Settings
10
- include ActionAuthorization
11
10
  include Decidim::NeedsPermission
12
11
 
13
12
  include ParticipatorySpaceContext
@@ -25,9 +25,10 @@ module Decidim
25
25
  # When a managed user accepts the invitation is promoted to non-managed user.
26
26
  def accept_resource
27
27
  resource = resource_class.accept_invitation!(update_resource_params)
28
- resource.update!(newsletter_notifications_at: Time.zone.now) if update_resource_params[:newsletter_notifications]
28
+ resource.update!(newsletter_notifications_at: Time.current) if update_resource_params[:newsletter_notifications]
29
29
  resource.update!(managed: false) if resource.managed?
30
30
  resource.update!(accepted_tos_version: resource.organization.tos_version)
31
+ Decidim::Gamification.increment_score(resource.invited_by, :invitations) if resource.invited_by
31
32
  resource
32
33
  end
33
34
 
@@ -11,7 +11,7 @@ module Decidim
11
11
 
12
12
  before_action :authenticate_user!
13
13
 
14
- helper_method :username_list, :conversation
14
+ helper_method :conversation
15
15
 
16
16
  def new
17
17
  enforce_permission_to :create, :conversation
@@ -30,10 +30,7 @@ module Decidim
30
30
 
31
31
  StartConversation.call(@form) do
32
32
  on(:ok) do |conversation|
33
- render action: :create, locals: {
34
- conversation: conversation,
35
- form: MessageForm.new
36
- }
33
+ redirect_to conversation_path(conversation)
37
34
  end
38
35
 
39
36
  on(:invalid) do
@@ -52,8 +49,6 @@ module Decidim
52
49
  enforce_permission_to :read, :conversation, conversation: conversation
53
50
 
54
51
  @conversation.mark_as_read(current_user)
55
-
56
- @form = MessageForm.new
57
52
  end
58
53
 
59
54
  def update
@@ -77,10 +72,6 @@ module Decidim
77
72
  def conversation
78
73
  @conversation ||= Conversation.find(params[:id])
79
74
  end
80
-
81
- def username_list(users)
82
- users.pluck(:name).join(", ")
83
- end
84
75
  end
85
76
  end
86
77
  end
@@ -13,12 +13,10 @@ module Decidim
13
13
  @user = current_user
14
14
  @organization = current_organization
15
15
 
16
- if newsletter.sent?
17
- @encrypted_token = Decidim::NewsletterEncryptor.sent_at_encrypted(@user.id, newsletter.sent_at) if @user.present?
18
- @body = parse_interpolations(newsletter.body[I18n.locale.to_s], @user, newsletter.id)
19
- else
20
- redirect_to "/404"
21
- end
16
+ raise ActionController::RoutingError, "Not Found" unless newsletter.sent?
17
+
18
+ @encrypted_token = Decidim::NewsletterEncryptor.sent_at_encrypted(@user.id, newsletter.sent_at) if @user.present?
19
+ @body = parse_interpolations(newsletter.body[I18n.locale.to_s], @user, newsletter.id)
22
20
  end
23
21
 
24
22
  def unsubscribe
@@ -3,6 +3,10 @@
3
3
  module Decidim
4
4
  # The controller to handle the user's notifications deletion.
5
5
  class NotificationsController < Decidim::ApplicationController
6
+ def index
7
+ enforce_permission_to :read, :notification
8
+ end
9
+
6
10
  def destroy
7
11
  notification = notifications.find(params[:id])
8
12
  enforce_permission_to :destroy, :notification, notification: notification
@@ -19,19 +19,15 @@ module Decidim
19
19
  enforce_permission_to :read, :public_page, page: page
20
20
  if params[:id] == "home"
21
21
  render :home
22
- else
22
+ elsif page
23
23
  render :decidim_page
24
+ else
25
+ raise ActionController::RoutingError, "Not Found"
24
26
  end
25
27
  end
26
28
 
27
29
  def page
28
30
  @page ||= current_organization.static_pages.find_by(slug: params[:id])
29
31
  end
30
-
31
- private
32
-
33
- def stats
34
- @stats ||= HomeStatsPresenter.new(organization: current_organization)
35
- end
36
32
  end
37
33
  end
@@ -8,8 +8,23 @@ module Decidim
8
8
  helper_method :user, :active_content
9
9
 
10
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"
11
+ return redirect_to notifications_path if current_user == user
12
+ @content_cell = "decidim/following"
13
+ end
14
+
15
+ def following
16
+ @content_cell = "decidim/following"
17
+ render :show
18
+ end
19
+
20
+ def followers
21
+ @content_cell = "decidim/followers"
22
+ render :show
23
+ end
24
+
25
+ def badges
26
+ @content_cell = "decidim/badges"
27
+ render :show
13
28
  end
14
29
 
15
30
  private
@@ -20,10 +35,5 @@ module Decidim
20
35
  organization: current_organization
21
36
  )
22
37
  end
23
-
24
- def active_content
25
- return "following" if current_user != user && params[:active].blank?
26
- params[:active].presence
27
- end
28
38
  end
29
39
  end
@@ -14,7 +14,7 @@ module Decidim
14
14
 
15
15
  def newsletter_notifications_at
16
16
  return nil unless newsletter_notifications
17
- Time.zone.now
17
+ Time.current
18
18
  end
19
19
  end
20
20
  end
@@ -42,7 +42,7 @@ module Decidim
42
42
 
43
43
  def newsletter_at
44
44
  return nil unless newsletter?
45
- Time.zone.now
45
+ Time.current
46
46
  end
47
47
 
48
48
  private
@@ -2,18 +2,6 @@
2
2
 
3
3
  module Decidim
4
4
  module ActionAuthorizationHelper
5
- # Public: Renders a modal that explains why she can't perform an action,
6
- # if that's the case. The modal isn't shown by default, and it's usually
7
- # triggered by `action_authorized_link_to` or `action_authorized_button_to`.
8
- #
9
- # action - The action to authenticate against.
10
- #
11
- # Returns a String with the modal.
12
- def action_authorization_modal(action)
13
- render partial: "decidim/shared/action_authorization_modal",
14
- locals: { action: action.to_s }
15
- end
16
-
17
5
  # Public: Emulates a `link_to` but conditionally renders a popup modal
18
6
  # blocking the action in case the user isn't allowed to perform it.
19
7
  #
@@ -23,28 +11,7 @@ module Decidim
23
11
  #
24
12
  # Returns a String with the link.
25
13
  def action_authorized_link_to(action, *arguments, &block)
26
- if block_given?
27
- body = block
28
- url = arguments[0]
29
- html_options = arguments[1]
30
- else
31
- body = arguments[0]
32
- url = arguments[1]
33
- html_options = arguments[2]
34
- end
35
-
36
- unless current_user_authorized?(action)
37
- html_options ||= {}
38
- html_options["onclick"] = "event.preventDefault();"
39
- html_options["data-open"] = current_user ? "#{action.to_s.underscore}AuthorizationModal" : "loginModal"
40
- url = ""
41
- end
42
-
43
- if block_given?
44
- link_to(url, html_options, &body)
45
- else
46
- link_to(body, url, html_options)
47
- end
14
+ authorized_to(:link, action, arguments, block)
48
15
  end
49
16
 
50
17
  # Public: Emulates a `button_to` but conditionally renders a popup modal
@@ -56,34 +23,72 @@ module Decidim
56
23
  #
57
24
  # Returns a String with the button.
58
25
  def action_authorized_button_to(action, *arguments, &block)
59
- if block_given?
26
+ authorized_to(:button, action, arguments, block)
27
+ end
28
+
29
+ # Public: Emulates a `link_to` but conditionally renders a popup modal
30
+ # blocking the action in case the user isn't logged id.
31
+ #
32
+ # *arguments - A regular set of arguments that would be provided to
33
+ # `link_to`.
34
+ #
35
+ # Returns a String with the link.
36
+ def logged_link_to(*arguments, &block)
37
+ authorized_to(:link, nil, arguments, block)
38
+ end
39
+
40
+ # Public: Emulates a `button_to` but conditionally renders a popup modal
41
+ # blocking the action in case the user isn't logged id.
42
+ #
43
+ # *arguments - A regular set of arguments that would be provided to
44
+ # `button_to`.
45
+ #
46
+ # Returns a String with the button.
47
+ def logged_button_to(*arguments, &block)
48
+ authorized_to(:button, nil, arguments, block)
49
+ end
50
+
51
+ private
52
+
53
+ def authorized_to(tag, action, arguments, block)
54
+ if block
60
55
  body = block
61
56
  url = arguments[0]
62
- html_options = arguments[1] || {}
57
+ html_options = arguments[1]
63
58
  else
64
59
  body = arguments[0]
65
60
  url = arguments[1]
66
- html_options = arguments[2] || {}
61
+ html_options = arguments[2]
67
62
  end
68
63
 
69
- unless current_user_authorized?(action)
70
- html_options["data-open"] = current_user ? "#{action.to_s.underscore}AuthorizationModal" : "loginModal"
64
+ html_options ||= {}
65
+ resource = html_options.delete(:resource)
66
+
67
+ if !current_user
68
+ html_options["data-open"] = "loginModal"
69
+ url = ""
70
+ elsif action && !action_authorized_to(action, resource: resource).ok?
71
+ html_options["data-open"] = "authorizationModal"
72
+ html_options["data-open-url"] = modal_path(action, resource)
71
73
  url = ""
72
74
  end
73
75
 
74
76
  html_options["onclick"] = "event.preventDefault();" if url == ""
75
77
 
76
- if block_given?
77
- button_to(url, html_options, &body)
78
+ if block
79
+ send("#{tag}_to", url, html_options, &body)
78
80
  else
79
- button_to(body, url, html_options)
81
+ send("#{tag}_to", body, url, html_options)
80
82
  end
81
83
  end
82
84
 
83
- private
84
-
85
- def current_user_authorized?(action)
86
- current_user && action_authorization(action).ok?
85
+ def modal_path(action, resource)
86
+ resource_params = if resource
87
+ { resource_name: resource.resource_manifest.name, resource_id: resource.id }
88
+ else
89
+ {}
90
+ end
91
+ decidim.authorization_modal_path(authorization_action: action, component_id: current_component.id, **resource_params)
87
92
  end
88
93
  end
89
94
  end
@@ -32,5 +32,23 @@ module Decidim
32
32
 
33
33
  presenter
34
34
  end
35
+
36
+ # Generates a link to be added to the global Edit link so admins
37
+ # can easily manage data without having to look for it at the admin
38
+ # panel when they're at a public page.
39
+ #
40
+ # link - The String with the URL.
41
+ # action - The Symbol action to check the permissions for.
42
+ # subject - The Symbol subject to perform the action to.
43
+ # extra_context - An optional Hash to check the permissions.
44
+ #
45
+ # Returns nothing.
46
+ def edit_link(link, action, subject, extra_context = {})
47
+ return unless current_user
48
+ return unless admin_allowed_to?(action, subject, extra_context)
49
+ return if content_for?(:edit_link)
50
+
51
+ content_for(:edit_link, link)
52
+ end
35
53
  end
36
54
  end
@@ -10,7 +10,7 @@ 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)
13
+ options = { context: { current_user: current_user } }.deep_merge(options)
14
14
 
15
15
  cell "decidim/card", model, options
16
16
  end
@@ -10,6 +10,10 @@ module Decidim
10
10
  context[:controller].class.to_s == "Decidim::Proposals::ProposalsController"
11
11
  end
12
12
 
13
+ def collaborative_drafts_controller?
14
+ context[:controller].class.to_s == "Decidim::Proposals::CollaborativeDraftsController"
15
+ end
16
+
13
17
  def posts_controller?
14
18
  context[:controller].class.to_s == "Decidim::Blogs::PostsController"
15
19
  end
@@ -35,9 +39,9 @@ module Decidim
35
39
 
36
40
  def flagable?
37
41
  return unless from_context
38
- return unless proposals_controller?
42
+ return unless proposals_controller? || collaborative_drafts_controller?
39
43
  return if index_action?
40
- return if from_context.official?
44
+ return if from_context.try(:official?)
41
45
  true
42
46
  end
43
47
  end