decidim-core 0.9.2 → 0.9.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f989779c4209adbf2b018283befc02b9c1982630d4136de2a54b5d3b18177884
4
- data.tar.gz: b58475aa61559da81c33914954679d2db50e2d1b8f91d3cb7e235ef8beb1513d
3
+ metadata.gz: bb155e8d59a117cddb772f80d367de9d7abe021ea6d37af2f8d6b080a7f94bf8
4
+ data.tar.gz: a429cb952493c92af576ab9253dbc66884c87cbc1de2f2d4a743d5006828a027
5
5
  SHA512:
6
- metadata.gz: 447f6cefe4f3c989be9fad58e509cc9aadc03260b97418a8ea3f025f8dffb4dd6756c7204d129311f05aeeb98bf96f3b9ad76f9e948a5b6de15e122ceb2243fb
7
- data.tar.gz: d2a569060ec1f2697cf872b265509a2b2582f936e77f6d8a298ef8fbce76976efd0448a9e8f0640f530dd7036aa4658788e7f0f078b2ff8fdfe17444722d48c8
6
+ metadata.gz: 9fb306e7dcee5e6124143546150283368face417e8774244cf7893d72900316fb98a7cde6a3c66adb951eea4ae49581963a9ef79c2ebcadb534f26c9a594d01b
7
+ data.tar.gz: '041917204f85f7af4d8d0269934a23c06ee19a3223b26295eafb8213f22eebd44cd5bedce0df6148fe9eed59c4403dc70b78ede416531476b81af830c351bf96'
@@ -41,6 +41,7 @@ module Decidim
41
41
  @user = Decidim::User.new(
42
42
  name: form.name,
43
43
  email: form.email.downcase,
44
+ nickname: User.nicknamize(form.name),
44
45
  organization: form.organization,
45
46
  admin: form.role == "admin",
46
47
  roles: form.role == "admin" ? [] : [form.role].compact
@@ -3,22 +3,7 @@
3
3
  module Decidim
4
4
  # Helper that provides convenient methods to deal with translated attributes.
5
5
  module TranslationsHelper
6
- # Public: Returns the translation of an attribute using the current locale,
7
- # if available. Checks for the organization default locale as fallback.
8
- #
9
- # attribute - A Hash where keys (strings) are locales, and their values are
10
- # the translation for each locale.
11
- #
12
- # Returns a String with the translation.
13
- def translated_attribute(attribute)
14
- return "" if attribute.nil?
15
- return attribute unless attribute.is_a?(Hash)
16
-
17
- attribute[I18n.locale.to_s].presence ||
18
- attribute[current_organization.default_locale].presence ||
19
- attribute[attribute.keys.first].presence ||
20
- ""
21
- end
6
+ include Decidim::TranslatableAttributes
22
7
 
23
8
  # Public: Creates a translation for each available language in the list
24
9
  # given a translation key.
@@ -7,6 +7,8 @@ module Decidim
7
7
  helper Decidim::ResourceHelper
8
8
 
9
9
  def event_received(event, event_class_name, resource, user, extra)
10
+ return unless user.email
11
+
10
12
  with_user(user) do
11
13
  @organization = user.organization
12
14
  event_class = event_class_name.constantize
@@ -28,7 +28,7 @@ module Decidim
28
28
  validates :locale, inclusion: { in: :available_locales }, allow_blank: true
29
29
  validates :tos_agreement, acceptance: true, allow_nil: false, on: :create
30
30
  validates :avatar, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_avatar_size } }
31
- validates :email, :nickname, uniqueness: { scope: :organization }, unless: -> { deleted? || managed? }
31
+ validates :email, :nickname, uniqueness: { scope: :organization }, unless: -> { deleted? || managed? || nickname.blank? }
32
32
  validates :email, 'valid_email_2/email': { disposable: true }
33
33
 
34
34
  validate :all_roles_are_valid
@@ -1,18 +1,20 @@
1
- <div class="card--list__item">
2
- <div class="card--list__text">
3
- <%= link_to notification.event_class_instance.resource_path do %>
4
- <%= resource_icon notification.resource, class: "icon--chat card--list__icon" %>
5
- <% end %>
6
- <div>
7
- <h5 class="card--list__heading">
8
- <%= notification.event_class_instance.notification_title %>
9
- </h5>
10
- <span class="text-small"><%= l notification.created_at.to_date, format: :long %></span>
1
+ <% if notification.resource %>
2
+ <div class="card--list__item">
3
+ <div class="card--list__text">
4
+ <%= link_to notification.event_class_instance.resource_path do %>
5
+ <%= resource_icon notification.resource, class: "icon--chat card--list__icon" %>
6
+ <% end %>
7
+ <div>
8
+ <h5 class="card--list__heading">
9
+ <%= notification.event_class_instance.notification_title %>
10
+ </h5>
11
+ <span class="text-small"><%= l notification.created_at.to_date, format: :long %></span>
12
+ </div>
13
+ </div>
14
+ <div class="card--list__data">
15
+ <%= link_to notification, class: "mark-as-read-button card--list__data__icon", remote: true, method: :delete do %>
16
+ <%= icon "check", class: "icon icon--chevron-right" %>
17
+ <% end %>
11
18
  </div>
