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,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pg_search"
4
+
5
+ module Decidim
6
+ # A Searchable Resource.
7
+ # This is a model to a PgSearch table that indexes all searchable resources.
8
+ # This table is used to perform textual searches.
9
+ #
10
+ # Main attributes are:
11
+ # - locale: One entry per locale is required, so each resource will be indexed once per locale.
12
+ # - content_a: The most relevant textual content.
13
+ # - content_b: The second most relevant textual content.
14
+ # - content_c: The third most relevant textual content.
15
+ # - content_d: The less relevant textual content.
16
+ # - datetime: The timestamp that places this resource in the line of time. Used as second criteria (first is text relevance) for sorting.
17
+ #
18
+ class SearchableResource < ApplicationRecord
19
+ include PgSearch
20
+
21
+ belongs_to :organization,
22
+ foreign_key: "decidim_organization_id",
23
+ class_name: "Decidim::Organization"
24
+ belongs_to :scope,
25
+ foreign_key: "decidim_scope_id",
26
+ class_name: "Decidim::Scope",
27
+ optional: true
28
+ belongs_to :resource, polymorphic: true
29
+ belongs_to :decidim_participatory_space, polymorphic: true
30
+
31
+ validates :locale, uniqueness: { scope: :resource }
32
+
33
+ pg_search_scope :global_search,
34
+ against: { content_a: "A", content_b: "B", content_c: "C", content_d: "D" },
35
+ order_within_rank: "datetime DESC"
36
+ end
37
+ end
@@ -36,6 +36,10 @@ module Decidim
36
36
  Decidim::AdminLog::StaticPagePresenter
37
37
  end
38
38
 
39
+ def self.sorted_by_i18n_title(locale = I18n.locale)
40
+ order([Arel.sql("title->? ASC"), locale])
41
+ end
42
+
39
43
  # Whether this is page is a default one or not.
40
44
  #
41
45
  # Returns Boolean.
@@ -7,16 +7,18 @@ module Decidim
7
7
  # A User is a citizen that wants to join the platform to participate.
8
8
  class User < ApplicationRecord
9
9
  include Nicknamizable
10
+ include Resourceable
10
11
  include Decidim::Followable
11
12
  include Decidim::Loggable
12
13
 
13
14
  OMNIAUTH_PROVIDERS = [:facebook, :twitter, :google_oauth2, (:developer if Rails.env.development?)].compact
14
15
  ROLES = %w(admin user_manager).freeze
15
16
 
16
- devise :invitable, :database_authenticatable, :registerable, :confirmable,
17
+ devise :invitable, :database_authenticatable, :registerable, :confirmable, :timeoutable,
17
18
  :recoverable, :rememberable, :trackable, :decidim_validatable,
18
19
  :omniauthable, omniauth_providers: OMNIAUTH_PROVIDERS,
19
- request_keys: [:env], reset_password_keys: [:decidim_organization_id, :email]
20
+ request_keys: [:env], reset_password_keys: [:decidim_organization_id, :email],
21
+ confirmation_keys: [:decidim_organization_id, :email]
20
22
 
21
23
  belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"
22
24
  has_many :identities, foreign_key: "decidim_user_id", class_name: "Decidim::Identity", dependent: :destroy
@@ -25,11 +27,13 @@ module Decidim
25
27
  has_many :notifications, foreign_key: "decidim_user_id", class_name: "Decidim::Notification", dependent: :destroy
26
28
  has_many :access_grants, class_name: "Doorkeeper::AccessGrant", foreign_key: :resource_owner_id, dependent: :destroy
27
29
  has_many :access_tokens, class_name: "Doorkeeper::AccessToken", foreign_key: :resource_owner_id, dependent: :destroy
30
+ has_many :following_follows, foreign_key: "decidim_user_id", class_name: "Decidim::Follow", dependent: :destroy
28
31
 
29
32
  validates :name, presence: true, unless: -> { deleted? }
30
- validates :nickname, presence: true, unless: -> { deleted? || managed? }
33
+ validates :nickname, presence: true, unless: -> { deleted? || managed? }, length: { maximum: Decidim::User.nickname_max_length }
31
34
  validates :locale, inclusion: { in: :available_locales }, allow_blank: true
32
35
  validates :tos_agreement, acceptance: true, allow_nil: false, on: :create
36
+ validates :tos_agreement, acceptance: true, if: :user_invited?
33
37
  validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
34
38
  validates :email, :nickname, uniqueness: { scope: :organization }, unless: -> { deleted? || managed? || nickname.blank? }
35
39
 
@@ -45,6 +49,10 @@ module Decidim
45
49
  scope :officialized, -> { where.not(officialized_at: nil) }
