decidim-core 0.26.1 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/card_m/show.erb +1 -1
  3. data/app/cells/decidim/followers_cell.rb +1 -1
  4. data/app/cells/decidim/notification/show.erb +1 -1
  5. data/app/cells/decidim/notification_cell.rb +6 -0
  6. data/app/commands/decidim/update_user_interests.rb +5 -1
  7. data/app/controllers/concerns/decidim/skip_timeoutable.rb +17 -0
  8. data/app/controllers/decidim/timeouts_controller.rb +2 -6
  9. data/app/forms/decidim/user_interest_scope_form.rb +1 -1
  10. data/app/helpers/decidim/application_helper.rb +4 -0
  11. data/app/helpers/decidim/meta_tags_helper.rb +24 -1
  12. data/app/helpers/decidim/sanitize_helper.rb +8 -2
  13. data/app/models/decidim/action_log.rb +1 -0
  14. data/app/models/decidim/user_base_entity.rb +1 -0
  15. data/app/packs/src/decidim/external_link.js +6 -0
  16. data/app/packs/src/decidim/map/controller/static.js +6 -5
  17. data/app/packs/src/decidim/session_timeouter.js +10 -5
  18. data/app/validators/password_validator.rb +12 -3
  19. data/app/views/decidim/devise/invitations/edit.html.erb +2 -2
  20. data/app/views/layouts/decidim/_timeout_modal.html.erb +2 -0
  21. data/config/initializers/devise.rb +2 -1
  22. data/config/locales/ar.yml +17 -0
  23. data/config/locales/ca.yml +17 -2
  24. data/config/locales/cs.yml +7 -0
  25. data/config/locales/de.yml +8 -2
  26. data/config/locales/en.yml +7 -0
  27. data/config/locales/es-MX.yml +19 -4
  28. data/config/locales/es-PY.yml +15 -0
  29. data/config/locales/es.yml +15 -0
  30. data/config/locales/fi-plain.yml +8 -0
  31. data/config/locales/fi.yml +8 -1
  32. data/config/locales/fr-CA.yml +8 -1
  33. data/config/locales/fr.yml +35 -28
  34. data/config/locales/hu.yml +1 -0
  35. data/config/locales/it.yml +8 -0
  36. data/config/locales/ja.yml +8 -1
  37. data/config/locales/pt.yml +2 -2
  38. data/config/locales/sv.yml +3 -1
  39. data/lib/decidim/content_parsers/hashtag_parser.rb +1 -1
  40. data/lib/decidim/content_parsers/resource_parser.rb +97 -0
  41. data/lib/decidim/content_parsers.rb +1 -0
  42. data/lib/decidim/content_processor.rb +2 -1
  43. data/lib/decidim/content_renderers/resource_renderer.rb +30 -0
  44. data/lib/decidim/content_renderers.rb +1 -0
  45. data/lib/decidim/core/test/factories.rb +2 -1
  46. data/lib/decidim/core/version.rb +1 -1
  47. data/lib/devise/models/decidim_validatable.rb +3 -3
  48. metadata +11 -13
  49. data/app/cells/decidim/endorsement_buttons_cell.rb.2 +0 -211
  50. data/app/helpers/decidim/social_share_button_helper.rb +0 -26
  51. data/lib/decidim/social_share/service.rb +0 -33
  52. data/lib/decidim/social_share/service_registry.rb +0 -63
  53. data/lib/decidim/social_share.rb +0 -45
@@ -21,7 +21,7 @@ pt:
21
21
  details: Comentários adicionais
22
22
  user:
23
23
  about: Sobre
24
- email: O seu email
24
+ email: O seu e-mail
25
25
  name: O seu nome
26
26
  nickname: Alcunha
27
27
  password: Palavra-passe
@@ -44,7 +44,7 @@ pt:
44
44
  attributes:
45
45
  decidim/user:
46
46
  current_password: Senha atual
47
- email: Email
47
+ email: E-mail
48
48
  name: Alcunha
49
49
  password: Senha
50
50
  password_confirmation: Confirmação da senha