12
19
  </div>
13
- <div class="card--list__data">
14
- <%= link_to notification, class: "mark-as-read-button card--list__data__icon", remote: true, method: :delete do %>
15
- <%= icon "check", class: "icon icon--chevron-right" %>
16
- <% end %>
17
- </div>
18
- </div>
20
+ <% end %>
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FixNicknameIndex < ActiveRecord::Migration[5.1]
4
+ class User < ApplicationRecord
5
+ self.table_name = :decidim_users
6
+ end
7
+
8
+ def change
9
+ Decidim::User.where(nickname: nil)
10
+ .where(deleted_at: nil)
11
+ .where(managed: false)
12
+ .find_each { |u| u.update_attributes(nickname: Decidim::User.nicknamize(u.name)) }
13
+
14
+ # rubocop:disable Rails/SkipsModelValidations
15
+ Decidim::User.where(nickname: nil)
16
+ .update_all("nickname = ''")
17
+ # rubocop:enable Rails/SkipsModelValidations
18
+
19
+ change_column_default :decidim_users, :nickname, ""
20
+ change_column_null(:decidim_users, :nickname, false)
21
+ end
22
+ end
@@ -5,7 +5,7 @@ module Decidim
5
5
  # Abstract base class for content parsers, so they have the same contract
6
6
  #
7
7
  # @example How to use a content parser class
8
- # parser = Decidim::ContentParsers::CustomParser.new(content)
8
+ # parser = Decidim::ContentParsers::CustomParser.new(content, context)
9
9
  # parser.rewrite # returns the content rewritten
10
10
  # parser.metadata # returns a Metadata object
11
11
  #
@@ -17,11 +17,16 @@ module Decidim
17
17
  # @return [String] the content to be rewritten
18
18
  attr_reader :content
19
19
 
20
+ # @return [Hash] with context information
21
+ attr_reader :context
22
+
20
23
  # Gets initialized with the `content` to parse
21
24
  #
22
25
  # @param content [String] already rewritten content or regular content
23
- def initialize(content)
26
+ # @param context [Hash] arbitrary information to have a context
27
+ def initialize(content, context)
24
28
  @content = content || ""
29
+ @context = context
25
30
  end
26
31
 
27
32
  # Parse the `content` and return it modified
@@ -21,13 +21,14 @@ module Decidim
21
21
  MENTION_REGEX = /(^|\s)@([a-zA-Z0-9]\w*)/
22
22
 
23
23
  # Replaces found mentions matching a nickname of an existing
24
- # user with a global id. Other mentions found that doesn't
25
- # match an existing user are returned as is.
24
+ # user in the current organization with a global id. Other
25
+ # mentions found that doesn't match an existing user are
26
+ # returned as is.
26
27
  #
27
28
  # @return [String] the content with the valid mentions replaced by a global id
28
29
  def rewrite
29
30
  content.gsub(MENTION_REGEX) do |match|
30
- if (user = Decidim::User.find_by(nickname: Regexp.last_match[2]))
31
+ if (user = Decidim::User.where(nickname: Regexp.last_match[2], organization: context[:current_organization]).first)
31
32
  Regexp.last_match[1] + user.to_global_id.to_s
32
33
  else
33
34
  match
@@ -38,7 +39,7 @@ module Decidim
38
39
  # (see BaseParser#metadata)
39
40
  def metadata
40
41
  Metadata.new(
41
- Decidim::User.where(nickname: content.scan(MENTION_REGEX).flatten)
42
+ Decidim::User.where(nickname: content.scan(MENTION_REGEX).flatten, organization: context[:current_organization])
42
43
  )
43
44
  end
44
45
  end
@@ -22,7 +22,7 @@ module Decidim
22
22
  # declare the other side making it "transparent" (declaring the class and leaving it empty).
23
23
  #
24
24
  # @example How to parse a content