46
50
  scope :not_officialized, -> { where(officialized_at: nil) }
47
51
 
52
+ def user_invited?
53
+ invitation_token_changed? && invitation_accepted_at_changed?
54
+ end
55
+
48
56
  # Public: Allows customizing the invitation instruction email content when
49
57
  # inviting a user.
50
58
  #
@@ -89,6 +97,28 @@ module Decidim
89
97
  Decidim::Follow.where(user: self, followable: followable).any?
90
98
  end
91
99
 
100
+ # Public: Returns a collection with all the entities this user is following.
101
+ #
102
+ # This can't be done as with a `has_many :following, through: :following_follows`
103
+ # since it's a polymorphic relation and Rails doesn't know how to load it. With
104
+ # this implementation we only query the database once for each kind of following.
105
+ #
106
+ # Returns an Array of Decidim::Followable
107
+ def following
108
+ @following ||= begin
109
+ followings = following_follows.pluck(:decidim_followable_type, :decidim_followable_id)
110
+ grouped_followings = followings.each_with_object({}) do |(type, following_id), all|
111
+ all[type] ||= []
112
+ all[type] << following_id
113
+ all
114
+ end
115
+
116
+ grouped_followings.flat_map do |type, ids|
117
+ type.constantize.where(id: ids)
118
+ end
119
+ end
120
+ end
121
+
92
122
  def unread_conversations
93
123
  Decidim::Messaging::Conversation.unread_by(self)
94
124
  end
@@ -107,6 +137,12 @@ module Decidim
107
137
  )
108
138
  end
109
139
 
140
+ def tos_accepted?
141
+ return true if managed
142
+ return false if accepted_tos_version.nil?
143
+ accepted_tos_version >= organization.tos_version
144
+ end
145
+
110
146
  protected
111
147
 
112
148
  # Overrides devise email required validation.
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Default permissions class for all components and spaces. It disauthorizes all
5
+ # actions by any kind of user. Also works as a default implementation so other
6
+ # components can inherit from it and get some cenvenience methods.
7
+ class DefaultPermissions
8
+ def initialize(user, permission_action, context = {})
9
+ @user = user
10
+ @permission_action = permission_action
11
+ @context = context
12
+ end
13
+
14
+ def permissions
15
+ permission_action
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :user, :permission_action, :context
21
+
22
+ def disallow!
23
+ permission_action.disallow!
24
+ end
25
+
26
+ def allow!
27
+ permission_action.allow!
28
+ end
29
+
30
+ def toggle_allow(condition)
31
+ condition ? allow! : disallow!
32
+ end
33
+
34
+ def read_participatory_space_action?
35
+ permission_action.action == :read &&
36
+ [:participatory_space, :component].include?(permission_action.subject)
37
+ end
38
+
39
+ def authorized?(permission_action)
40
+ return unless component
41
+
42
+ ActionAuthorizer.new(user, component, permission_action).authorize.ok?
43
+ end
44
+
45
+ def current_settings
46
+ @current_settings ||= context.fetch(:current_settings, nil)
47
+ end
48
+
49
+ def component_settings
50
+ @component_settings ||= context.fetch(:component_settings, nil)
51
+ end
52
+
53
+ def component
54
+ @component ||= context.fetch(:current_component)
55
+ end
56
+
57
+ def space
58
+ @space ||= component.participatory_space
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class Permissions < DefaultPermissions
5
+ def permissions
6
+ read_public_pages_action?
7
+ locales_action?
8
+ component_public_action?
9
+ search_scope_action?
10
+
11
+ return permission_action unless user
12
+ return user_manager_permissions if not_admin? && user_manager?
13
+
14
+ manage_self_user_action?
15
+ authorization_action?
16
+ follow_action?
17
+ notification_action?
18
+ conversation_action?
19
+
20
+ permission_action
21
+ end
22
+
23
+ private
24
+
25
+ def read_public_pages_action?
26
+ return unless permission_action.subject == :public_page &&
27
+ permission_action.action == :read
28
+ allow!
29
+ end
30
+
31
+ def locales_action?
32
+ return unless permission_action.subject == :locales
33
+ allow!
34
+ end
35
+
36
+ def component_public_action?
37
+ return unless permission_action.subject == :component &&
38
+ permission_action.action == :read
39
+
40
+ toggle_allow(component.published?)
41
+ end
42
+
43
+ def search_scope_action?
44
+ return unless permission_action.subject == :scope
45
+ toggle_allow([:search, :pick].include?(permission_action.action))
46
+ end
47
+
48
+ def manage_self_user_action?
49
+ return unless permission_action.subject == :user
50
+ toggle_allow(context.fetch(:current_user, nil) == user)
51
+ end
52
+
53
+ def authorization_action?
54
+ return unless permission_action.subject == :authorization
55
+ authorization = context.fetch(:authorization, nil)
56
+
57
+ case permission_action.action
58
+ when :create
59
+ toggle_allow(authorization.user == user && not_already_active?(authorization))
60
+ when :update
61
+ toggle_allow(authorization.user == user && !authorization.granted?)
62
+ end
63
+ end
64
+
65
+ def follow_action?
66
+ return unless permission_action.subject == :follow
67
+ return allow! if permission_action.action == :create
68
+
69
+ follow = context.fetch(:follow, nil)
70
+ toggle_allow(follow&.user == user)
71
+ end
72
+
73
+ def notification_action?
74
+ return unless permission_action.subject == :notification
75
+ return allow! if permission_action.action == :read
76
+
77
+ notification = context.fetch(:notification, nil)
78
+ toggle_allow(notification&.user == user)
79
+ end
80
+
81
+ def conversation_action?
82
+ return unless permission_action.subject == :conversation
83
+ return allow! if [:create, :list].include?(permission_action.action)
84
+
85
+ conversation = context.fetch(:conversation, nil)
86
+ toggle_allow(conversation.participants.include?(user))
87
+ end
88
+
89
+ def not_already_active?(authorization)
90
+ Verifications::Authorizations.new(organization: user.organization, user: user, name: authorization.name).none?
91
+ end
92
+
93
+ def user_manager_permissions
94
+ Decidim::UserManagerPermissions.new(user, permission_action, context).permissions
95
+ end
96
+
97
+ def not_admin?
98
+ !user.admin?
99
+ end
100
+
101
+ # Whether the user has the user_manager role or not.
102
+ def user_manager?
103
+ user.role? "user_manager"
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ class UserManagerPermissions < DefaultPermissions
5
+ def permissions
6
+ allow! if read_admin_dashboard_action?
7
+ allow! if impersonate_managed_user_action?
8
+
9
+ permission_action
10
+ end
11
+
12
+ private
13
+
14
+ def read_admin_dashboard_action?
15
+ permission_action.subject == :admin_dashboard &&
16
+ permission_action.action == :read
17
+ end
18
+
19
+ def impersonate_managed_user_action?
20
+ permission_action.subject == :managed_user &&
21
+ permission_action.action == :impersonate
22
+ end
23
+ end
24
+ end
@@ -30,7 +30,8 @@ module Decidim
30
30
  facebook_handler: :string,