@@ -22,6 +22,7 @@ sv:
22
22
  user:
23
23
  about: Om
24
24
  email: Din e-postadress
25
+ locale: Språk
25
26
  name: Ditt namn
26
27
  nickname: Användarnamn
27
28
  password: Lösenord
@@ -107,6 +108,7 @@ sv:
107
108
  decidim:
108
109
  accessibility:
109
110
  external_link: Extern länk
111
+ front_page_link: Gå till startsidan
110
112
  logo: "%{organization}s logotyp"
111
113
  skip_button: Gå till innehåll
112
114
  account:
@@ -1651,7 +1653,7 @@ sv:
1651
1653
  title: Vill du fortsätta med din session?
1652
1654
  user_menu:
1653
1655
  account: 'Användarkonto: %{name}'
1654
- admin_dashboard: Admin kontrollpanel
1656
+ admin_dashboard: Adminpanel
1655
1657
  conversations: Konversationer
1656
1658
  notifications: Meddelanden
1657
1659
  profile: Mitt konto
@@ -18,7 +18,7 @@ module Decidim
18
18
 
19
19
  # Matches a hashtag if it starts with a letter or number
20
20
  # and only contains letters, numbers or underscores.
21
- HASHTAG_REGEX = /\B#([[:alnum:]](?:[[:alnum:]]|_)*)\b/i.freeze
21
+ HASHTAG_REGEX = /\s\K\B#([[:alnum:]](?:[[:alnum:]]|_)*)\b/i.freeze
22
22
 
23
23
  # Replaces hashtags name with new or existing hashtags models global ids.
24
24
  #
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ContentParsers
5
+ # A parser that searches mentions of Resources in content.
6
+ #
7
+ # @see BaseParser Examples of how to use a content parser
8
+ class ResourceParser < BaseParser
9
+ # Matches a URL
10
+ URL_REGEX_SCHEME = '(?:http(s)?:\/\/)'
11
+ URL_REGEX_CONTENT = '[\w.-]+[\w\-\._~:\/?#\[\]@!\$&\'\(\)\*\+,;=.]+'
12
+ URL_REGEX_END_CHAR = '[\d]'
13
+ # Matches a mentioned resource ID (~(d)+ expression)
14
+ ID_REGEX = /~(\d+)/.freeze
15
+
16
+ # Replaces found mentions matching an existing
17
+ # Resource with a global id for that Resource. Other mentions found that doesn't
18
+ # match an existing Resource are returned as they are.
19
+ #
20
+ # @return [String] the content with the valid mentions replaced by a global id.
21
+ def rewrite
22
+ rewrited_content = parse_for_urls(content)
23
+ parse_for_ids(rewrited_content)
24
+ end
25
+
26
+ private
27
+
28
+ def parse_for_urls(content)
29
+ content.gsub(url_regex) do |match|
30
+ resource = resource_from_url_match(match)
31
+ if resource
32
+ update_metadata(resource)
33
+ resource.to_global_id
34
+ else
35
+ match
36
+ end
37
+ end
38
+ end
39
+
40
+ def parse_for_ids(content)
41
+ content.gsub(ID_REGEX) do |match|
42
+ resource = resource_from_id_match(Regexp.last_match(1))
43
+ if resource
44
+ update_metadata(resource)
45
+ resource.to_global_id
46
+ else
47
+ match
48
+ end
49
+ end
50
+ end
51
+
52
+ def resource_from_url_match(match)
53
+ uri = URI.parse(match)
54
+ return if uri.path.blank?
55
+ return unless find_organization(uri.host)
56
+
57
+ resource_id = uri.path.split("/").last
58
+ find_resource_by_id(resource_id)
59
+ rescue URI::InvalidURIError
60
+ Rails.logger.error("#{e.message}=>#{e.backtrace}")
61
+ nil
62
+ end
63
+
64
+ def resource_from_id_match(match)
65
+ resource_id = match
66
+ find_resource_by_id(resource_id)
67
+ end
68
+
69
+ def find_resource_by_id(id)
70
+ if id.present?
71
+ spaces = Decidim.participatory_space_manifests.flat_map do |manifest|
72
+ manifest.participatory_spaces.call(context[:current_organization]).public_spaces
73
+ end
74
+ components = Component.where(participatory_space: spaces).published
75
+ model_class.constantize.where(component: components).find_by(id: id)
76
+ end
77
+ end
78
+
79
+ def find_organization(uri_host)
80
+ current_organization = context[:current_organization]
81
+ (current_organization.host == uri_host) || current_organization.secondary_hosts.include?(uri_host)
82
+ end
83
+
84
+ def url_regex
85
+ raise "Not implemented"
86
+ end
87
+
88
+ def model_class
89
+ raise "Not implemented"
90
+ end
91
+
92
+ def update_metadata(resource)
93
+ # code to update metadata - needs to be overwritten
94
+ end
95
+ end
96
+ end
97
+ end
@@ -9,5 +9,6 @@ module Decidim
9
9
  autoload :NewlineParser, "decidim/content_parsers/newline_parser"