25
- # parsed = Decidim::ContentProcessor.parse(content)
25
+ # parsed = Decidim::ContentProcessor.parse(content, context)
26
26
  # parsed.rewrite # contains rewritten content
27
27
  # parsed.metadata # contains the merged metadata of all parsers
28
28
  #
@@ -42,10 +42,13 @@ module Decidim
42
42
  # This calls all registered processors one after the other and collects the
43
43
  # metadata for each one and the resulting modified content
44
44
  #
45
+ # @param content [String] already rewritten content or regular content
46
+ # @param context [Hash] with information to inject to the parsers as context
47
+ #
45
48
  # @return [Result] a Result object with the content rewritten and the metadata
46
- def self.parse(content)
49
+ def self.parse(content, context)
47
50
  parsed = Decidim.content_processors.each_with_object(rewrite: content, metadata: {}) do |type, result|
48
- parser = parser_klass(type).constantize.new(result[:rewrite])
51
+ parser = parser_klass(type).constantize.new(result[:rewrite], context)
49
52
  result[:rewrite] = parser.rewrite
50
53
  result[:metadata][type] = parser.metadata
51
54
  end
@@ -24,11 +24,13 @@ shared_context "simple event" do
24
24
  let(:resource_path) { resource_locator(resource).path }
25
25
  let(:resource_url) { resource_locator(resource).url }
26
26
  let(:resource_title) { resource.title["en"] }
27
+ let(:participatory_space) { resource.participatory_space }
28
+ let(:participatory_space_title) { participatory_space.title["en"] }
27
29
  let(:author) { resource.author }
28
30
  let(:author_presenter) { Decidim::UserPresenter.new(author) }
29
31
  end
30
32
 
31
- shared_examples_for "an simple event" do
33
+ shared_examples_for "a simple event" do
32
34
  describe "types" do
33
35
  subject { described_class }
34
36
 
@@ -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.9.2"
7
+ "0.9.3"
8
8
  end
9
9
  end
10
10
  end
@@ -13,22 +13,23 @@ module Decidim
13
13
  i18n_attributes :author_name, :author_nickname, :author_path, :author_url
14
14
 
15
15
  def author_nickname
16
- author_presenter.nickname
16
+ author_presenter&.nickname.to_s
17
17
  end
18
18
 
19
19
  def author_name
20
- author_presenter.name
20
+ author_presenter&.name.to_s
21
21
  end
22
22
 
23
23
  def author_path
24
- author_presenter.profile_path
24
+ author_presenter&.profile_path.to_s
25
25
  end
26
26
 
27
27
  def author_url
28
- author_presenter.profile_url
28
+ author_presenter&.profile_url.to_s
29
29
  end
30
30
 
31
31
  def author_presenter
32
+ return unless author
32
33
  @author ||= Decidim::UserPresenter.new(author)
33
34
  end
34
35
 
@@ -6,6 +6,8 @@ module Decidim
6
6
  # add more logic to a `Decidim::Notification` and are used to render them in the
7
7
  # notifications dashboard and to generate other notifications (emails, for example).
8
8
  class BaseEvent
9
+ include Decidim::TranslatableAttributes
10
+
9
11
  class_attribute :types
10
12
  self.types = []
11
13
 
@@ -88,7 +90,13 @@ module Decidim
88
90
  end
89
91
 
90
92
  def resource_title
91
- resource.title.is_a?(Hash) ? resource.title[I18n.locale.to_s] : resource.title
93
+ return unless resource
94
+
95
+ if resource.respond_to?(:title)
96
+ translated_attribute(resource.title)
97
+ elsif resource.respond_to?(:name)
98
+ translated_attribute(resource.name)
99
+ end
92
100
  end
93
101
  end
94
102
  end
@@ -71,9 +71,14 @@ module Decidim
71
71
  resource_path: resource_path,
72
72
  resource_title: resource_title,
73
73
  resource_url: resource_url,
74
+ participatory_space_title: participatory_space_title,
74
75
  scope: i18n_scope
75
76
  }
76
77
  end
78
+
79
+ def participatory_space_title
80
+ translated_attribute(participatory_space.try(:title))
81
+ end
77
82
  end
78
83
  end
79
84
  end
@@ -7,6 +7,7 @@ module Decidim
7
7
  # following the conventions set on `Decidim::TranslatableAttributes`.
8
8
  class FormBuilder < FoundationRailsHelper::FormBuilder
9
9
  include ActionView::Context
10
+ include Decidim::TranslatableAttributes
10
11
 
11
12
  # Public: generates a check boxes input from a collection and adds help
12
13
  # text and errors.
@@ -436,18 +437,18 @@ module Decidim
436
437
 