31
31
  instagram_handler: :string,
32
32
  youtube_handler: :string,
33
- github_handler: :string
33
+ github_handler: :string,
34
+ tos_version: :datetime
34
35
  }
35
36
  end
36
37
 
@@ -67,21 +67,15 @@ module Decidim
67
67
  "&nbsp;".html_safe
68
68
  else
69
69
  safe_join([
70
- content_tag(:h4, I18n.t(name, scope: "pages.home.statistics"), class: "home-pam__title"),
70
+ content_tag(:h4, I18n.t(name, scope: "decidim.pages.home.statistics"), class: "home-pam__title"),
71
71
  content_tag(:span, " #{number_with_delimiter(data)}", class: "home-pam__number #{name}")
72
72
  ])
73
73
  end
74
74
  end
75
75
  end
76
76
 
77
- def public_participatory_spaces
78
- @public_participatory_spaces ||= Decidim.participatory_space_manifests.flat_map do |manifest|
79
- manifest.participatory_spaces.call(organization).public_spaces
80
- end
81
- end
82
-
83
77
  def published_components
84
- @published_components ||= Component.where(participatory_space: public_participatory_spaces).published
78
+ @published_components ||= organization.published_components
85
79
  end
86
80
  end
87
81
  end
@@ -38,5 +38,13 @@ module Decidim
38
38
  def display_mention
39
39
  link_to nickname, profile_path, class: "user-mention"
40
40
  end
41
+
42
+ def followers_count
43
+ __getobj__.followers.count
44
+ end
45
+
46
+ def following_count
47
+ __getobj__.following_follows.count
48
+ end
41
49
  end
42
50
  end
@@ -59,15 +59,12 @@ module Decidim
59
59
  #
60
60
  # Returns whatever the given block returns.
61
61
  def perform_action!(action, resource, author, extra_log_info = {})