10
10
  autoload :LinkParser, "decidim/content_parsers/link_parser"
11
11
  autoload :InlineImagesParser, "decidim/content_parsers/inline_images_parser"
12
+ autoload :ResourceParser, "decidim/content_parsers/resource_parser"
12
13
  end
13
14
  end
@@ -100,7 +100,8 @@ module Decidim
100
100
  simple_format(
101
101
  render_without_format(content, options),
102
102
  {},
103
- wrapper_tag: wrapper_tag
103
+ wrapper_tag: wrapper_tag,
104
+ sanitize: false
104
105
  )
105
106
  end
106
107
 
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ContentRenderers
5
+ class ResourceRenderer < BaseRenderer
6
+ # Matches a global id representing a Decidim::User
7
+
8
+ # Replaces found Global IDs matching an existing resource with
9
+ # a link to its show page. The Global IDs representing an
10
+ # invalid Resource are replaced with '???' string.
11
+ #
12
+ # @return [String] the content ready to display (contains HTML)
13
+ def render(_options = nil)
14
+ return content unless content.respond_to?(:gsub)
15
+
16
+ content.gsub(regex) do |resource_gid|
17
+ resource = GlobalID::Locator.locate(resource_gid)
18
+ resource.presenter.display_mention
19
+ rescue ActiveRecord::RecordNotFound
20
+ resource_id = resource_gid.split("/").last
21
+ "~#{resource_id}"
22
+ end
23
+ end
24
+
25
+ def regex
26
+ raise "Not implemented"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -7,5 +7,6 @@ module Decidim
7
7
  autoload :UserGroupRenderer, "decidim/content_renderers/user_group_renderer"
8
8
  autoload :HashtagRenderer, "decidim/content_renderers/hashtag_renderer"
9
9
  autoload :LinkRenderer, "decidim/content_renderers/link_renderer"
10
+ autoload :ResourceRenderer, "decidim/content_renderers/resource_renderer"
10
11
  end
11
12
  end
@@ -125,7 +125,7 @@ FactoryBot.define do
125
125
 
126
126
  factory :user, class: "Decidim::User" do
127
127
  email { generate(:email) }
128
- password { "password1234" }
128
+ password { "decidim123456" }
129
129
  password_confirmation { password }
130
130
  name { generate(:name) }
131
131
  nickname { generate(:nickname) }
@@ -139,6 +139,7 @@ FactoryBot.define do
139
139
  accepted_tos_version { organization.tos_version }
140
140
  email_on_notification { true }
141
141
  email_on_moderations { true }
142
+ extended_data { {} }
142
143
 
143
144
  trait :confirmed do
144
145
  confirmed_at { Time.current }
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-core version.
5
5
  module Core
6
6
  def self.version
7
- "0.26.1"
7
+ "0.26.2"
8
8
  end
9
9
  end
10
10
  end
@@ -11,7 +11,6 @@ module Devise
11
11
  # Validatable adds the following options to devise_for:
12
12
  #
13
13
  # * +email_regexp+: the regular expression used to validate e-mails;
14
- # * +password_length+: a range expressing password length. Defaults to 8..72.
15
14
  #
16
15
  module DecidimValidatable
17
16
  # All validations used by this module.
@@ -33,7 +32,8 @@ module Devise
33
32
 
34
33
  validates_presence_of :password, if: :password_required?
35
34
  validates_confirmation_of :password, if: :password_required?
36
- validates_length_of :password, within: password_length, allow_blank: true
35
+
36
+ validates :password, password: { name: :name, email: :email, username: :nickname }
37
37
  end
38
38
  end
39
39
 
@@ -61,7 +61,7 @@ module Devise
61
61
 
62
62
  # Methods to be injected at class level.
63
63
  module ClassMethods
64
- Devise::Models.config(self, :email_regexp, :password_length)
64
+ Devise::Models.config(self, :email_regexp)
65
65
  end
66
66
  end
67
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.1
4
+ version: 0.26.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-03-25 00:00:00.000000000 Z
13
+ date: 2022-06-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_link_to
@@ -256,14 +256,14 @@ dependencies:
256
256
  requirements:
257
257
  - - "~>"
258
258
  - !ruby/object:Gem::Version
259
- version: '1.5'
259
+ version: 1.7.5
260
260
  type: :runtime
261
261
  prerelease: false
262
262
  version_requirements: !ruby/object:Gem::Requirement
263
263
  requirements:
264
264
  - - "~>"
265
265
  - !ruby/object:Gem::Version
266
- version: '1.5'
266
+ version: 1.7.5
267
267
  - !ruby/object:Gem::Dependency
268
268
  name: hashdiff
269
269
  requirement: !ruby/object:Gem::Requirement
@@ -754,28 +754,28 @@ dependencies:
754
754
  requirements:
755
755
  - - '='
756
756
  - !ruby/object:Gem::Version
757
- version: 0.26.1
757
+ version: 0.26.2
758
758
  type: :runtime
759
759
  prerelease: false
760
760
  version_requirements: !ruby/object:Gem::Requirement
761
761
  requirements:
762
762
  - - '='
763
763
  - !ruby/object:Gem::Version
764
- version: 0.26.1
764
+ version: 0.26.2
765
765
  - !ruby/object:Gem::Dependency
766
766
  name: decidim-dev
767
767
  requirement: !ruby/object:Gem::Requirement
768
768
  requirements:
769
769
  - - '='
770
770
  - !ruby/object:Gem::Version
771
- version: 0.26.1
771
+ version: 0.26.2
772
772
  type: :development
773
773
  prerelease: false
774
774
  version_requirements: !ruby/object:Gem::Requirement
775
775
  requirements:
776
776
  - - '='
777
777
  - !ruby/object:Gem::Version
778
- version: 0.26.1
778
+ version: 0.26.2
779
779
  description: Adds core features so other engines can hook into the framework.
780
780
  email:
781
781
  - josepjaume@gmail.com
@@ -886,7 +886,6 @@ files:
886
886
  - app/cells/decidim/endorsement_buttons/select_identity_button.erb
887
887
  - app/cells/decidim/endorsement_buttons/show.erb
888
888
  - app/cells/decidim/endorsement_buttons_cell.rb
889
- - app/cells/decidim/endorsement_buttons_cell.rb.2
890
889
  - app/cells/decidim/endorsers_list/show.erb
891
890
  - app/cells/decidim/endorsers_list_cell.rb
892
891
  - app/cells/decidim/fingerprint/show.erb
@@ -1066,6 +1065,7 @@ files:
1066
1065
  - app/controllers/concerns/decidim/resource_versions_concern.rb
1067
1066
  - app/controllers/concerns/decidim/safe_redirect.rb
1068
1067
  - app/controllers/concerns/decidim/settings.rb
1068
+ - app/controllers/concerns/decidim/skip_timeoutable.rb
1069
1069
  - app/controllers/concerns/decidim/use_organization_time_zone.rb