437
438
  def categories_for_select(scope)
438
439
  sorted_main_categories = scope.first_class.includes(:subcategories).sort_by do |category|
439
- category.name[I18n.locale.to_s]
440
+ translated_attribute(category.name, category.participatory_space.organization)
440
441
  end
441
442
 
442
443
  sorted_main_categories.flat_map do |category|
443
- parent = [[category.name[I18n.locale.to_s], category.id]]
444
+ parent = [[translated_attribute(category.name, category.participatory_space.organization), category.id]]
444
445
 
445
446
  sorted_subcategories = category.subcategories.sort_by do |subcategory|
446
- subcategory.name[I18n.locale.to_s]
447
+ translated_attribute(subcategory.name, subcategory.participatory_space.organization)
447
448
  end
448
449
 
449
450
  sorted_subcategories.each do |subcategory|
450
- parent << ["- #{subcategory.name[I18n.locale.to_s]}", subcategory.id]
451
+ parent << ["- #{translated_attribute(subcategory.name, subcategory.participatory_space.organization)}", subcategory.id]
451
452
  end
452
453
 
453
454
  parent
@@ -42,7 +42,7 @@ module Decidim
42
42
  2.step do |n|
43
43
  return candidate unless exists?(nickname: candidate)
44
44
 
45
- candidate = numbered_variation_of(candidate, n)
45
+ candidate = numbered_variation_of(name, n)
46
46
  end
47
47
  end
48
48
 
@@ -49,6 +49,30 @@ module Decidim
49
49
  end
50
50
  end
51
51
 
52
+ included do
53
+ # Public: Returns the translation of an attribute using the current locale,
54
+ # if available. Checks for the organization default locale as fallback.
55
+ #
56
+ # attribute - A Hash where keys (strings) are locales, and their values are
57
+ # the translation for each locale.
58
+ #
59
+ # organization - An optional Organization to get the default locale from.
60
+ #
61
+ # Returns a String with the translation.
62
+ def translated_attribute(attribute, organization = nil)
63
+ return "" if attribute.nil?
64
+ return attribute unless attribute.is_a?(Hash)
65
+
66
+ organization ||= try(:current_organization)
67
+ organization_locale = organization.try(:default_locale)
68
+
69
+ attribute[I18n.locale.to_s].presence ||
70
+ attribute[organization_locale].presence ||
71
+ attribute[attribute.keys.first].presence ||
72
+ ""
73
+ end
74
+ end
75
+
52
76
  private
53
77
 
54
78
  def translatable_attribute_setter(name, locale, value)
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.9.2
4
+ version: 0.9.3
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: 2018-02-09 00:00:00.000000000 Z
13
+ date: 2018-02-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: active_link_to
@@ -506,28 +506,28 @@ dependencies:
506
506
  requirements:
507
507
  - - '='
508
508
  - !ruby/object:Gem::Version
509
- version: 0.9.2
509
+ version: 0.9.3
510
510
  type: :runtime
511
511
  prerelease: false
512
512
  version_requirements: !ruby/object:Gem::Requirement
513
513
  requirements:
514
514
  - - '='
515
515
  - !ruby/object:Gem::Version
516
- version: 0.9.2
516
+ version: 0.9.3
517
517
  - !ruby/object:Gem::Dependency
518
518
  name: decidim-dev
519
519
  requirement: !ruby/object:Gem::Requirement
520
520
  requirements:
521
521
  - - '='
522
522
  - !ruby/object:Gem::Version
523
- version: 0.9.2
523
+ version: 0.9.3
524
524
  type: :development
525
525
  prerelease: false
526
526
  version_requirements: !ruby/object:Gem::Requirement
527
527
  requirements:
528
528
  - - '='
529
529
  - !ruby/object:Gem::Version
530
- version: 0.9.2
530
+ version: 0.9.3
531
531
  description: Adds core features so other engines can hook into the framework.
532
532
  email:
533
533
  - josepjaume@gmail.com
@@ -1048,6 +1048,7 @@ files:
1048
1048
  - db/migrate/20180123125432_add_omnipresent_banner_short_description_to_decidim_organizations.rb
1049
1049
  - db/migrate/20180123125452_add_omnipresent_banner_url_to_decidim_organizations.rb
1050
1050
  - db/migrate/20180125063433_add_highlighted_content_banner_to_decidim_organizations.rb
1051
+ - db/migrate/20180221101934_fix_nickname_index.rb
1051
1052
  - db/seeds.rb
1052
1053
  - db/seeds/homepage_image.jpg
1053
1054
  - lib/decidim/abilities.rb