62
- PaperTrail.whodunnit(gid(author)) do
63
- klass = resource.is_a?(Class) ? resource : resource.class
64
- klass.transaction do
65
- Decidim::ApplicationRecord.transaction do
66
- result = block_given? ? yield : nil
67
- loggable_resource = resource.is_a?(Class) ? result : resource
68
- log(action, author, loggable_resource, extra_log_info)
69
- result
70
- end
62
+ PaperTrail.request(whodunnit: gid(author)) do
63
+ Decidim::ApplicationRecord.transaction do
64
+ result = block_given? ? yield : nil
65
+ loggable_resource = resource.is_a?(Class) ? result : resource
66
+ log(action, author, loggable_resource, extra_log_info)
67
+ return result
71
68
  end
72
69
  end
73
70
  end
@@ -8,7 +8,7 @@ module Decidim
8
8
  description "A user"
9
9
 
10
10
  interfaces [
11
- Decidim::Core::AuthorInterface
11
+ -> { Decidim::Core::AuthorInterface }
12
12
  ]
13
13
 
14
14
  field :name, !types.String, "The user's name"
@@ -3,28 +3,74 @@
3
3
  <div class="row collapse">
4
4
  <div class="columns large-8 large-centered text-center page-title">
5
5
  <h1><%= t "devise.invitations.edit.header" %></h1>
6
+
7
+ <p><%= t("devise.invitations.edit.subtitle").html_safe %></p>
6
8
  </div>
7
9
  </div>
8
10
 
9
11
  <div class="row">
10
- <div class="columns medium-7 large-5 medium-centered">
11
- <div class="card">
12
- <div class="card__content">
13
- <%= decidim_form_for resource, as: resource_name, url: invitation_path(resource_name, invite_redirect: params[:invite_redirect]), html: { method: :put, class: "register-form new_user" } do |f| %>
12
+ <div class="columns large-6 medium-10 medium-centered">
13
+ <%= decidim_form_for resource, as: resource_name, url: invitation_path(resource_name, invite_redirect: params[:invite_redirect]), html: { method: :put, class: "register-form new_user" } do |f| %>
14
+ <div class="card">
15
+ <div class="card__content">
16
+ <legend><%= t("sign_up_as.legend", scope: "decidim.devise.registrations.new") %></legend>
17
+
14
18
  <%= f.hidden_field :invitation_token %>
15
19
 
16
- <%= f.text_field :nickname, help_text: t("devise.invitations.edit.nickname_help", organization: current_organization.name) %>
20
+ <div class="field">
21
+ <%= f.text_field :nickname, help_text: t("devise.invitations.edit.nickname_help", organization: current_organization.name), required: "required" %>
22
+ </div>
17
23
 
18
24
  <% if f.object.class.require_password_on_accepting %>
19
- <%= f.password_field :password %></p>
25
+ <div class="field">
26
+ <%= f.password_field :password, required: "required" %></p>
27
+ </div>
20
28
 
21
- <%= f.password_field :password_confirmation %></p>
29
+ <div class="field">
30
+ <%= f.password_field :password_confirmation, required: "required" %></p>
31
+ </div>
22
32
  <% end %>
33
+ </div>
34
+ </div>
35
+
36
+ <div class="card" id="card__tos">
37
+ <div class="card__content">
38
+ <legend>
39
+ <%= t("tos_title", scope: "decidim.devise.registrations.new") %>
40
+ </legend>
41
+
42
+ <p class="tos-text">
43
+ <%= strip_tags(translated_attribute(terms_and_conditions_page.content)) %>
44
+ </p>
23
45
 
24
- <p><%= f.submit t("devise.invitations.edit.submit_button", class: "button expanded") %></p>
25
- <% end %>
46
+ <div class="field">
47
+ <% link = link_to t("terms", scope: "decidim.devise.registrations.new"), page_path("terms-and-conditions"), target: "_blank" %>
48
+ <% label = t("tos_agreement", scope: "decidim.devise.registrations.new", link: link) %>
49
+ <%= f.check_box :tos_agreement, label: label, required: "required" %>
50
+ </div>
51
+ </div>
26
52
  </div>
27
- </div>
53
+
54
+ <div class="card" id="card__newsletter">
55
+ <div class="card__content">
56
+ <legend><%= t("newsletter_title", scope: "decidim.devise.registrations.new") %></legend>
57
+ <fieldset>
58
+ <div class="field">
59
+ <%= f.check_box :newsletter_notifications, label: t("newsletter", scope: "decidim.devise.registrations.new") %>
60
+ </div>
61
+ </fieldset>
62
+ </div>
63
+ </div>
64
+
65
+ <div class="card">
66
+ <div class="card__content">
67
+ <div class="actions">
68
+ <%= f.submit t("devise.invitations.edit.submit_button"), class: "button expanded" %>
69
+ </div>
70
+ </div>
71
+ </div>
72
+
73
+ <% end %>
28
74
  </div>
29
75
  </div>
30
76
  </div>