1070
1070
  - app/controllers/concerns/decidim/user_blocked_checker.rb
1071
1071
  - app/controllers/concerns/decidim/user_groups.rb
@@ -1215,7 +1215,6 @@ files:
1215
1215
  - app/helpers/decidim/sanitize_helper.rb
1216
1216
  - app/helpers/decidim/scopes_helper.rb
1217
1217
  - app/helpers/decidim/searches_helper.rb
1218
- - app/helpers/decidim/social_share_button_helper.rb
1219
1218
  - app/helpers/decidim/tooltip_helper.rb
1220
1219
  - app/helpers/decidim/traceability_helper.rb
1221
1220
  - app/helpers/decidim/translations_helper.rb
@@ -2309,6 +2308,7 @@ files:
2309
2308
  - lib/decidim/content_parsers/inline_images_parser.rb
2310
2309
  - lib/decidim/content_parsers/link_parser.rb
2311
2310
  - lib/decidim/content_parsers/newline_parser.rb
2311
+ - lib/decidim/content_parsers/resource_parser.rb
2312
2312
  - lib/decidim/content_parsers/user_group_parser.rb
2313
2313
  - lib/decidim/content_parsers/user_parser.rb
2314
2314
  - lib/decidim/content_processor.rb
@@ -2316,6 +2316,7 @@ files:
2316
2316
  - lib/decidim/content_renderers/base_renderer.rb
2317
2317
  - lib/decidim/content_renderers/hashtag_renderer.rb
2318
2318
  - lib/decidim/content_renderers/link_renderer.rb
2319
+ - lib/decidim/content_renderers/resource_renderer.rb
2319
2320
  - lib/decidim/content_renderers/user_group_renderer.rb
2320
2321
  - lib/decidim/content_renderers/user_renderer.rb
2321
2322
  - lib/decidim/core.rb
@@ -2534,9 +2535,6 @@ files:
2534
2535
  - lib/decidim/settings_manifest.rb
2535
2536
  - lib/decidim/shareable_with_token.rb
2536
2537
  - lib/decidim/snippets.rb
2537
- - lib/decidim/social_share.rb
2538
- - lib/decidim/social_share/service.rb
2539
- - lib/decidim/social_share/service_registry.rb
2540
2538
  - lib/decidim/stats_registry.rb
2541
2539
  - lib/decidim/traceable.rb
2542
2540
  - lib/decidim/translatable_attributes.rb
@@ -1,211 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- # This cell renders the endrosement button and the endorsements count.
5
- # It only supports one row of buttons per page due to current tag ids used by javascript.
6
- class EndorsementButtonsCell < Decidim::ViewModel
7
- include LayoutHelper
8
- include CellsHelper
9
- include EndorsableHelper
10
- include ResourceHelper
11
- include Decidim::SanitizeHelper
12
-
13
- delegate :current_user, to: :controller, prefix: false
14
- delegate :current_settings, to: :controller, prefix: false
15
- delegate :current_component, to: :controller, prefix: false
16
- delegate :allowed_to?, to: :controller, prefix: false
17
-
18
- def show
19
- render
20
- end
21
-
22
- # Public: Renders the "Endorse" button.
23
- # Contains all the logic about how the button should be rendered
24
- # and which actions the button must trigger.
25
- #
26
- # It takes into account:
27
- # - if endorsements are enabled
28
- # - if users are logged in
29
- # - if users can endorse with many identities (of their user_groups)
30
- # - if users require verification
31
- def render_endorsements_button
32
- render_disabled_endorsements_button if endorsements_blocked_or_user_can_not_participate?
33
- render_user_login_button unless current_user
34
- render "select_identity_button" if current_user_and_allowed? && user_has_verified_groups?
35
- render_user_identity_endorse_button if current_user_and_allowed?
36
-
37
- render_verification_modal
38
- end
39
-
40
- # Public: Renders the counter of endorsements that appears in m-cards.
41
- def render_endorsements_count
42
- content = icon("bullhorn", class: "icon--small", aria_label: t("decidim.endorsable.endorsements_count"), role: "img")
43
- content += resource.endorsements_count.to_s
44
- html_class = "button small compact button--shadow secondary"
45
- html_class += " active" if fully_endorsed?(resource, current_user)
46
- tag_params = { id: "resource-#{resource.id}-endorsements-count", class: html_class }
47
- if resource.endorsements_count.positive?
48
- link_to "#list-of-endorsements", tag_params do
49
- content
50
- end
51
- else
52
- content_tag(:div, tag_params) do
53
- content
54
- end
55
- end
56
- end
57
-
58
- # Public: Renders the endorsements button but disabled.
59
- # To be used to let the user know that endorsements are enabled but are blocked or cant participate.
60
- def render_disabled_endorsements_button
61
- content_tag :span, class: "#{card_button_html_class} #{endorsement_button_classes(from_resourcess_list: false)} disabled", disabled: true, title: endorse_translated do
62
- endorse_translated + render_screen_reader_context_title
63
- end
64
- end
65
-
66
- # Public: Render content for screen readers only (accessibility)
67
- def render_screen_reader_context_title
68
- content_tag :span, class: "show-for-sr" do
69
- decidim_html_escape(resource_title(resource))
70
- end
71
- end
72
-
73
- # Public: Returns the CSS classes used for proposal endorsement button in both proposals list and show pages
74
- #
75
- # from_resourcess_list - A boolean to indicate if the template is rendered from the list page of the resource.
76
- #
77
- # Returns a string with the value of the css classes.
78
- def endorsement_button_classes(from_resourcess_list: false)
79
- return "small" if from_resourcess_list
80
-
81
- "button small compact light button--sc expanded secondary"
82
- end
83
-
84
- # Public: Returns the CSS classes used for proposal endorsement button
85
- def card_button_html_class
86
- "card__button button"
87
- end
88
-
89
- # Public: Renders a button to endorse the given +resource+ with the personal identity of the user.
90
- # To override the translation for both buttons: endorse and unendorse (use to be the name of the user/user_group).
91
- #
92
- # This button may have different behaviours:
93
- # - If the user is not logged in, the button will open the signin/signup popup.
94
- # - If the user is logged in, and the resource has not been endorsed, the button will allow to endorse.
95
- # - If the user is logged in, and the resource has already been endorsed, the button will allow to UNendorse.
96
- #
97
- # Parameters:
98
- # resources - The endorsable resource.
99
- def render_user_identity_endorse_button
100
- content_tag(:div, id: "resource-#{resource.id}-endorsement-button") do
101
- if !current_user
102
- render_user_login_button
103
- elsif resource.endorsed_by?(current_user)
104
- unendorse_label = t("decidim.endorsement_buttons_cell.already_endorsed")
105
- destroy_endorsement_url = path_to_destroy_endorsement(resource)
106
- action_authorized_button_to(
107
- :endorse,
108
- destroy_endorsement_url,
109
- resource: resource,
110
- method: :delete,
111
- remote: true,
112
- class: "button #{endorsement_button_classes} active",
113
- id: "endorsement_button"
114
- ) do
115
- unendorse_label + render_screen_reader_context_title
116
- end
117
- else
118
- action_authorized_button_to(
119
- :endorse,
120
- path_to_create_endorsement(resource),
121
- resource: resource,
122
- remote: true,
123
- class: "button #{endorsement_button_classes}",
124
- id: "endorsement_button"
125
- ) do
126
- endorse_translated + render_screen_reader_context_title
127
- end
128
- end
129
- end
130
- end
131
-
132
- # Public: The resource being un/endorsed is the Cell's model.
133
- def resource
134
- model
135
- end
136
-
137
- # Public: produce the reveal identities URL as the cell doesn't have access to routes
138
- def reveal_identities_url
139
- decidim.identities_endorsement_path(resource.to_gid.to_param)
140
- end
141
-
142
- # Public: produce the path to endorsements from the engine routes as the cell doesn't have access to routes
143
- def endorsements_path(*args)
144
- decidim.endorsements_path(*args)
145
- end
146
-
147
- # Public: produce the path to an endorsement from the engine routes as the cell doesn't have access to routes
148
- def endorsement_path(*args)
149
- decidim.endorsement_path(*args)
150
- end
151
-
152
- # Public; returns the identity presenter for user and user groups
153
- def endorsement_identity_presenter(endorsement)
154
- if endorsement.user_group
155
- Decidim::UserGroupPresenter.new(endorsement.user_group)
156
- else
157
- Decidim::UserPresenter.new(endorsement.author)
158
- end
159
- end
160
-
161
- private
162
-
163
- # Private: render the user login button for visitors (non logged in users)
164
- def render_user_login_button
165
- action_authorized_button_to(:endorse,
166
- path_to_create_endorsement(resource),
167
- resource: resource,
168
- class: "button #{endorsement_button_classes}") do
169
- endorse_translated + render_screen_reader_context_title
170
- end
171
- end
172
-
173
- # Private: render the verification modal when there's a current user that needs an authorization
174
- def render_verification_modal
175
- button_to(endorsement_path(resource),
176
- data: { open: "authorizationModal", "open-url": modal_path(:endorse, resource) },
177
- class: "#{card_button_html_class} #{endorsement_button_classes(from_resourcess_list: false)}") do
178
- endorse_translated + render_screen_reader_context_title
179
- end
180
- end
181
-
182
- # Private: check if the endorsements are blocked or the user can't participate
183
- #
184
- # Returns a boolean
185
- def endorsements_blocked_or_user_can_not_participate?
186
- current_settings.endorsements_blocked? || !current_component.participatory_space.can_participate?(current_user)
187
- end
188
-
189
- # Private: check if there's an user logged in and they have permissions
190
- #
191
- # Returns a boolean
192
- def current_user_and_allowed?
193
- current_user && allowed_to?(:create, :endorsement, resource: resource)
194
- end
195
-
196
- # Private: check if there's an user logged in and they have user groups associated
197
- #
198
- # Returns a boolean
199
- def user_has_verified_groups?
200
- current_user && Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.any?
201
- end
202
-
203
- def endorse_translated
204
- @endorse_translated ||= t("decidim.endorsement_buttons_cell.endorse")
205
- end
206
-
207
- def raw_model
208
- model.try(:__getobj__) || model
209
- end
210
- end
211
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- # A Helper that reimplements the SocialShareButton gem helpers, so that we don't depend on it anymore.
5
- module SocialShareButtonHelper
6
- def social_share_button_tag(title, **args)
7
- content_tag :div, class: "social-share-button" do
8
- render_social_share_buttons(enabled_services, title, **args)
9
- end
10
- end
11
-
12
- def render_social_share_buttons(services, title, **args)
13
- services.map do |service|
14
- link_to service.formatted_share_uri(title, **args), rel: "nofollow", class: "ssb-icon ssb-#{service.name}", title: t(".share_on", service: service.name) do
15
- image_tag service.icon_path
16
- end
17
- end.join.html_safe
18
- end
19
-
20
- private
21
-
22
- def enabled_services
23
- Decidim::SocialShare.enabled_services
24
- end
25
- end
26
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module SocialShare
5
- # This class represents an abstract social network.
6
- class Service
7
- include Decidim::AttributeObject::Model
8
- include ActiveModel::Validations
9
-
10
- # The name of the social networking service.
11
- attribute :name, String
12
-
13
- # The icon of the social networking service.
14
- attribute :icon, String
15
-
16
- # The share_url of the social networking service.
17
- attribute :share_uri, String
18
-
19
- # TODO validate #{url} in share_url
20
-
21
- def formatted_share_uri(title, **args)
22
- format(share_uri, title: title, **args)
23
- end
24
-
25
- # Public: Returns an image of the icon for this social network.
26
- #
27
- # Returns a String with the icon.
28
- def icon_path
29
- ActionController::Base.helpers.asset_pack_path("media/images/#{icon}")
30
- end
31
- end
32
- end
33
- end